cancel
Showing results for 
Search instead for 
Did you mean: 

IAP bootloader not working with FREERTOS application

S_1
Associate III

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();
}

1 ACCEPTED SOLUTION

Accepted Solutions
S_1
Associate III

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();
}

View solution in original post

7 REPLIES 7
S_1
Associate III

Update: While debugging, It goes to HardFault_Handler(). Can anyone know why and how to solve it ?

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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?

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S_1
Associate III

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.

S_1
Associate III

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();
}

Cwu.21
Associate

S@mp,

thanks for your solution. It is great help to me and also work for SMT32F413.

best regards