AnsweredAssumed Answered

STM32L1 :my custom Bootloader doesn't boot my new program

Question asked by thib.glo on Jun 23, 2015
Latest reply on Jun 23, 2015 by Clive One

I made my own bootloader for an STM32L1 board. My algorithm is simple : - first, I erase the memory I need to write my new program on my flash. - then, I write 4 bytes per 4 bytes my new program ( I receive it from the USART of the board)

       
  • then i push the RESET button of my card, and nothing happens ...

My new program should blink a LED but nothing happens and I d'ont understand why ...

Do i have to write my own RESET function? Here is my code if you want to give a try.

void BootLoader(void) {
 
    //clear all ITs
    USART_ITConfig_boot( USART1, USART_IT_RXNE, 0);
    uint32_t start_adr, end_adr;
    uint8_t status, i;
    uint8_t buffer[4096];
    uint8_t sizeRcv[2];
    uint16_t tailleSector = 0x1000;
    uint32_t adr;
    uint8_t nbSector = 0;
 
    //size fixée en dur
    uint16_t k = 0;
    uint8_t size1 = 0;
    uint8_t size2 = 0;
    uint16_t sizeBin = 0;
    //taille sector
    uint16_t tailleSecteurDec = 4096;
    SendString_boot("BOOTLOADER ON.....\r\n", USART2);
    //adress
    //First Sector
    start_adr = WRITE_START_ADDR;
    end_adr = start_adr + tailleSector;
    //erasing flags
 
    FLASH_ClearFlag_boot(
                FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                        | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR
                        | FLASH_FLAG_OPTVERRUSR | FLASH_FLAG_RDERR);
 
    FLASH_Unlock_boot();
    sizeBin = 51400;
    nbSector = (uint8_t) (sizeBin / tailleSecteurDec) + 1;
    if(nbSector > 30){
        SendString_boot("cannot overrite memory : too much sectors used\r\n",USART2);
 
    }
 
    for (i = 0; i <= (127 - 1); i++) {
        if(end_adr < 0x0808FFFF){
            status = Flash_Erase(start_adr, end_adr);
            start_adr = end_adr;
            end_adr = end_adr + tailleSector;
            SendString_boot(" ERASING SECTOR DONE \r\n", USART2);
        }
        else{
            SendString_boot("END OF FLASH MEMORY\r\n", USART2);
 
        }
    }
 
    SendString_boot("ERASING COMPLETE\r\n", USART2);
    start_adr = WRITE_START_ADDR;
    //receive frames
 
    adr = WRITE_START_ADDR;
    do {
 
        SendString_boot("ACK_READY", USART1);
        SendString_boot("ACK_READY\r\n", USART2);
        //receive 32 bytes
        if (sizeBin - k > 4096)
            Receive_Data_boot(buffer, 4096);
        else
            Receive_Data_boot(buffer, sizeBin - k);
 
 
        //write 32 bytes in memory
        if (sizeBin - k > 4096)
            status = Flash_Write(adr, buffer, 4096);
        else
            status = Flash_Write(adr, buffer, sizeBin - k);
        //on check si on ecrit bien au bon endroit
 
        //increment cpt
        k = k + 4096;
        adr = adr + 0x1000;
        i++;
        //check CRC
        //TODO
        SendString_boot("...FLASH DONE ON  ", USART2);
        SendString_boot("\r\n", USART2);
 
 
        SendString_boot("  SECTOR DONE \r\n", USART2);
 
    } while (k < sizeBin);
 
    SendString_boot("END", USART1);
    SendString_boot("ACK_END\r\n", USART2);
    FLASH_Lock_boot();
 
}

Outcomes