Reading "User data storage option bytes"?

ramimo
Thu Jul 27, 2017 12:15 pm
Hi,

the STMF1 has two special bytes, called “User data storage option bytes”. You can write them with the Flash Loader Demonstrator. That would be highly useful for special versions, at least for me :) Unfortunately, I did not find any hint on how to read these two bytes at runtime. Any ideas?


martinayotte
Thu Jul 27, 2017 1:20 pm
[ramimo – Thu Jul 27, 2017 12:15 pm] –
the STMF1 has two special bytes, called “User data storage option bytes”.

I don’t see any such references in datasheets, where did you saw that other than Flash Loader Demonstrator ?
Perhaps it is simple bytes written somewhere at the end of uploaded firmware …


zmemw16
Thu Jul 27, 2017 2:01 pm
@ramimo
googled “Flash Loader Demonstrator User data storage option bytes”
first answer http://www.st.com/resource/en/user_manu … 171488.pdf
basic search, so not too difficult
stephen

martinayotte
Thu Jul 27, 2017 2:30 pm
[zmemw16 – Thu Jul 27, 2017 2:01 pm] –
basic search, so not too difficult

But this doesn’t provide of any infos where those bytes are located in the chip, for example in STM32F103C8.


ramimo
Thu Jul 27, 2017 2:31 pm
@martinayotte I found only some doc about the Demonstrator. No hint where it is stored or if there is a special access method or address on where to find these bytes.

@zmemw16: It is funny when some people think that they are the only one who know about Google. Yes, I googled for about 30 minutes. Yes, I found the docs about the Demonstrator (after about 10 seconds). Yes, the Demonstrator can read and write these two bytes. And no, there is no information whatsoever on how you can do that at runtime. So I posted my question here.


martinayotte
Thu Jul 27, 2017 2:36 pm
Ok ! I think I’ve found it here at page 20 :

http://www.st.com/content/ccc/resource/ … 283419.pdf

0x1FFFF804

EDIT : BTW, the 0x1FFFF804 is for STM32F1xx, for the F4xx it seems to be 0x1FFFC004


Rick Kimball
Thu Jul 27, 2017 2:55 pm
If you don’t want to write any code you could usean stlink device with either openocd or BMP.

$ openocd -f ebay_f103c8_micro.cfg -c ‘init’ -c ‘stm32f1x options_read 0’ -c ‘exit’
Open On-Chip Debugger 0.10.0+dev-00096-gf605a23 (2017-04-22-13:47)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v28 API v2 SWIM v18 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 0.007864
Error: target voltage may be too low for reliable debugging
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : device id = 0x20036410
Info : flash size = 64kbytes
Option Byte: 0x3fffffc
Readout Protection Off
Software Watchdog
Stop: No reset generated
Standby: No reset generated
User Option0: 0xff
User Option1: 0xff
$


ramimo
Thu Jul 27, 2017 7:12 pm
@martinayotte, no idea how you can know where that’s documented, but thanks!

martinayotte
Thu Jul 27, 2017 7:36 pm
I did figured out after few minutes of googling, then I found the registers address in STM PDF provide above.

zmemw16
Thu Jul 27, 2017 7:50 pm
i’ve both the reference & programming manuals, never thought to look in them – strange :idea:
srp

ramimo
Thu Jul 27, 2017 9:43 pm
Just to be a little bit of help:

#define USERDATASTORAGEOPTIONSBYTE1 *((byte*)0x1FFFF804)
#define USERDATASTORAGEOPTIONSBYTE2 *((byte*)0x1FFFF806)

That might be useful for the STM32 Arduino libs. With better naming, of course.

Thanks :)


RogerClark
Thu Jul 27, 2017 10:03 pm
Can you just read and write to these locations, or does a page of flash ( or similar ) need to be unlocked first

Is there a limit to the number of times they can be written to, e.g. Like the number of erases for pages of flash


ramimo
Fri Jul 28, 2017 8:45 am
I am not a flash expert, but I am 100% sure that you can write these bytes without writing the whole page. It’s possible that this specific flash page, with all the important flags, is write protected nomatterwhat, until you set the boot jumpers accordingly.

For me, reading these bytes is all I want right now. _Setting_ them would be great because they are not erased when you flash a new program on the STM32.


RogerClark
Fri Jul 28, 2017 10:37 am
You can also use the EEPROM library which uses Flash to emulate the EEPROM on AVR and does not normally get overwritten as you can pick a flash page at the top of the available Flash, which won’t get touched unless your program takes up all the pages in flash.

There are also a few bytes of special ram (I forget their name) which survive a soft reboot, but are not retained if you power cycle the board


ramimo
Fri Jul 28, 2017 7:09 pm
I wanted to write that I am 100% sure that you can’t write these bytes without writing the whole page. About the EEPROM: it’s definitely worth a try, especially because almost all STM32F103 have 128kb. Nothing for period updates, but good for eg. saving configurations.

Rick Kimball
Fri Jul 28, 2017 7:28 pm
PM0075 enumerates the required steps to change the user option bytes

“2.3.5 Option byte programming
The option bytes are programmed differently from normal user addresses. The number of
option bytes is limited to 8 (4 for write protection, 1 for read protection, 1 for configuration
and 2 for user data storage). After unlocking the FPEC, the user has to authorize the
programming of the option bytes by writing the same set of KEYS (KEY1 and KEY2) to the
FLASH_OPTKEYR register to set the OPTWRE bit in the FLASH_CR register (refer to
Section 2.3.1 for key values). Then the user has to set the OPTPG bit in the FLASH_CR
register and perform a half-word write operation at the desired Flash address.

… that and lots more to read

libopencm3 seems to have some code to deal with option bytes

https://github.com/libopencm3/libopencm … f01.c#L178


Leave a Reply

Your email address will not be published. Required fields are marked *