# HiFive1 Rev B. LED bug

**URL:** <https://forums.sifive.com/t/hifive1-rev-b-led-bug/2383>\
**Category:** HiFive1 Rev B\
**Created:** [May 23, 2019, 6:36pm UTC](https://forums.sifive.com/t/hifive1-rev-b-led-bug/2383 "2019-05-23T18:36:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thornschuh](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/thornschuh/32/134_2.png) [@thornschuh](https://forums.sifive.com/u/thornschuh)\
**Post date:** [May 23, 2019, 6:36pm UTC](https://forums.sifive.com/t/hifive1-rev-b-led-bug/2383/1 "2019-05-23T18:36:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![penguinwashere](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/penguinwashere/32/683_2.png) [@penguinwashere](https://forums.sifive.com/u/penguinwashere)\
**Post date:** [May 24, 2019, 3:27am UTC](https://forums.sifive.com/t/hifive1-rev-b-led-bug/2383/2 "2019-05-24T03:27:14Z")

</div>

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
