5
5
from collections import namedtuple
6
6
from distutils .spawn import find_executable
7
7
import subprocess
8
+ import re
8
9
9
10
from tools .arm_pack_manager import Cache
10
11
from tools .targets import TARGET_MAP
@@ -26,10 +27,11 @@ def __init__(self, target):
26
27
self .svd = dev_format .format (self .dname , self .debug_svd )
27
28
self .reg_file = dev_format .format (self .dname , self .compile_header )
28
29
self .debug_interface = self .uv_debug ()
30
+ self .flash_dll = self .generate_flash_dll ()
29
31
30
32
def uv_debug (self ):
31
33
"""Return a namedtuple of information about uvision debug settings"""
32
- UVDebug = namedtuple ('UVDebug' ,['bin_loc' ,'core_flag' ])
34
+ UVDebug = namedtuple ('UVDebug' ,['bin_loc' ,'core_flag' , 'key' ])
33
35
34
36
# CortexMXn => pCMX
35
37
cpu = self .core .replace ("Cortex-" , "C" )
@@ -38,12 +40,72 @@ def uv_debug(self):
38
40
cpu_flag = "p" + cpu
39
41
40
42
# Locations found in Keil_v5/TOOLS.INI
41
- debuggers = {"st-link" :'STLink\\ ST-LINKIII-KEIL_SWO.dll' ,
42
- "j-link" :'Segger\\ JL2CM3.dll' ,
43
- "cmsis-dap" :'BIN\\ CMSIS_AGDI.dll' ,
44
- "nulink" :'NULink\\ Nu_Link.dll' }
45
- binary = debuggers [self .debug_interface .lower ()]
46
- return UVDebug (binary , cpu_flag )
43
+ debuggers = {"st-link" : ('STLink\\ ST-LINKIII-KEIL_SWO.dll' , 'ST-LINKIII-KEIL_SWO' ),
44
+ "j-link" :('Segger\\ JL2CM3.dll' , 'JL2CM3' ),
45
+ "cmsis-dap" :('BIN\\ CMSIS_AGDI.dll' , 'CMSIS_AGDI' ),
46
+ "nulink" :('NULink\\ Nu_Link.dll' ,'Nu_Link' )}
47
+ res = debuggers [self .debug .lower ()]
48
+ binary = res [0 ]
49
+ key = res [1 ]
50
+
51
+ return UVDebug (binary , cpu_flag , key )
52
+
53
+ def generate_flash_dll (self ):
54
+ '''Flash DLL string from uvision
55
+ S = SW/JTAG Clock ID
56
+ C = CPU index in JTAG chain
57
+ P = Access Port
58
+ For the Options for Target -> Debug tab -> settings -> "Flash" tab in the dialog:
59
+ FD = RAM Start for Flash Functions
60
+ FC = RAM Size for Flash Functions
61
+ FN = Number of Flash types
62
+ FF = Flash File Name (without an extension)
63
+ FS = Start Address of the Flash Device
64
+ FL = Size of the Flash Device
65
+ FP = Full path to the Device algorithm (RTE)
66
+
67
+ Necessary to flash some targets. Info gathered from algorithms field of pdsc file.
68
+ '''
69
+ fl_count = 0
70
+ def get_mem_no_x (mem_str ):
71
+ mem_reg = "\dx(\w+)"
72
+ m = re .search (mem_reg , mem_str )
73
+ return m .group (1 ) if m else None
74
+
75
+ RAMS = [(get_mem_no_x (info ["start" ]), get_mem_no_x (info ["size" ]))
76
+ for mem , info in self .target_info ["memory" ].items () if "RAM" in mem ]
77
+ format_str = "UL2CM3(-S0 -C0 -P0 -FD{ramstart}" + " -FC{ramsize} " + "-FN{num_algos} {extra_flags})"
78
+ ramstart = ''
79
+ #Default according to Keil developer
80
+ ramsize = '1000'
81
+ if len (RAMS )>= 1 :
82
+ ramstart = RAMS [0 ][0 ]
83
+ extra_flags = []
84
+ for name , info in self .target_info ["algorithm" ].items ():
85
+ if int (info ["default" ])== 0 :
86
+ continue
87
+ name_reg = "\w*/([\w_]+)\.flm"
88
+ m = re .search (name_reg , name .lower ())
89
+ fl_name = m .group (1 ) if m else None
90
+ name_flag = "-FF" + str (fl_count ) + fl_name
91
+
92
+ start , size = get_mem_no_x (info ["start" ]), get_mem_no_x (info ["size" ])
93
+ rom_start_flag = "-FS" + str (fl_count )+ str (start )
94
+ rom_size_flag = "-FL" + str (fl_count ) + str (size )
95
+
96
+ if info ["ramstart" ] is not None and info ["ramsize" ] is not None :
97
+ ramstart = get_mem_no_x (info ["ramstart" ])
98
+ ramsize = get_mem_no_x (info ["ramsize" ])
99
+
100
+ path_flag = "-FP" + str (fl_count ) + "($$Device:" + self .dname + "$" + name + ")"
101
+
102
+ extra_flags .extend ([name_flag , rom_start_flag , rom_size_flag , path_flag ])
103
+ fl_count += 1
104
+
105
+ extra = " " .join (extra_flags )
106
+ return format_str .format (ramstart = ramstart ,
107
+ ramsize = ramsize ,
108
+ extra_flags = extra , num_algos = fl_count )
47
109
48
110
49
111
class Uvision (Exporter ):
@@ -134,6 +196,7 @@ def generate(self):
134
196
or 'd' in ctx ['device' ].core .lower () else 2
135
197
ctx .update (self .format_flags ())
136
198
self .gen_file ('uvision/uvision.tmpl' , ctx , self .project_name + ".uvprojx" )
199
+ self .gen_file ('uvision/uvision_debug.tmpl' , ctx , self .project_name + ".uvoptx" )
137
200
138
201
def build (self ):
139
202
ERRORLEVEL = {
0 commit comments