AdaCore / Ada_Drivers_Library

Ada source code and complete sample GNAT projects for selected bare-board platforms supported by GNAT.
BSD 3-Clause "New" or "Revised" License
240 stars 141 forks source link

Microbit Button_B not working #267

Closed simonjwright closed 6 years ago

simonjwright commented 6 years ago

In boards/MicroBit/src/microbit-buttons.adb, function State, we have

      if Button =  Button_B then
         --  For a reason that I don't understand right now, the B button is a
         --  always detected as pressed (low). As far as I can see the code is
         --  the same as button A and probing the hardware didn't show any
         --  problem...
         raise Program_Error with "Button B is not working...";
      end if;

I believe I’ve found the reason: in microbit-time.adb, procedure Initialize, we have

         Clocks.Set_Low_Freq_Source (Clocks.LFCLK_XTAL);

(weird, there isn’t a crystal attached to the low-frequency inputs at all; the only crystals on the board are 16 MHz, not the 32 kHz you’d need for the low frequency source), and this has the effect of what on STM chips would be called an alternate function on that pin, so that GPIO pin 26 is effectively disconnected.

Fix:

         Clocks.Set_Low_Freq_Source (Clocks.LFCLK_SYNTH);

(the HF clock appears to run without needing any configuration).

Fabien-Chouteau commented 6 years ago

Thank you @simonjwright !

As you can see here, I knew there was a problem but couldn't find why. I even checked the hardware :)

I will make a patch for this.

Thanks again