Use of SYSTEM_HALT_HOOK with HAL

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
trepidacious
Posts: 58
Joined: Mon Jan 21, 2013 3:36 pm
Been thanked: 1 time

Use of SYSTEM_HALT_HOOK with HAL

Post by trepidacious »

I was just looking at SYSTEM_HALT_HOOK, and I can't find any examples of using it. My use case is just to change the mode of a few pins on port_halt, to put a board into a safe state when it halts. It seems like this would be a reasonable use of the hook?

However I can't work out how to use HAL functions from the hook, e.g. palSetPadMode. Is this possible?

I'm running on an STM32F4, custom board, if that makes any difference, thanks.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Use of SYSTEM_HALT_HOOK with HAL

Post by Giovanni »

Hi,

The issue is that hal.h is not necessarily included where the macro is placed. The workaround is to just call a function from the hook placed in another module:

extern void myfunc(void);
myfunc();

The module containing myfunc() can include hal.h and use pal functions/macros.

Note that from that hook you should make no assumptions regarding the system state (interrupts enabled or disabled, thread context or ISR context etc).

Giovanni
Post Reply