/* USER CODE BEGIN Header */ /** ****************************************************************************** * File Name : app_freertos.c * Description : Code for freertos applications ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "FreeRTOS.h" #include "task.h" #include "main.h" #include "cmsis_os.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "i2c.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ extern I2C_HandleTypeDef hi2c1; /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ uint8_t Blink_speed = 0; /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN Variables */ /* USER CODE END Variables */ /* Definitions for defaultTask */ osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { .name = "defaultTask", .priority = (osPriority_t) osPriorityNormal, .stack_size = 128 * 4 }; /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ void JumpToBootloader(void) ; /* USER CODE END FunctionPrototypes */ void StartDefaultTask(void *argument); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ /** * @brief FreeRTOS initialization * @param None * @retval None */ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* USER CODE BEGIN RTOS_MUTEX */ /* add mutexes, ... */ /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ /* USER CODE BEGIN RTOS_QUEUES */ /* add queues, ... */ /* USER CODE END RTOS_QUEUES */ /* Create the thread(s) */ /* creation of defaultTask */ defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ /* USER CODE END RTOS_EVENTS */ } /* USER CODE BEGIN Header_StartDefaultTask */ /** * @brief Function implementing the defaultTask thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_StartDefaultTask */ void StartDefaultTask(void *argument) { /* USER CODE BEGIN StartDefaultTask */ Blink_speed = 0; int var = 0; /* Infinite loop */ for(;;) { if(Blink_speed == 0){ for(var=0;var < 6; var++){ HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); osDelay(500); } } else if(Blink_speed == 1){ for(var=0;var < 6; var++){ HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); osDelay(50); } } else if(Blink_speed == 2){ for(var=0;var < 6; var++){ HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); osDelay(100); } } } /* USER CODE END StartDefaultTask */ } /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ void JumpToBootloader(void) { void (*SysMemBootJump)(void); /** * Step: Set system memory address. * * For STM32F429, system memory is on 0x1FFF 0000 * For other families, check AN2606 document table 110 with descriptions of memory addresses */ volatile uint32_t addr = 0x1FFF0000; /** * Step: Disable RCC, set it to default (after reset) settings * Internal clock, no PLL, etc. */ HAL_RCC_DeInit(); HAL_DeInit(); /** * Step: Disable systick timer and reset it to default values */ SysTick->CTRL = 0; SysTick->LOAD = 0; SysTick->VAL = 0; MX_I2C1_Init(); /** * Step: Disable all interrupts */ __disable_irq(); /** * Step: Remap system memory to address 0x0000 0000 in address space * For each family registers may be different. * Check reference manual for each family. */ __HAL_RCC_SYSCFG_CLK_ENABLE(); __DSB(); __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); //Call HAL macro to do this for you __DSB(); __ISB(); SCB->VTOR = 0; /** * Step: Set jump memory location for system memory * Use address with 4 bytes offset which specifies jump location where program starts */ SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4))); /** * Step: Set main stack pointer. * This step must be done last otherwise local variables in this function * don't have proper value since stack pointer is located on different position * Set direct address location which specifies stack pointer in SRAM location */ __set_MSP(*(uint32_t *)addr); __set_PSP(*(uint32_t *)addr); /** * Step: Actually call our function to jump to set location * This will start system memory execution */ SysMemBootJump(); } /** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == PUSH_BUTTON_Pin) { if(Blink_speed ==1){ Blink_speed =2; JumpToBootloader(); } else{ Blink_speed ++; } } } /* USER CODE END Application */