Reset Handler Crash Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
chrismerck
Posts: 21
Joined: Fri Mar 14, 2014 12:35 am
Been thanked: 4 times

Reset Handler Crash

Post by chrismerck »

Does anyone know what can cause the ResetHandler code to be corrupted? My project was working, but now crashes shortly after boot. Below is my ResetHandler code, which contains a jump to chvprintf, which seems wrong...

What could cause this to happen?

I'm running ChibiOS 16.1.5 on STM32F205. My project was previously booting, but now crashes immediately. I'm trying to use Olimex ARM-USB-TINY-H with the SWD converter. Interestingly my STLINK (from nucleo) fails to even see the micro anymore.



Code: Select all

   +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   |0x80001c0 <Reset_Handler>       cpsid  i                                                                                                                                                                |
   |0x80001c2 <Reset_Handler+2>     ldr    r0, [pc, #136]  ; (0x800024c <endfiniloop+4>)                                                                                                                    |
   |0x80001c4 <Reset_Handler+4>     msr    PSP, r0                                                                                                                                                          |
  >|0x80001c8 <Reset_Handler+8>     movs   r0, #2                                                                                                                                                           |
   |0x80001ca <Reset_Handler+10>    msr    CONTROL, r0                                                                                                                                                      |
   |0x80001ce <Reset_Handler+14>    isb    sy                                                                                                                                                               |
   |0x80001d2 <Reset_Handler+18>    bl     0x80011e0 <chvprintf(BaseSequentialStream*, char const*, va_list)+496>                                                                                           |
   |0x80001d6 <Reset_Handler+22>    bl     0x8001240 <chvprintf(BaseSequentialStream*, char const*, va_list)+592>                                                                                           |
   |0x80001da <Reset_Handler+26>    ldr    r0, [pc, #116]  ; (0x8000250 <endfiniloop+8>)                                                                                                                    |
   |0x80001dc <Reset_Handler+28>    ldr    r1, [pc, #116]  ; (0x8000254 <endfiniloop+12>)                                                                                                                   |
   |0x80001de <Reset_Handler+30>    ldr    r2, [pc, #120]  ; (0x8000258 <endfiniloop+16>)                                                                                                                   |
   |0x80001e0 <msloop>              cmp    r1, r2                                                                                                                                                           |
   |0x80001e2 <msloop+2>            itt    cc                                                                                                                                                               |
   |0x80001e4 <msloop+4>            strcc.w        r0, [r1], #4                                                                                                                                             |
   |0x80001e8 <msloop+8>            bcc.n  0x80001e0 <msloop>                                                                                                                                               |
   |0x80001ea <msloop+10>           ldr    r1, [pc, #112]  ; (0x800025c <endfiniloop+20>)                                                                                                                   |
   |0x80001ec <msloop+12>           ldr    r2, [pc, #92]   ; (0x800024c <endfiniloop+4>)                                                                                                                    |
   +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
remote Remote target In: Reset_Handler                                                                                                                                              Line: ??   PC: 0x80001c8
(gdb)
Attachments
reset_handler_dissasm
reset_handler_dissasm
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Reset Handler Crash

Post by Giovanni »

Hi,

The device could have failed, can you try another one?

You could try to use the ST-Link utility and use the option Settings->"connect under reset", if the connection succeed then erase the flash.

Giovanni
chrismerck
Posts: 21
Joined: Fri Mar 14, 2014 12:35 am
Been thanked: 4 times

Re: Reset Handler Crash

Post by chrismerck »

Thankfully the chip was not bad. Here's what the issue was and how I solved it:

tl;dr: I was not erasing before writing.

---

Details:

My script for loading the bin file was not correct. I could write once after erasing the chip, but then my updates would fail to run. Bits would be cleared but not set (due to nature of flash memory) and so I got corrupted code that looked odd in the debugger.

I figured out the problem by just running OpenOCD:

Code: Select all

sudo openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg   -f interface/ftdi/olimex-arm-jtag-swd.cfg   -f target/stm32f2x.cfg   -l .openocd.log   -c "init" &


Then connecting via telnet:

Code: Select all

telnet localhost 4444


Using the `reg` command I confirmed that I could read/write registers. Then I read the flash:

Code: Select all

> dump_image dump 0x8000000 0x40000
dumped 262144 bytes in 3.726296s (68.701 KiB/s)


And I compare with what I was supposedly flashing, by running:

Code: Select all

hexdump -C dump

in one terminal and

Code: Select all

hexdump -C build/ch.bin

in another terminal.

Sure enough, the code was different. I then tried manually flashing firmware via openocd:

Code: Select all

flash write_image erase build/ch.bin 0x8000000

And I get my flashing heartbeat light again :lol:

The key was the "erase" parameter. Adding that parameter to my gdb script solved the issue :)
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: Reset Handler Crash

Post by rew »

Hey! Your STM32F205 has "classical" flash behaviour: Bits can be programmed without limit from 1 to 0, but from 0 to 1 requires an erase. Later STM chips have a "per byte" (*) limitation that you can either program from 0xff to some value, and then from any value to zero, but nothing else.

(*) or halfword or word.
Post Reply