2020-05-28 09:49 AM
Hello everyone!
I am trying to copy RAM data to FLASH. I am using STM32L412KB evaluation module. I have made a USB of my own. I am able to talk over the USB. It's a 34Kb mass storage device. I can make a .txt file and store it but, every time I connect the USB after power cycle, it has to be formatted as everything is in the RAM. Basically, I want my USB to use the FLASH storage instead of RAM. So, there's 2 things here that I have to figure out.
Firstly, I'll connect my USB to the computer, make a .txt file and save it. Now, I'd copy the entire RAM to FLASH through a memcpy or something. HOW?
Secondly, I'll want my USB to use Flash storage instead of RAM. With flash having all the RAM data, it'll now be able to retain data after power cycle. HOW?
Thank you!
2020-05-28 10:02 AM
In short, you need to:
Look at the HAL_FLASH functions.
2020-05-28 10:37 AM
The memory needs to be in an erased state, you get one shot of writing each "line"
Here writing memory on an L432, should be a close proxy, but surely the L4Cube libraries have examples
void FLASH_ProgramBuffer(uint32_t Address, uint32_t Size, uint8_t *Buffer)
{
uint64_t *p = (uint64_t *)Buffer;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
while(Size)
{
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, *p++) != HAL_OK)
{
// Fail Handler
break;
}
Address += 8;
Size -= min(8, Size);
}
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
}