bootloader to FreeRTOS on stm32f0x
Hi, I'm trying to jump to a FreeRTOS app via a bootloader that i made. I'm pretty new to this. I know there is a lot of similar topic on the internet but none of them fixed my problem. When I try to jump to my FreeRTOS app with my bootloader, nothing happens.
Here is the function i'm using to jump.
void jumpToEntry(void)
{
const JumpStruct* vector_p = (JumpStruct*)A_MAIN_IMAGE_ADDR;
deinitEverything();
asm("msr msp, %0; bx %1;" : : "r"(vector_p->stack_addr), "r"(vector_p->func_p));
}
void deinitEverything()
{
HAL_UART_DeInit(&huart2);
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
}Before jumping on a FreeRTOS application, I did my tests to jump on a simple blinky and it has a super weird behaviour.
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
while (1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
char c[10];
sprintf(c, "tick: %ld\r\n",HAL_GetTick());
HAL_Delay(1000);
}
}The only way to make this simple blinky to work was to had the 2 lines where I put the result of HAL_GetTick() in a random char array that I don't even use. If I just toggle pin and delay, the code seems to crash on the HAL_Delay.
I must precise that my blinky and my FreeRTOS are working fine if I flash them at the beginning of the flash (0x000800 0000). The problem must be something that I miss in the process of making a bootloader with a stm32f030R8.
Here is the code of my FreeRTOS code. I saw in a lot of guide that the vector table must be remapped, but with the cortex m0 it seems that i can't use SCB->VTOR . So I try to use a method I saw on this forum earlier. I'm not even sure it works in my case. I saw another method directly on the arm official website but it doesn't even compile (the commented part in the Remap_Table function).
volatile uint32_t VectorTable[48] __attribute__((section(".RAMVectorTable")));
void Remap_Table(void)
{
// uint32_t *vector_table = (uint32_t *)&_stext;
// uint32_t *vtor = (uint32_t *)0xE000ED08;
// *vtor = ((uint32_t)vector_table & 0xFFFFFFF8);
uint32_t i = 0;
for (i = 0; i < 48; i++)
{
VectorTable[i] = *(__IO uint32_t *)(0x08004070 + (i << 2));
}
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_SYSCFG_REMAPMEMORY_SRAM();
}
/**
* @brief Retargets the C library printf function to the USART.
* @PAram None
* @retval None
*/
int __io_putchar(int ch)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/**
* @brief Function implementing the defaultTask thread.
* @PAram argument: Not used
* @retval None
*/
void StartDefaultTask(void *argument)
{
/* Infinite loop */
for (;;)
{
printf("blinkzer \r\n");
HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
osDelay(500);
}
}
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
Remap_Table();
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
printf("before os init\r\n");
/* Init scheduler */
osKernelInitialize();
printf("before task\r\n");
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
while (1)
{
}
}My defaulTask is also a blinky and I added a reimplementation of io_putchar to use the printf and see it through a console like minicom.
I suspect the crash due to misinitialization of a clock or that interrupts are not managed correctly. The code may crash at the systemclock_config of my FreeRTOS app because I can't see any printf i my console so it must be a problem before usart init. And the generated System_clock config is not the same in my bootloader/blinky and my freeRTOS app. To precise my method, I followed a step by step tutorial made by ST in this video:
https://www.youtube.com/watch?v=lood3ehvGJ4
Thank you if anyone wants to help me. I apologize if the answer has already been given in any topic here that I would've missed. Also I may have done some dumb mistake since I'm only a beginner with RTOS and bootloader creation.