HiFive1 Rev B. LED bug

Hi,
while stepping through the Welcome program with the debugger I noticed that the metal_led_off/on methods seem to be inverted (*off switches the LED on actually and *on switches off).

This happens because according to the schematic the LEDs are connected with the cathodes to the gpio pins, so setting the pin to 0 will illuminate them.

The code in sifive.gpio-leds.c must be changed like this:

void __metal_driver_led_on (struct metal_led *led)
{
    struct __metal_driver_sifive_gpio_led *_led = (void *)(led);

    if (_led->gpio != NULL) {
        metal_gpio_set_pin((struct metal_gpio *) _led->gpio, _led->pin, 0); // TH
    }
}

void __metal_driver_led_off (struct metal_led *led)
{
   struct __metal_driver_sifive_gpio_led *_led = (void *)(led);

    if (_led->gpio != NULL) {
        metal_gpio_set_pin((struct metal_gpio *) _led->gpio, _led->pin, 1); //TH
    }
}

BTW: What is the best way to rebuild the metal library after a change? I noticed that make … clean and make … software will also trigger a rebuild of metal, but only make … software will not.

1 Like

There’s supposed to be an XOR bit you can toggle in the gpio register that inverts the output. Maybe they just forgot to add that? Which seems like a weird thing to forget when your leds are inverted