0
\$\begingroup\$

The bootloader should jump to the Application after some verification. For now lets assume it straightaway jumps there. I am working on B-L475E-IOT01A2 device, which uses ARM M4 Cortex. I am using STM32Cube IDE for writing the code. Here is the code(main() code) for implementing it.

int  boot_main(void)
{

pFunction appEntry;
uint32_t appStack;

/* Check if firmware update required */
if(checkFirmwareUpdate())
{

    /* Perform the update */
    performFirmwareUpdate();

}

/* Get the application stack pointer (First entry in the application vector table) */
appStack = (uint32_t) *((__IO uint32_t*)APPLICATION_ADDRESS);

/* Get the application entry point (Second entry in the application vector table) */
appEntry = (pFunction) *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);

/* Reconfigure vector table offset register to match the application 
location */
SCB->VTOR = APPLICATION_ADDRESS;

/* Set the application stack pointer */
    __set_MSP(appStack);

/* Start the application */
    appEntry();

    while(1);

}

I have also set the correct memory addresses in both the linker script files. The Application I am using here is FREERTOS. Here are the Linker Script Files:-

BootLoader

/* Entry Point */
ENTRY(Boot_Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20017fff;   /* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200 ;    /* required amount of heap  */
_Min_Stack_Size = 0x400 ;   /* required amount of stack */

/* Memories definition */ 
MEMORY
{
FLASH   (rx)    : ORIGIN = 0x08000000,  LENGTH = 44K

RAM2    (rwx)   : ORIGIN = 0x10000000,  LENGTH = 32K
RAM (rwx)   : ORIGIN = 0x20000000,  LENGTH = 96K
}<br/>


Application

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20018000;    /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x0000;     /* required amount of heap */  
_Min_Stack_Size = 0x800; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 96K
RAM2 (xrw)      : ORIGIN = 0x10000000, LENGTH = 32K
FLASH (rx)      : ORIGIN = 0x0800B000, LENGTH = 459K    /* Use only the           
                                                        first bank */
FLASH_UC (r)    : ORIGIN = 0x0807DC00, LENGTH = 9K      /* Fixed-location 
                                                            area */
}


STM32 has only 1MB of flash memory and the main memory is organized into two banks each of 512KB. So I am just using the first bank(512KB).
The Application contains some lines of code which print some values to the screen. So whenever I try running the BootLoader I can't see anything being printed.(There is no problem with the Application. It is running smoothly)

Can anyone point out what I am missing in my code? Or is there some problem in memory allocation?

Thanks

\$\endgroup\$
  • 1
    \$\begingroup\$ Please don't format as code stuff which isn't code. \$\endgroup\$ – Dmitry Grigoryev Jul 8 at 13:32
  • 1
    \$\begingroup\$ There isn't really enough information here to have an answerable question - you need to debug it and figure out what is actually happening. Beware that a lot of startup code assumes a processor at reset state and not one that is already "used" - sometimes it is best to set a flag, reset, and have some assembly before the C startup branch to the target. There are existing questions on this subject here which you should read. \$\endgroup\$ – Chris Stratton Jul 8 at 13:50
  • \$\begingroup\$ @ChrisStratton's advice is spot on. Don't bother trying to jump between firmwares (be it the STM32 bootloader or your applications). If you ever succeed, it'll be out of luck and you will loose hours to understand the next time it starts failing. To safely exit from bootloader mode, you need to reset. To safely switch between application firmwares, you need to reset. \$\endgroup\$ – user72833 Jul 8 at 14:23
  • \$\begingroup\$ _estack = 0x20017fff; is not a valid stack address, it should be divisible by 4. (8 according to some ARM docs, but STM32s don't seem to care). \$\endgroup\$ – berendi - protesting Jul 8 at 14:31
  • \$\begingroup\$ Verify that appStack and appEntry do indeed contain the expected values, i.e. they weren't overwritten by flashing the bootloader after the app. If both are correct, step into appEntry() in instruction debug mode to see where it lands. \$\endgroup\$ – berendi - protesting Jul 8 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.