summaryrefslogtreecommitdiff
path: root/ports/stm
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-08-26 18:50:26 -0400
committerLucian Copeland <hierophect@gmail.com>2020-08-26 18:50:26 -0400
commit8d2299e61e482f0edbf9f58bd20043761a30492a (patch)
tree9ee7c5402119e79795eb05d19ffbc9e50b49a4f8 /ports/stm
parentde9fd4a0fb26c1a62b97d6175c75568b68e50abd (diff)
parent58a7419b4ffcc99a7ea290f878f65b7e09acf027 (diff)
Merge remote-tracking branch 'upstream/main' into stm32-meowbit-fix
Diffstat (limited to 'ports/stm')
-rw-r--r--ports/stm/common-hal/pulseio/PulseOut.c6
-rw-r--r--ports/stm/common-hal/pulseio/PulseOut.h4
-rw-r--r--ports/stm/common-hal/pwmio/PWMOut.c (renamed from ports/stm/common-hal/pulseio/PWMOut.c)28
-rw-r--r--ports/stm/common-hal/pwmio/PWMOut.h (renamed from ports/stm/common-hal/pulseio/PWMOut.h)8
-rw-r--r--ports/stm/common-hal/pwmio/__init__.c1
-rw-r--r--ports/stm/mphalport.h4
-rw-r--r--ports/stm/peripherals/stm32f4/stm32f401xe/periph.h4
-rw-r--r--ports/stm/peripherals/stm32f4/stm32f405xx/periph.h4
-rw-r--r--ports/stm/peripherals/stm32f4/stm32f407xx/periph.h4
-rw-r--r--ports/stm/peripherals/stm32f4/stm32f411xe/periph.h4
-rw-r--r--ports/stm/peripherals/stm32f4/stm32f412zx/periph.h4
-rw-r--r--ports/stm/peripherals/stm32f7/stm32f746xx/periph.h16
-rw-r--r--ports/stm/peripherals/stm32f7/stm32f767xx/periph.h18
-rw-r--r--ports/stm/peripherals/stm32h7/stm32h743xx/periph.h16
-rw-r--r--ports/stm/supervisor/internal_flash.c4
-rw-r--r--ports/stm/supervisor/port.c14
16 files changed, 74 insertions, 65 deletions
diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c
index eec1049dd..3bf23ad14 100644
--- a/ports/stm/common-hal/pulseio/PulseOut.c
+++ b/ports/stm/common-hal/pulseio/PulseOut.c
@@ -32,7 +32,7 @@
#include "py/gc.h"
#include "py/runtime.h"
#include "shared-bindings/pulseio/PulseOut.h"
-#include "shared-bindings/pulseio/PWMOut.h"
+#include "shared-bindings/pwmio/PWMOut.h"
#include "supervisor/shared/translate.h"
#include STM32_HAL_H
@@ -113,7 +113,7 @@ void pulseout_reset() {
}
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
- const pulseio_pwmout_obj_t* carrier,
+ const pwmio_pwmout_obj_t* carrier,
const mcu_pin_obj_t* pin,
uint32_t frequency,
uint16_t duty_cycle) {
@@ -143,7 +143,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self,
tim_handle.Instance->SR = 0;
// The HAL can't work with const, recast required.
- self->pwmout = (pulseio_pwmout_obj_t*)carrier;
+ self->pwmout = (pwmio_pwmout_obj_t*)carrier;
turn_off(self);
}
diff --git a/ports/stm/common-hal/pulseio/PulseOut.h b/ports/stm/common-hal/pulseio/PulseOut.h
index aa97396d0..29894f27d 100644
--- a/ports/stm/common-hal/pulseio/PulseOut.h
+++ b/ports/stm/common-hal/pulseio/PulseOut.h
@@ -28,13 +28,13 @@
#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PULSEOUT_H
#include "common-hal/microcontroller/Pin.h"
-#include "common-hal/pulseio/PWMOut.h"
+#include "common-hal/pwmio/PWMOut.h"
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
- pulseio_pwmout_obj_t *pwmout;
+ pwmio_pwmout_obj_t *pwmout;
} pulseio_pulseout_obj_t;
void pulseout_reset(void);
diff --git a/ports/stm/common-hal/pulseio/PWMOut.c b/ports/stm/common-hal/pwmio/PWMOut.c
index 4bcb07212..85427185e 100644
--- a/ports/stm/common-hal/pulseio/PWMOut.c
+++ b/ports/stm/common-hal/pwmio/PWMOut.c
@@ -27,8 +27,8 @@
#include <stdint.h>
#include "py/runtime.h"
-#include "common-hal/pulseio/PWMOut.h"
-#include "shared-bindings/pulseio/PWMOut.h"
+#include "common-hal/pwmio/PWMOut.h"
+#include "shared-bindings/pwmio/PWMOut.h"
#include "supervisor/shared/translate.h"
#include "shared-bindings/microcontroller/__init__.h"
@@ -75,7 +75,7 @@ void pwmout_reset(void) {
}
}
-pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
+pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
const mcu_pin_obj_t* pin,
uint16_t duty,
uint32_t frequency,
@@ -96,7 +96,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
//if pin is same
if (l_tim->pin == pin) {
//check if the timer has a channel active, or is reserved by main timer system
- if (reserved_tim[l_tim_index] != 0) {
+ if (l_tim_index < TIM_BANK_ARRAY_LEN && reserved_tim[l_tim_index] != 0) {
// Timer has already been reserved by an internal module
if (stm_peripherals_timer_is_reserved(mcu_tim_banks[l_tim_index])) {
tim_taken_internal = true;
@@ -204,7 +204,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
return PWMOUT_OK;
}
-void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
+void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
for (size_t i = 0; i < TIM_BANK_ARRAY_LEN; i++) {
if (mcu_tim_banks[i] == self->handle.Instance) {
never_reset_tim[i] = true;
@@ -214,7 +214,7 @@ void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
}
}
-void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
+void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
for(size_t i = 0; i < TIM_BANK_ARRAY_LEN; i++) {
if (mcu_tim_banks[i] == self->handle.Instance) {
never_reset_tim[i] = false;
@@ -223,12 +223,12 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
}
}
-bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
+bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) {
return self->tim == NULL;
}
-void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
- if (common_hal_pulseio_pwmout_deinited(self)) {
+void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
+ if (common_hal_pwmio_pwmout_deinited(self)) {
return;
}
//var freq shuts down entire timer, others just their channel
@@ -249,17 +249,17 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
self->tim = NULL;
}
-void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
+void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) {
uint32_t internal_duty_cycle = timer_get_internal_duty(duty, self->period);
__HAL_TIM_SET_COMPARE(&self->handle, self->channel, internal_duty_cycle);
self->duty_cycle = duty;
}
-uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
+uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) {
return self->duty_cycle;
}
-void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) {
+void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency) {
//don't halt setup for the same frequency
if (frequency == self->frequency) {
return;
@@ -296,10 +296,10 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_
self->period = period;
}
-uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) {
+uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) {
return self->frequency;
}
-bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t* self) {
+bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t* self) {
return self->variable_frequency;
}
diff --git a/ports/stm/common-hal/pulseio/PWMOut.h b/ports/stm/common-hal/pwmio/PWMOut.h
index 57ab143b9..5d8001202 100644
--- a/ports/stm/common-hal/pulseio/PWMOut.h
+++ b/ports/stm/common-hal/pwmio/PWMOut.h
@@ -24,8 +24,8 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PWMOUT_H
-#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PWMOUT_H
+#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H
+#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H
#include "common-hal/microcontroller/Pin.h"
@@ -44,8 +44,8 @@ typedef struct {
uint16_t duty_cycle;
uint32_t frequency;
uint32_t period;
-} pulseio_pwmout_obj_t;
+} pwmio_pwmout_obj_t;
void pwmout_reset(void);
-#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PWMOUT_H
+#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H
diff --git a/ports/stm/common-hal/pwmio/__init__.c b/ports/stm/common-hal/pwmio/__init__.c
new file mode 100644
index 000000000..9e551a107
--- /dev/null
+++ b/ports/stm/common-hal/pwmio/__init__.c
@@ -0,0 +1 @@
+// No pwmio module functions.
diff --git a/ports/stm/mphalport.h b/ports/stm/mphalport.h
index 69f2c489c..2c4caf3b2 100644
--- a/ports/stm/mphalport.h
+++ b/ports/stm/mphalport.h
@@ -38,8 +38,8 @@ static inline mp_uint_t mp_hal_ticks_ms(void) {
return supervisor_ticks_ms32();
}
// Number of bytes in receive buffer
-volatile uint8_t usb_rx_count;
-volatile bool mp_cdc_enabled;
+extern volatile uint8_t usb_rx_count;
+extern volatile bool mp_cdc_enabled;
int receive_usb(void);
diff --git a/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h b/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h
index ae416bda1..c38e9ea98 100644
--- a/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h
+++ b/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h
@@ -51,7 +51,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[6];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 44
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F401XE_PERIPH_H
diff --git a/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h b/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h
index 020bff370..5b64fe10c 100644
--- a/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h
+++ b/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h
@@ -58,8 +58,8 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 67
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
//SDIO
extern SDIO_TypeDef * mcu_sdio_banks[1];
diff --git a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h
index 55c00ee93..fb6348aba 100644
--- a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h
+++ b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h
@@ -51,7 +51,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[12];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 56
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PERIPH_H
diff --git a/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h b/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h
index 14a73d12f..f78cb57a7 100644
--- a/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h
+++ b/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h
@@ -51,7 +51,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[7];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 44
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F411XE_PERIPH_H
diff --git a/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h b/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h
index f6b001a4e..40afd27f4 100644
--- a/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h
+++ b/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h
@@ -52,7 +52,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[12];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 60
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F412ZX_PERIPH_H
diff --git a/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h b/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h
index 26f4ad2b5..f20896e22 100644
--- a/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h
+++ b/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h
@@ -31,28 +31,28 @@
//I2C
extern I2C_TypeDef * mcu_i2c_banks[4];
-const mcu_periph_obj_t mcu_i2c_sda_list[10];
-const mcu_periph_obj_t mcu_i2c_scl_list[10];
+extern const mcu_periph_obj_t mcu_i2c_sda_list[10];
+extern const mcu_periph_obj_t mcu_i2c_scl_list[10];
//SPI
extern SPI_TypeDef * mcu_spi_banks[6];
-const mcu_periph_obj_t mcu_spi_sck_list[14];
-const mcu_periph_obj_t mcu_spi_mosi_list[15];
-const mcu_periph_obj_t mcu_spi_miso_list[12];
+extern const mcu_periph_obj_t mcu_spi_sck_list[14];
+extern const mcu_periph_obj_t mcu_spi_mosi_list[15];
+extern const mcu_periph_obj_t mcu_spi_miso_list[12];
//UART
extern USART_TypeDef * mcu_uart_banks[MAX_UART];
extern bool mcu_uart_has_usart[MAX_UART];
-const mcu_periph_obj_t mcu_uart_tx_list[15];
-const mcu_periph_obj_t mcu_uart_rx_list[15];
+extern const mcu_periph_obj_t mcu_uart_tx_list[15];
+extern const mcu_periph_obj_t mcu_uart_rx_list[15];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 55
extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F746XX_PERIPH_H
diff --git a/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h b/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h
index 438964c3e..70f03f258 100644
--- a/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h
+++ b/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h
@@ -30,28 +30,28 @@
//I2C
extern I2C_TypeDef * mcu_i2c_banks[4];
-const mcu_periph_obj_t mcu_i2c_sda_list[12];
-const mcu_periph_obj_t mcu_i2c_scl_list[12];
+extern const mcu_periph_obj_t mcu_i2c_sda_list[12];
+extern const mcu_periph_obj_t mcu_i2c_scl_list[12];
//SPI
extern SPI_TypeDef * mcu_spi_banks[6];
-const mcu_periph_obj_t mcu_spi_sck_list[18];
-const mcu_periph_obj_t mcu_spi_mosi_list[18];
-const mcu_periph_obj_t mcu_spi_miso_list[15];
+extern const mcu_periph_obj_t mcu_spi_sck_list[18];
+extern const mcu_periph_obj_t mcu_spi_mosi_list[18];
+extern const mcu_periph_obj_t mcu_spi_miso_list[15];
//UART
extern USART_TypeDef * mcu_uart_banks[MAX_UART];
extern bool mcu_uart_has_usart[MAX_UART];
-const mcu_periph_obj_t mcu_uart_tx_list[24];
-const mcu_periph_obj_t mcu_uart_rx_list[25];
+extern const mcu_periph_obj_t mcu_uart_tx_list[24];
+extern const mcu_periph_obj_t mcu_uart_rx_list[25];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 55
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
-const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
+extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F767XX_PERIPH_H
diff --git a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h
index 9aa2f7366..e3902e7c7 100644
--- a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h
+++ b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h
@@ -30,26 +30,26 @@
//I2C
extern I2C_TypeDef * mcu_i2c_banks[4];
-const mcu_periph_obj_t mcu_i2c_sda_list[12];
-const mcu_periph_obj_t mcu_i2c_scl_list[12];
+extern const mcu_periph_obj_t mcu_i2c_sda_list[12];
+extern const mcu_periph_obj_t mcu_i2c_scl_list[12];
//SPI
extern SPI_TypeDef * mcu_spi_banks[6];
-const mcu_periph_obj_t mcu_spi_sck_list[19];
-const mcu_periph_obj_t mcu_spi_mosi_list[19];
-const mcu_periph_obj_t mcu_spi_miso_list[16];
+extern const mcu_periph_obj_t mcu_spi_sck_list[19];
+extern const mcu_periph_obj_t mcu_spi_mosi_list[19];
+extern const mcu_periph_obj_t mcu_spi_miso_list[16];
//UART
extern USART_TypeDef * mcu_uart_banks[MAX_UART];
extern bool mcu_uart_has_usart[MAX_UART];
-const mcu_periph_obj_t mcu_uart_tx_list[25];
-const mcu_periph_obj_t mcu_uart_rx_list[26];
+extern const mcu_periph_obj_t mcu_uart_tx_list[25];
+extern const mcu_periph_obj_t mcu_uart_rx_list[26];
//Timers
#define TIM_BANK_ARRAY_LEN 14
#define TIM_PIN_ARRAY_LEN 58
-TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
+extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32H743XX_PERIPH_H
diff --git a/ports/stm/supervisor/internal_flash.c b/ports/stm/supervisor/internal_flash.c
index 864403c36..78ee4f3e6 100644
--- a/ports/stm/supervisor/internal_flash.c
+++ b/ports/stm/supervisor/internal_flash.c
@@ -177,13 +177,13 @@ void port_internal_flash_flush(void) {
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
// get the sector information
uint32_t sector_size;
- uint32_t sector_start_addr;
+ uint32_t sector_start_addr = 0xffffffff;
#if defined(STM32H7)
EraseInitStruct.Banks = get_bank(_cache_flash_addr);
#endif
EraseInitStruct.Sector = flash_get_sector_info(_cache_flash_addr, &sector_start_addr, &sector_size);
EraseInitStruct.NbSectors = 1;
- if (sector_size > sizeof(_flash_cache)) {
+ if (sector_size > sizeof(_flash_cache) || sector_start_addr == 0xffffffff) {
reset_into_safe_mode(FLASH_WRITE_FAIL);
}
diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c
index 5ce92f70a..e21105001 100644
--- a/ports/stm/supervisor/port.c
+++ b/ports/stm/supervisor/port.c
@@ -38,9 +38,13 @@
#include "common-hal/busio/UART.h"
#endif
#if CIRCUITPY_PULSEIO
-#include "common-hal/pulseio/PWMOut.h"
#include "common-hal/pulseio/PulseOut.h"
#include "common-hal/pulseio/PulseIn.h"
+#endif
+#if CIRCUITPY_PWMIO
+#include "common-hal/pwmio/PWMOut.h"
+#endif
+#if CIRCUITPY_PULSEIO || CIRCUITPY_PWMIO
#include "timers.h"
#endif
#if CIRCUITPY_SDIOIO
@@ -230,12 +234,16 @@ void reset_port(void) {
#if CIRCUITPY_SDIOIO
sdioio_reset();
#endif
-#if CIRCUITPY_PULSEIO
+#if CIRCUITPY_PULSEIO || CIRCUITPY_PWMIO
timers_reset();
- pwmout_reset();
+#endif
+#if CIRCUITPY_PULSEIO
pulseout_reset();
pulsein_reset();
#endif
+#if CIRCUITPY_PWMIO
+ pwmout_reset();
+#endif
}
void reset_to_bootloader(void) {