hard fault after configure systick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-12 12:31 AM
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 ?
- Labels:
-
STM32F7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-12 10:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-12 11:02 AM
> The NVIC_EnableIRQ doesn't work for SysTick!!!!
Very well spotted, Tomas! - essentially the same thing Clive said but yes, it's imperative. And the comment at NVIC_EnableIRQ() says that, too.
----- [following is not reply to the original post]
Out of curiosity I had a look at NVIC_EnableIRQ() in the CMSIS headers I'm using for ages (namely
* @file core_cm4.h
* @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File
* @version V2.10
:(
static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
/* NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); enable interrupt */
NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] = (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); /* enable interrupt */
}
Wow. IRQn_Type is an enum and signedness of that is implementation-defined; however, I don't quite get what was the benefit of the double cast (clearly it won't "heal" the improper use with SysTick and other "negative-numbered" exceptions). (In newer CMSIS the commented-out line is omitted.)
I'm apparently not alone: https://github.com/ARM-software/CMSIS_5/issues/248
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-12 12:27 PM
I was perhaps a little too subtle there, herding cats, should have pulled the cattle prod....
It abends because the negative pointer math is super bad.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-12 3:36 PM
In more updated CubeMX versions, it says "Value cannot be negative" in comment.
GCC compatible compiler even could assert this in compile time ( if (__builtin_constant_p(IRQn) ) _Static_assert (IRQn > 0) ... )
-- pa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-12 3:49 PM
> GCC compatible compiler even could assert
Good idea, but 1. it should be told to ARM as this is in CMSIS; 2. _Static_assert is C11, so I guess this would work only if gcc is run with some of the C11-related -std switch.
JW

- « Previous
-
- 1
- 2
- Next »