Author Topic: STM32 HAL FLASH  (Read 7241 times)

0 Members and 1 Guest are viewing this topic.

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
STM32 HAL FLASH
« on: September 17, 2022, 09:03:16 pm »
Hi all,

I'm working on a Nucleo-32L432KC. I want to save one variable (two bytes) in the flash memory and read it back to that variable at power-on. (There's no EEPROM internally in the uc, or externally on my project).

There's very basic information about STM32 HAL FLASH library in the HAL user manual
https://www.st.com/resource/en/user_manual/um1725-description-of-stm32f4-hal-and-lowlayer-drivers-stmicroelectronics.pdf

I found this

https://www.st.com/resource/en/application_note/an4894-eeprom-emulation-techniques-and-software-for-stm32-microcontrollers-stmicroelectronics.pdf

It's all a bit daunting to me, so I'm looking for clearer instructions to get started. Any tips or advice where to start actually?



 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30325
  • Country: nl
    • NCT Developments
Re: STM32 HAL FLASH
« Reply #1 on: September 17, 2022, 09:08:26 pm »
Use the flash controller directly. If it is the same as on the STM32F103, then it is easier to just read/write to the registers compared to using the HAL.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
Re: STM32 HAL FLASH
« Reply #2 on: September 17, 2022, 09:14:49 pm »
And is there any documentation for that available?
 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 638
  • Country: be
Re: STM32 HAL FLASH
« Reply #3 on: September 17, 2022, 09:26:33 pm »
Make sure you write 8 bytes at a time, see Section 3.3.7 of the reference manual.
 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 638
  • Country: be
Re: STM32 HAL FLASH
« Reply #4 on: September 17, 2022, 09:30:42 pm »
And is there any documentation for that available?

Vendor's web site is quite handy.
 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 638
  • Country: be
Re: STM32 HAL FLASH
« Reply #5 on: September 18, 2022, 02:57:16 pm »
You can find some examples of accessing flash via STM32 HAL here: https://cpp.hotexamples.com/examples/-/-/HAL_FLASH_Lock/cpp-hal_flash_lock-function-examples.html

Basically, you would need three functions:
Code: [Select]
HAL_FLASH_Unlock()
HAL_FLASH_Program()
HAL_FLASH_Lock()
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
Re: STM32 HAL FLASH
« Reply #6 on: September 18, 2022, 05:09:33 pm »
And is there any documentation for that available?

Vendor's web site is quite handy.

Personal opinion, but silicon makers don't really excel in clear easy-to-understand documentation, especially if you want to know how to start using the part (for the first time). They are usually more of a listing of features and capabilities, rather than a manual explaining how to use/connect it and how to use it in specific situations (with appropriate examples).
 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 638
  • Country: be
Re: STM32 HAL FLASH
« Reply #7 on: September 18, 2022, 06:58:34 pm »
Personal opinion, but silicon makers don't really excel in clear easy-to-understand documentation, especially if you want to know how to start using the part (for the first time). They are usually more of a listing of features and capabilities, rather than a manual explaining how to use/connect it and how to use it in specific situations (with appropriate examples).

It depends on the vendor. Some have rather clear documentation, like Nordic Semi. Some have ambiguous one written in poor English and lacking crucial details.

You would look for at least a reference manual for your part. STM32L432 is 1600 pages long, compared to 150-odd pages of data sheet. Then, there are application notes. Again, of varying quality.

STM suggests the developer to use their STM32Cube to configure your project and generate code. Corresponding documentation can be found here.

There is STM repository on the github.

Yes, there is always learning curve, and the amount of time you spend learning depends greatly on your prior experience. "First ever MCU" -- you could easily be lost in details and frustrated by lack of examples. "Yet another MCU" -- you know exactly which section to navigate to for the clock tree or DMA channel mapping.
« Last Edit: September 18, 2022, 07:06:33 pm by eutectique »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30325
  • Country: nl
    • NCT Developments
Re: STM32 HAL FLASH
« Reply #8 on: September 18, 2022, 07:36:45 pm »
From what I've seen ST definitely isn't in the bracket of 'clear documentation'. HAL documentation seems to be Doxygen crap so not very useful. And it looks like the API has changed a few times so many examples are outdated / irrelevant. My method for writing code for STM32 parts is to look at the HAL code for the details and then write my own 'driver' in a simple and clear way.

If you want excellent documentation, switch to the LPC ARM microcontrollers from NXP. ST's documentation is a cold shower in comparison; a lot of details are missing.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6928
  • Country: es
Re: STM32 HAL FLASH
« Reply #9 on: September 19, 2022, 08:07:43 am »
Remember you also have the RTC backup registers, 128bytes that are kept by Vbat.
In low pin count stm32s Vbat and vdd are internally connected, so you would have to add a small battery or supercap with a series charging resistor, I think the user must detect external VDD somehow and enter Vbat mode by SW, that way only the RTC circuitry is kept.
Not sure, never used it, but it's a userful feature!
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 133
  • Country: be
Re: STM32 HAL FLASH
« Reply #10 on: September 19, 2022, 08:43:45 pm »
Thanks. Don't think it's an option for my current project, but something to keep in mind. (Vbat is indeed not an external pin on my device and the entire design is not really made to be very low power)....
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->