Flash access data

1. Experimental purpose

Use the flash storage function of the microROS control board to learn the data saving function of ESP32 when it is powered off.

 

2. Hardware connection

As shown in the figure below, the microROS control board integrates the ESP32-S3-WROOM-1U-N4R2 core module. It not only has internal space, but also has an additional 4MB FLASH program space and 2MB PSRAM memory space. You only need to connect the type-C data cable Connect the computer to the microROS control board as a firmware burning function.

image-20240112174901940

 

3. Core code analysis

The virtual machine path corresponding to the program source code is:

Initialize the flash chip. Since the pins of the flash chip have been reserved internally in ESP32-S3, there is no need to separately configure the pins of the flash chip when using the ESP32-S3-WROOM core module.

There are many types of flash chip access, and different keys are used to distinguish different data locations. Here we take reading an int32 type of data from flash as an example.

Write an int32 type data to the flash chip.

Read a uint16 data from the flash chip.

Write a uint16 data to the flash chip.

Read a piece of data from the flash chip.

Write a piece of data to the flash chip.

In order to distinguish the area where flash stores data, the following different FKEYs are defined to distinguish different data.

For ease of use, add the key component key to the flash project, and then modify the value stored in the flash by reading the status of the key.

 

4. Compile, download and flash firmware

Use a Type-C data cable to connect the virtual machine/computer and the microROS control board. If the system pops up, choose to connect to the virtual machine.

Activate the ESP-IDF development environment. Note that every time you open a new terminal, you need to activate the ESP-IDF development environment before compiling the firmware.

Enter the project directory

Compile, flash, and open the serial port simulator

If you need to exit the serial port simulator, press Ctrl+]

 

5. Experimental results

The serial port simulator prints the "hello yahboom" greeting. Since the blob in the flash is read for the first time as unconfirmed data, after the program is burned for the first time, the read blob line reads garbled characters. You only need to press the KEY1 key to refresh the blob data in the flash, and the next time you turn on the computer No garbled characters will be read.

image-20240112182437932

At this time, you can press the BOOT button, and the saved u16 value will increase. If you press the KEY1 key, the saved blob value will increase.

After pressing the reset key, the currently written data is read.

image-20240112182836640