No interrupts after jump to main program from custo bootloader (HAL libraires)
Hello Community,
I have problem with starting main program after jump from bootloader. I am using ECLIPSE with SW4STM32 and CubeMX.
Ok, what I did:
1. I writed bootloader which is prepared with settings: Linker file: ——————————————————————————– /* Specify the memory areas */ MEMORY { BOOTLOADER (rx): ORIGIN = 0x08000000, LENGTH = 24K FIRMWARE (rx) : ORIGIN = 0x08006000, LENGTH = 256K – 24K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K – 192 /* 192 for vector table */ } /* Main app start address symbol */ _main_app_start_address = 0x08006000;/* For main application, change BOOTLOADER by FIRMWARE */
REGION_ALIAS(“FLASH�?, BOOTLOADER ); ——————————————————————————– 2. Jump function:// disable global interrupt
__disable_irq();
// Disable all peripheral interrupts
HAL_NVIC_DisableIRQ(SysTick_IRQn);
HAL_NVIC_DisableIRQ(WWDG_IRQn);
HAL_NVIC_DisableIRQ(RTC_IRQn);
HAL_NVIC_DisableIRQ(FLASH_IRQn);
HAL_NVIC_DisableIRQ(RCC_IRQn);
HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
HAL_NVIC_DisableIRQ(DMA1_Channel1_IRQn);
HAL_NVIC_DisableIRQ(DMA1_Channel2_3_IRQn);
HAL_NVIC_DisableIRQ(DMA1_Channel4_5_IRQn);
HAL_NVIC_DisableIRQ(ADC1_IRQn);
HAL_NVIC_DisableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
HAL_NVIC_DisableIRQ(TIM1_CC_IRQn);
HAL_NVIC_DisableIRQ(TIM3_IRQn);
HAL_NVIC_DisableIRQ(TIM6_IRQn);
HAL_NVIC_DisableIRQ(TIM7_IRQn);
HAL_NVIC_DisableIRQ(TIM14_IRQn);
HAL_NVIC_DisableIRQ(TIM15_IRQn);
HAL_NVIC_DisableIRQ(TIM16_IRQn);
HAL_NVIC_DisableIRQ(TIM17_IRQn);
HAL_NVIC_DisableIRQ(I2C1_IRQn);
HAL_NVIC_DisableIRQ(I2C2_IRQn);
HAL_NVIC_DisableIRQ(SPI1_IRQn);
HAL_NVIC_DisableIRQ(SPI2_IRQn);
HAL_NVIC_DisableIRQ(USART1_IRQn);
HAL_NVIC_DisableIRQ(USART2_IRQn);
HAL_NVIC_DisableIRQ(USART3_6_IRQn);
// main app start address defined in linker file
extern uint32_t _main_app_start_address;
uint32_t MemoryAddr = (uint32_t)&_main_app_start_address;
uint32_t *pMem = (uint32_t *)MemoryAddr;
// First address is the stack pointer initial value
__set_MSP(*pMem); // Set stack pointer
// Now get main app entry point address
pMem++;
void (*pMainApp)(void) = (void (*)(void))(*pMem);
// Jump to main application (0x0800 6004)
pMainApp();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
3. I writedsimply FIRMWARE program which blinking one led using while loop and shoud blinking second led using IRQs –> void HAL_SYSTICK_Callback(void);
Blinking by IRQs not working. Blinking by while loop is working
4. Linker file from FIRMWARE:
——————————————————————————– /* Specify the memory areas */ MEMORY { BOOTLOADER (rx): ORIGIN = 0x08000000, LENGTH = 24K FIRMWARE (rx) : ORIGIN = 0x08006000, LENGTH = 256K – 24K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K – 192 /* 192 for vector table */ } /* Main app start address symbol */ _main_app_start_address = 0x08006000;/* For main application, change BOOTLOADER by FIRMWARE */
REGION_ALIAS(“FLASH�?, FIRMWARE ); ——————————————————————————–5. In FIRMWARE program first function in main is Remap_Table();
void Remap_Table(void)
{
// Copy interrupt vector table to the RAM.
volatile uint32_t *VectorTable = (volatile uint32_t *)0x20000000;
uint32_t ui32_VectorIndex = 0;
for(ui32_VectorIndex = 0; ui32_VectorIndex < 48; ui32_VectorIndex++)
{
VectorTable[ui32_VectorIndex] = *(__IO uint32_t*)((uint32_t)FIRMWARE_START_ADDR + (ui32_VectorIndex << 2));
}
__HAL_RCC_AHB_FORCE_RESET();
// Enable SYSCFG peripheral clock
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_AHB_RELEASE_RESET();
// Remap RAM into 0x0000 0000
__HAL_SYSCFG_REMAPMEMORY_SRAM();
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
I tried set __enable_irq(); after Remap_table(); and before main while loop and in other places from Remap_table() to main while loop and it does not work.
6. I did test with FIRMWARE and set in linker: ——————————————————————————– MEMORY { BOOTLOADER (rx): ORIGIN = 0x08000000, LENGTH = 24K FIRMWARE (rx) : ORIGIN = 0x08006000, LENGTH = 256K – 24K RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K – 192 /* 192 for vector table */ } /* Main app start address symbol */ _main_app_start_address = 0x08006000;/* For main application, change BOOTLOADER by FIRMWARE */
REGION_ALIAS(“FLASH�?, BOOTLOADER); ——————————————————————————– then I deleted Remap function and __enable_irq();, compiled it and writed it to MCU by programmer –> blinking by while loop and IRQs worked good.I heard about problem with starting FIRMWARE after custom bootloader witch is writed with HAL libraries. I think, I have this problem.Can someone give me some advice ?
MCU is STM32F030RCT6
Regards
Dawid
