2

I have some hardware that has an STM32 chip in it. I normally use an ST Link/V2 USB programmer and STM32CubeProgrammer to flash the firmware file. In this case, it'a 152KB file with the extension .out.

Flashing via STM32CubeProgrammer works fine. I'm now trying to automate the process and write a bash script to flash the devices using stlink tools.

I try to use the command st-flash --reset write filename.out 0x08000000 but receive the errors:

2023-03-23T16:33:28 INFO common.c: Attempting to write 156016 (0x26170) bytes to stm32 address: 134217728 (0x8000000)
2023-03-23T16:33:28 ERROR common.c: addr too high
2023-03-23T16:33:28 INFO common.c: Go to Thumb mode

The output from the STM32CubeProgrammer software when successfully flashing the file says:

  16:42:43 : Memory Programming ...
  16:42:43 : Opening and parsing file: node_1_15.out
  16:42:43 :   File          : filename.out
  16:42:43 :   Size          : 12.80 KB 
  16:42:43 :   Address       : 0x08000000 
  16:42:43 : Erasing memory corresponding to segment 0:
  16:42:43 : Erasing internal memory sectors [0 102]
  16:42:43 : Download in Progress:
  16:42:44 : File download complete

As far as I can tell, the starting memory address is the same, the file is the same and it's the same programmer. I can't see why STM32CubeProgrammer shows a much smaller file size however (12.8KB vs 152KB).

Can anyone offer any guidance as to how I can proceed?

fistameeny
  • 1,048
  • 2
  • 14
  • 27
  • It sounds like your `.out` file has other stuff in it than just the binary data of your program, e.g. headers, debug info, etc. Maybe you can convert it to a `.bin` file with `objcopy` then program that? – pmacfarlane Mar 23 '23 at 17:37
  • Yes, that's a very good point - I suspect it may have a bunch of headers and debug info in it. With your pointer, I've tried with another variant I have of the file and have managed to see some blocks being flashed. It still needs some tweaking, but thank you, that was the info I needed. – fistameeny Mar 23 '23 at 20:12
  • Looking at [the documentation](https://github.com/stlink-org/stlink/blob/develop/doc/tutorial.md) for the `stlink` tool, it looks like it only supports `binary` and `ihex` files. – pmacfarlane Mar 23 '23 at 20:26

1 Answers1

1

I'm not entirely sure what format your filename.out file is, but it could be the very old a.out format that old versions of Unix used. It has mostly been supplanted by things like the ELF file format.

If that's the case, it contains more than just the raw binary data that you need to program into FLASH. It probably has some kind of header, and possible debugging information too, which is why it is much larger.

STM32CubeProgrammer (and STM32CubeIDE) can program various types of files onto an STM32, such as .elf files, .bin files, and, it appears, .out files. I'd believe that the actual binary data is only 12.8 KB.

However, the stlink tool only supports binary and ihex files. From the documentation:

--format st-flash Specify file image format to read or write. Valid formats are binary and ihex.

So I'd guess the st-flash tool is treating your file as if it was a binary, and trying to program the whole file into flash.

Therefore, you'll either need to convert your .out file into one of those formats, or, if you are in charge of the build process for this program, modify it to generate one as part of the build. If you're using the GNU binutils then objcopy can probably do it for you.

pmacfarlane
  • 3,057
  • 1
  • 7
  • 24
  • Thanks for your detailed reply. I'm flashing firmware produced by someone else, but should be able to ask them to adapt the process. In the meantime, I'll try to see if I can use objcopy to convert the existing file somehow. – fistameeny Mar 27 '23 at 09:41