Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


HardFault debugging

Hello everyone, I am developing a board and am fairly new working with stm32. My source code is triggering a hard fault in an unpredictable manner. It will run fine until I place a breakpoint or interact with the system workbench IDE in any way, at this point something triggers a hardfault. I am wondering how I can debug this problem I’ve found the following method at https://freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.htmlQuestion to store the location of the program counter at time the fault occurs in a variable to try to understand whats causing the hard fault. However I am never reaching the
prvGetRegistersFromStack function from within the hardfault handler. The program just jumps to some strange address. Interestingly when I place the same instructions anywhere else in the program the function can be reached. Does anyone have any insight on what could be causing this or how to properly debug hard faults?

void HardFault_Handler(void) {
__ASM volatile(“BKPT #01”);
__asm volatile
(
” tst lr, #4 \n”
” ite eq \n”
” mrseq r0, msp \n”
” mrsne r0, psp \n”
” ldr r1, r0, #24 \n”
” ldr r2, handler2_address_const \n”
” bx r2 \n”
” handler2_address_const: .word prvGetRegistersFromStack \n”
);
}

void prvGetRegistersFromStack(uint32_t *pulFaultStackAddress) {
/* These are volatile to try and prevent the compiler/linker optimising them
away as the variables never actually get used. If the debugger won’t show the
values of the variables, make them global my moving their declaration outside
of this function. */
volatile uint32_t r0 attributeunused;
volatile uint32_t r1 attributeunused;
volatile uint32_t r2 attributeunused;
volatile uint32_t r3 attributeunused;
volatile uint32_t r12 attributeunused;
volatile uint32_t lr attributeunused; /* Link register. */
volatile uint32_t pc attributeunused; /* Program counter. */
volatile uint32_t psr attributeunused;/* Program status register. */

r0 = pulFaultStackAddress;
r1 = pulFaultStackAddress;
r2 = pulFaultStackAddress;
r3 = pulFaultStackAddress;

r12 = pulFaultStackAddress;
lr = pulFaultStackAddress;
pc = pulFaultStackAddress;
psr = pulFaultStackAddress;

/* When the following line is hit, the variables contain the register values. */
__ASM volatile(“BKPT #01”);
for( ;; );
}

 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs