Page 1 of 1
STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 12:42 pm
by DrunkenDonkey
I finally got my discovery board and tried to run ChibiOS on it, but facing some very weird issue - it looks like after Chibi inits, the system works for very small period of time before crashing into the HardFaultVector(). This happens both with my program and the discovery demo program (demos\ARMCM3-STM32L152-DISCOVERY), almost looks like some watchdog is enabled, however I enabled IDWG and it does into reset handler like it should, not crashing. In my main I tried:
Code: Select all
int main(void)
{
halInit();
//chSysInit();
u32 i;
u32 time=chTimeNow();
u32 result=0;
for(i=0;i<10000000;i++)
{
result++;
}
This works okay, however, if I enable chSysInit it crashes somewhere inside that loop. Same stuff with removed loop, but just using functions, like printf, when chSysInit passed the HardFaultVector is called in between. Using latest, 3454 revision, totally weird... any clues?
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 12:48 pm
by Giovanni
Hi,
After how much time does this happen? I never experienced it.
chSysInit() enables interrupts, this could be the difference.
Giovanni
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 1:18 pm
by DrunkenDonkey
Yeah, you are right, it is the interrupts, removing chSysEnable() in chSysInit() fixes it, but when it hits the first sleep... How to calculate the time? It is very small, matter of microseconds, but can't really call chTimeNow from HardFaultVector.
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 1:21 pm
by Giovanni
It does not fix it, it just hides the problem. It is strange because the demo has been tested using three different compilers and I never experienced this crash.
You should verify the chip is correctly flashed.
Giovanni
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 1:39 pm
by DrunkenDonkey
I cleaned and rebuilt the project, formatted the flash clean, then downloaded the binary via the j-link gdb server (SWD, 1000 khz) with "Verify download" enabled and it still crashed. Went and read the flash and saved to a file, all the differences are in a few bytes at the start:
Original bin:
Code: Select all
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 00 40 00 20 D1 02 00 08 41 34 00 08 51 34 00 08 .@. С...A4..Q4..
00000010 81 34 00 08 91 34 00 08 A1 34 00 08 90 03 00 08 Ѓ4..‘4..Ў4..ђ...
00000020 90 03 00 08 90 03 00 08 90 03 00 08 C1 03 00 08 ђ...ђ...ђ...Б...
00000030 90 03 00 08 90 03 00 08 90 03 00 08 A1 03 00 08 Ñ’...Ñ’...Ñ’...ÐŽ...
00000040 90 03 00 08 B1 22 00 08 11 23 00 08 41 23 00 08 ђ...±"...#..A#..
00000050 90 03 00 08 90 03 00 08 61 20 00 08 91 20 00 08 ђ...ђ...a ..‘ ..
00000060 C1 20 00 08 F1 20 00 08 21 21 00 08 91 1A 00 08 Б ..Ñ ..!!..‘...
00000070 D1 1A 00 08 11 1B 00 08 51 1B 00 08 91 1B 00 08 С.......Q...‘...
00000080 D1 1B 00 08 11 1C 00 08 71 1E 00 08 90 03 00 08 С.......q...ђ...
00000090 90 03 00 08 90 03 00 08 71 23 00 08 51 21 00 08 Ñ’...Ñ’...q#..Q!..
000000A0 90 03 00 08 90 03 00 08 90 03 00 08 90 03 00 08 Ñ’...Ñ’...Ñ’...Ñ’...
000000B0 90 03 00 08 90 03 00 08 91 27 00 08 A1 2E 00 08 ђ...ђ...‘'..Ў...
000000C0 C1 2E 00 08 E1 2E 00 08 01 2F 00 08 90 03 00 08 Б...б..../..ђ...
000000D0 90 03 00 08 11 33 00 08 31 33 00 08 51 33 00 08 Ñ’....3..13..Q3..
000000E0 F1 21 00 08 90 03 00 08 E1 22 00 08 90 03 00 08 Ñ!..Ñ’...б"..Ñ’...
000000F0 90 03 00 08 00 00 00 00 00 00 00 00 00 00 00 00 Ñ’...............
Downloaded:
Code: Select all
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 03 40 03 20 D1 02 00 08 41 34 00 08 51 34 00 08 .@. С...A4..Q4..
00000010 81 34 00 08 91 34 00 08 A1 34 00 08 90 03 00 08 Ѓ4..‘4..Ў4..ђ...
00000020 90 03 00 08 90 03 00 08 90 03 00 08 C1 03 00 08 ђ...ђ...ђ...Б...
00000030 90 03 00 08 90 03 00 08 90 03 00 08 A1 03 00 08 Ñ’...Ñ’...Ñ’...ÐŽ...
00000040 90 03 00 08 B1 22 00 08 11 23 00 08 41 23 00 08 ђ...±"...#..A#..
00000050 90 03 00 08 90 03 00 08 61 20 00 08 91 20 00 08 ђ...ђ...a ..‘ ..
00000060 C1 20 00 08 F1 20 00 08 21 21 00 08 91 1A 00 08 Б ..Ñ ..!!..‘...
00000070 D1 1A 00 08 11 1B 00 08 51 1B 00 08 91 1B 00 08 С.......Q...‘...
00000080 D1 1B 00 08 11 1C 00 08 71 1E 00 08 90 03 00 08 С.......q...ђ...
00000090 90 03 00 08 90 03 00 08 71 23 00 08 51 21 00 08 Ñ’...Ñ’...q#..Q!..
000000A0 90 03 00 08 90 03 00 08 90 03 00 08 90 03 00 08 Ñ’...Ñ’...Ñ’...Ñ’...
000000B0 90 03 00 08 90 03 00 08 91 27 00 08 A1 2E 00 08 ђ...ђ...‘'..Ў...
000000C0 C1 2E 00 08 E1 2E 00 08 01 2F 00 08 90 03 00 08 Б...б..../..ђ...
000000D0 90 03 00 08 11 33 00 08 31 33 00 08 51 33 00 08 Ñ’....3..13..Q3..
000000E0 F1 21 00 08 90 03 00 08 E1 22 00 08 90 03 00 08 Ñ!..Ñ’...б"..Ñ’...
000000F0 90 03 00 08 FF FF FF FF FF FF FF FF FF FF FF FF Ñ’...ÑÑÑÑÑÑÑÑÑÑÑÑ
There are 03 40 03 instead of 00 40 00 at the start, then 12 0xFF instead of 0x00. No idea if this is normal or not.
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 1:50 pm
by Giovanni
Can you try using the integrated ST-Link? you may use the ST visual programmer.
Just to rule out a possible cause.
Giovanni
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 2:48 pm
by DrunkenDonkey
It looks the problem lies in J-Link gdb support... J-link flash can program it correctly and it works. Done like a thousand tries with no luck. As for ST-Link - yeah, the utility works and successfully programs the code, yet, I can't for the life of me figure out how to run gdb server on top of ST-Link to be able to use it, looked all over the place and except of some openocd patches that are not in the 0.5.0 release I don't see how I can use with eclipse...

Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 2:54 pm
by Giovanni
I don't think OpenOCD will ever support ST-Link but there is this project that implements a GDB server for ST-Link:
https://github.com/texane/stlink/issues/10The problem is that it is for Linux only right now, I asked about possible Windows support but apparently there is a problem with a library. Anyway, ST-Link works perfectly with IAR and Keil IDEs, you may try one of those (I prefer Eclipse anyway...).
Giovanni
Re: STM32L Discovery board timed crash?
Posted: Sat Oct 29, 2011 3:09 pm
by DrunkenDonkey
Deer god, it WORKS!!!! I'm now afraid to set even 1 more breakpoint to not break it, generally made it work with randomly trying stuff:
- J-Link gdb server have "Verify download" and "Init regs on start" enabled
- GDB init script:
Code: Select all
target remote localhost:2331
monitor flash device = STM32L152R8
monitor flash download = 1
monitor flash breakpoints = 0
monitor clrbp
monitor endian little
monitor speed 30
monitor reset
monitor sleep 100
set remote memory-write-packet-size 1024
set remote memory-write-packet-size fixed
monitor speed auto
- GDB run commands:
Code: Select all
monitor reset
monitor sleep 100
monitor reg r13 = (0x00000000)
monitor reg pc = (0x00000004)
#break ResetHandler
break main
continue
As for keil and iar, when then do make IDEs that are at least better than notepad++ they may justify the $4000 price tag, eclipse all the way (well, I don't exactly love eclipse, but compared to the joke of an environment keil/iar sell, eclipse shines in the morning)