This is a strange one for me and I certainly did not expect to get so completely stumped in my first day or so of learning the STM32CubeIDE. The first order of the day was making the onboard led blink with
HAL_GPIO_TogglePin(GPIOC, LED1_Pin);
HAL_Delay(500);
Going through the New Project/pin config and code generator this worked fine inside the while loop provided in the main.c file but when I called my own function inside the loop with the HAL commands it stops working. The code loops and calls my function mainLoop() but any HAL commands inside my function don't do anything.
Why is this - am I missing some kind of handle that must be passed or an #include to extend the scope of HAL commands within a source file and not just main() itself?
while (1)
{
HAL_GPIO_TogglePin(GPIOC, LED1_Pin);
void mainLoop(void);
// HAL_Delay(500); // works fine when uncommented
}
} // end of main()
void mainLoop(void)
{
HAL_Delay(200); // this does nothing
} // no HAL commands actioned
Yes, you are quite right and thanks for that. My stupid question was the result of me actually trying to put mainLoop() in another .cpp file, with appropriate .h header file containing the prototype and call it from the main.c while loop. Since I got an undefined reference to mainLoop linker error, I moved mainloop() back into main.c and then tried to run the prototype. Doh!
So, despite my flawed attempt to simplify the problem, I still cannot call my mainloop() function with its HAL commands residing in another .cpp file. Additionally, although I have yet to reach this point, are the HAL commands available in every project source file or will I need to #include a particular header?