Skip to main content
cai.bai
Associate II
Sep 12, 2018 7:31 AM UTC
Question

hard fault after configure systick

i use NUCLEO - F767ZI and test a simple code as follow

int sum(int a,int b){
 
 return a+b;
}
 
int main(void){
 
 int dly;
 
 __enable_irq();
 SysTick_Config(100000);
 NVIC_EnableIRQ(SysTick_IRQn);
 
 dly = sum(1,3);
 return 0;
}

i debug it and when call sum(1,3), it will goto hard fault.

if comment ​NVIC_EnableIRQ(SysTick_IRQn); call and it work fine.

can someone help me ?

This topic has been closed for replies.

14 replies

waclawek.jan
Super User
Sep 12, 2018 7:43 AM UTC

I don't think you are supposed to return from main().

JW

cai.bai
cai.baiAuthor
Associate II
Sep 12, 2018 7:47 AM UTC

this is example code,actually ,if call NVIC_EnableIRQ(SysTick_IRQn); it will goto hard fault before return;

AvaTar
Senior III
Sep 12, 2018 8:03 AM UTC

Do you have an interrupt handler routine for SysTick, don't you ?

And you have checked in the Map file, or ?

cai.bai
cai.baiAuthor
Associate II
Sep 12, 2018 8:35 AM UTC

yes,i'm sure SysTick_Handler define correctly

AvaTar
Senior III
Sep 12, 2018 8:45 AM UTC

And implemented + placed correctly ?

cai.bai
cai.baiAuthor
Associate II
Sep 12, 2018 9:50 AM UTC

yes ,map like

  i.SysTick_Handler            0x08000254  Section    0 main.o(i.SysTick_Handler)

  i.SystemInit               0x08000258  Section    0 system_stm32f7xx.o(i.SystemInit)

  i.__scatterload_copy           0x080002bc  Section    14 handlers.o(i.__scatterload_copy)

  i.__scatterload_null           0x080002ca  Section    2 handlers.o(i.__scatterload_null)

  i.__scatterload_zeroinit         0x080002cc  Section    14 handlers.o(i.__scatterload_zeroinit)

  i.main                  0x080002dc  Section    0 main.o(i.main)

  i.sum                  0x08000358  Section    0 main.o(i.sum)

i think it not about SysTick_Handler, because it goto hard fault before call sum(...)

AvaTar
Senior III
Sep 12, 2018 10:14 AM UTC

And did you evaluate the hardfault reason (SCB regs) ?

Tesla DeLorean
Guru
Sep 12, 2018 12:59 PM UTC

Really shouldn't need to do that, if you've configured the SysTick it should have the SCB set up.

Remember it is a System Handler, not an IRQ in the broader sense, and the IRQn will be negative

HAL_NVIC_SetPriority() would be usable

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tomas DRESLER
Associate II
Sep 12, 2018 5:29 PM UTC

How big is the stack and is it defined within reachable RAM? Are other interrupts working well?

Is the VTOR modified in start-up code? It must be aligned or else HF will occur, too.

Tomas DRESLER
Associate II
Sep 12, 2018 5:32 PM UTC

The NVIC_EnableIRQ doesn't work for SysTick!!!! It doesn't have any Enable or Disable bit within NVIC. Leave all on SysTick_Config(100000); alone.