2018-11-22 08:24 PM
Hi all,
I am using stm32l486 MCU and trying to use stmcube internal flash example code. As i see we have API "HAL_FLASH_Program" to program word or double word. Is it possible to write byte data by doing type casting and increasing the address by 1?
Could anyone help on this.
Thanks,
John
2018-11-22 10:30 PM
Flash usually has an unprogrammed value of 0xFF (per byte). So setting bytes of a word you do not want to program to 0xFF will do the job. The hardware supports only word or double word write, so type casting will not work.
If a Flash cell contains 0xFF, you can "program" it to 0xFF as often as you want. Once the value of a bit is 0, it can not be changed until you erase (usuall the whole block).
There <<are>> vendors that return 0x00 for unprogrammed internal Flash, and programming will set bits to 1. So reading datasheets is a good practice.
2018-11-26 08:36 PM
Hi @Community member :
Thanks for the reply.
Can I combined the bytes and write as a word or double word as below:
data32 = wr_buff[3] | (wr_buff[2]<<8) | (wr_buff[1]<<16) | (wr_buff[0]<<24);
HAL_FLASH_Program(TYPEPROGRAM_WORD, Address, data32);
Thanks,
John
2018-11-26 09:04 PM
Hi,
If I am not wrong I think stm32l4 series supports only double-word (64-bit) program. So can i combine as below:
data64 = wr_buff[7] | (wr_buff[6]<<8) | (wr_buff[5]<<16) | (wr_buff[4]<<24) | (wr_buff[3]<<32) | (wr_buff[2]<<40) | (wr_buff[1]<<48) | (wr_buff[0]<<56);
but the shift count is too large.
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, data64);
2018-11-26 10:09 PM
I didn't work with the L4 yet.
Shifting is one way to combine the data. Not sure what you mean with "too large".
Another option would be a union, laying a 46 bit variable and a byte array "on top" of each other.
2018-11-27 01:22 AM
The way the ECC works it does not permit a single byte write, or write to unaligned memory addresses.
2018-11-27 01:24 AM
You have the byte order backward and would need to cast values to uint64_t before shifting.
2018-11-27 01:50 AM
Many thanks @Community member