Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


How to add header on beginning of FW for bootloader use

I’m using STM32L053 and there is a bootloader will check the application FW’s header.
The application firmware should have a header of 3 words (12 bytes):
attribute((section(“.fwhdr”)))
const volatile boot_fwhdr fwhdr = {
// CRC and size will be patched by external tool
.crc = 0,
.size = BOOT_MAGIC_SIZE,
.entrypoint = (uint32_t) _start,
};
The bootloader will check the CRC and length(after run python tool to create).
The third word is the pointer to your entry point function.
The bootloader will jump to that address upon startup.

And the question is how to add the header on beginning of FW for bootloader use ?
How to add the pointer of entry point function as the header on my FW?
The bootloader is create by gcc and some .ld file, but I don’t know how to add the header on my current project by using Keil or SW4STM32.

Nick

France

Hi Nick,

I can’t answer for Keil, but SW4STM32 uses gcc link editor, so you should just add a section before the .isr_vectors (or replacing it as you probably don’t need it as is):
.text: {
    KEEP(*(.fwdhr))
    KEEP(*(.isr_vector))
    ...

Then your firmware header will be inserted in front of your program.

Bernard (Ac6)

Hi Bernard
Thanks for your reply, I will try to add header by using SW4STM32.
My project are using Keil, so I need porting to SW4STM32 first, the free IDE tool is more best.
Is there anything we should be attention that porting from Keil to SW4STM32? or I should using STM32cubeMX to generate SW4STM32 project than porting current project to it?

Nick

France

Hi Nick,

The main advantage of STM32CubeMX being to generate the initialization code for your board, something you don’t need as you already have working code, I think the best would be to create a new project using SW4STM32 and copy your code in the src directory (either directly or in subdirectories, as you already structured it), with include files in inc.

Regarding the ST-provided firmware, you have two options:

  1. keep it in your source code
    • create a project without firmware
    • import all the code you compiled with Keil, keeping the directory structure
  2. have it imported by SW4STM32
    • only copy your code, not the firmware from ST
    • you may even import the firmware in a separate static library so thatyou can upgrade it simply if needed.
    • note that some third-party middlewares, like FreeRTOS, will be always included within th ecreated project, as they depend on application-specific configuration files


Hope this helps,

Bernard (Ac6)

Hi Bernard
There is a problem that when I add the header on linker scripts file (stm32l073xx_flash.ld)
The original file is

/* Entry Point */
ENTRY(Reset_Handler)

/* Define output sections */
SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text*)

KEEP(*(.init))
KEEP(*(.fini))
.....

.....

The original entry point is Reset_Handler~~ and the Reset_Handler in (startup_stm32l073xx.s) will do

/* Call the clock system intitialization function.*/
bl SystemInit
/* Call static constructors */
bl __libc_init_array
/* Call the application’s entry point.*/
bl main

What should I do to add the KEEP(*(.fwdhr)) on stm32l073xx_flash.ld?
The fwdhr’s third word is entrypoint , but the original entrypoint is Reset_Handler, I am confused.

Nick



Hi Bernard

Thank you for your advice . it is so helpful to me.

Nick


 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs