2020-08-31 08:50 AM
I have build a IAP bootloader at 0x8000000 and test with a simple blink app at 0x8040000 which works fine but if I add FreeRTOS for the same blink app at 0x8040000 its not working. It jump to the blink application but it doesn't pass the SystemClock_Config() function while under debugging. Did I miss anything to configure?
/* Blink app */
int main(void)
{
/* USER CODE BEGIN 1 */
SCB->VTOR = 0x8040000;
/* 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();
/* USER CODE BEGIN 2 */
while(1){
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0 | GPIO_PIN_1,GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0 | GPIO_PIN_1,GPIO_PIN_RESET);
HAL_Delay(500);
}
/* USER CODE END 2 */
/* 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) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* 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 */
}
/* IAP Bootloader */
#define APP_ADDRESS 0x8040000
if (((*(__IO uint32_t*)APP_ADDRESS) & 0x2FFE0000 ) == 0x20000000) {
HAL_RCC_DeInit();
HAL_DeInit();
JumpAddress = *(__IO uint32_t*) (APP_ADDRESS + 4);
Jump = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t*) APP_ADDRESS);
Jump();
}
Solved! Go to Solution.
2020-08-31 01:39 PM
I solved it. The problem is, I didn't disabled SysTick in the bootloader before jump. Now I corrected the IAP bootloader with below changes.
I used this https://github.com/akospasztor/stm32-bootloader as a reference.
/* IAP Bootloader */
#define APP_ADDRESS 0x8040000
if (((*(__IO uint32_t*)APP_ADDRESS) & 0x2FFE0000 ) == 0x20000000) {
HAL_RCC_DeInit();
HAL_DeInit();
/* Disable SysTick */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
JumpAddress = *(__IO uint32_t*) (APP_ADDRESS + 4);
Jump = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t*) APP_ADDRESS);
Jump();
}
2020-08-31 09:14 AM
Update: While debugging, It goes to HardFault_Handler(). Can anyone know why and how to solve it ?
2020-08-31 10:14 AM
Make sure the code you are calling sets up the Vector Table properly, ie SCB-.>VTOR = 0x08040000; in SystemInit() or wherever
User/System state is perhaps not conducive to control transfer and protected instructions.
Do not call from interrupt context (callbacks), the NVIC doesn't unwind properly.
Have the Hard Fault Handler output actionable data. Posted multiple examples of this.
2020-08-31 11:50 AM
When the application is without freeRTOS, it works fine. But, only I get hardfault when using with freeRTOS. So, If it is under above mentioned case, it should not work in the without freeRTOS app, right?
2020-08-31 12:21 PM
Easily checked
No data on why it is Hard Faulting
If the App expects the processor in a reset state you might want to have an expedited path in the Loader's Reset_Handler to transfer control to the App's Reset_Handler
2020-08-31 12:31 PM
Thank you for your reply. But I am a newbie on this. I am bit confused to approach your solution. Could you help me with reference or example?
it will be helpful to understand your suggested solution.
2020-08-31 01:39 PM
I solved it. The problem is, I didn't disabled SysTick in the bootloader before jump. Now I corrected the IAP bootloader with below changes.
I used this https://github.com/akospasztor/stm32-bootloader as a reference.
/* IAP Bootloader */
#define APP_ADDRESS 0x8040000
if (((*(__IO uint32_t*)APP_ADDRESS) & 0x2FFE0000 ) == 0x20000000) {
HAL_RCC_DeInit();
HAL_DeInit();
/* Disable SysTick */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
JumpAddress = *(__IO uint32_t*) (APP_ADDRESS + 4);
Jump = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t*) APP_ADDRESS);
Jump();
}
2020-10-27 08:49 AM
S@mp,
thanks for your solution. It is great help to me and also work for SMT32F413.
best regards
2024-11-12 04:11 PM
hi~
I am also experiencing the very same problem while implementing IAP while using Freertos. I would appreciate it if you could let me know how you solved it.