Giter VIP home page Giter VIP logo

akospasztor / stm32-bootloader Goto Github PK

View Code? Open in Web Editor NEW
850.0 68.0 295.0 2.54 MB

Customizable Bootloader for STM32 microcontrollers. This example demonstrates how to perform in-application-programming of a firmware located on an external SD card with FAT32 file system.

Home Page: https://akospasztor.github.io/stm32-bootloader

License: Other

C 98.80% Assembly 0.99% Python 0.17% Makefile 0.04%
bootloader in-app-programming iap flasher stm32 stm32l4 stm32l476 mcu microcontroller flash

stm32-bootloader's People

Contributors

akospasztor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stm32-bootloader's Issues

Not an issue - a question - SCB->VTOR issue with F103?

Hi,

This is a shot in the dark and a cry for help.
I am writing a simple bootloader for STM32 F103 series using Arduino IDE.
I figured all the settings and am pretty sure I have set the linker loader script and VTOR table right.
I am confident of that because when I load the target firmware to 0x80080000 address with the cube programmer it works fine and VTOR is set correctly.

However, when I jump to the firmware from the bootloader, the VTOR is not set to 0x8008000! It remains 0x8000000. No idea why!
It is such a simple code and yet, something does not work.
Have you encountered any issues with F103 line?

Thank you!

void boot_jump2Address(const uint32_t address)
{
  uint32_t appStack;
  pFunction appEntry;
 
//  Serial.print("boot_jump2Address=0x"); Serial.println((uint32_t)address, HEX);

  // get the application stack pointer (1st entry in the app vector table)
  appStack = (uint32_t)*((__IO uint32_t*)address);
//  Serial.print("appStack=0x"); Serial.println((uint32_t)appStack, HEX);
 
  // Get the app entry point (2nd entry in the app vector table
  appEntry = (pFunction)*(__IO uint32_t*)(address + 4);
//  Serial.print("appEntry=0x"); Serial.println((uint32_t)appEntry, HEX);

  delay(1000);



  
  HAL_RCC_DeInit();
  HAL_DeInit();
 
  SysTick->CTRL = 0;
  SysTick->LOAD = 0;
  SysTick->VAL  = 0;
 
  // Reconfigure vector table offset to match the app location
  delay(100);
  
  __disable_irq();
  SCB->VTOR = 0x8008000;
  __DSB();
  __enable_irq();


  __set_MSP(appStack); // Set app stack pointer

  appEntry(); // Start the app
 
  while (1); // never reached
}

STM32 Flash HAL: HAL_FLASH_Program

Hi Akos,

When I use the below function, it writes the bytes in the correct flash address, however bytes are written in LSB

HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, flash_ptr, data)

e.g.:
when I write 0x0A1B2C3D4C5E6F55
I see that this 0x556F5E4C3D2C1B0A was written on the memory

Could you please confirm if that is also the case with you?
If that is the case, is there a way to write the data in MSB without updating the flash HAL?

Many thanks in advance

Support for STM32F4 series

Hi, I am trying to adapt this library for STM32F401 MCU and it seems like there are a ton of configurations that are different. Could you suggest what's the best way to port this implementation to F4?

Port on STM32F4 Error!

I have an STM32F4 Discovery board. And i am porting this code to my board. But it have so much error, mainly related to HAL FLASH. I am using HAL library. Anyone have bootloader for STM32F4?

HardFault at f_read

I tried with different clock settings (divider) for SD IO, but no success as I always get HardFault error at:
fr = f_read(&SDFile, &data, 8, &num);
(@ reading from file)

Do I need to check some other configuration as-well?

ad.1:
for the test, I put the f_read at different places, and I found that if it is called before Bootloader_Erase() it is ok, but if it was placed right after it, the Hard_Fault appears

Is it a bug in function Bootloader_Erase()?

OK, here is your soure code, if I use a MCU only 256KB like stm32l476rc, all the flash in the bank1 from page1 to 128(every page is 2K), so the NbrOfPages must be < FLASH_PAGE_NBPERBANK(256), but in your program, it will skip the if(NbrOfPages > FLASH_PAGE_NBPERBANK).

And the program will not erase the BANK1, cause it will be skipped.

Maybe i was wrong, Thank you for your contribution, it help me a lot, it write very clearly and easy reading.

uint8_t Bootloader_Erase(void)
{
    uint32_t NbrOfPages = 0;
    uint32_t PageError  = 0;
    FLASH_EraseInitTypeDef pEraseInit;
    HAL_StatusTypeDef status = HAL_OK;

    HAL_FLASH_Unlock();

    /* Get the number of pages to erase */
    NbrOfPages = (FLASH_BASE + FLASH_SIZE - APP_ADDRESS) / FLASH_PAGE_SIZE;

    if(NbrOfPages > FLASH_PAGE_NBPERBANK)
    {
        pEraseInit.Banks     = FLASH_BANK_1;
        pEraseInit.NbPages   = NbrOfPages % FLASH_PAGE_NBPERBANK;
        pEraseInit.Page      = FLASH_PAGE_NBPERBANK - pEraseInit.NbPages;
        pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
        status               = HAL_FLASHEx_Erase(&pEraseInit, &PageError);

        NbrOfPages = FLASH_PAGE_NBPERBANK;
    }

    if(status == HAL_OK)
    {
        pEraseInit.Banks     = FLASH_BANK_2;
        pEraseInit.NbPages   = NbrOfPages;
        pEraseInit.Page      = FLASH_PAGE_NBPERBANK - pEraseInit.NbPages;
        pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
        status               = HAL_FLASHEx_Erase(&pEraseInit, &PageError);
    }

    HAL_FLASH_Lock();

    return (status == HAL_OK) ? BL_OK : BL_ERASE_ERROR;
}

Linker Script Question

Hello, I am trying to port this to work on a STM32F107 based custom board and was hoping for some clarification on how to setup the .ld file. From your example I see that the start address is mapped to 8000000 with a length of 8000.

Do you also have to setup a flash partition for the application memory? It seems like the code is able to jump to the main application at the 80008000 address but that memory region is not defined in the .ld file.

My end goal is to have it set up with the Bootloader, app memory, an update cache (for storing downloaded bin files) and a small region at the end for storing some user data.

Could you please clarify if the .ld file needs this information or not?

Shared SDIO+fatfs

The Bootloader currently uses SDIO+fatfs to read the new firmware file. If I want to use SDIO+fatfs in application code, it will be in memory twice. Is there a way to share the SDIO+fatfs through some clever linking?

How to build the firmware image

Hello,
thank you for your great bootloader code, which is the first code, which runs perfectly for me and is easy understandable.
But I have one question. How can I build the firmware update image?
CubeIDE gives me an Intel hex file, .ELF file or an binary file which is almost 140MB large.
Thank you for your help

stm32-bootloader for stm32f103xxxx series

hello akospasztor,

first of all thanks for ur driver.
my application is also same as ur application but for stm32f103xxxx series.

can u suggest in writing this driver for my controlller....please...

thanks,
sankar

Check for app bug?

return ( ((*(__IO uint32_t*)APP_ADDRESS) & ~(RAM_SIZE-1)) == 0x20000000 ) ? BL_OK : BL_NO_APP;

Perhaps I'm missing something but if RAM_SIZE = 0x00040000 then (RAM_SIZE - 1) = 0x0003ffff, then inverted it equals 0xfffc0000. Then 0x20040000 & 0xfffc0000 = 0x20040000 which is not equal to 0x20000000. This assumes that the first 4 bytes of the app point to the end of the RAM space which I think it does at least on my app.

Error : Jump to application

Hi,
I am trying this example for my STM32F429zi, and I can erase and flash the memory but I am not able to run the application code, please can you suggest to me where I am doing wrong.

I am attaching my code. if any other details are required please let me know.

Thanks
BootTest.zip

How to compute the RAM_SIZE?

Hi,

In your bootloader.h file you have the following:

/* MCU RAM size, used for checking accurately whether flash contains valid application */
#if (STM32L496xx)
#define RAM_SIZE        (uint32_t)0x00040000
#elif (STM32L476xx)
#define RAM_SIZE        (uint32_t)0x00018000
#endif

My question is - how did you compute these values? I'm not sure how to get from 320K / 128K of RAM to those numbers.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.