stm32/mboot: Fix mp_hal_delay_us() and add mp_hal_ticks_ms().
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
fd01b6c779
commit
97f09fda3e
@ -95,6 +95,9 @@
|
|||||||
// These bits are used to detect valid application firmware at APPLICATION_ADDR
|
// These bits are used to detect valid application firmware at APPLICATION_ADDR
|
||||||
#define APP_VALIDITY_BITS (0x00000003)
|
#define APP_VALIDITY_BITS (0x00000003)
|
||||||
|
|
||||||
|
// For 1ms system ticker.
|
||||||
|
static volatile uint32_t systick_ms;
|
||||||
|
|
||||||
// Global dfu state
|
// Global dfu state
|
||||||
dfu_context_t dfu_context SECTION_NOZERO_BSS;
|
dfu_context_t dfu_context SECTION_NOZERO_BSS;
|
||||||
|
|
||||||
@ -104,6 +107,10 @@ uint32_t get_le32(const uint8_t *b) {
|
|||||||
return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
|
return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mp_uint_t mp_hal_ticks_ms(void) {
|
||||||
|
return systick_ms;
|
||||||
|
}
|
||||||
|
|
||||||
void mp_hal_delay_us(mp_uint_t usec) {
|
void mp_hal_delay_us(mp_uint_t usec) {
|
||||||
// use a busy loop for the delay
|
// use a busy loop for the delay
|
||||||
// sys freq is always a multiple of 2MHz, so division here won't lose precision
|
// sys freq is always a multiple of 2MHz, so division here won't lose precision
|
||||||
@ -113,11 +120,10 @@ void mp_hal_delay_us(mp_uint_t usec) {
|
|||||||
const uint32_t ucount = SystemCoreClock / 2000000 * usec / 2;
|
const uint32_t ucount = SystemCoreClock / 2000000 * usec / 2;
|
||||||
#endif
|
#endif
|
||||||
for (uint32_t count = 0; ++count <= ucount;) {
|
for (uint32_t count = 0; ++count <= ucount;) {
|
||||||
|
__NOP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile uint32_t systick_ms;
|
|
||||||
|
|
||||||
void mp_hal_delay_ms(mp_uint_t ms) {
|
void mp_hal_delay_ms(mp_uint_t ms) {
|
||||||
if (__get_PRIMASK() == 0) {
|
if (__get_PRIMASK() == 0) {
|
||||||
// IRQs enabled, use systick
|
// IRQs enabled, use systick
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user