NVIC_EnableIRQ(SysTick_IRQn)

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.

 

问题解答

1.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.

 

2.

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().

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值