stlink icon indicating copy to clipboard operation
stlink copied to clipboard

[feature] Add utility to flash to STM32 data EEPROM area

Open dflogeras opened this issue 10 years ago • 13 comments

It would be great to have a command line utility to flash a binary file directly to the data EEPROM in STM32 devices (ie address starting 0x8080000 on the STM32Lxx devices). I use this to store things like a device serial number, which is separate and distinct from the program EEPROM version. Currently I write a small program to store what I need in the data EEPROM, then replace it with the real firmware, but it would be good to eliminate this step and just use stlink to do it.

dflogeras avatar Aug 18 '15 19:08 dflogeras

A related feature would be the capability to erase the EEPROM space, the bulk erase presently only clears the main FLASH.

niallp avatar Dec 15 '15 23:12 niallp

Had a similar requirement for an STM32L051 device. While searching for methods to do the same, came across the following.. https://www.purplealienplanet.com/node/56

Based on the approach mentioned in that page, made some modifications in order to use the existing flash write functions to program the EEPROM. What I did was,

  1. Added EEPROM base address, size and page size fields to the device parameter structures.
  2. In main(), after ruling out flash & RAM as destinations for write operation, one more check is performed to see if it is a valid EEPROM address for the connected device.
  3. If yes, the flash params (base, size and page size) of the _stlink structure (sl) are overwritten with the EEPROM params and the existing flash write APIs are used for writing to EEPROM.

I was able to successfully write to the EEPROM of the following STM32L0 devices a. STM32L031K6 (Nucleo 32 board) b. STM32L051K8 (custom board)

The changes are available in the fork I created. https://github.com/manuvelayudhan/stlink

If someone can review the same to verify if this is the right approach to the problem, it will be helpful.

Possible improvements are

  1. Instead of using the existing flash write APIs, a new set of dedicated EEPROM write APIs can be added.
  2. Current version will work for STM32L0 category 2/category 3 devices only.

manuvelayudhan avatar Feb 27 '18 09:02 manuvelayudhan

@manuvelayudhan your fork works for me to allow for eeprom writing, would be nice to see it pulled into mainline.

niallp avatar Jun 25 '18 20:06 niallp

Not sure if the current implementation is the best possible / correct one.. Any suggestions to improve it? Or should I just create a pull request from the current state?

manuvelayudhan avatar Jun 26 '18 06:06 manuvelayudhan

@manuvelayudhan ... I haven't looked too deeply but it seems a fairly minor tweak for useful functionality, all I'd suggest is merging in master and making sure nothing breaks in the latest (didn't see anything obvious).

niallp avatar Jun 26 '18 17:06 niallp

@dflogeras @manuvelayudhan @niallp: I believe this feature is still missing. What is the current state of this for all of you?

Nightwalker-87 avatar Mar 20 '20 11:03 Nightwalker-87

I agree this is unimplemented, but I have no opinion on how to proceed. In recent times, when I've needed said function, I've had access to a windows computer and just used ST's utility to do so.

dflogeras avatar Mar 20 '20 15:03 dflogeras

I see, but it may be useful for others. This makes me feel like we should leave this open, but of course can keep you out of the topic for the ongoing conversation.

Nightwalker-87 avatar Mar 20 '20 16:03 Nightwalker-87

On 2020-03-20 9:02 a.m., Nightwalker-87 wrote:

I see, but it may be useful for others. This makes me feel like we should leave this open, but of course can keep you out of the topic for the ongoing conversation.

I've used the patch by Manu when I've needed it though haven't touched it for a while. It would be nice to see the functionality in the mainline.

            ... Niall

niallp avatar Mar 23 '20 00:03 niallp

This should better go into the code. I'm not so happy if such workarounds remain present for too long. As it reads, this could also be an ordinary feature.

Nightwalker-87 avatar Mar 23 '20 15:03 Nightwalker-87

@Ant-ON: Is there still a reasonable way of implementing this after the recent contributions to the st-flash source code? Unfortunately @manuvelayudhan seems to be inactive by now, but the patch is still present in his fork.

Nightwalker-87 avatar May 02 '21 19:05 Nightwalker-87

@Nightwalker-87 Doesn't look like a good implementation https://github.com/manuvelayudhan/stlink/commit/fc1b5fb2188f3bff548536dbabdffe4283546326

Ant-ON avatar May 04 '21 05:05 Ant-ON

Hm, ok. Thanks for the feedback. Maybe someone else has a better idea then.

Nightwalker-87 avatar May 04 '21 16:05 Nightwalker-87

Closing this issue due to inactivity and in relation to the given feedback above.

Nightwalker-87 avatar Aug 27 '22 09:08 Nightwalker-87