User Tools

Site Tools


How to write a parameter in the flash


The QuimDC is using a STM32F103RCT7 processor and have 512KiB flash memory. The processor is a high-density device and its layout memory is as in the following table :

The firmware is flash at the beginning i.e. at address 0x08000000. The parameters will be saved at the end of the flash.

There is a prefetch buffer (2 × 64-bit words). It means that we will not have in memory :

Address 0x0807F000 0x0807F001
Data 0x02001234 0x07056789

but :

Address 0x0807F000 0x0807F001 0x0807F002 0x0807F003 0x0807F004
Data 0x02001234 0x89020012 0x67890200 0x05678902 0x07056789

So we must take it into account when writing to the flash.

For more information concerning the flash programming refer to the programming manual.

C Application Programming Interface

To read value from address 0x0803F80F :

// We just use a pointer to access to value
uint32_t value = *(uint32_t*)(uint32_t)(0x0803F80F);

To write value at address 0x0803F80F :

#include <libstm32/stm32f10x_flash.h>
uint32_t value = 20;
// We must erase the page containing 0x0803F80F before to be able to write values

Keeping parameters after the QuimDC has been flashed

We use the stm32flash utility to flash the QuimDC. By default, it erase all the content of the flash before writing the new firmware. To keep some of the flash content we can use the -e option :

-e num Specify to erase only num pages before writing the flash.
Default is to erase the whole flash. With -e 0 the flash would
not be erased.

For example, if we want to erase only the first 100 pages, the command in common/make/ becomes :

stm32flash -w $(PROJECT).bin -v -e 100 -b 115200 -g 0x0 /dev/tty$(USB)

There is a Makefile flag named KEEP_USER_CONFIG that allows the user to keep all his configurations when performing a “make serial” command.

For more information concerning the stm32flash command refer to man page.

Cyclic Redundancy Check

A Cyclic Redundancy Check (CRC) is used to check whether or not the parameters are corrupt. Beware to update it when new parameters are added to the flash. (!!! Trying to compute the CRC on a too large amount of words make the cli freeze !!!)

Parameters storage layout

The first time parameters are saved, the ADDR_CHECK must be set to 0.

Name Address Description
ADDR_CHECK_PARAMETERS_INIT 0x0807FFF8 Check whether or not they are parameters
ADDR_PARAMETERS_CRC 0x0807FFFC Cyclic Redundancy Check of the parameters page

Each parameter will be assigned an unique address in memory.

Name Address
MotorRightCanDataWatchdogValue 0x0807F800
MotorRightSpeedPidP 0x0807F804
MotorRightSpeedPidI 0x0807F808
MotorRightSpeedPidD 0x0807F80C
MotorRightSpeedPidDo 0x0807F810
MotorRightSpeedPidShift 0x0807F814
MotorRightSpeedPidUIAntiWULimit 0x0807F818
MotorRightCurrentPidP 0x0807F81C
MotorRightCurrentPidI 0x0807F820
MotorRightCurrentPidD 0x0807F824
MotorRightCurrentPidDo 0x0807F828
MotorRightCurrentPidShift 0x0807F82C
MotorRightCurrentPidUIAntiWULimit 0x0807F830
MotorRightPositionPidP 0x0807F834
MotorRightPositionPidI 0x0807F838
MotorRightPositionPidD 0x0807F83C
MotorRightPositionPidDo 0x0807F840
MotorRightPositionPidShift 0x0807F844
MotorRightPositionPidUIAntiWULimit 0x0807F848
MotorRightControlLoopFunction 0x0807F84C
MotorRightResistanceMotor 0x0807F850
MotorRightKvMotor 0x0807F854
MotorRightTicksPerTurnMotor 0x0807F858
MotorRightMaxVoltage 0x0807F85C
Name Address
MotorLeftCanDataWatchdogValue 0x0807F860
MotorLeftSpeedPidP 0x0807F864
MotorLeftSpeedPidI 0x0807F868
MotorLeftSpeedPidD 0x0807F86C
MotorLeftSpeedPidDo 0x0807F870
MotorLeftSpeedPidShift 0x0807F874
MotorLeftSpeedPidUIAntiWULimit 0x0807F878
MotorLeftCurrentPidP 0x0807F87C
MotorLeftCurrentPidI 0x0807F880
MotorLeftCurrentPidD 0x0807F884
MotorLeftCurrentPidDo 0x0807F888
MotorLeftCurrentPidShift 0x0807F88C
MotorLeftCurrentPidUIAntiWULimit 0x0807F890
MotorLeftPositionPidP 0x0807F894
MotorLeftPositionPidI 0x0807F898
MotorLeftPositionPidD 0x0807F89C
MotorLeftPositionPidDo 0x0807F8A0
MotorLeftPositionPidShift 0x0807F8A4
MotorLeftPositionPidUIAntiWULimit 0x0807F8A8
MotorLeftControlLoopFunction 0x0807F8AC
MotorLeftResistanceMotor 0x0807F8B0
MotorLeftKvMotor 0x0807F8B4
MotorLeftTicksPerTurnMotor 0x0807F8B8
MotorLeftMaxVoltage 0x0807F8BC

how_to_write_a_parameter_in_the_flash.txt · Last modified: 2018/05/22 10:33 (external edit)