During the development of an embedded device, I encountered a one time bug with no interruptions working. It’s important to understand that this device usually works fine, and has been for a few years now, without changes of this code part.
After a few investigation, GDB showed me that I was blocked in a while loop, of a delay function :
void delay_ns(uint32_t ns)
{
SysTick->CTRL = 0;
SysTick->VAL = 0;
SysTick->LOAD = 16 * ns; // 16 for 16 MHz
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)) //BUG HERE
;
SysTick->CTRL = 0;
}
I’m not an MCU dev, and I’m doing my best to understand what’s at stake here, but the main informations are :
- I’m working with a Cortex-M0+
- Here’s the definition of Systick
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
- Here’s SysTick’s Type definition
typedef struct
{
__IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
I seem to understand that a error on SysTick is pretty much impossible, and as I do not fully understand MCU’s behaviour, I’m wondering where this error comes from.
I’d be glad if you were able to help me in any way !
1