Blinky timing error on Nucleo L476RG Custom Board

I created a minimal custom Nucleo L476RG board. There is no 8 MHz crystal on the board and only a 32.768 KHz crystal. I connected an LED to PA_5 pin and trying to test the blinky program. I upload codes to the custom board via SWD connection from another Nucleo STLink. I am powering the board of 3.3V DC power supply.

The problem is the timing in blink. While i set it to 1 sec, the LED does blink on and off for one second but in between, sometimes, it blinks 5 times a second. Same thing happens if I set timing to some other time. The LED randomly blinks 5-6 times a second now and then after blinking for set time properly for 2-3 seconds. This happens regardless of the SWD connectors disconnected or connected.

NOTE THAT THE PROBLEM DOES NOT OCCUR FOR ARDUINO COMPILATION OF THE SAME PROGRAM.

Mbed program (DOES NOT WORK FINE):

    #include "mbed.h"
    DigitalOut ledpin(PA_5);
    int main(){
      ledpin = 1;
      while(1){
        ledpin = !ledpin;
        thread_sleep_for(250);
      }
    }

Arduino Code (WORKS FINE):

int led = 13;
bool val = 1;  
void setup() {
 pinMode(led, OUTPUT);
}

 
void loop() {
 digitalWrite(led, val);  
 val = !val;
 delay(250);       

}

Any idea what the problem is?

Hi,
I probably do not help you with it, because I have no experience with that but did you check the serial output (PA_2, PA_3)? That blinking behavior seems to be the MbedOS chrash signalization.

BR, Jan

Hey thanks for the headsup, here’s the serial log I got:

++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x8003AF9
Error Value: 0x0
Current Thread: Id: 0x0 Entry: 0x800042D StackSize: 0x0 StackMem: 0x800045D SP: 0x20017F78
For more info, visit: mbedos-error
– MbedOS Error Info –
SetSysClock failed

Do you have also the original Nucleo-L476RG and did you tried to upload same binary to it?

BR, Jan

Ya the same binary works on the original Nucleo. To take it one step further and try and emulate the original Nucleo as close as possible to mine, I even broke off the STLink programmer off it so that it just becomes a standalone STM32L476RGT6 chip like mine, still the binaries work fine on the original Nucleo!

BTW I noticed something, my own Nucleo and the original Nucleo have only difference… The original Nucleo uses a 32KHz oscillator with two 6pF load capacitors… I used a different model with two 4pF load capacitors… Is that causing an issue?

Sorry, my experinces with a hardware developing are zero. Maybe @hudakz can help you.

I can only recommend, make some verification like measure the output of your crystal circuit with an oscilloscope. Or try to wiring the signal from another source, where you know it si working and compare the result with original Nucleo.

Anyway, I do not know what exactly can be different between Arduino and Mbed settings but theoretically in Arduino’s settings can be used internal oscillator maybe and that can make the different behavior.

BR, Jan

1 Like

You need to create a custom target definition for your board, that would be the clean solution. I guess your compile command is using the Nucleo target. The Nucleo boards do not have a crystal or oszillator, instead they are using the clock from the STLink and the default setting is to use EXTC.
The error that is shown comes from the clock setting that failed:
.\mbed-os\targets\TARGET_STM\TARGET_STM32L4\TARGET_STM32L476xG\TARGET_NUCLEO_L476RG\system_clock.c

you can try to add a mbed_app.json to your project with this settings:

{
  "NUCLEO_L476RG": {
    "overrides": {
            "clock_source": "USE_PLL_HSI",
            "lse_available": 1
      }
    }
}

Then the MCU should run with internal oszillator. It looks like the LSE can not be used as the system clock.
USE_PLL_MSI might work also, this is also an internal clock that can be calibrated by your 32 kHz crystal, you can try this also, should be better.

1 Like

@JohnnyK thanks. Well Arduino is not an OS so it does not care about RTCs and instead uses internal timers to do the trick. Thanks for your help I found the issue with the clock.

@JojoS thanks for the insight. Nucleo L476RG does have a LSE crystal (X2) connected to 32 KHz inputs and no it does not use MCO from STLink. Other Nucleo boards use MCO from STLink. L476RG uses HSI as it does not have X3/HSE or MCO.

image
image

What I don’t understand, why will a different model for X2 (and consequently C31 and C32) cause issues with setting system clock? I did use one from ST’s list of recommended oscillators:

I am not sure but maybe it’s because of different clock startup times? I will do some more debugging to see what’s wrong.

ok, I checked again, NUCLEO_L476RG derives settings from MCU_STM32L4, and default for the clock is MSI. With lse_availble, it tries to sync with the 32 kHz crystal. If this fails, it could show the error.
You can try the setting lse_available=0.
And with HSI the board should run also.

By using a debugger and setting a breakpoint in SetSysClock(void), you may see which clock is used and where it fails to init.

1 Like

@JojoS thanks I will do that and see.