Issues enabling specific Audio DAC on Raspberry Pi 3B

Hi *,

I’m currently facing issues getting a specific DAC to work with my Raspberry Pi 3B (UEFI setup). Here’s an overview of my setup and tests so far:

Tested DACs:

  • Justboom DAC HAT (PCM5122)
  • Raspiaudio Audio+ V2 (PCM5201A)

Both DACs work seamlessly on Volumio and Raspbian with the dtoverlay=hifiberry-dac configuration (/boot/config.txt), or by using the Raspiaudio script (which applies the same overlay and blacklists certain modules). You can find the script here: Raspiaudio Audio+ V2.

On NixOS, the Justboom DAC works even without enabling the hifiberry-dac overlay (see snippet below), but I haven’t been able to get the Raspiaudio Audio+ V2 DAC to work. I
tried the following configuration, but unfortunately, it hasn’t resolved the
issue:

  boot.kernelPackages = pkgs.linuxPackages_rpi3;

  hardware.i2c.enable = true;
  hardware.deviceTree.enable = true;
  hardware.deviceTree = {
    filter = "bcm*-rpi-3-b.dtb";
    # Equivalent to: https://github.com/raspberrypi/linux/blob/fbd8b3facb36ce888b1cdcf5f45a78475a8208f2/arch/arm/boot/dts/overlays/hifiberry-dac-overlay.dts
    overlays = [
      "${config.boot.kernelPackages.kernel}/dtbs/overlays/hifiberry-dac.dtbo"
    ];
  };

I’ve compared the loaded kernel modules between Raspbian/Volumio and NixOS, but I’m still struggling to pinpoint the issue. On Raspbian/Volumio, the Raspiaudio Audio+ V2 DAC appears in /proc/asound/cards as:

[sndrpihifiberry] Rpi-simple - snd_rpi_hifiberry_dac

Despite trying different approaches, including using different dtsText as an overlay, I
haven’t had any luck.

Has anyone encountered a similar issue or could provide insights into what I
might be missing? Your suggestions would be greatly appreciated!

Thanks in advance,
qitta

Some things you could try that I did to get it working for a different overlay:

  1. I set hardware.deviceTree.enable = true
  2. I set hardware.raspberry-pi."4".apply-overlays-dtmerge.enable = true;
  3. I created a systemd service to apply the overlay:
  systemd.services = {
    "load-pwm-2chan-overlay" = {
      serviceConfig = {
        Type = "oneshot";
      };
      wantedBy = ["multi-user.target"];
      script = ''
        ${pkgs.libraspberrypi}/bin/dtoverlay -d ${config.boot.kernelPackages.kernel}/dtbs/overlays/ pwm-2chan || echo "already in use"
      '';
    };
  };

To be honest I don’t know which of those made the difference or if all of them were needed. I just stopped once it was working :slight_smile:

@eblechschmidt thanks for the quick response. I tried this with the hifiberry-dac using the overlay apply-overlays-dtmerge from nixos-hardware copied from the Pi 4 modules - but it did not work :(. I checked what the systemd service did in my case by running the dtoverlay command manually, and it gave me the following error: Failed to apply overlay '0_hifiberry-dac' (kernel)

Where does the 0_ come from? It does look a bit odd but I’m no expert in the dtoverlay topic tbh. Can you share the code for your last try where you got the error?

The code was basically:

systemd.services = {
    "hifiberry-dac-overlay" = {
      serviceConfig = {
        Type = "oneshot";
      };
      wantedBy = ["multi-user.target"];
      script = ''
        ${pkgs.libraspberrypi}/bin/dtoverlay -d ${config.boot.kernelPackages.kernel}/dtbs/overlays/ hifiberry-dac || echo "already in use"
      '';
    };
  };

As the systemd log showed me ‘already in use’ so I took the script from the systemd unit and run it manuelly as root which gave me the error message - which was probably the reason why the systemd unit finished with ‘already in use’. I have no idea where the ‘0’ comes from, it is probably some prefix added by dtoverlay - but I don’t know.

I run basically /nix/store/kazlclbwkcpdnj5jnmlylj6v4daral9n-libraspberrypi-unstable-2022-06-16/bin/dtoverlay -d /nix/store/h3wxf22qpym479dk07ac18q32vzwrzq6-linux-rpi-6.6.51-stable_20241008/dtbs/overlays/ hifiberry-dac which gave me the Failed to apply overlay '0_hifiberry-dac' (kernel) error.

Can you check if the overlay is in that folder?

@eblechschmidt yes it is in that folder - if I use a non-existing overlay I also get a different error message.

Ok. I‘m probably not much help anymore :wink:. Maybe check dmesg for info on why the overlay would not load?

@eblechschmidt thanks for your support. As I have seen so far, dmesg doesn’t provide any useful information to resolve this issue.