@ -183,22 +183,20 @@ def print_int_obj(val, needed_mpzs):
needed_mpzs . add ( val )
def print_periph ( periph_name , periph_val , needed_qstrs , needed_ mpzs ) :
def print_periph ( periph_name , periph_val , needed_mpzs ) :
qstr = periph_name . upper ( )
print ( " { MP_ROM_QSTR(MP_QSTR_ %s ), " % qstr , end = " " )
print_int_obj ( periph_val , needed_mpzs )
print ( " }, " )
needed_qstrs . add ( qstr )
def print_regs ( reg_name , reg_defs , needed_qstrs , needed_ mpzs ) :
def print_regs ( reg_name , reg_defs , needed_mpzs ) :
reg_name = reg_name . upper ( )
for r in reg_defs :
qstr = reg_name + " _ " + r [ 0 ]
print ( " { MP_ROM_QSTR(MP_QSTR_ %s ), " % qstr , end = " " )
print_int_obj ( r [ 1 ] , needed_mpzs )
print ( " }, // %s -bits, %s " % ( r [ 2 ] , r [ 3 ] ) )
needed_qstrs . add ( qstr )
# This version of print regs groups registers together into submodules (eg GPIO submodule).
@ -208,7 +206,7 @@ def print_regs(reg_name, reg_defs, needed_qstrs, needed_mpzs):
# As such, we don't use this version.
# And for the number of constants we have, this function seems to use about the same amount
# of ROM as print_regs.
def print_regs_as_submodules ( reg_name , reg_defs , modules , needed_qstrs ) :
def print_regs_as_submodules ( reg_name , reg_defs , modules ) :
mod_name_lower = reg_name . lower ( ) + " _ "
mod_name_upper = mod_name_lower . upper ( )
modules . append ( ( mod_name_lower , mod_name_upper ) )
@ -220,14 +218,12 @@ STATIC const mp_rom_map_elem_t stm_%s_globals_table[] = {
"""
% ( mod_name_lower , mod_name_upper )
)
needed_qstrs . add ( mod_name_upper )
for r in reg_defs :
print (
" { MP_ROM_QSTR(MP_QSTR_ %s ), MP_ROM_INT( %#x ) }, // %s -bits, %s "
% ( r [ 0 ] , r [ 1 ] , r [ 2 ] , r [ 3 ] )
)
needed_qstrs . add ( r [ 0 ] )
print (
""" };
@ -247,13 +243,6 @@ const mp_obj_module_t stm_%s_obj = {
def main ( ) :
cmd_parser = argparse . ArgumentParser ( description = " Extract ST constants from a C header file. " )
cmd_parser . add_argument ( " file " , nargs = 1 , help = " input file " )
cmd_parser . add_argument (
" -q " ,
" --qstr " ,
dest = " qstr_filename " ,
default = " build/stmconst_qstr.h " ,
help = " Specified the name of the generated qstr header file " ,
)
cmd_parser . add_argument (
" --mpz " ,
dest = " mpz_filename " ,
@ -269,14 +258,13 @@ def main():
reg_defs [ " GPIO " ] . append ( [ " BSRRL " , 0x18 , 16 , " legacy register " ] )
reg_defs [ " GPIO " ] . append ( [ " BSRRH " , 0x1A , 16 , " legacy register " ] )
needed_qstrs = set ( )
needed_mpzs = set ( )
print ( " // Automatically generated from %s by make-stmconst.py " % args . file [ 0 ] )
print ( " " )
for periph_name , periph_val in periphs :
print_periph ( periph_name , periph_val , needed_qstrs , needed_ mpzs )
print_periph ( periph_name , periph_val , needed_mpzs )
for reg in (
" ADC " ,
@ -309,8 +297,8 @@ def main():
" IPCC " ,
) :
if reg in reg_defs :
print_regs ( reg , reg_defs [ reg ] , needed_qstrs , needed_ mpzs )
# print_regs_as_submodules(reg, reg_defs[reg], modules, needed_qstrs )
print_regs ( reg , reg_defs [ reg ] , needed_mpzs )
# print_regs_as_submodules(reg, reg_defs[reg], modules)
# print("#define MOD_STM_CONST_MODULES \\")
# for mod_lower, mod_upper in modules:
@ -318,12 +306,6 @@ def main():
print ( " " )
with open ( args . qstr_filename , " wt " ) as qstr_file :
print ( " #if MICROPY_PY_STM_CONST " , file = qstr_file )
for qstr in sorted ( needed_qstrs ) :
print ( " Q( {} ) " . format ( qstr ) , file = qstr_file )
print ( " #endif // MICROPY_PY_STM_CONST " , file = qstr_file )
with open ( args . mpz_filename , " wt " ) as mpz_file :
for mpz in sorted ( needed_mpzs ) :
assert 0 < = mpz < = 0xFFFFFFFF