User Tools

Site Tools


how_to_write_a_parameter_in_the_flash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

how_to_write_a_parameter_in_the_flash [2016/08/10 16:45] romainhow_to_write_a_parameter_in_the_flash [2018/05/22 10:33] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== How to write a parameter in the flash ======
  
 +----
 +===== Description =====
 +
 +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 :
 +
 +{{ ::hight.png |}}
 +
 +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 | 0x**07056789** |
 +but :
 +^ Address    | 0x0807F000 | 0x0807F001 | 0x0807F002 | 0x0807F003 | 0x0807F004 |
 +^ Data       | 0x02001234 | 0x**89**020012 | 0x**6789**0200 | 0x**056789**02 | 0x**07056789** |
 +So we must take it into account when writing to the flash.
 +
 +
 +For more information concerning the flash programming refer to the [[http://www.st.com/web/en/resource/technical/document/programming_manual/CD00283419.pdf|programming manual]].
 +
 +----
 +
 +
 +===== C Application Programming Interface =====
 +
 +To read value from address 0x0803F80F :
 +<code c>
 +// We just use a pointer to access to value
 +uint32_t value = *(uint32_t*)(uint32_t)(0x0803F80F);
 +</code>
 +
 +To write value at address 0x0803F80F :
 +<code c>
 +#include <libstm32/stm32f10x_flash.h>
 +
 +uint32_t value = 20;
 +FLASH_Unlock();
 +// We must erase the page containing 0x0803F80F before to be able to write values
 +FLASH_ErasePage(0x0803F800);
 +FLASH_ProgramWord(0x0803F80F,value);
 +FLASH_Lock();
 +</code>
 +
 +----
 +
 +===== 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/Makefile.mk becomes :
 +
 +<code bash>
 +stm32flash -w $(PROJECT).bin -v -e 100 -b 115200 -g 0x0 /dev/tty$(USB)
 +</code>
 +
 +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 [[http://manpages.ubuntu.com/manpages/wily/man1/stm32flash.1.html|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 by 127.0.0.1