cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7A3 HAL_FLASH_Program() data and address alignment

KAgga.1
Associate III

Hello There,

I'm working on an IAP application based on STM32H7A3 and have a query related to code alignment.

Correct me if I'm wrong, as per my understanding HAL_FLASH_Program() in H7A3 writes a flash word (i,e., 16 Bytes) at a time. If so, then it must need data to be a multiple of 16.

Then also for an IAP, the target bin should also be 16 byte aligned? If yes, then how to make it correctly.

Regards,

Keshav Aggarwal

7 REPLIES 7

Shouldn't be hard to align a .BIN, start with how you build it with the Linker.

Pad the file with void bytes to get the desired lengths.

For .HEX there's the potential to output short or misaligned lines of data, you might have to buffer and process multiple lines, and their might be voids you need to fill with padding bytes.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KAgga.1
Associate III

I'm using .bin,

You mean manually adding 0x00 as required to the last byte of bin to be aligned with 16 Bytes?

Pavel A.
Evangelist III

https://github.com/STMicroelectronics/STM32CubeH7/blob/4fdaa91bd55f9b4fc5c03fbc929b93566acea76e/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c#L147

The flash program unit in STM32H7 is multiple of 32-bit words.

For STM32H7A: 4 32-bit words (16 bytes).

This is both the program unit size and required alignment.

The MCU itself cannot move 16 bytes at once, so it writes 4 32-bit words into successive addresses.

After the 4th write, programming of the whole 16-byte unit starts automatically.

https://github.com/STMicroelectronics/STM32CubeH7/blob/4fdaa91bd55f9b4fc5c03fbc929b93566acea76e/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c#L244-L259

So yes, the size must be multiple of 16 bytes.

You don't have to pad the image file to 16 bytes, the padding can be added by the updater program.

Or 0xFF, to attain the desired lengths/widths

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for replying!

You don't have to pad the image file to 16 bytes, the padding can be added by the updater program.

How can it be done?

Thanks for your help.

Check linker script alignment directives.

Do some simple STDIO file manipulation in C if you have too.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..