RHaguiuda
RHaguiuda

Reputation: 3259

Cortex-M3 NVIC_EnableIRQ(Systick_IRQn) causes hard fault exception

I'm using a Cortex-M3 LPC1548 from NXP with uVision IDE.

In the main() function, if I use:

SysTick_Config(SystemCoreClock * SYSTICK_INT_FREQ); 
NVIC_EnableIRQ(SysTick_IRQn);  // <--- HardFault happens in this line.

I got a HardFault exception everytime.

However, if I remove the NVIC_EnableIRQ(...) like this:

SysTick_Config(SystemCoreClock * SYSTICK_INT_FREQ); 

code runs fine.

Does anyone knows why enabling Systick interrupt causes a HardFault?

I've done this before in a Cortex-M0 and never had problems.

Upvotes: 3

Views: 4429

Answers (2)

RHaguiuda
RHaguiuda

Reputation: 3259

What needs to be very clear here is that NVIC_EnableIRQ() can only be used to enable/disable exceptions numbers with values greater than 16.

Exceptions with numbers greater than 16 are called interrupt inputs while below 16 are system exceptions.

That means that the system exceptions listed below (example for Cortex-M3) cannot be used with NVIC_EnableIRQn():

  • 1 Reset
  • 2.NMU
  • 3.HardFault
  • 4.MemManage Fault
  • 5.Bus Fault
  • 6.Usage Fault
  • 7-10. Reserved
  • 11 SVC
  • 12 Debug Monitor
  • 13 Reserved
  • 14 PendSV
  • 15 Systick

So, the Systick Interrupt should never be activated using NVIC_EnableIRQ because it's an system exception. If one is using the CMSIS function SysTick_Config() no interrupt activation is needed since this function takes care of activating the Systick interrupt.

P.S. Information was taken from the excelent book from Joseph Yiu, The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors and by analysing the function NVIC_EnableIRQ().

Upvotes: 5

Turbo J
Turbo J

Reputation: 7701

Systick_IRQn is a negative value, you cannot use NVIC_EnableIRQ() with Systick. The out-of-bounds register access probably causes your hardfault.

The systick interrupt is enabled as soon as the corresponding bit in Systick->CTRL is set.

However, NVIC_SetPriority() supports Systick_IRQn among others like PendSV_IRQn.

Upvotes: 2

Related Questions