Skip to main content
cai.bai
Associate II
September 12, 2018
Question

hard fault after configure systick

  • September 12, 2018
  • 14 replies
  • 3386 views

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
September 12, 2018

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

JW

cai.bai
cai.baiAuthor
Associate II
September 12, 2018

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

AvaTar
Senior III
September 12, 2018

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
September 12, 2018

yes,i'm sure SysTick_Handler define correctly

AvaTar
Senior III
September 12, 2018

And implemented + placed correctly ?

cai.bai
cai.baiAuthor
Associate II
September 12, 2018

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
September 12, 2018

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

Tesla DeLorean
Guru
September 12, 2018

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 VenmoUp vote any posts that you find helpful, it shows what's working..
Tomas DRESLER
Associate II
September 12, 2018

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
September 12, 2018

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.