SD card activity external LED

Hi guys,

I am hoping somebody here has the experience/knowhow to either help me do this or tell me that it is not possible.

I am looking to add an external LED or two to my Potato board, I would like to be able to use the GPIO pins to power an LED for displaying SD card activity, mainly so I can see at a glance whether the board has crashed out or not once I put it in a case. I have done this on a Pi 3b+ but cannot work it out on the Potato.

Is the blue onboard LED equivalent to this?

The board is running HF Raspbian if that helps. Any help or advice is greatly appreciated! TIA!

1 Like

This is what is called triggers in the Linux LED subsystem. You just have to set the trigger to mmc1 in order for the LED to blink based on SD card activity. It should be in /sys/class/led/.

If you want to make it permanent, you have to write a device tree overlay that targets the led and change the trigger to “mmc1”. This is done through the libretech wiring tool.

1 Like

Thanks, are you able to offer a brief example at all?

https://boot.libre.computer/ci/aml-s905x-cc.dts

Search for LEDs. Then create an overlay that targets that path and set a new trigger.

You can look at how other overlays are written to write your own.

2 Likes

Thanks again, making progress haha! I’ve written this:

/dts-v1/;
/plugin/;

/ {
compatible = “libretech,cc”, “amlogic,s905x”, “amlogic,meson-gxl”;

fragment@0 {
target = <&leds>;
overlay {
my_led: myled {
label = “statusLED”;
gpios = <&gpiox_5>;
linux,default-trigger = “mmc1”;
};
};
};
};

Please tell me if there is anything amiss (I wouldn’t be surprised).

Also I am running into an error when trying to merge:

Failed to apply libre-computer/aml-s905x-cc/dt/SDLED.dtbo (-1)

Unfortunately I can’t seem to find much documentation anywhere regarding this.

1 Like

If you look at the bottom of the dts, there’s shortcuts to nodes called “labels”, not to be mistaken with led-labels. The format target = <&label> will not work for LEDs since there’s no label on the LED node. You have to use an absolute path. There’s examples of this in other overlays.

gpios need 3 things: <&gpio GPIOX_5 GPIO_ACTIVE_HIGH>;

Otherwise it looks good. Great job trying this.

1 Like

Slowly but surely… can’t wait for the satisfaction of it finally working!

Could you elaborate on the absolute path I am looking for? This is by far the deepest I have delved into linux lol. Am I pointing this to /proc?

Thanks for your help!

This is where I am currently…

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/meson-gxl-gpio.h>

/ {
compatible = “libretech,cc”, “amlogic,s905x”, “amlogic,meson-gxl”;

fragment@0 {
target = “/sys/class/leds/”;
__ overlay__ {
SD_status@0 {
label = “statusLED”;
dc-gpios = <&gpio GPIOX_5 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “mmc1”;
};
};
};
};

The bold line is the one in question, right? The built perfectly fine but now when merging I am getting a -6 error.

1 Like

Sorry for this :sweat_smile:

I have got it up and running! :partying_face:

Only issue I’m having is the brightness of the LED but that’s a challenge for tomorrow.

Thanks so much for the help! :smiley:

This is my current code

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/meson-gxl-gpio.h>

/ {
compatible = “libretech,cc”, “amlogic,s905x”, “amlogic,meson-gxl”,“gpio-leds”;

fragment@0 {
target-path = “/leds”;
overlay {
SD_status@0 {
label = “statusLED”;
gpios = <&gpio GPIOX_5 GPIO_ACTIVE_HIGH>;
linux,default-trigger = “mmc1”;
};
};
};
};

2 Likes

Looks good. Great job!

Further to this, would I use the same format to add an external light for showing data over usb ports? Would this just be triggered by something like ttyUSB?

The list of available triggers is limited by the kernel code. We enable all of the triggers that are available upstream. But the process is the same for the available triggers on any GPIO.

Is there a list, a way to list or somewhere I can find these triggers?

Just cat the triggers file and it will show you a list along with which one is selected.