Assigning floats to adresses in a hex file

1

I am trying to assign floats to different SRAM adresses in a microcontroller. I am doing this for the first time so I don't have any idea if this is the correct way to do this. So basically I need a Python tool that saves those different values to the corresponding adresses and then generate a HEX file. And then I load the HEX file. I am currently trying intelhex library :

def float_to_hex(f):
    return hex(struct.unpack('<I', struct.pack('<f', f))[0])
ih = IntelHex()
ih[1] = 0x00000000
adress=0x7000180c
for x in a:
    ih.putsz(adress, float_to_hex(x))
    #ih.gets(adress,14)
    adress=adress+0x4
adress=0x70001878
for y in b:
    ih.putsz(adress, float_to_hex(y))
    adress=adress+0x4
adress=0x700018e4
ih.putsz(adress, float_to_hex(c))
adress=0x700018e8
for z in d:
    ih.putsz(adress, float_to_hex(z))
    adress=adress+0x4
ih.tofile("foo.hex", format='hex')

Using this method, I get the following HEX file:

:020000040000FA
:0100010000FE
:0200000470008A
:10180C0030783465307834643078346430783463CC
:10181C0030783463307834643078346430783465BC
:10182C0030783464307834643078346330783463AE
:10183C00307834643078346430783464307834649C
:10184C00307834643078346330783464307834648D
:10185C00307834653078346430783464307834647B
:10186C00307834643078346430783464307834636D
:10187C003078346330783463307834613078346164
:10188C003078346330783463307834633078346251
:10189C003078346230783461307834613078346345
:1018AC003078346330783463307834623078346232
:1018BC003078346130783463307834633078346322
:1018CC003078346330783463307834623078346212
:1018DC003078346330783463307834333078633034
:1018EC0030786266307834303078336630783366EE
:1018FC0030786262307834303078336630783366E2
:10190C00307863303078343030783430307863303D
:10191C0030783430307862643078343030786266C5
:10192C003078343030783430307833663078343046
:10193C0030786266307834303078343030786266A3
:10194C0030786266307834303078343030783430F7
:10195C003078336330786330307862653078336652
:10196C00307863303078336630783366307833666D
:10197C0030786266307833663078626630783362FD
:10198C003078336630783430307863303078626653
:10199C0030786330307862633078626630783365E3
:1019AC0030783366307833663078626630786330FE
:1019BC003078343030783366307862663078343052
:1019CC00307834303078336630786265307833660E
:1019DC0030786266307834303078626630786330D4
:1019EC0030786266307833663078336530783430EE
:1019FC0030786330307863303078626630786330BA
:101A0C0030783366307834303078336630786266CC
:101A1C00307833663078626630786265307862662A
:101A2C0030783366307834303078336630786330E1
:101A3C003078626530786266307862653078633011
:101A4C003078633030786266307834303078336692
:101A5C00307833643078336530783366307862664A
:101A6C00307833663078626630783363307833663A
:101A7C00307834303078336630783366307862665C
:101A8C0030786266307862663078633030786266BF
:101A9C003078343030786330307862663078343077
:101AAC003078336630783366307863303078633032
:101ABC003078336630783430307862663078633022
:101ACC003078343030786330307834303078336577
:101ADC003078626630786266307834303078343002
:101AEC00307862663078336630786266307862655A
:101AFC00307862663078626630786266307834307E
:101B0C0030783430307863303078626630783363D4
:101B1C003078633030786266307862633078343095
:101B2C00307834303078626630786266307833667C
:101B3C00307863303078626630783366307862653E
:101B4C0030783365307862653078626630786264FC
:101B5C003078626630783430307863303078336582
:101B6C0030786330307863303078336530783430A7
:101B7C003078626530783366307833663078336528
:101B8C003078633030783430307834303078626686
:101B9C003078626530783430307863303078626613
:101BAC0030783366307862663078626630786330CD
:101BBC003078343030783365307862663078343051
:101BCC0030786266307862663078343030783366DC
:101BDC003078633030783366307863303078336601
:101BEC0030783366307862663078336630783365B7
:101BFC003078633030786330307834303078336616
:101C0C00307862643078336630783365307833649A
:101C1C003078626630783430307863303078626592
:101C2C00307863303078626630783365307862654E
:101C3C0030786330307833663078626630783430A0
:101C4C0030783430307833653078343030786266C0
:101C5C003078626530786266307834303078633052
:101C6C00307833643078336630786266307863303D
:101C7C003078343030786330307862663078343095
:101C8C003078626630786330307833643078343052
:101C9C00307834303078626630786266307833650C
:101CAC0030786266307833663078633030783366FB
:101CBC00307862663078343030783366307833661A
:101CCC003078343030786330307862663078343045
:101CDC003078343030783430307862663078343064
:101CEC00307834303078343030786330307863305A
:101CFC00307863303078633030783430307863301B
:101D0C00307862663078336530786330307862666C
:101D1C0030786330307863303078343030786330FA
:101D2C0030786330307833633078343030783366E1
:101D3C003078626630786266307834303078633070
:101D4C00307833663078336630783365307863308A
:101D5C0030783366307833663078336630783430A8
:101D6C00307862663078336630786330307834306F
:101D7C003078343030783366307863303078633094
:101D8C003078633030786266307863303078343055
:101D9C003078633030786266307833643078633012
:101DAC00307834303078633030783366307862662F
:101DBC0030783365307862663078626630783366B6
:101DCC0030786266307834303078626630786330E0
:101DDC003078343030783430307834303078336692
:101DEC003078626630786266307833653078626657
:101DFC0030783366307833663078626630783364A6
:101E0C00307862663078626430786330307833646E
:101E1C00307834303078343030783366307833661C
:101E2C003078336630786266307833663078336673
:101E3C0030783366307834303078633030786330D3
:101E4C0030786330307834303078626630783430C3
:101E5C003078626630783366307833663078336544
:101E6C00307834303078626630786265307862640D
:101E7C00307833653078336630786330307834308E
:101E8C00307863303078343030783366307862664E
:101E9C0030786266307833663078626630783365D5
:101EAC003078633030783430307862663078336430
:101EBC0030783366307833653078336630786266E4
:101ECC003078626630786266307862663078626646
:101EDC0030786266307833663078336430786330CB
:101EEC0030783365307863303078626630783430EF
:101EFC00307834303078343030783366307833663C
:101F0C00307862663078633030786330307833669E
:101F1C0030786330307833663078343030786330F2
:101F2C0030783366307834303078626530783430DD
:071F3C0033376334386600FF
:00000001FF

And in order to load the file I need to delete the first two lines of the HEX file. And after loading it, the values saved in the different adresses are wrong, for example in 0x7000180c I get 0x65347830 instead of 0x4e5b1090 which is the hex of 9.18823936e+08. I also tried saving the floats in strings but I also get wrong values in the SRAM. What am I doing wrong?

python
hex-file
asked on Stack Overflow Nov 6, 2020 by (unknown user)

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0