2025-02-11 04:38 AM
STM32CubeIDE 1.17.0 - using the CMSIS headers - NUCLEO F411RE
I have the following function that is trying to use SYSTICK to give a delay in milliseconds,
#include "stm32f4xx.h" // actaully contained in another header put here for question clarity
/* SYSTICK defines */
#define CTRL_ENABLE (1U<<0)
#define CTRL_CLKSRC (1U<<2)
#define CTRL_COUNTFLAG (1U<<16)
#define SYSTICK_LOAD_VAL 16000
void systick_delay_ms(uint32_t delay)
{
/* Register names are different in Cortex ref doc to those in CMSIS header */
/* Reload systick with number of clocks / ms - SYSTICK_RVR*/
//SysTick->LOAD(SYSTICK_LOAD_VAL);
SysTick->LOAD(SYSTICK_LOAD_VAL);
/* Clear systick current value register - SYSTICK_CVR*/
SysTick->VAL = 0;
/* Enable systick & select to use internal clock src */
SysTick->CTRL = CTRL_CLKSRC | CTRL_ENABLE;
for(int i = 0; i < delay; i++)
{
/* Wait until the COUNTFLAG is set - SYSTICK_CSR */
while((SysTick->CTRL & CTRL_COUNTFLAG) == 0){}
}
SysTick->CTRL = 0;
}
When compiled though throws the following error,
arm-none-eabi-gcc "../Src/gen_bluetooth_driver.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DNUCLEO_F411RE -DSTM32 -DSTM32F4 -DSTM32F411RETx -DSTM32F411xE -c -I../Inc -I"..//chip_headers/CMSIS/Device/ST/STM32F4xx/Include" -I"..//chip_headers/CMSIS/Include" -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Src/gen_bluetooth_driver.d" -MT"Src/gen_bluetooth_driver.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Src/gen_bluetooth_driver.o"
In file included from ..//chip_headers/CMSIS/Device/ST/STM32F4xx/Include/stm32f411xe.h:140,
from ..//chip_headers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:154,
from ../Inc/gen_bluetooth_driver.h:4,
from ../Src/gen_bluetooth_driver.c:1:
../Src/gen_bluetooth_driver.c: In function 'systick_delay_ms':
..//chip_headers/CMSIS/Include/core_cm4.h:1561:29: error: called object is not a function or function pointer
1561 | #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
| ^
../Src/gen_bluetooth_driver.c:143:9: note: in expansion of macro 'SysTick'
143 | SysTick->LOAD(SYSTICK_LOAD_VAL);
| ^~~~~~~
When I chased up the `Systick` define in `core_cm4.h' I find that `SysTick` is defined as I expected, snippets below,
What am I missing here?
Solved! Go to Solution.
2025-02-11 05:03 AM
What are you intending here:
SysTick->LOAD(SYSTICK_LOAD_VAL);
That doesn't make sense?
You've written as if LOAD is function/macro call, but LOAD is just the name of a register
Did you mean
SysTick->LOAD = SYSTICK_LOAD_VAL;
2025-02-11 05:03 AM
What are you intending here:
SysTick->LOAD(SYSTICK_LOAD_VAL);
That doesn't make sense?
You've written as if LOAD is function/macro call, but LOAD is just the name of a register
Did you mean
SysTick->LOAD = SYSTICK_LOAD_VAL;
2025-02-11 05:05 AM
Aaahhh yes, I'm on auto-pilot & just couldn't see it, thanks