cancel
Showing results for 
Search instead for 
Did you mean: 

hard fault after configure systick

cai.bai
Associate II

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 ?

14 REPLIES 14

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

JW

cai.bai
Associate II

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

AvaTar
Lead

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

And you have checked in the Map file, or ?

cai.bai
Associate II

yes,i'm sure SysTick_Handler define correctly

AvaTar
Lead

And implemented + placed correctly ?

cai.bai
Associate II

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
Lead

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

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
Up vote any posts that you find helpful, it shows what's working..
Tomas DRESLER
Senior II

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.