2020-08-10 03:21 PM
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 Mbed 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.
Very very weird: THE PROBLEM DOES NOT OCCUR FOR ARDUINO COMPILATION OF THE EXACT SAME PROGRAM.
Mbed code:
#include "mbed.h"
DigitalOut ledpin(PA_5);
int main(){
ledpin = 1;
while(1){
ledpin = !ledpin;
thread_sleep_for(250);
}
}
Arduino Code:
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?
2020-08-11 04:49 AM
Well, you didn't mention which mbed you are using mbed.org, mbed os, ...?
But anyway: the programs are not the same.
For the mbed one you were using a call to thread_sleep_for(), which is intended for an RTOS, while you were using delay() for the Arduino one. And no, they are not identical.
If you are using mbed.org you could try wait() instead.
Good luck!
/Peter
2020-08-11 09:50 AM
I was using mbed 6 (also tried with mbed 5). I tried using wait(). Same result.
After a whole day of debugging, found out mbed throwing up the following error on Serial:
++ 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: https://mbed.com/s/error?error=0x80FF0100&tgt=NUCLEO_L476RG
– MbedOS Error Info –
SetSysClock failed
It looks like my board had only one difference to the original Nucleo L476RG: the X2 (LSE) and C31, C32, I used a different LSE model with 4pF capacitances compared to the Nucleo L476RG, which uses 6.8pF load capacitances with a different oscillator model (though both are from Abracon). https://www.st.com/resource/en/user_manual/dm00105823-stm32-nucleo-64-boards-mb1136-stmicroelectronics.pdf
I am not sure if this is messing up with clock startup times, but I did use an oscillator from the list recommended by ST: https://www.st.com/resource/en/application_note/cd00221665-oscillator-design-guide-for-stm8afals-stm32-mcus-and-mpus-stmicroelectronics.pdf