cancel
Showing results for 
Search instead for 
Did you mean: 

flashing STM32 - BIN specification

blul
Associate II
Posted on March 07, 2014 at 18:23

Hi. I'm writing a pc tool for flashing STM32F407 using USART. I got familiar with AN2606 (bootloader) and AN3155 (USART protocol). One thing I don't know is the BIN file specification. Can I just write to STM32 the content of BIN file? Or maybe is there any other data except program code in it? Anybody can help me?

#flashing-stm32 #bin-file
7 REPLIES 7
trevor23
Associate III
Posted on March 07, 2014 at 18:30

Normally a bin file is just raw data you write to flash as is. There is no addressing or other info in the file, just binary program data. So nice and easy for your program to write using the ST bootloader.

blul
Associate II
Posted on March 07, 2014 at 18:38

Thanks for the reply.

When I use Flash Loader Demo, then I choose an option concerning erasing: ''erase only necessary pages'', so I thought there is some other information in BIN file like memory address.
chen
Associate II
Posted on March 07, 2014 at 18:45

Hi

''BIN'' is short for binary. As Trevor says - it is just the raw binary (assembler op codes).

''When I use Flash Loader Demo, then I choose an option concerning erasing: ''erase only necessary pages'', so I thought there is some other information in BIN file like memory address.''

I bet the Erase will not work is there is no file loaded - it must be measuring the size of the raw binary and erasing the number of flash Sectors to match.

Andrew Neil
Evangelist III
Posted on March 07, 2014 at 20:43

''it is just the raw binary (assembler op codes)''

No, raw binary is not assembler opcodes!

Raw binary is the machine instructions - and a BIN file will also contain some data...
blul
Associate II
Posted on March 07, 2014 at 20:54

Can you give me more details about BIN file? What kind of data? Do you know BIN specification?

Posted on March 07, 2014 at 21:05

It's a collection of 8-bit bytes, nothing magic, it doesn't have a ''definition''. You have to specify the address the data resides at, it's not in the file. The size can be inferred from the file system.

Can you use standard io functions? fopen?

f = fopen(''some.bin'', ''rb'');

Want to examine the content, get a file viewer or hex editor type application.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 07, 2014 at 21:12

Hello World type app .BIN dumped out

[Offset] [ Binary Data in File ] [ASCII equivalent]
00000000 : 18 04 00 20 9D 01 00 08 - 03 03 00 08 FF 02 00 08 ... ............
00000010 : 01 03 00 08 F5 01 00 08 - 1D 06 00 08 00 00 00 00 ................
00000020 : 00 00 00 00 00 00 00 00 - 00 00 00 00 E9 03 00 08 ................
00000030 : F7 01 00 08 00 00 00 00 - 09 03 00 08 AD 04 00 08 ................
00000040 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000050 : C3 01 00 08 C3 01 00 08 - F9 01 00 08 C3 01 00 08 ................
00000060 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000070 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000080 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000090 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
000000A0 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
000000B0 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
000000C0 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
000000D0 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
000000E0 : C3 01 00 08 C3 01 00 08 - 07 03 00 08 C3 01 00 08 ................
000000F0 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000100 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000110 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000120 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000130 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000140 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 05 03 00 08 ................
00000150 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000160 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000170 : C3 01 00 08 C3 01 00 08 - C3 01 00 08 C3 01 00 08 ................
00000180 : C3 01 00 08 C3 01 00 08 - DF F8 0C D0 00 F0 20 F8 .............. .
00000190 : 00 48 00 47 95 06 00 08 - 18 04 00 20 09 48 01 68 .H.G....... .H.h
000001A0 : 41 F4 70 01 01 60 08 48 - 80 47 08 48 00 47 00 00 A.p..`.H.G.H.G..
000001B0 : FE E7 FE E7 FE E7 FE E7 - FE E7 FE E7 FE E7 FE E7 ................
000001C0 : FE E7 FE E7 88 ED 00 E0 - B1 04 00 08 89 01 00 08 ................
000001D0 : 06 4C 07 4D 06 E0 E0 68 - 40 F0 01 03 94 E8 07 00 .L.M...h@.......
000001E0 : 98 47 10 34 AC 42 F6 D3 - FF F7 D2 FF B8 06 00 08 .G.4.B..........
000001F0 : D8 06 00 08 FE E7 70 47 - 70 47 00 00 1C B5 4F F4 ......pGpG....O.
00000200 : C0 60 00 90 02 20 8D F8 - 04 00 00 21 8D F8 06 10 .`... .....!....
00000210 : 8D F8 07 10 08 4C 8D F8 - 05 00 69 46 20 46 00 F0 .....L....iF F..
00000220 : 0D F8 07 22 09 21 20 46 - 00 F0 59 F8 07 22 0A 21 ...''.! F..Y..''.!
00000230 : 20 46 00 F0 54 F8 1C BD - 00 00 02 40 F0 B5 00 23 F..T......@...#
00000240 : 01 24 03 27 0D 68 04 FA - 03 F2 15 40 95 42 42 D1 .$.'.h.....@.BB.
00000250 : D0 F8 00 C0 5E 00 07 FA - 06 F5 2C EA 05 0C C0 F8 ....^.....,.....
00000260 : 00 C0 91 F8 04 C0 D0 F8 - 00 E0 0C FA 06 FC 4C EA ..............L.
00000270 : 0E 0C C0 F8 00 C0 91 F8 - 04 C0 BC F1 01 0F 02 D0 ................
00000280 : BC F1 02 0F 1F D1 D0 F8 - 08 C0 2C EA 05 0C C0 F8 ..........,.....
00000290 : 08 C0 91 F8 05 C0 D0 F8 - 08 E0 0C FA 06 FC 4C EA ..............L.
000002A0 : 0E 0C C0 F8 08 C0 D0 F8 - 04 C0 2C EA 02 0C C0 F8 ..........,.....
000002B0 : 04 C0 42 68 91 F8 06 C0 - 0C FA 03 FC 1F FA 8C FC ..Bh............
000002C0 : 42 EA 0C 02 42 60 C2 68 - AA 43 C2 60 CA 79 C5 68 B...B`.h.C.`.y.h
000002D0 : B2 40 2A 43 C2 60 5B 1C - 10 2B B3 D3 F0 BD 4B 07 .@*C.`[..+....K.
000002E0 : DB 0E 9A 40 C9 08 10 B5 - 00 EB 81 00 01 6A 0F 24 ...@.........j.$
000002F0 : 9C 40 A1 43 01 62 01 6A - 11 43 01 62 10 BD FE E7 .@.C.b.j.C.b....
00000300 : FE E7 70 47 70 47 70 47 - 70 47 00 00 04 4A 00 29 ..pGpGpGpG...J.)
00000310 : 11 68 01 D0 01 43 00 E0 - 81 43 11 60 70 47 00 00 .h...C...C.`pG..
00000320 : 30 38 02 40 04 4A 00 29 - 11 68 01 D0 01 43 00 E0 @.J.).h...C..
00000330 : 81 43 11 60 70 47 00 00 - 44 38 02 40 10 B5 01 21 .C.`pG..D8.@...!
00000340 : 10 20 FF F7 EF FF 01 21 - BD E8 10 40 08 46 FF F7 . .....!...@.F..
00000350 : DD BF 00 00 70 B5 21 4A - 11 68 21 4B 11 F0 0C 01 ....p.!J.h!K....
00000360 : 04 D0 5D 10 04 29 03 D0 - 08 29 03 D0 03 60 1B E0 ..]..)...)...`..
00000370 : 05 60 19 E0 19 49 09 1F - 0C 68 C4 F3 80 56 0C 68 .`...I...h...V.h
00000380 : 04 F0 3F 04 16 B1 B5 FB - F4 F3 01 E0 B3 FB F4 F3 ..?.............
00000390 : 0C 68 09 68 C4 F3 88 14 - 63 43 C1 F3 01 41 49 1C .h.h....cC...AI.
000003A0 : 49 00 B3 FB F1 F1 01 60 - 11 68 0E 4B 01 F0 F0 01 I......`.h.K....
000003B0 : 09 09 5C 5C 01 68 E1 40 - 41 60 14 68 04 F4 E0 54 ..\\.h.@A`.h...T
000003C0 : A4 0A 1C 5D 21 FA 04 F4 - 84 60 12 68 02 F4 60 42 ...]!....`.h..`B
000003D0 : 52 0B 9A 5C D1 40 C1 60 - 70 BD 00 00 08 38 02 40 R..\.@.`p....8.@
000003E0 : 00 24 F4 00 04 00 00 20 - 70 47 00 00 29 48 00 21 .$..... pG..)H.!
000003F0 : 02 68 42 F4 80 32 02 60 - 4F F4 A0 63 02 68 01 F1 .hB..2.`O..c.h..
00000400 : 01 01 12 F4 00 3F 01 D1 - 99 42 F7 D1 01 68 8A 03 .....?...B...h..
00000410 : 21 49 2F D5 20 4A 38 32 - 13 68 43 F0 80 53 13 60 !I/. JhC..S.`
00000420 : 1E 4A 13 68 43 F4 80 43 - 13 60 0A 68 0A 60 0A 68 .J.hC..C.`.h.`.h
00000430 : 42 F4 00 42 0A 60 0A 68 - 42 F4 A0 52 0A 60 0B 1F B..B.`.hB..R.`..
00000440 : 17 4A 1A 60 02 68 42 F0 - 80 72 02 60 02 68 92 01 .J.`.hB..r.`.h..
00000450 : FC D5 14 4B 40 F2 05 62 - 1A 60 0A 68 22 F0 03 02 ...K@..b.`.h''...
00000460 : 0A 60 0A 68 42 F0 02 02 - 0A 60 0A 68 C2 F3 81 02 .`.hB....`.h....
00000470 : 02 2A FA D1 0A 68 22 F4 - 00 02 0A 60 06 4A 0A 49 .*...h''....`.J.I
00000480 : 7C 32 11 60 01 68 41 F0 - 80 61 01 60 01 68 09 01 |2.`.hA..a.`.h..
00000490 : FC D5 70 47 00 38 02 40 - 08 38 02 40 00 70 00 40 ..pG.8.@.8.@.p.@
000004A0 : 08 54 40 07 00 3C 02 40 - 00 30 00 50 70 47 00 00 .T@..<.@.0.PpG..
000004B0 : 0F 48 10 B5 01 68 41 F0 - 01 01 01 60 0C 4A 00 21 .H...hA....`.J.!
000004C0 : 08 32 11 60 02 68 0B 4B - 1A 40 02 60 03 1D 0A 4A .2.`.h.K.@.`...J
000004D0 : 1A 60 02 68 22 F4 80 22 - 02 60 05 48 0C 30 01 60 .`.h''..''.`.H.0.`
000004E0 : FF F7 84 FF 05 49 4F F0 - 00 60 08 60 10 BD 00 00 .....IO..`.`....
000004F0 : 00 38 02 40 FF FF F6 FE - 10 30 00 24 08 ED 00 E0 .8.@.....0.$....
00000500 : 1F B5 4F F4 16 50 00 90 - 00 20 AD F8 04 00 AD F8 ..O..P... ......
00000510 : 06 00 AD F8 08 00 AD F8 - 0C 00 0C 20 05 4C AD F8 ........... .L..
00000520 : 0A 00 69 46 20 46 00 F0 - 19 F8 01 21 20 46 00 F0 ..iF F.....! F..
00000530 : 03 F8 1F BD 00 10 01 40 - 00 29 81 89 02 D0 41 F4 .......@.)....A.
00000540 : 00 51 01 E0 21 F4 00 51 - 81 81 70 47 02 46 00 20 .Q..!..Q..pG.F.
00000550 : 12 88 0A 42 00 D0 01 20 - 70 47 00 00 7F B5 04 46 ...B... pG.....F
00000560 : 00 8A 0D 46 20 F4 40 51 - E8 88 08 43 20 82 A0 89 ...F .@Q...C ...
00000570 : 41 F2 0C 61 88 43 A9 88 - 2A 89 11 43 6A 89 02 43 A..a.C..*..Cj..C
00000580 : 11 43 A1 81 A0 8A 20 F4 - 40 71 A8 89 08 43 A0 82 .C.... .@q...C..
00000590 : 68 46 FF F7 DF FE 1D 48 - 84 42 02 D0 1C 48 84 42 hF.....H.B...H.B
000005A0 : 01 D1 03 98 00 E0 02 98 - A1 89 09 04 00 29 00 EB .............)..
000005B0 : C0 01 01 EB 00 10 29 68 - 02 DA 4F EA 41 01 01 E0 ......)h..O.A...
000005C0 : 4F EA 81 01 B0 FB F1 F2 - 64 20 B2 FB F0 F1 4F EA O.......d ....O.
000005D0 : 01 11 4F EA 11 13 6F F0 - 18 05 6B 43 02 EB 83 02 ..O...o...kC....
000005E0 : A3 89 1D 04 4F F0 32 03 - 06 D5 03 EB C2 02 B2 FB ....O.2.........
000005F0 : F0 F0 00 F0 07 00 05 E0 - 03 EB 02 12 B2 FB F0 F0 ................
00000600 : 00 F0 0F 00 08 43 20 81 - 7F BD 00 00 00 10 01 40 .....C ........@
00000610 : 00 14 01 40 C1 F3 08 01 - 81 80 70 47 FE E7 00 00 ...@......pG....
00000620 : 01 4A 02 49 00 F0 13 B8 - 71 06 00 08 00 00 00 20 .J.I....q......
00000630 : 02 E0 08 C8 12 1F 08 C1 - 00 2A FA D1 70 47 70 47 .........*..pGpG
00000640 : 00 20 01 E0 01 C1 12 1F - 00 2A FB D1 70 47 2D E9 . .......*..pG-.
00000650 : F0 41 16 46 0F 46 04 46 - 00 25 03 E0 39 46 B0 47 .A.F.F.F.%..9F.G
00000660 : 6D 1C 64 1C 20 78 00 28 - F8 D1 28 46 BD E8 F0 81 m.d. x.(..(F....
00000670 : 70 B5 07 4D 04 46 80 21 - 28 46 FF F7 67 FF 00 28 p..M.F.!(F..g..(
00000680 : F9 D0 A1 B2 28 46 FF F7 - C5 FF 20 46 70 BD 00 00 ....(F.... Fp...
00000690 : 00 10 01 40 FF F7 52 FE - FF F7 B0 FD FF F7 30 FF ...@..R.......0.
000006A0 : 01 A0 FF F7 BD FF FB E7 - 48 65 6C 6C 6F 20 57 6F ........Hello Wo
000006B0 : 72 6C 64 21 0D 0A 00 00 - D8 06 00 08 00 00 00 20 rld!...........
000006C0 : 14 00 00 00 30 06 00 08 - EC 06 00 08 14 00 00 20 ....0..........
000006D0 : 04 04 00 00 40 06 00 08 - 00 00 00 00 00 00 00 00 ....@...........
000006E0 : 01 02 03 04 01 02 03 04 - 06 07 08 09 ** ** ** ** ............

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..