@@ -33,30 +33,34 @@ def build(env):
33
33
env .template ("startup_platform.c.in" )
34
34
35
35
# delay code that must be tuned for each family
36
- # (cycles per loop, setup cost in loops, max us shift )
36
+ # (cycles per loop, setup cost in loops)
37
37
tuning = {
38
- "g4" : (3 , 4 , 5 ), # CM4 tested on G476 in RAM
39
- "l0" : (3 , 4 , 6 ), # CM0+ tested on L031 in RAM
40
- "g0" : (3 , 4 , 5 ), # CM0+ tested on G072 in RAM
41
- "f7" : (4 , 4 , 4 ), # CM7 tested on F767 in ITCM
42
- "h7" : (4 , 4 , 3 ), # CM7 tested on H743 in ITCM
43
- "l4" : (3 , 4 , 5 ), # CM4 tested on L476 in SRAM2
44
- "f3" : (3 , 4 , 5 ), # CM4 tested on F334, F303 in CCM RAM
38
+ "g4" : (3 , 4 ), # CM4 tested on G476 in RAM
39
+ "l0" : (3 , 4 ), # CM0+ tested on L031 in RAM
40
+ "g0" : (3 , 4 ), # CM0+ tested on G072 in RAM
41
+ "f7" : (4 , 4 ), # CM7 tested on F767 in ITCM
42
+ "h7" : (4 , 4 ), # CM7 tested on H743 in ITCM
43
+ "l4" : (3 , 4 ), # CM4 tested on L476 in SRAM2
44
+ "f3" : (3 , 4 ), # CM4 tested on F334, F303 in CCM RAM
45
45
46
46
# Defaults of (4, 4) for these families:
47
- "l1" : (4 , 4 , 6 ), # CM3 tested on L152 in RAM
48
- "f0" : (4 , 4 , 6 ), # CM3 tested on F071 in RAM
49
- "f1" : (4 , 4 , 5 ), # CM3 tested on F103 in RAM
50
- "f4" : (4 , 4 , 4 ), # CM4 tested on F401, F411, F446 in RAM
51
- "f2" : (4 , 4 , 4 ), # CM3 guessed based on documentation
47
+ "l1" : (4 , 4 ), # CM3 tested on L152 in RAM
48
+ "f0" : (4 , 4 ), # CM3 tested on F071 in RAM
49
+ "f1" : (4 , 4 ), # CM3 tested on F103 in RAM
50
+ "f4" : (4 , 4 ), # CM4 tested on F401, F411, F446 in RAM
51
+ "f2" : (4 , 4 ), # CM3 guessed based on documentation
52
52
}[target .family ]
53
53
54
+ # us_shift is an optimization to limit error via fractional math
55
+ frequency = int (env [":target" ].get_driver ("rcc" )["max-frequency" ][0 ])
56
+ us_shift = 32 - math .ceil (math .log2 (frequency ))
57
+
54
58
env .substitutions .update ({
55
59
"with_cm0" : env [":target" ].has_driver ("core:cortex-m0*" ),
56
60
"with_cm7" : env [":target" ].has_driver ("core:cortex-m7*" ),
57
61
"loop" : tuning [0 ],
58
62
"shift" : int (math .log2 (tuning [1 ])),
59
- "us_shift" : tuning [ 2 ] ,
63
+ "us_shift" : us_shift ,
60
64
"with_assert" : env .has_module (":architecture:assert" )
61
65
})
62
66
env .template ("../cortex/delay_ns.cpp.in" , "delay_ns.cpp" )
0 commit comments