setInterval and setTimeout on nucleo board...strange behaviours #4584
Replies: 1 comment
-
Posted at 2015-04-15 by @gfwilliams Hi, It could be related to this: espruino/Espruino#457 Basically ST made several different types of ST Nucleo board with different frequency crystals (or none at all). There was some more discussion on it here: http://forum.espruino.com/conversations/258669/ If your board is one of the affected then you can do a simple hardware mod to fix it. Posted at 2015-04-15 by hexfet13 Thanks Gordon, Posted at 2015-04-15 by @gfwilliams On some builds (maybe the F401? I can't remember), Espruino tries to use the RTC for time measurement - unfortunately it only runs at 32kHz, which isn't enough for accurate time measurement. So what it does is it uses the SYSTICK (basically the instruction counter) and tries to match it up with the RTC - so you get microsecond-accurate measurements while being able to turn off the main clock and sleep. But if the main oscillator is way off what's expected then I guess it'll probably have trouble doing that reliably, which could be your problem. I've just tried that code on 1v72 on the Pico (which uses almost the same processor) and it works great, so it probably is something like that. Posted at 2015-04-15 by hexfet13 According to (page 50) Posted at 2015-04-15 by DrAzzy Sigh... Gor Okay. First off, the low speed external crystal has nothing to do with the speed that the chip is clocked at. It could be used for the RTC, but that would require changes to the Espruino firmware. Typically Gordon does not support external crystals on boards other than the official board, unless someone else does it (he's got lots of much higher priority work for official boards on his plate). In order to get your STMF401 Nucleo working at the right speed, you have to connect the clock signal from the ST-LINK section of the board to the input of the F401. On the back, locate the "jumper pads" marked SB16 MCO and SB50 MCO. Connect those two jumpers (ie with a blob of solder) and the board will run at the correct speed. I don't attempt to understand why the Nucleo board is designed the way it is - it surely is not how I would do it. Posted at 2015-04-15 by hexfet13 Closing SB16 and SB50 the blink frequency is 10.00Hz and seems stable, without stops between blinks. Posted at 2015-04-15 by DrAzzy I'm sure it's possible, but you'd need to dig through the details of how the clock is set up. I think the Pico uses a 401 with external crystal; looking at the code for that might be a starting point. I always found the Espruino firmware code to be very difficult to read, understand, and modify. I don't know if you can get the correct speed using internal oscillator, or whether you need an external crystal for that on these chips. Posted at 2015-04-15 by @gfwilliams About the 32k crystal - yes, it looks like I don't use that on the F401. You could prod around in the code looking at USE_RTC if you wanted to enable it, but it might be better without. Afaik the regulator isn't very efficient on those boards so going into 'deep' sleep doesn't actually save you much anyway. As far as the oscillator, check out the file here: https://github.com/espruino/Espruino/blob/master/targetlibs/stm32f4/lib/system_stm32f4xx.c That is basically standard ST initialisation code - you might be able to fiddle it to use the internal oscillator if you want to... My feeling was that it fell back to the internal one if the external didn't work, but maybe the resistance/capacitance of the board is such that it actually gets driven (albeit irregularly) from the ST-LINK even when the jumpers aren't connected? It's explain the strange behaviour. Posted at 2015-04-16 by hexfet13 Hi all, Posted at 2015-04-16 by @gfwilliams Great! I'd be interested to see what changed if you diff the files. Maybe it just removed this whole chunk: https://github.com/espruino/Espruino/blob/master/targetlibs/stm32f4/lib/system_stm32f4xx.c#L478-L565 Posted at 2015-04-19 by hexfet13 Hi, i'm apologize for this long delay but i tried to understand how cubemx works...
But, i don't understand: where did you get your system_stm32f4xx.c library? it was generated from an ST tools? Posted at 2015-04-19 by hexfet13 Well, the reply to my question is: StdPeriph_lib. This library for STM32 contains the file i asked, used in espruino code. The difference is that in this one there is the function SetSysClock that is not present in the same file generated by CubeMx . Posted at 2015-04-20 by @gfwilliams Yes - ST have changed their libraries. Espruino still uses the old ones. I plan to change to CubeMX at some point (along with adding the USB HID support), but that's unlikely to happen for at least a month. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-04-15 by hexfet13
Hi all, i tried this simple code to test espruino 1.76 on my nucleo board (with stm32f401 processor) to blink the green led:
What i see: the led blinks really slower than expected (expected period about 0.1 seconds) and after 22 blinks about the led stop blinks for about 1.5-2 seconds and then starts again blinking with the first couple of blinks faster than the remainings 20 blink. My multimeter tells me that the blink frequency is 2.13Hz vs 10Hz than expected.
I don't understand this strange behaviours, can anyone help me to understand where is the problem?
Beta Was this translation helpful? Give feedback.
All reactions