Soft reset

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

rambo
Posts: 2
Joined: Sat Sep 06, 2014 3:53 pm

Re: Soft reset

Post by rambo »

@MarkusS

I end up in _unhandled_exception for some reason:

Code: Select all

(gdb) break ResetHandler
Breakpoint 1 at 0x8001580: file ChibiOS/os/ports/GCC/ARMCMx/crt0.c, line 282.
(gdb) cont
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, ResetHandler () at ChibiOS/os/ports/GCC/ARMCMx/crt0.c:282
282     uint32_t *magic_word =  (uint32_t *)(SYMVAL(__ram_end__) - 4); // look at the last word in ram
(gdb) step
283     if (*magic_word == 0xDEADBEEF) {
(gdb) step
373   }
(gdb) step
284         *magic_word = 0; // reset magic flag
(gdb) step
285         ((funcp_t) (*(uint32_t *)0x1FFF0004U))(); // jump into boot loader
(gdb) step
284         *magic_word = 0; // reset magic flag
(gdb) step
285         ((funcp_t) (*(uint32_t *)0x1FFF0004U))(); // jump into boot loader
(gdb) step
^C
Program received signal SIGINT, Interrupt.
_unhandled_exception () at ChibiOS/os/ports/GCC/ARMCMx/STM32F4xx/vectors.c:226
226   void _unhandled_exception(void) {
(gdb) bt
#0  _unhandled_exception ()
    at ChibiOS/os/ports/GCC/ARMCMx/STM32F4xx/vectors.c:226
#1  <signal handler called>
#2  0x00000000 in ?? ()
#3  0x1fff3d2a in ?? ()
#4  0x1fff3d2a in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)
ych
Posts: 45
Joined: Tue Mar 03, 2015 11:38 pm
Has thanked: 17 times
Been thanked: 11 times

Re: Soft reset

Post by ych »

MarkusS,

Thank you for your code examples, it helps :).

In the end I improve your example by moving changes which you made in os/ports/GCC/ARMCMx/crt0.c to board.c in __early_init function

Code: Select all

void __early_init(void) {
  if (MAGIC_DATA_CHECK()) {
    MAGIC_DATA_CLEAN();
    __set_CONTROL(0);
    __set_MSP((*(uint32_t *)0x1FFF0000U)); // this constant taken from "Device-dependent bootloader parameters" section of AN2606
    ((void (*)(void)) (*(uint32_t *)0x1FFF0004U))();
  } else {
    stm32_clock_init();
  }
}

and yes I init stack pointer (as described int video tutorial), because I have issue without it.
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Soft reset

Post by Korken »

Did anyone get it working without using the magic during startup?
I've been trying to jump too the bootloader as well (after all deinit of ChibiOS and clocks), but the chip (STM32F405) just resets instead...
Also I've been searching the AN2606 why it resets, but I cannot find an explanation.
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Soft reset

Post by alex31 »

Hello,

I occasionally use NVIC_SystemReset and it works for all my projects ... but one.

I have a project where NVIC_SystemReset, and even chibios watchdog don't do anything, the MCU (stm32F4, chibios 16.1.5) continue
to run after an explicit reset request or watchog counter reaching end.

Any idea before i begin the game of difference between the projects where it works and this one who think he is chuck norris ?

Alexandre
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Soft reset

Post by Giovanni »

I cannot imagine a way to make a reset-resistant application even if I wish to do so...

Giovanni
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Soft reset

Post by alex31 »

got it.

I was running on debugger (black magic probe, master branch) , and for an unknown reason, the bmp maintain NRST pin at high level,
and this cancel software reset.

Alexandre
User avatar
aGuegu
Posts: 29
Joined: Thu Dec 07, 2017 4:15 am
Has thanked: 1 time
Been thanked: 5 times

Re: Soft reset

Post by aGuegu »

For STM32F103, coretx M-3 based chip,

Code: Select all

void softreset(void) {
  *(uint32_t *)(0xE000ED0CUL) = 0x05FA0000UL | (*(uint32_t *)(0xE000ED0CUL) & 0x0700) | 0x04;
}


It is mainly the NVIC_SystemReset in core_cm3.h in stdperiph lib. Other cores have this function too.

According to RM0008, this software reset works same as the external NRST pin reset.
User avatar
sabdulqadir
Posts: 49
Joined: Fri Mar 23, 2018 7:29 pm
Has thanked: 13 times
Been thanked: 4 times

Re: Soft reset

Post by sabdulqadir »

Giovanni wrote:Hi,

It depends :-)

There is procedure to shutdown entirely the OS, it is described in this article: http://www.chibios.org/dokuwiki/doku.ph ... os:stop_os

If you have threads performing critical operations like writes in EEPROM or Flash then you may want to safely stop the threads then perform the reset.

Giovanni

Can you update the link?

Thanks,
AQ
Post Reply