cancel
Showing results for 
Search instead for 
Did you mean: 

Read/Write configuration data in Internal flash

Me Mostafa
Associate
Posted on February 26, 2018 at 13:56

Hello All,

I do a project for STM32f303 and I am a beginner not experienced one. I want to write configuration data in the internal flash. I used these functions for read and write.

void write_flash (uint32_t Addr, uint8_t Data1, uint8_t Data2 )

{

HAL_FLASH_Unlock();

HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, Addr, ((uint16_t)Data1 | (((uint16_t)Data2)<< 8)) );

HAL_FLASH_Lock();

}

uint8_t read_flash (uint32_t Addr)

{

return *(__IO uint8_t*)Addr;

}

I tried them and it worked well. I can modify the data and every time I power on the micro I could get my data. My question is -> 'Is this a good way forreading fromflash memory?' I did not modify the linker script and I did not use a user data section. I just make sure that my code will not reach to the pages of configuration data.

I want to understand the difference in behavior between what I did and the other way like this

MEMORY{RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 8K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 120K DATA (rwx) : ORIGIN = 0x801E800, LENGTH = 8k}/* Define output sections */SECTIONS{ .user_data : { . = ALIGN(4); KEEP(*(.user_data)) . = ALIGN(4); } > DATA
__attribute__((__section__('.user_data'))) const char userConfig[64];

#cortex-m4-mcu-firmware-development #stm32f3 #mcu
0 REPLIES 0