15
15
import itertools
16
16
import binascii
17
17
import intelhex
18
+ import json
19
+
18
20
19
21
FIB_BASE = 0x2000
20
22
FLASH_BASE = 0x3000
21
23
FW_REV = 0x01000100
24
+ TRIM_BASE = 0x2800
25
+
22
26
def ranges (i ):
23
27
for _ , b in itertools .groupby (enumerate (i ), lambda x_y : x_y [1 ] - x_y [0 ]):
24
28
b = list (b )
@@ -51,7 +55,7 @@ def add_fib_at_start(arginput):
51
55
end = max (max (start_end_pairs ))
52
56
53
57
assert start >= FLASH_BASE , ("Error - start 0x%x less than begining of user\
54
- flash area" % start )
58
+ flash area" % start )
55
59
# Compute checksum over the range (don't include data at location of crc)
56
60
size = end - start + 1
57
61
data = input_hex_file .tobinarray (start = start , size = size )
@@ -62,7 +66,7 @@ def add_fib_at_start(arginput):
62
66
checksum = (start + size + crc32 + fw_rev ) & 0xFFFFFFFF
63
67
64
68
print ("Writing FIB: base 0x%08X, size 0x%08X, crc32 0x%08X, fw rev 0x%08X,\
65
- checksum 0x%08X" % (start , size , crc32 , fw_rev , checksum ))
69
+ checksum 0x%08X" % (start , size , crc32 , fw_rev , checksum ))
66
70
67
71
#expected initial values used by daplink to validate that it is a valid bin
68
72
#file added as dummy values in this file because the fib area preceeds the
@@ -80,18 +84,20 @@ def add_fib_at_start(arginput):
80
84
81
85
#expected fib structure
82
86
#typedef struct fib{
83
- #uint32_t base; /**< Base offset of firmware, indicating what flash the
84
- # firmware is in. (will never be 0x11111111) */
85
- #uint32_t size; /**< Size of the firmware */
86
- #uint32_t crc; /**< CRC32 for firmware correctness check */
87
- #uint32_t rev; /**< Revision number */
88
- #uint32_t checksum; /**< Check-sum of information block */
87
+ #uint32_t base; /**< Base offset of firmware, indicating what flash the
88
+ # firmware is in. (will never be 0x11111111) */
89
+ #uint32_t size; /**< Size of the firmware */
90
+ #uint32_t crc; /**< CRC32 for firmware correctness check */
91
+ #uint32_t rev; /**< Revision number */
92
+ #uint32_t checksum; /**< Check-sum of information block */
89
93
#}fib_t, *fib_pt;
90
94
91
95
fib_start = FIB_BASE
92
96
dummy_fib_size = 20
93
97
fib_size = 20
98
+ trim_size = 24
94
99
user_code_start = FLASH_BASE
100
+ trim_area_start = TRIM_BASE
95
101
96
102
# Write FIB to the file in little endian
97
103
output_hex_file [fib_start + 0 ] = (dummy_sp >> 0 ) & 0xFF
@@ -146,7 +152,51 @@ def add_fib_at_start(arginput):
146
152
output_hex_file [fib_start + 39 ] = (checksum >> 24 ) & 0xFF
147
153
148
154
#pad the rest of the file
149
- for i in range (fib_start + dummy_fib_size + fib_size , user_code_start ):
155
+ for i in range (fib_start + dummy_fib_size + fib_size , trim_area_start ):
156
+ output_hex_file [i ] = 0xFF
157
+
158
+ # add trim data from json
159
+ with open ('./mbed-os/targets/TARGET_ONSEMI/TARGET_NCS36510/ncs36510_user_trim.json' ) as json_data :
160
+ trimdata = json .load (json_data )
161
+ mac_addr_low = int (trimdata ["mac-addr-low" ], 16 )
162
+ mac_addr_high = int (trimdata ["mac-addr-high" ], 16 )
163
+ clk_32k_trim = int (trimdata ["32KHz-clk-trim" ], 16 )
164
+ clk_32m_trim = int (trimdata ["32MHz-clk-trim" ], 16 )
165
+ rssi_trim = int (trimdata ["rssi-trim" ], 16 )
166
+ txtune = int (trimdata ["txtune-trim" ], 16 )
167
+
168
+ output_hex_file [trim_area_start + 0 ] = mac_addr_low & 0xFF
169
+ output_hex_file [trim_area_start + 1 ] = (mac_addr_low >> 8 ) & 0xFF
170
+ output_hex_file [trim_area_start + 2 ] = (mac_addr_low >> 16 ) & 0xFF
171
+ output_hex_file [trim_area_start + 3 ] = (mac_addr_low >> 24 ) & 0xFF
172
+
173
+ output_hex_file [trim_area_start + 4 ] = mac_addr_high & 0xFF
174
+ output_hex_file [trim_area_start + 5 ] = (mac_addr_high >> 8 ) & 0xFF
175
+ output_hex_file [trim_area_start + 6 ] = (mac_addr_high >> 16 ) & 0xFF
176
+ output_hex_file [trim_area_start + 7 ] = (mac_addr_high >> 24 ) & 0xFF
177
+
178
+ output_hex_file [trim_area_start + 8 ] = clk_32k_trim & 0xFF
179
+ output_hex_file [trim_area_start + 9 ] = (clk_32k_trim >> 8 ) & 0xFF
180
+ output_hex_file [trim_area_start + 10 ] = (clk_32k_trim >> 16 ) & 0xFF
181
+ output_hex_file [trim_area_start + 11 ] = (clk_32k_trim >> 24 ) & 0xFF
182
+
183
+ output_hex_file [trim_area_start + 12 ] = clk_32m_trim & 0xFF
184
+ output_hex_file [trim_area_start + 13 ] = (clk_32m_trim >> 8 ) & 0xFF
185
+ output_hex_file [trim_area_start + 14 ] = (clk_32m_trim >> 16 ) & 0xFF
186
+ output_hex_file [trim_area_start + 15 ] = (clk_32m_trim >> 24 ) & 0xFF
187
+
188
+ output_hex_file [trim_area_start + 16 ] = rssi_trim & 0xFF
189
+ output_hex_file [trim_area_start + 17 ] = (rssi_trim >> 8 ) & 0xFF
190
+ output_hex_file [trim_area_start + 18 ] = (rssi_trim >> 16 ) & 0xFF
191
+ output_hex_file [trim_area_start + 19 ] = (rssi_trim >> 24 ) & 0xFF
192
+
193
+ output_hex_file [trim_area_start + 20 ] = txtune & 0xFF
194
+ output_hex_file [trim_area_start + 21 ] = (txtune >> 8 ) & 0xFF
195
+ output_hex_file [trim_area_start + 22 ] = (txtune >> 16 ) & 0xFF
196
+ output_hex_file [trim_area_start + 23 ] = (txtune >> 24 ) & 0xFF
197
+
198
+ # pad the rest of the area with 0xFF
199
+ for i in range (trim_area_start + trim_size , user_code_start ):
150
200
output_hex_file [i ] = 0xFF
151
201
152
202
#merge two hex files
@@ -155,4 +205,3 @@ def add_fib_at_start(arginput):
155
205
# Write out file(s)
156
206
output_hex_file .tofile (file_name_hex , 'hex' )
157
207
output_hex_file .tofile (file_name_bin , 'bin' )
158
-
0 commit comments