AnsweredAssumed Answered

Problems with custom bootloader on STM32F4

Question asked by Roberto Fortunato on Jun 1, 2017
Latest reply on Jan 16, 2018 by Bogdan Golab

I have some problems to implement a bootloader in a STM32F4. I searched on internet and I found coherent informations and examples, but I 'm not able to make simple test work.


Here my simple code:


bootloader (writed on 0x08000000 address):


#define APPLICATION_ADDRESS        0x08008000


typedef void (*pFunction)(void);
pFunction appEntry;
uint32_t appStack, test, i;


int main(void){


    /* 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 */


    /* Set the application stack pointer */


    /* Start the application */




    return 0;




program (writed on 0x08008000 address):


int main(void){
    register uint32_t tl;


    GPIO_InitTypeDef GPIO_InitStructure;
    ErrorStatus HSEStartUpStatus;


    // Enable HSE
    // Wait till HSE is ready
    HSEStartUpStatus = RCC_WaitForHSEStartUp();
    if(HSEStartUpStatus == SUCCESS){
        // HCLK = SYSCLK impostato a 168 tick
        // PCLK2 = HCLK/2 perché massimo è 84Mhz
        // PCLK1 = HCLK/4 perché massimo è 42Mhz
        // PLLCLK = 168 MHz
        RCC_PLLConfig(RCC_PLLSource_HSE, 12, 336, 2, 7);
        // PLLCLK = 144 MHz
        //RCC_PLLConfig(RCC_PLLSource_HSE, 12, 288, 2, 6);
        // Enable PLL
        // Wait till PLL is ready
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
        // Select PLL as system clock source
        // Wait till PLL is used as system clock source
        while(RCC_GetSYSCLKSource() != 0x08){}
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOG, &GPIO_InitStructure);


    GPIO_SetBits(GPIOG, GPIO_Pin_4);


        for(tl=0; tl < 0xFFFFFF; tl++);        // about 0.6 seconds    
        GPIO_ToggleBits(GPIOG, GPIO_Pin_4);


    return 0;


I write program to 0x08000000 address for test and it works, so I'm sure there is no bugs.


When I use bootloader system doesn't work. I try to understand with debugger and I see that instruction appEntry(); has no effect and next command is while(1);


Can anyone tell me where it is wrong?