I wrote a bootloader code. The flash space range of bootloader is 0x27000-0x3b000, and the flash space of app is 0x3b000-0x80000, but the app doesn't work. What's the problem?
My project consists of STM32 + 4G + nrf52833. When the 52833 firmware needs to be updated, the cloud service will send the 52833 firmware to STM32, and then STM32 will send the firmware to 52833 through the UART interface.
sdk:nRF5_SDK_17.0.2_d674dde
The flash distribution framework is as follows:
bootloader:
typedef void (*iapfun)(void); #define FLASH_APP1_ADDR 0x3B000 //app code start address iapfun jump2app; __asm void MSR_MSP(uint32_t addr) { MSR MSP, r0 //set Main Stack value BX r14 } //Jump to application segment //appxaddr:app code start address void iap_load_app(uint32_t appxaddr) { jump2app=(iapfun)*(uint32_t*)(appxaddr+4); //The second word in the user code area is the program start address (reset address) #if 1 MSR_MSP(*(uint32_t*)appxaddr); //Initialize the app stack pointer ,(the first word in the user code area is #else //used to store the stack top address) __set_MSP(appxaddr); #endif jump2app(); //jump to APP. } timer_out_st timer_period; void handle_period_event(void) { static uint32_t jump_to_app_timer = 0, pir_detect_ok_num = 0; static uint8_t dataW,dataR; if(!IsTimeOut(&timer_period)) return; TimeOutSet(&timer_period,10); mcu_led_set(); if(++jump_to_app_timer > 300) { jump_to_app_timer=0; { printf("jump to app,0x3B000=%08x\n",*(uint32_t*)(FLASH_APP1_ADDR)); nrf_delay_ms(100); // Turn off the peripherals used uart_close(0); uart_close(1); sk_timer_set(0); iap_load_app(FLASH_APP1_ADDR); } // This information will not be printed if it works properly printf("***err to jump app\n"); } }
app:
SCB->VTOR = 0x3B000; // remap interrupt vector table address