2024-11-17 05:23 AM - last edited on 2024-11-18 04:12 AM by Andrew Neil
Hello, everybody! I'm relatively new to STM32 microcontrollers and have a moderate knowledge of C programming and a fair understanding of electronics.
Over the past few months, I've been learning to properly set up STM32F4 series MCUs, specifically the F401RET6U (Nucleo board) and the F411CEU6 (Black Pill board), using bare-metal approach. I've spent considerable time watching tutorial videos and reading online guides to help me get started.
I'm now at a point where I can set up the clock and read from and write to GPIOs.
From what I understand, setting up peripherals involves configuring the correct values in the appropriate registers in the right order.
I would like to learn how to use embedded flash memory to store information that needs to be retained after a power loss. So far, I've struggled to find a guide or tutorial that I can fully understand. Could someone please assist me with this or point me in the right direction?
Thank you very much, and have a blessed week, everyone!
2024-11-17 08:29 AM
Bare metal means you read the Reference Manual (RM) and protocol docs related to the bus in question.
You can check the HAL / CubeF4 examples for writing the Internal FLASH, once you have that working you can review the library source to confirm the mechanics described in the RM
2024-11-17 09:30 AM
> how to use embedded flash memory to store information that needs to be retained after a power loss.
Can you describe your requirements with more details? Do you want to save small amounts of data not frequently, for example calibration or configuration data - or make something like logger or recorder? For the former you will find many examples on github and youtube. But for the latter use the internal flash of STM32 is not optimal.
2024-11-18 04:11 AM
@HellasT wrote:From what I understand, setting up peripherals involves configuring the correct values in the appropriate registers in the right order.
Yes, that's a very good summary!
@HellasT wrote:I would like to learn how to use embedded flash memory to store information that needs to be retained after a power loss. So far, I've struggled to find a guide or tutorial that I can fully understand.!
As @Tesla DeLorean said, the whole point of "The Bare Metal Way" is that you commit to studying the device documentation (Datasheet, Reference Manual, Application Notes, etc) in detail, understanding it, and then implementing what it tells you.
"The HAL Way" exists so that you don't have to go into all that arcane detail.
The HAL is all open-source - so you can always look into how it does its stuff at the register level.
See this current thread on using Flash for non-volatile storage on STM32F4:
@HellasT wrote:F411CEU6 (Black Pill board)
Note that there is a high likelihood that the STM32 on a Black (or Blue or other coloured) Pill board will not be genuine ...
2024-11-27 01:39 PM
Sorry for my late response. Yes that i do. I read the reference manuals. I've learned for example how to setup the latency and prefetch. Im not finished with the reference manual yet though.
2024-11-27 01:41 PM
That's right. To save small amount of data like for example a user defined pin number for an alarm system.
2024-11-27 01:58 PM
I sure try hard.As @Tesla DeLorean said, the whole point of "The Bare Metal Way" is that you commit to studying the device documentation (Datasheet, Reference Manual, Application Notes, etc) in detail, understanding it, and then implementing what it tells you.
"The HAL Way" exists so that you don't have to go into all that arcane detail.
The HAL is all open-source - so you can always look into how it does its stuff at the register level
HAL is awesome. Its just me thinking that if i try hard to learn "bare metal techniques" it will be easier and more clear for me to use HAL later on.
Im going to check it out soon !
Note that there is a high likelihood that the STM32 on a Black (or Blue or other coloured) Pill board will not be genuine ...
Agreed but to play with and learn, i use what i can get my hands on. The original gear which by the way i usually get from reputable dealers like mouser etc, i keep for projects to be developed and implemented
2024-11-27 02:17 PM
Thank you all for taking the time to reply. I truly value your input and understand how precious your time is. Although I’m not a professional, I’m putting a lot of effort into learning how to work with STM32s properly. Your guidance and suggestions mean a great deal to me. Thank you again for your support!
2024-11-27 03:52 PM
For the F4's use some of the earlier sectors for smaller data.
The primary sector needs to manage the initial boot, but subsequent 16KB and 64KB are better than 128KB
Sectors need to be erased before use. The writes need to be aligned, here at least 32-bits, other architectures it's wider.
2024-12-01 03:06 PM
Well said !
I am looking for ways to bind the sector that i will be using so that the compiler will not use it for any other purpose.
Im planning to use F401RET6U's sector 3 which is the last 16k sector. I have actually been thinking to declare an array that it's start address would be the start address of sector 3 and initialize it with 0xFF. something like this :
const char data[16*1024] = {0xFF}; But i have no idea how to implement it.