Why are initializations in main executing repeatedly if I add a function?
Hi! I am starting to learn embedded programming using a NUCLEO-F439ZI and can't seem to understand why are the initializations in main executing repeatedly when adding an initialization function call that i wrote. I haven't changed any part of the code that STM32CubeIDE generates, i've only added a new source folder with a few classes. What i want to do is perform an initialization on startup and then go about with the normal execution of the program.
I will attach the main function below, as well as the initialization files that i wrote.
int main(void)
{
/* USER CODE BEGIN 1 */
initModules(); // if i comment this out, everything works fine
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_IWDG_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Call init function for freertos objects (in freertos.c) */
MX_FREERTOS_Init();
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}The Callback for external interrupt and initialization functions are declared in the following files:
#ifndef INIT_H_
#define INIT_H_
#include <usart.h>
#ifdef __cplusplus
extern "C"
{
#endif
extern void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
extern void initModules(void);
#ifdef __cplusplus
}
#endif
#endif /* INIT_H_ */#include "Init.h"
#include "Workers/SC20MPB.h"
#ifdef __cplusplus
extern "C"
{
#endif
static SC20MPB *gpCamera = nullptr;
static void createCamera();
void initModules(void)
{
createCamera();
}
static void createCamera()
{
if (nullptr == gpCamera)
{
static SC20MPB camera(&huart1);
gpCamera = &camera;
// gpCamera->setUARTHandle(&huart1); // stupid must be deleted
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (nullptr != gpCamera)
{
gpCamera->captureImageCmd();
}
}
#ifdef __cplusplus
}
;
#endifI have also tried adding 'initModules();' to freertos.c, but somehow i encounter the same problem. Please let me know if I should add any more pieces of code.
