File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
common-hal/microcontroller Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 42
42
// This routine should work even when interrupts are disabled. Used by OneWire
43
43
// for precise timing.
44
44
void common_hal_mcu_delay_us (uint32_t delay ) {
45
- //TODO: implement equivalent of mp_hal_delay_us(delay);
46
- //this is fairly annoying in the STM32 HAL
45
+ // sys freq is always a multiple of 2MHz, so division here won't lose precision
46
+ const uint32_t ucount = HAL_RCC_GetSysClockFreq () / 2000000 * delay / 2 ;
47
+ for (uint32_t count = 0 ; ++ count <= ucount ;) {
47
48
}
48
49
49
- void common_hal_mcu_disable_interrupts () {
50
+ volatile uint32_t nesting_count = 0 ;
51
+ void common_hal_mcu_disable_interrupts (void ) {
52
+ __disable_irq ();
53
+ __DMB ();
54
+ nesting_count ++ ;
50
55
}
51
56
52
- void common_hal_mcu_enable_interrupts () {
57
+ void common_hal_mcu_enable_interrupts (void ) {
58
+ if (nesting_count == 0 ) {
59
+ // This is very very bad because it means there was mismatched disable/enables so we
60
+ // "HardFault".
61
+ HardFault_Handler ();
62
+ }
63
+ nesting_count -- ;
64
+ if (nesting_count > 0 ) {
65
+ return ;
66
+ }
67
+ __DMB ();
68
+ __enable_irq ();
53
69
}
54
70
55
71
void common_hal_mcu_on_next_reset (mcu_runmode_t runmode ) {
@@ -58,7 +74,7 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
58
74
}
59
75
60
76
void common_hal_mcu_reset (void ) {
61
- filesystem_flush ();
77
+ filesystem_flush (); //TODO: implement as part of flash improvements
62
78
NVIC_SystemReset ();
63
79
}
64
80
Original file line number Diff line number Diff line change 33
33
#include "lib/utils/interrupt_char.h"
34
34
#include "py/mpconfig.h"
35
35
36
- //extern nrfx_uarte_t serial_instance;
37
-
38
36
extern volatile uint64_t ticks_ms ;
39
37
40
38
#define mp_hal_ticks_ms () ((mp_uint_t) ticks_ms)
You can’t perform that action at this time.
0 commit comments