Initial work for STM32. Need to fix us delay and PulseIn still.

This commit is contained in:
Scott Shawcroft 2020-03-20 12:58:34 -07:00
parent 6db11cf68b
commit 2623022c84
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
21 changed files with 238 additions and 271 deletions

View File

@ -172,6 +172,8 @@ SRC_STM32 = \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \
@ -193,7 +195,6 @@ SRC_C += \
background.c \
fatfs_port.c \
mphalport.c \
tick.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
peripherals/stm32f4/$(MCU_SUB_VARIANT)/pins.c \

View File

@ -36,6 +36,8 @@
#define BOARD_OSC_DIV (12)
#define BOARD_RTC_CLOCK RCC_RTCCLKSOURCE_LSE
// On-board flash
#define SPI_FLASH_MOSI_PIN (&pin_PB05)
#define SPI_FLASH_MISO_PIN (&pin_PB04)

View File

@ -56,7 +56,7 @@
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */
#define HAL_RNG_MODULE_ENABLED
/* #define HAL_RTC_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_MMC_MODULE_ENABLED */

View File

@ -33,3 +33,5 @@
#define FLASH_PAGE_SIZE (0x4000)
#define BOARD_OSC_DIV (8)
#define BOARD_RTC_CLOCK RCC_RTCCLKSOURCE_LSE

View File

@ -56,7 +56,7 @@
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */
#define HAL_RNG_MODULE_ENABLED
/* #define HAL_RTC_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_MMC_MODULE_ENABLED */

View File

@ -35,7 +35,6 @@
#include "py/stream.h"
#include "supervisor/shared/translate.h"
#include "tick.h"
#include "stm32f4xx_hal.h"
#define ALL_UARTS 0xFFFF

View File

@ -33,8 +33,6 @@
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "tick.h"
void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* self,
const mcu_pin_obj_t* data0, const mcu_pin_obj_t* command, const mcu_pin_obj_t* chip_select,
const mcu_pin_obj_t* write, const mcu_pin_obj_t* read, const mcu_pin_obj_t* reset) {

View File

@ -41,31 +41,9 @@
#include "stm32f4xx_hal.h"
//tested divisor value for busy loop in us delay
#define LOOP_TICKS 12
STATIC uint32_t get_us(void) {
uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq()/1000000;
uint32_t micros, sys_cycles;
do {
micros = supervisor_ticks_ms32();
sys_cycles = SysTick->VAL; //counts backwards
} while (micros != supervisor_ticks_ms32()); //try again if ticks_ms rolled over
return (micros * 1000) + (ticks_per_us * 1000 - sys_cycles) / ticks_per_us;
}
void common_hal_mcu_delay_us(uint32_t delay) {
if (__get_PRIMASK() == 0x00000000) {
//by default use ticks_ms
uint32_t start = get_us();
while (get_us()-start < delay) {
__asm__ __volatile__("nop");
}
} else {
//when SysTick is disabled, approximate with busy loop
const uint32_t ucount = HAL_RCC_GetSysClockFreq() / 1000000 * delay / LOOP_TICKS;
for (uint32_t count = 0; ++count <= ucount;) {
}
}
}

View File

@ -24,18 +24,17 @@
* THE SOFTWARE.
*/
#include "py/mphal.h"
#include "shared-bindings/neopixel_write/__init__.h"
#include "tick.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "common-hal/microcontroller/Pin.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_ll_gpio.h"
#include "supervisor/port.h"
uint64_t next_start_tick_ms = 0;
uint32_t next_start_tick_us = 1000;
uint64_t next_start_raw_ticks = 0;
//sysclock divisors
#define MAGIC_800_INT 900000 // ~1.11 us -> 1.2 field
@ -59,9 +58,9 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
uint32_t t0 = (sys_freq/MAGIC_800_T0H);
uint32_t t1 = (sys_freq/MAGIC_800_T1H);
// This must be called while interrupts are on in case we're waiting for a
// future ms tick.
wait_until(next_start_tick_ms, next_start_tick_us);
// Wait to make sure we don't append onto the last transmission. This should only be a tick or
// two.
while (port_get_raw_ticks(NULL) < next_start_raw_ticks) {}
GPIO_TypeDef * p_port = pin_port(digitalinout->pin->port);
uint32_t p_mask = pin_mask(digitalinout->pin->number);
@ -90,13 +89,7 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
__enable_irq();
// Update the next start.
current_tick(&next_start_tick_ms, &next_start_tick_us);
if (next_start_tick_us < 100) {
next_start_tick_ms += 1;
next_start_tick_us = 100 - next_start_tick_us;
} else {
next_start_tick_us -= 100;
}
next_start_raw_ticks = port_get_raw_ticks(NULL) + 4;
}
#pragma GCC pop_options

View File

@ -32,7 +32,6 @@
#include "py/runtime.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/pulseio/PulseIn.h"
#include "tick.h"
#include "stm32f4xx_hal.h"
@ -47,9 +46,8 @@ static void pulsein_handler(uint8_t num) {
EXTI->PR = 1 << num;
// Grab the current time first.
uint32_t current_us;
uint64_t current_ms;
current_tick(&current_ms, &current_us);
uint32_t current_us = 0;
uint64_t current_ms = 0;
// current_tick gives us the remaining us until the next tick but we want the number since the last ms.
current_us = 1000 - current_us;

View File

@ -37,7 +37,6 @@
#include "stm32f4xx_hal.h"
#include "common-hal/microcontroller/Pin.h"
#include "tick.h"
// A single timer is shared amongst all PulseOut objects under the assumption that
// the code is single threaded.

View File

@ -35,21 +35,6 @@
#include "supervisor/shared/tick.h"
#include "stm32f4xx_hal.h"
void mp_hal_delay_ms(mp_uint_t delay) {
uint64_t start_tick = supervisor_ticks_ms64();
uint64_t duration = 0;
while (duration < delay) {
RUN_BACKGROUND_TASKS;
// Check to see if we've been CTRL-Ced by autoreload or the user.
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
break;
}
duration = (supervisor_ticks_ms64() - start_tick);
// TODO(tannewt): Go to sleep for a little while while we wait.
}
}
void mp_hal_delay_us(mp_uint_t delay) {
common_hal_mcu_delay_us(delay);
}

View File

@ -58,7 +58,9 @@ void stm32f4_peripherals_clocks_init(void) {
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
// APB1 must always be on so that we can talk to the RTC for timing.
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
// TODO: Only turn on APB2 when it is needed to save power.
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}

View File

@ -65,7 +65,7 @@ void stm32f4_peripherals_clocks_init(void) {
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
* clocks dividers */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

View File

@ -100,7 +100,7 @@ uint32_t supervisor_flash_get_block_count(void) {
return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS;
}
void supervisor_flash_flush(void) {
void port_internal_flash_flush(void) {
}
static int32_t convert_block_to_flash_addr(uint32_t block) {

View File

@ -28,7 +28,7 @@
#include <stdint.h>
#include "supervisor/port.h"
#include "boards/board.h"
#include "tick.h"
#include "lib/timeutils/timeutils.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/busio/I2C.h"
@ -43,6 +43,8 @@
#include "stm32f4xx_hal.h"
static RTC_HandleTypeDef _hrtc;
safe_mode_t port_init(void) {
HAL_Init();
__HAL_RCC_SYSCFG_CLK_ENABLE();
@ -51,11 +53,33 @@ safe_mode_t port_init(void) {
stm32f4_peripherals_clocks_init();
stm32f4_peripherals_gpio_init();
tick_init();
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSE_CONFIG(RCC_LSE_ON);
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) {}
__HAL_RCC_RTC_CONFIG(BOARD_RTC_CLOCK);
__HAL_RCC_RTC_ENABLE();
_hrtc.Instance = RTC;
_hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
// Divide async as little as possible so that we have 32768 count in subseconds.
_hrtc.Init.AsynchPrediv = 0x0;
_hrtc.Init.SynchPrediv = 0x7fff; // 32768 ticks per second
_hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
HAL_StatusTypeDef result = HAL_RTC_Init(&_hrtc);
if (result != HAL_OK) {
asm("bkpt");
}
return NO_SAFE_MODE;
}
void SysTick_Handler(void) {
// Read the CTRL register to clear the SysTick interrupt.
SysTick->CTRL;
HAL_IncTick();
}
void reset_port(void) {
reset_all_pins();
i2c_reset();
@ -106,3 +130,109 @@ void HardFault_Handler(void) {
asm("nop;");
}
}
// This function is called often for timing so we cache the seconds elapsed computation based on the
// register value. The STM HAL always does shifts and conversion if we use it directly.
volatile uint32_t seconds_to_date = 0;
volatile uint32_t cached_date = 0;
volatile uint32_t seconds_to_minute = 0;
volatile uint32_t cached_hours_minutes = 0;
uint64_t port_get_raw_ticks(uint8_t* subticks) {
uint32_t subseconds = 0x8000 - (uint32_t)(RTC->SSR);
uint32_t time = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK);
uint32_t date = (uint32_t)(RTC->DR & RTC_DR_RESERVED_MASK);
if (date != cached_date) {
uint32_t year = (uint8_t)((date & (RTC_DR_YT | RTC_DR_YU)) >> 16U);
uint8_t month = (uint8_t)((date & (RTC_DR_MT | RTC_DR_MU)) >> 8U);
uint8_t day = (uint8_t)(date & (RTC_DR_DT | RTC_DR_DU));
// Add 2000 since the year is only the last two digits.
year = 2000 + (uint32_t)RTC_Bcd2ToByte(year);
month = (uint8_t)RTC_Bcd2ToByte(month);
day = (uint8_t)RTC_Bcd2ToByte(day);
seconds_to_date = timeutils_seconds_since_2000(year, month, day, 0, 0, 0);
cached_date = date;
}
uint32_t hours_minutes = time & (RTC_TR_HT | RTC_TR_HU | RTC_TR_MNT | RTC_TR_MNU);
if (hours_minutes != cached_hours_minutes) {
uint8_t hours = (uint8_t)((time & (RTC_TR_HT | RTC_TR_HU)) >> 16U);
uint8_t minutes = (uint8_t)((time & (RTC_TR_MNT | RTC_TR_MNU)) >> 8U);
hours = (uint8_t)RTC_Bcd2ToByte(hours);
minutes = (uint8_t)RTC_Bcd2ToByte(minutes);
seconds_to_minute = 60 * (60 * hours + minutes);
}
uint8_t seconds = (uint8_t)(time & (RTC_TR_ST | RTC_TR_SU));
seconds = (uint8_t)RTC_Bcd2ToByte(seconds);
if (subticks != NULL) {
*subticks = subseconds % 32;
}
return ((uint64_t) 1024) * (seconds_to_date + seconds_to_minute + seconds) + subseconds / 32;
}
void RTC_WKUP_IRQHandler(void) {
supervisor_tick();
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&_hrtc, RTC_FLAG_WUTF);
__HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
}
void RTC_Alarm_IRQHandler(void) {
RTC->ISR = ~RTC_FLAG_ALRAF;
HAL_RTC_DeactivateAlarm(&_hrtc, RTC_ALARM_A);
}
// Enable 1/1024 second tick.
void port_enable_tick(void) {
HAL_StatusTypeDef result = HAL_RTCEx_SetWakeUpTimer_IT(&_hrtc, 32768 / 1024 / 2, RTC_WAKEUPCLOCK_RTCCLK_DIV2);
if (result != HAL_OK) {
asm("bkpt");
}
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 1, 0U);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
}
extern volatile uint32_t autoreload_delay_ms;
// Disable 1/1024 second tick.
void port_disable_tick(void) {
if (autoreload_delay_ms > 1) {
asm("bkpt");
}
HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
HAL_RTCEx_DeactivateWakeUpTimer(&_hrtc);
}
void port_interrupt_after_ticks(uint32_t ticks) {
uint64_t raw_ticks = port_get_raw_ticks(NULL) + ticks;
RTC_AlarmTypeDef alarm;
if (ticks > 1024) {
timeutils_struct_time_t tm;
timeutils_seconds_since_2000_to_struct_time(raw_ticks / 1024, &tm);
alarm.AlarmTime.Hours = tm.tm_hour;
alarm.AlarmTime.Minutes = tm.tm_min;
alarm.AlarmTime.Seconds = tm.tm_sec;
alarm.AlarmDateWeekDay = tm.tm_mday;
alarm.AlarmMask = RTC_ALARMMASK_ALL;
} else {
alarm.AlarmMask = RTC_ALARMMASK_NONE;
}
alarm.AlarmTime.SubSeconds = 32768 - ((raw_ticks % 1024) * 32);
alarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
alarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_SET;
alarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
alarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
alarm.Alarm = RTC_ALARM_A;
HAL_RTC_SetAlarm_IT(&_hrtc, &alarm, RTC_FORMAT_BIN);
}
void port_sleep_until_interrupt(void) {
// Clear the FPU interrupt because it can prevent us from sleeping.
if (__get_FPSCR() & ~(0x9f)) {
__set_FPSCR(__get_FPSCR() & ~(0x9f));
(void) __get_FPSCR();
}
// Call wait for interrupt ourselves if the SD isn't enabled.
__WFI();
}

View File

@ -26,7 +26,6 @@
*/
#include "tick.h"
#include "supervisor/usb.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"

View File

@ -1,81 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "tick.h"
#include "supervisor/filesystem.h"
#include "supervisor/shared/tick.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "stm32f4xx.h"
void SysTick_Handler(void) {
// SysTick interrupt handler called when the SysTick timer reaches zero
// (every millisecond).
// Do things common to all ports when the tick occurs
supervisor_tick();
}
uint32_t HAL_GetTick(void) //override ST HAL
{
return (uint32_t)supervisor_ticks_ms32();
}
void tick_init() {
uint32_t ticks_per_ms = SystemCoreClock/ 1000;
SysTick_Config(ticks_per_ms); // interrupt is enabled
NVIC_EnableIRQ(SysTick_IRQn);
// Bump up the systick interrupt so nothing else interferes with timekeeping.
NVIC_SetPriority(SysTick_IRQn, 0);
NVIC_SetPriority(OTG_FS_IRQn, 1);
}
void tick_delay(uint32_t us) {
uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000;
uint32_t us_between_ticks = SysTick->VAL / ticks_per_us;
uint64_t start_ms = supervisor_ticks_ms64();
while (us > 1000) {
while (supervisor_ticks_ms64() == start_ms) {}
us -= us_between_ticks;
start_ms = supervisor_ticks_ms64();
us_between_ticks = 1000;
}
while (SysTick->VAL > ((us_between_ticks - us) * ticks_per_us)) {}
}
// us counts down!
void current_tick(uint64_t* ms, uint32_t* us_until_ms) {
uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000;
*ms = supervisor_ticks_ms32();
*us_until_ms = SysTick->VAL / ticks_per_us;
}
void wait_until(uint64_t ms, uint32_t us_until_ms) {
uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000;
while(supervisor_ticks_ms64() <= ms && SysTick->VAL / ticks_per_us >= us_until_ms) {}
}

View File

@ -1,44 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_STM32F4_TICK_H
#define MICROPY_INCLUDED_STM32F4_TICK_H
#include "py/mpconfig.h"
#include <stdint.h>
extern struct timer_descriptor ms_timer;
void tick_init(void);
void tick_delay(uint32_t us);
void current_tick(uint64_t* ms, uint32_t* us_until_ms);
// Do not call this with interrupts disabled because it may be waiting for
// ticks_ms to increment.
void wait_until(uint64_t ms, uint32_t us_until_ms);
#endif // MICROPY_INCLUDED_STM32F4_TICK_H

View File

@ -111,7 +111,7 @@ mp_uint_t flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_bloc
return supervisor_flash_read_blocks(dest, block_num - PART1_START_BLOCK, num_blocks);
}
volatile bool filesystem_dirty;
volatile bool filesystem_dirty = false;
mp_uint_t flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
if (block_num == 0) {
@ -137,7 +137,9 @@ void supervisor_flash_flush(void) {
supervisor_external_flash_flush();
#endif
// Turn off ticks now that our filesystem has been flushed.
supervisor_disable_tick();
if (filesystem_dirty) {
supervisor_disable_tick();
}
filesystem_dirty = false;
}

View File

@ -118,18 +118,22 @@ void mp_hal_delay_ms(mp_uint_t delay) {
volatile size_t tick_enable_count = 0;
extern void supervisor_enable_tick(void) {
common_hal_mcu_disable_interrupts();
if (tick_enable_count == 0) {
port_enable_tick();
}
tick_enable_count++;
common_hal_mcu_enable_interrupts();
}
extern void supervisor_disable_tick(void) {
common_hal_mcu_disable_interrupts();
if (tick_enable_count > 0) {
tick_enable_count--;
}
if (tick_enable_count == 0) {
port_disable_tick();
}
common_hal_mcu_enable_interrupts();
}