From dd58be19eef0be304e1b0530fe6e7408ab9b9b84 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Thu, 21 Sep 2023 11:40:26 +0200 Subject: [PATCH 01/78] esp32: Fix Partition.writeblocks() partial write corruption. To simulate a partial erase, the code reads a native block, erases it, and writes back the data before and after the erased area. However, the current logic was filling the area after the erased block with data from the beginning of the native block-aligned data, instead of applying the proper offset. Fixes #12474. Signed-off-by: Luca Burelli --- ports/esp32/esp32_partition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32/esp32_partition.c b/ports/esp32/esp32_partition.c index 17aa34e560e8..3bca3b52731d 100644 --- a/ports/esp32/esp32_partition.c +++ b/ports/esp32/esp32_partition.c @@ -200,7 +200,7 @@ STATIC mp_obj_t esp32_partition_writeblocks(size_t n_args, const mp_obj_t *args) check_esp_err(esp_partition_write(self->part, addr, self->cache, o)); } if (top_addr < addr + NATIVE_BLOCK_SIZE_BYTES) { - check_esp_err(esp_partition_write(self->part, top_addr, self->cache, addr + NATIVE_BLOCK_SIZE_BYTES - top_addr)); + check_esp_err(esp_partition_write(self->part, top_addr, self->cache + (top_addr - addr), addr + NATIVE_BLOCK_SIZE_BYTES - top_addr)); } o = 0; addr += NATIVE_BLOCK_SIZE_BYTES; From 13cc280eaeb2f01aa78631019057f6ff22d33384 Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Sat, 29 Jul 2023 19:49:12 +0200 Subject: [PATCH 02/78] stm32/adc: Fix STM32H5 support. Fixed the preliminary STM32H5 ADC support for pyb.ADC: - Run ADC on PCLK/16. - Use STM32 ADC library channel literals (__HAL_ADC_DECIMAL_NB_TO_CHANNEL). - Use correct temperature conversion for H5 (30C, 130C calibration points). Signed-off-by: Rene Straub --- ports/stm32/adc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index 20cd2499e13a..7680ecbefd0f 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -352,7 +352,7 @@ STATIC void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) { adch->Init.DataAlign = ADC_DATAALIGN_RIGHT; adch->Init.DMAContinuousRequests = DISABLE; #elif defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L4) || defined(STM32WB) - #if defined(STM32G4) + #if defined(STM32G4) || defined(STM32H5) adch->Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV16; #else adch->Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; @@ -395,7 +395,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) { STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) { ADC_ChannelConfTypeDef sConfig; - #if defined(STM32G0) || defined(STM32G4) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB) + #if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB) sConfig.Rank = ADC_REGULAR_RANK_1; if (__HAL_ADC_IS_CHANNEL_INTERNAL(channel) == 0) { channel = __HAL_ADC_DECIMAL_NB_TO_CHANNEL(channel); @@ -897,6 +897,9 @@ float adc_read_core_temp_float(ADC_HandleTypeDef *adcHandle) { return 0; } float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 100.0f; + #elif defined(STM32H5) + int32_t raw_value = adc_config_and_read_ref(adcHandle, ADC_CHANNEL_TEMPSENSOR); + float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 100.0f; #else int32_t raw_value = adc_config_and_read_ref(adcHandle, ADC_CHANNEL_TEMPSENSOR); float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 80.0f; From 8f9bba0a1a36caf3afd86b27b1e860225f85cc6a Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Sat, 5 Aug 2023 14:21:41 +0200 Subject: [PATCH 03/78] stm32/adc: Add support for STM32H5 ADC2 inputs. Select ADC instance based on pin information to support ADC2 inputs. Display ADC instance number similar to machine_adc (STM32H5 only): Signed-off-by: Rene Straub --- ports/stm32/adc.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index 7680ecbefd0f..d153f547ddec 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -51,9 +51,14 @@ /// val = adc.read_core_vref() # read MCU VREF /* ADC definitions */ +#if defined(STM32H5) +// STM32H5 features two ADC instances, ADCx and pin_adc_table are set dynamically +#define PIN_ADC_MASK (PIN_ADC1 | PIN_ADC2) +#else #define ADCx (ADC1) #define PIN_ADC_MASK PIN_ADC1 #define pin_adc_table pin_adc1 +#endif #if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || \ defined(STM32H7B3xx) || defined(STM32H7B3xxQ) @@ -379,8 +384,8 @@ STATIC void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) { #endif } -STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) { - adc_obj->handle.Instance = ADCx; +STATIC void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) { + adc_obj->handle.Instance = adc; adcx_init_periph(&adc_obj->handle, ADC_RESOLUTION_12B); #if (defined(STM32G4) || defined(STM32L4)) && defined(ADC_DUALMODE_REGSIMULT_INJECSIMULT) @@ -495,7 +500,15 @@ STATIC uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32 STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in); + #if defined STM32H5 + unsigned adc_id = 1; + if (self->handle.Instance == ADC2) { + adc_id = 2; + } + mp_printf(print, "pin_name, PRINT_STR); mp_printf(print, " channel=%u>", self->channel); } @@ -510,6 +523,13 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ // 1st argument is the pin name mp_obj_t pin_obj = args[0]; + #if defined(STM32H5) + // STM32H5 has two ADC instances where some pins are only available on ADC1 or ADC2 (but not both). + // Assume we're using a channel of ADC1. Can be overridden for ADC2 later in this function. + ADC_TypeDef *adc = ADC1; + const pin_obj_t *const *pin_adc_table = pin_adc1; + uint32_t num_adc_pins = MP_ARRAY_SIZE(pin_adc1); + #endif uint32_t channel; if (mp_obj_is_int(pin_obj)) { @@ -520,6 +540,13 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ // No ADC function on the given pin. mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%q) doesn't have ADC capabilities"), pin->name); } + #if defined(STM32H5) + if ((pin->adc_num & PIN_ADC2) == PIN_ADC2) { + adc = ADC2; + pin_adc_table = pin_adc2; + num_adc_pins = MP_ARRAY_SIZE(pin_adc2); + } + #endif channel = pin->adc_channel; } @@ -528,20 +555,32 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ } // If this channel corresponds to a pin then configure the pin in ADC mode. + #if defined(STM32H5) + if (channel < num_adc_pins) { + const pin_obj_t *pin = pin_adc_table[channel]; + if (pin != NULL) { + mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0); + } + } + #else if (channel < MP_ARRAY_SIZE(pin_adc_table)) { const pin_obj_t *pin = pin_adc_table[channel]; if (pin != NULL) { mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0); } } + #endif pyb_obj_adc_t *o = m_new_obj(pyb_obj_adc_t); memset(o, 0, sizeof(*o)); o->base.type = &pyb_adc_type; o->pin_name = pin_obj; o->channel = channel; - adc_init_single(o); - + #if defined(STM32H5) + adc_init_single(o, adc); + #else + adc_init_single(o, ADCx); + #endif return MP_OBJ_FROM_PTR(o); } From 64d24fccd6d5469c38ea4440cd43a03aec750835 Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Sat, 5 Aug 2023 14:23:29 +0200 Subject: [PATCH 04/78] stm32/adc: Optimize sampling time for G4, H5, L4 and WB MCUs. Signed-off-by: Rene Straub --- ports/stm32/adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index d153f547ddec..6bd0f4ce25b6 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -444,7 +444,7 @@ STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) if (__HAL_ADC_IS_CHANNEL_INTERNAL(channel)) { sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5; } else { - sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5; + sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5; } sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; From 72ef2e6291eedfe237b8b086a44ac570ce8b7f0d Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Wed, 2 Aug 2023 09:13:16 +0200 Subject: [PATCH 05/78] stm32/machine_adc: Fix and improve STM32H5 support. Changes are: - Run ADC on PCLK/16. - Verify and optimize timings (ADC_STAB_DELAY_US, ADC_SAMPLETIME_DEFAULT). - Add support for STM32H5 VBAT and COREVDD channels on ADC2. - Replace ADC constants in machine_adc_locals_dict_table. - Convert STM32 literal to channel numbers in adc_config_channel with corresponding STM32 LL library functions (__LL_ADC_IS_CHANNEL_INTERNAL(), __LL_ADC_CHANNEL_TO_DECIMAL_NB()). Reasoning for the second last point: the STM32 driver literals are uint32_t that don't work with MP_ROM_INT() which handles signed 31 bit integers only. Introduce enumerator machine_adc_internal_ch_t to define external channels (0..19), internal channels (256..) and the special channel VREF (0xffff). Values are converted to STM32 literals with adc_ll_channel() when required in adc_config_and_read_u16(). Signed-off-by: Rene Straub --- ports/stm32/machine_adc.c | 130 ++++++++++++++++++++++++++++++-------- 1 file changed, 104 insertions(+), 26 deletions(-) diff --git a/ports/stm32/machine_adc.c b/ports/stm32/machine_adc.c index fee3d698dbb8..f41b80e0ad7b 100644 --- a/ports/stm32/machine_adc.c +++ b/ports/stm32/machine_adc.c @@ -48,7 +48,9 @@ #elif defined(STM32G4) #define ADC_STAB_DELAY_US (20) #elif defined(STM32H5) -#define ADC_STAB_DELAY_US (1) // TODO: Check if this is enough +// Stabilization delay = 1 conversion cycle +// ADC clk = PDIV / 16 = 250 MHz / 16 = 15.625 MHz -> 64 ns -> select 1 us +#define ADC_STAB_DELAY_US (1) #elif defined(STM32L4) #define ADC_STAB_DELAY_US (10) #elif defined(STM32WB) @@ -61,9 +63,14 @@ #elif defined(STM32F4) || defined(STM32F7) #define ADC_SAMPLETIME_DEFAULT ADC_SAMPLETIME_15CYCLES #define ADC_SAMPLETIME_DEFAULT_INT ADC_SAMPLETIME_480CYCLES -#elif defined(STM32G4) || defined(STM32H5) +#elif defined(STM32G4) #define ADC_SAMPLETIME_DEFAULT ADC_SAMPLETIME_12CYCLES_5 #define ADC_SAMPLETIME_DEFAULT_INT ADC_SAMPLETIME_247CYCLES_5 +#elif defined(STM32H5) +// Worst case sampling time: slow channel, 12 bits, 680 ohms -> 165 ns +// ADC clk = PDIV / 16 = 250 MHz / 16 = 15.625 MHz -> 64 ns -> 2.57 cycles -> select 6.5 cycles +#define ADC_SAMPLETIME_DEFAULT ADC_SAMPLETIME_6CYCLES_5 +#define ADC_SAMPLETIME_DEFAULT_INT ADC_SAMPLETIME_247CYCLES_5 #elif defined(STM32H7) #define ADC_SAMPLETIME_DEFAULT ADC_SAMPLETIME_8CYCLES_5 #define ADC_SAMPLETIME_DEFAULT_INT ADC_SAMPLETIME_387CYCLES_5 @@ -81,8 +88,65 @@ // Timeout for waiting for end-of-conversion #define ADC_EOC_TIMEOUT_MS (10) -// This is a synthesised channel representing the maximum ADC reading (useful to scale other channels) -#define ADC_CHANNEL_VREF (0xffff) +// Channel IDs for machine.ADC object +typedef enum _machine_adc_internal_ch_t { + // Regular external ADC inputs (0..19) + MACHINE_ADC_EXT_CH_0 = 0, + MACHINE_ADC_EXT_CH_19 = 19, + + // Internal ADC channels (256..) + MACHINE_ADC_INT_CH_VREFINT = 256, + MACHINE_ADC_INT_CH_TEMPSENSOR, + #if defined(ADC_CHANNEL_VBAT) + MACHINE_ADC_INT_CH_VBAT, + #endif + #if defined(ADC_CHANNEL_VDDCORE) + MACHINE_ADC_INT_CH_VDDCORE, + #endif + + // This is a synthesised channel representing the maximum ADC reading (useful to scale other channels) + MACHINE_ADC_CH_VREF = 0xffff // 0xffff for backward compatibility +} machine_adc_internal_ch_t; + +// Convert machine_adc_internal_ch_t value to STM32 library ADC channel literal. +// This function is required as literals are uint32_t types that don't map with MP_ROM_INT (31 bit signed). +STATIC uint32_t adc_ll_channel(uint32_t channel_id) { + uint32_t adc_ll_ch; + switch (channel_id) { + // external channels map 1:1 + case MACHINE_ADC_EXT_CH_0 ... MACHINE_ADC_EXT_CH_19: + adc_ll_ch = channel_id; + break; + + // internal channels are converted to STM32 ADC defines + case MACHINE_ADC_INT_CH_VREFINT: + adc_ll_ch = ADC_CHANNEL_VREFINT; + break; + case MACHINE_ADC_INT_CH_TEMPSENSOR: + #if defined(STM32G4) + adc_ll_ch = ADC_CHANNEL_TEMPSENSOR_ADC1; + #else + adc_ll_ch = ADC_CHANNEL_TEMPSENSOR; + #endif + break; + #if defined(ADC_CHANNEL_VBAT) + case MACHINE_ADC_INT_CH_VBAT: + adc_ll_ch = ADC_CHANNEL_VBAT; + break; + #endif + #if defined(ADC_CHANNEL_VDDCORE) + case MACHINE_ADC_INT_CH_VDDCORE: + adc_ll_ch = ADC_CHANNEL_VDDCORE; + break; + #endif + + // To save code memory for costly error handling, default to Vref for unknown channels + default: + adc_ll_ch = ADC_CHANNEL_VREFINT; + break; + }; + return adc_ll_ch; +} static inline void adc_stabilisation_delay_us(uint32_t us) { mp_hal_delay_us(us + 1); @@ -150,9 +214,9 @@ void adc_config(ADC_TypeDef *adc, uint32_t bits) { adc->CFGR2 = 2 << ADC_CFGR2_CKMODE_Pos; // PCLK/4 (synchronous clock mode) #elif defined(STM32F4) || defined(STM32F7) || defined(STM32L4) ADCx_COMMON->CCR = 0; // ADCPR=PCLK/2 - #elif defined(STM32G4) + #elif defined(STM32G4) || defined(STM32H5) ADC12_COMMON->CCR = 7 << ADC_CCR_PRESC_Pos; // PCLK/16 (asynchronous clock mode) - #elif defined(STM32H5) || defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) + #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) ADC12_COMMON->CCR = 3 << ADC_CCR_CKMODE_Pos; #elif defined(STM32H7) ADC12_COMMON->CCR = 3 << ADC_CCR_CKMODE_Pos; @@ -352,9 +416,16 @@ STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t samp #else adc_common->CCR |= ADC_CCR_VBATEN; #endif + #if defined(STM32H5) + } else if (channel == ADC_CHANNEL_VDDCORE) { + adc->OR |= ADC_OR_OP0; // Enable Vddcore channel on ADC2 + #endif + } + #if defined(STM32G4) || defined(STM32H5) + // G4 and H5 use encoded literals for internal channels -> extract ADC channel for following code + if (__LL_ADC_IS_CHANNEL_INTERNAL(channel)) { + channel = __LL_ADC_CHANNEL_TO_DECIMAL_NB(channel); } - #if defined(STM32G4) - channel = __LL_ADC_CHANNEL_TO_DECIMAL_NB(channel); adc->DIFSEL &= ~(1 << channel); // Set channel to Single-ended. #endif adc->SQR1 = (channel & 0x1f) << ADC_SQR1_SQ1_Pos | (1 - 1) << ADC_SQR1_L_Pos; @@ -391,10 +462,13 @@ STATIC uint32_t adc_read_channel(ADC_TypeDef *adc) { } uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) { - if (channel == ADC_CHANNEL_VREF) { + if (channel == MACHINE_ADC_CH_VREF) { return 0xffff; } + // Map internal channel_id to STM32 ADC driver value/literal. + channel = adc_ll_channel(channel); + // Select, configure and read the channel. adc_config_channel(adc, channel, sample_time); uint32_t raw = adc_read_channel(adc); @@ -421,7 +495,7 @@ const mp_obj_type_t machine_adc_type; typedef struct _machine_adc_obj_t { mp_obj_base_t base; ADC_TypeDef *adc; - uint32_t channel; + uint32_t channel; // one of machine_adc_internal_ch_t uint32_t sample_time; } machine_adc_obj_t; @@ -452,20 +526,25 @@ STATIC mp_obj_t machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, s uint32_t sample_time = ADC_SAMPLETIME_DEFAULT; ADC_TypeDef *adc; if (mp_obj_is_int(source)) { + channel = mp_obj_get_int(source); #if defined(STM32WL) adc = ADC; + #elif defined(STM32H5) + // on STM32H5 vbat and vddcore channels are on ADC2 + if (channel == MACHINE_ADC_INT_CH_VBAT || channel == MACHINE_ADC_INT_CH_VDDCORE) { + adc = ADC2; + } else { + adc = ADC1; + } #else adc = ADC1; #endif - channel = mp_obj_get_int(source); - if (channel == ADC_CHANNEL_VREFINT - #if defined(STM32G4) - || channel == ADC_CHANNEL_TEMPSENSOR_ADC1 - #else - || channel == ADC_CHANNEL_TEMPSENSOR - #endif + if (channel == MACHINE_ADC_INT_CH_VREFINT || channel == MACHINE_ADC_INT_CH_TEMPSENSOR #if defined(ADC_CHANNEL_VBAT) - || channel == ADC_CHANNEL_VBAT + || channel == MACHINE_ADC_INT_CH_VBAT + #endif + #if defined(ADC_CHANNEL_VDDCORE) + || channel == MACHINE_ADC_INT_CH_VDDCORE #endif ) { sample_time = ADC_SAMPLETIME_DEFAULT_INT; @@ -516,15 +595,14 @@ MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_u16_obj, machine_adc_read_u16); STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read_u16), MP_ROM_PTR(&machine_adc_read_u16_obj) }, - { MP_ROM_QSTR(MP_QSTR_VREF), MP_ROM_INT(ADC_CHANNEL_VREF) }, - { MP_ROM_QSTR(MP_QSTR_CORE_VREF), MP_ROM_INT(ADC_CHANNEL_VREFINT) }, - #if defined(STM32G4) - { MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(ADC_CHANNEL_TEMPSENSOR_ADC1) }, - #else - { MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(ADC_CHANNEL_TEMPSENSOR) }, - #endif + { MP_ROM_QSTR(MP_QSTR_VREF), MP_ROM_INT(MACHINE_ADC_CH_VREF) }, + { MP_ROM_QSTR(MP_QSTR_CORE_VREF), MP_ROM_INT(MACHINE_ADC_INT_CH_VREFINT) }, + { MP_ROM_QSTR(MP_QSTR_CORE_TEMP), MP_ROM_INT(MACHINE_ADC_INT_CH_TEMPSENSOR) }, #if defined(ADC_CHANNEL_VBAT) - { MP_ROM_QSTR(MP_QSTR_CORE_VBAT), MP_ROM_INT(ADC_CHANNEL_VBAT) }, + { MP_ROM_QSTR(MP_QSTR_CORE_VBAT), MP_ROM_INT(MACHINE_ADC_INT_CH_VBAT) }, + #endif + #if defined(ADC_CHANNEL_VDDCORE) + { MP_ROM_QSTR(MP_QSTR_CORE_VDD), MP_ROM_INT(MACHINE_ADC_INT_CH_VDDCORE) }, #endif }; STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); From 08c661c930a8d6256e3065064820fa30d5485d39 Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Fri, 11 Aug 2023 21:26:50 +0200 Subject: [PATCH 06/78] stm32/dac: Add STM32H5 DAC support, with dma_nohal implementation. Integrate DAC support for STM32H5. Implement STM32H5 GPDMA driver. The DMA driver is largely different from other STM32 variants. To support the DAC circular mode, memory based linked list DMA descriptors are used. Signed-off-by: Rene Straub --- ports/stm32/dac.c | 4 ++ ports/stm32/dma.c | 124 +++++++++++++++++++++++++++++++++++++++++++++- ports/stm32/dma.h | 6 +++ 3 files changed, 133 insertions(+), 1 deletion(-) diff --git a/ports/stm32/dac.c b/ports/stm32/dac.c index 7a446854f80a..142b7ea38799 100644 --- a/ports/stm32/dac.c +++ b/ports/stm32/dac.c @@ -173,6 +173,8 @@ STATIC void dac_start_dma(uint32_t dac_channel, const dma_descr_t *dma_descr, ui #if defined(STM32G4) // For STM32G4, DAC registers have to be accessed by words (32-bit). dma_align = DMA_MDATAALIGN_BYTE | DMA_PDATAALIGN_WORD; + #elif defined(STM32H5) + dma_align = 0; #else dma_align = DMA_MDATAALIGN_BYTE | DMA_PDATAALIGN_BYTE; #endif @@ -180,6 +182,8 @@ STATIC void dac_start_dma(uint32_t dac_channel, const dma_descr_t *dma_descr, ui #if defined(STM32G4) // For STM32G4, DAC registers have to be accessed by words (32-bit). dma_align = DMA_MDATAALIGN_HALFWORD | DMA_PDATAALIGN_WORD; + #elif defined(STM32H5) + dma_align = 0; #else dma_align = DMA_MDATAALIGN_HALFWORD | DMA_PDATAALIGN_HALFWORD; #endif diff --git a/ports/stm32/dma.c b/ports/stm32/dma.c index 94c293c0d0ee..298670f00e99 100644 --- a/ports/stm32/dma.c +++ b/ports/stm32/dma.c @@ -185,6 +185,24 @@ static const DMA_InitTypeDef dma_init_struct_sdio = { #endif #if defined(MICROPY_HW_ENABLE_DAC) && MICROPY_HW_ENABLE_DAC +#if defined(STM32H5) +// Default parameters to dma_init() for DAC tx +static const DMA_InitTypeDef dma_init_struct_dac = { + .Request = 0, // set by dma_init_handle + .BlkHWRequest = DMA_BREQ_SINGLE_BURST, + .Direction = DMA_MEMORY_TO_PERIPH, + .SrcInc = DMA_SINC_INCREMENTED, + .DestInc = DMA_DINC_FIXED, + .SrcDataWidth = DMA_SRC_DATAWIDTH_BYTE, + .DestDataWidth = DMA_DEST_DATAWIDTH_WORD, + .Priority = DMA_HIGH_PRIORITY, + .SrcBurstLength = 1, + .DestBurstLength = 1, + .TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0 | DMA_DEST_ALLOCATED_PORT0, + .TransferEventMode = DMA_TCEM_BLOCK_TRANSFER, + .Mode = DMA_NORMAL, // DMA_NORMAL or DMA_PFCTRL (peripheral flow control mode) +}; +#else // Default parameters to dma_init() for DAC tx static const DMA_InitTypeDef dma_init_struct_dac = { #if defined(STM32F4) || defined(STM32F7) @@ -207,6 +225,7 @@ static const DMA_InitTypeDef dma_init_struct_dac = { #endif }; #endif +#endif #if MICROPY_HW_ENABLE_DCMI static const DMA_InitTypeDef dma_init_struct_dcmi = { @@ -715,6 +734,10 @@ const dma_descr_t dma_SPI_1_RX = { GPDMA1_Channel0, GPDMA1_REQUEST_SPI1_RX, dma_ const dma_descr_t dma_SPI_1_TX = { GPDMA1_Channel1, GPDMA1_REQUEST_SPI1_TX, dma_id_1, &dma_init_struct_spi_i2c }; const dma_descr_t dma_SPI_2_RX = { GPDMA1_Channel2, GPDMA1_REQUEST_SPI2_RX, dma_id_2, &dma_init_struct_spi_i2c }; const dma_descr_t dma_SPI_2_TX = { GPDMA1_Channel3, GPDMA1_REQUEST_SPI2_TX, dma_id_3, &dma_init_struct_spi_i2c }; +#if MICROPY_HW_ENABLE_DAC +const dma_descr_t dma_DAC_1_TX = { GPDMA1_Channel4, GPDMA1_REQUEST_DAC1_CH1, dma_id_4, &dma_init_struct_dac }; +const dma_descr_t dma_DAC_2_TX = { GPDMA1_Channel5, GPDMA1_REQUEST_DAC1_CH2, dma_id_5, &dma_init_struct_dac }; +#endif static const uint8_t dma_irqn[NSTREAM] = { GPDMA1_Channel0_IRQn, @@ -1613,7 +1636,106 @@ void dma_nohal_start(const dma_descr_t *descr, uint32_t src_addr, uint32_t dst_a dma->CCR |= DMA_CCR_EN; } -#elif defined(STM32G0) || defined(STM32H5) || defined(STM32WB) || defined(STM32WL) +#elif defined(STM32H5) + +// Fully setup GPDMA linked list entry +typedef struct _dma_ll_full_t { + __IO uint32_t CTR1; + __IO uint32_t CTR2; + __IO uint32_t CBR1; + __IO uint32_t CSAR; + __IO uint32_t CDAR; + __IO uint32_t CLLR; +} dma_ll_full_t; + +// Align LL entry to 32 bytes to ensure it never crosses a 64 kB boundary +__ALIGNED(32) static __IO dma_ll_full_t lli1; + +void dma_nohal_init(const dma_descr_t *descr, uint32_t config) { + DMA_Channel_TypeDef *dma = descr->instance; + const DMA_InitTypeDef *init = descr->init; + + // Enable the DMA peripheral + dma_enable_clock(descr->id); + + // - LSM = 0, normal linked list mode + // - No interrupts + // - Not suspended, out of reset, disabled + // - Priority as defined by user + dma->CCR = init->Priority; + + uint32_t ctr1reg = 0; + ctr1reg |= init->SrcDataWidth; + ctr1reg |= init->SrcInc; + ctr1reg |= (((init->SrcBurstLength - 1) << DMA_CTR1_SBL_1_Pos)) & DMA_CTR1_SBL_1_Msk; + ctr1reg |= init->DestDataWidth; + ctr1reg |= init->DestInc; + ctr1reg |= (((init->DestBurstLength - 1) << DMA_CTR1_DBL_1_Pos)) & DMA_CTR1_DBL_1_Msk; + + uint32_t ctr2reg = 0; + ctr2reg |= init->BlkHWRequest; + ctr2reg |= init->Direction; + ctr2reg |= init->Mode; + ctr2reg |= init->TransferEventMode; + ctr2reg |= init->TransferAllocatedPort; + uint32_t reqsel = descr->sub_instance; + ctr2reg |= (reqsel << DMA_CTR2_REQSEL_Pos) & DMA_CTR2_REQSEL_Msk; + + dma->CBR1 = 0; // set length to zero, so that GPDMA engine fetches first LL entry immediately + dma->CSAR = 0; + dma->CDAR = 0; + + // Attach linked list entry + dma->CLBAR = (uint32_t)(&lli1) & 0xffff0000UL; // upper 16 bits of linked list addresses + + uint32_t cllrreg = 0; + cllrreg |= (DMA_CLLR_UT1 | DMA_CLLR_UT2 | DMA_CLLR_UB1 | DMA_CLLR_USA | DMA_CLLR_UDA | DMA_CLLR_ULL); + cllrreg |= (uint32_t)(&lli1) & 0x0000fffcUL; // lower 16 bits of linked list entry address + dma->CLLR = cllrreg; + + // Setup linked list control registers. Length and addresses are set in dma_nohal_start() + lli1.CTR1 = ctr1reg; + lli1.CTR2 = ctr2reg; + + if ((config & DMA_CIRCULAR) == DMA_CIRCULAR) { + lli1.CLLR = cllrreg; // pointer to itself for circular operation + } else { + lli1.CLLR = 0; // No next node, this is end of linked list chain + } +} + +void dma_nohal_deinit(const dma_descr_t *descr) { + DMA_Channel_TypeDef *dma = descr->instance; + + if ((dma->CCR & DMA_CCR_EN) == DMA_CCR_EN) { + // Suspend currently running channel. Wait until done, then reset to clear FIFOs. + dma->CCR |= DMA_CCR_SUSP; + + uint32_t t0 = mp_hal_ticks_ms(); + while ((dma->CSR & DMA_CSR_SUSPF) != DMA_CSR_SUSPF) { + if (mp_hal_ticks_ms() - t0 >= 100) { + // Timeout.. Abort to avoid blocking system forever + break; + } + } + + dma->CCR |= DMA_CCR_RESET; + } + dma->CCR &= ~DMA_CCR_EN; + dma->CCR = 0; + dma_deinit(descr); +} + +void dma_nohal_start(const dma_descr_t *descr, uint32_t src_addr, uint32_t dst_addr, uint16_t len) { + DMA_Channel_TypeDef *dma = descr->instance; + lli1.CBR1 = (len << DMA_CBR1_BNDT_Pos) & DMA_CBR1_BNDT_Msk; + lli1.CSAR = src_addr; + lli1.CDAR = dst_addr; + + dma->CCR |= DMA_CCR_EN; +} + +#elif defined(STM32G0) || defined(STM32WB) || defined(STM32WL) // These functions are currently not implemented or needed for this MCU. diff --git a/ports/stm32/dma.h b/ports/stm32/dma.h index 2afc94754187..fa3238413ea4 100644 --- a/ports/stm32/dma.h +++ b/ports/stm32/dma.h @@ -28,6 +28,12 @@ typedef struct _dma_descr_t dma_descr_t; +#if defined(STM32H5) +// STM32H5 GPDMA doesn't feature circular mode directly, so define doesn't exist in +// stm32 driver header. Define it here to make users like DAC driver happy. +#define DMA_CIRCULAR 0x00000001 +#endif + #if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32G0) || defined(STM32H5) || defined(STM32H7) extern const dma_descr_t dma_I2C_1_RX; From 82b4ab757603c52420f5e11470d0404ba93286ed Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 28 Sep 2023 16:24:45 +1000 Subject: [PATCH 07/78] stm32/boards: Move includes to after defines in all hal_conf.h files. The include of HAL headers should come after the HAL configuration defines, so that the headers can see whether the defines were made or not, to provide defaults and configure various things. Signed-off-by: Damien George --- .../stm32f4xx_hal_conf.h | 4 +- .../boards/ARDUINO_GIGA/stm32h7xx_hal_conf.h | 4 +- .../ARDUINO_NICLA_VISION/stm32h7xx_hal_conf.h | 4 +- .../ARDUINO_PORTENTA_H7/stm32h7xx_hal_conf.h | 4 +- .../B_L072Z_LRWAN1/stm32l0xx_hal_conf.h | 4 +- .../B_L475E_IOT01A/stm32l4xx_hal_conf.h | 4 +- .../stm32/boards/CERB40/stm32f4xx_hal_conf.h | 4 +- .../boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h | 4 +- .../stm32f4xx_hal_conf.h | 4 +- .../stm32f4xx_hal_conf.h | 4 +- .../boards/HYDRABUS/stm32f4xx_hal_conf.h | 4 +- .../boards/LEGO_HUB_NO6/stm32f4xx_hal_conf.h | 4 +- .../boards/LEGO_HUB_NO7/stm32f4xx_hal_conf.h | 7 +- .../boards/LIMIFROG/stm32l4xx_hal_conf.h | 4 +- .../stm32f4xx_hal_conf.h | 4 +- .../boards/MIKROE_QUAIL/stm32f4xx_hal_conf.h | 4 +- .../NETDUINO_PLUS_2/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F091RC/stm32f0xx_hal_conf.h | 4 +- .../boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F412ZG/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F413ZH/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F439ZI/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h | 4 +- .../boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h | 4 +- .../boards/NUCLEO_F746ZG/stm32f7xx_hal_conf.h | 4 +- .../boards/NUCLEO_F756ZG/stm32f7xx_hal_conf.h | 4 +- .../boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h | 4 +- .../boards/NUCLEO_G474RE/stm32g4xx_hal_conf.h | 4 +- .../boards/NUCLEO_H723ZG/stm32h7xx_hal_conf.h | 4 +- .../boards/NUCLEO_H743ZI/stm32h7xx_hal_conf.h | 4 +- .../boards/NUCLEO_L073RZ/stm32l0xx_hal_conf.h | 4 +- .../boards/NUCLEO_L432KC/stm32l4xx_hal_conf.h | 4 +- .../boards/NUCLEO_L452RE/stm32l4xx_hal_conf.h | 4 +- .../boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h | 4 +- .../boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h | 4 +- .../boards/OLIMEX_E407/stm32f4xx_hal_conf.h | 4 +- .../boards/OLIMEX_H407/stm32f4xx_hal_conf.h | 4 +- .../boards/PYBD_SF2/stm32f7xx_hal_conf.h | 4 +- .../boards/PYBLITEV10/stm32f4xx_hal_conf.h | 4 +- .../stm32/boards/PYBV10/stm32f4xx_hal_conf.h | 4 +- .../stm32/boards/PYBV11/stm32f4xx_hal_conf.h | 4 +- ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h | 4 +- ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h | 4 +- .../stm32f4xx_hal_conf.h | 4 +- .../boards/STM32F411DISC/stm32f4xx_hal_conf.h | 4 +- .../boards/STM32F429DISC/stm32f4xx_hal_conf.h | 4 +- .../boards/STM32F439/stm32f4xx_hal_conf.h | 4 +- .../boards/STM32F4DISC/stm32f4xx_hal_conf.h | 4 +- .../boards/STM32F769DISC/stm32f7xx_hal_conf.h | 4 +- .../boards/STM32F7DISC/stm32f7xx_hal_conf.h | 4 +- .../boards/STM32H573I_DK/stm32h5xx_hal_conf.h | 4 +- .../boards/STM32H7B3I_DK/stm32h7xx_hal_conf.h | 4 +- .../boards/STM32L476DISC/stm32l4xx_hal_conf.h | 4 +- .../STM32L496GDISC/stm32l4xx_hal_conf.h | 4 +- .../VCC_GND_F407VE/stm32f4xx_hal_conf.h | 4 +- .../VCC_GND_F407ZG/stm32f4xx_hal_conf.h | 4 +- .../VCC_GND_H743VI/stm32h7xx_hal_conf.h | 4 +- ports/stm32/boards/stm32f0xx_hal_conf_base.h | 50 +++++------ ports/stm32/boards/stm32f4xx_hal_conf_base.h | 66 +++++++------- ports/stm32/boards/stm32f7xx_hal_conf_base.h | 64 +++++++------- ports/stm32/boards/stm32g4xx_hal_conf_base.h | 88 +++++++++---------- ports/stm32/boards/stm32h7xx_hal_conf_base.h | 66 +++++++------- ports/stm32/boards/stm32l0xx_hal_conf_base.h | 50 +++++------ ports/stm32/boards/stm32l1xx_hal_conf_base.h | 58 ++++++------ ports/stm32/boards/stm32l4xx_hal_conf_base.h | 64 +++++++------- ports/stm32/boards/stm32wbxx_hal_conf_base.h | 42 ++++----- ports/stm32/boards/stm32wlxx_hal_conf_base.h | 38 ++++---- 69 files changed, 409 insertions(+), 416 deletions(-) diff --git a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/stm32f4xx_hal_conf.h b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/ARDUINO_GIGA/stm32h7xx_hal_conf.h b/ports/stm32/boards/ARDUINO_GIGA/stm32h7xx_hal_conf.h index b3b2e00dbb90..71cbac4765d3 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/ARDUINO_GIGA/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (16000000) #define LSE_VALUE (32768) @@ -48,4 +46,6 @@ #include "stm32h7xx_hal_mmc.h" #endif +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h7xx_hal_conf.h b/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h7xx_hal_conf.h index 737a2e5b0d24..dd71ad71b90e 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -48,4 +46,6 @@ #include "stm32h7xx_hal_mmc.h" #endif +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h7xx_hal_conf.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h7xx_hal_conf.h index 737a2e5b0d24..dd71ad71b90e 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -48,4 +46,6 @@ #include "stm32h7xx_hal_mmc.h" #endif +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/B_L072Z_LRWAN1/stm32l0xx_hal_conf.h b/ports/stm32/boards/B_L072Z_LRWAN1/stm32l0xx_hal_conf.h index c88a7065103d..a2293de902fe 100644 --- a/ports/stm32/boards/B_L072Z_LRWAN1/stm32l0xx_hal_conf.h +++ b/ports/stm32/boards/B_L072Z_LRWAN1/stm32l0xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L0XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L0XX_HAL_CONF_H -#include "boards/stm32l0xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -15,4 +13,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l0xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L0XX_HAL_CONF_H diff --git a/ports/stm32/boards/B_L475E_IOT01A/stm32l4xx_hal_conf.h b/ports/stm32/boards/B_L475E_IOT01A/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100644 --- a/ports/stm32/boards/B_L475E_IOT01A/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/B_L475E_IOT01A/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/CERB40/stm32f4xx_hal_conf.h b/ports/stm32/boards/CERB40/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/CERB40/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/CERB40/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h b/ports/stm32/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/ESPRUINO_PICO/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/GARATRONIC_NADHAT_F405/stm32f4xx_hal_conf.h b/ports/stm32/boards/GARATRONIC_NADHAT_F405/stm32f4xx_hal_conf.h index 7d6344f0a245..9505fb778817 100644 --- a/ports/stm32/boards/GARATRONIC_NADHAT_F405/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/GARATRONIC_NADHAT_F405/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (16000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/GARATRONIC_PYBSTICK26_F411/stm32f4xx_hal_conf.h b/ports/stm32/boards/GARATRONIC_PYBSTICK26_F411/stm32f4xx_hal_conf.h index 7d6344f0a245..9505fb778817 100644 --- a/ports/stm32/boards/GARATRONIC_PYBSTICK26_F411/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/GARATRONIC_PYBSTICK26_F411/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (16000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h b/ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/HYDRABUS/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/LEGO_HUB_NO6/stm32f4xx_hal_conf.h b/ports/stm32/boards/LEGO_HUB_NO6/stm32f4xx_hal_conf.h index 7d6344f0a245..9505fb778817 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/LEGO_HUB_NO6/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (16000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/LEGO_HUB_NO7/stm32f4xx_hal_conf.h b/ports/stm32/boards/LEGO_HUB_NO7/stm32f4xx_hal_conf.h index bd70912748a5..dfa27200ecab 100644 --- a/ports/stm32/boards/LEGO_HUB_NO7/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/LEGO_HUB_NO7/stm32f4xx_hal_conf.h @@ -5,10 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - -#include "stm32f4xx_hal_fmpi2c.h" - #define HAL_FMPI2C_MODULE_ENABLED // Oscillator values in Hz @@ -20,4 +16,7 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" +#include "stm32f4xx_hal_fmpi2c.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/LIMIFROG/stm32l4xx_hal_conf.h b/ports/stm32/boards/LIMIFROG/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100644 --- a/ports/stm32/boards/LIMIFROG/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/LIMIFROG/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/MIKROE_CLICKER2_STM32/stm32f4xx_hal_conf.h b/ports/stm32/boards/MIKROE_CLICKER2_STM32/stm32f4xx_hal_conf.h index f186d5a29228..24d394c398e3 100644 --- a/ports/stm32/boards/MIKROE_CLICKER2_STM32/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/MIKROE_CLICKER2_STM32/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/MIKROE_QUAIL/stm32f4xx_hal_conf.h b/ports/stm32/boards/MIKROE_QUAIL/stm32f4xx_hal_conf.h index b8b935915ff2..02da6f6576ad 100644 --- a/ports/stm32/boards/MIKROE_QUAIL/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/MIKROE_QUAIL/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define EXTERNAL_CLOCK_VALUE (12288000) @@ -15,4 +13,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (0) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h b/ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h index f186d5a29228..24d394c398e3 100644 --- a/ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NETDUINO_PLUS_2/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F091RC/stm32f0xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F091RC/stm32f0xx_hal_conf.h index d5b2c4f7a2e7..10db1b4e23be 100644 --- a/ports/stm32/boards/NUCLEO_F091RC/stm32f0xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F091RC/stm32f0xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F0XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F0XX_HAL_CONF_H -#include "boards/stm32f0xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -15,4 +13,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f0xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F0XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F401RE/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F411RE/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F412ZG/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F412ZG/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F412ZG/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F412ZG/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F413ZH/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F413ZH/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F413ZH/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F413ZH/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F429ZI/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F439ZI/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F439ZI/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F439ZI/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F439ZI/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F446RE/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h index 9355a3867de5..8190f7248212 100644 --- a/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h @@ -4,8 +4,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -15,4 +13,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F746ZG/stm32f7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F746ZG/stm32f7xx_hal_conf.h index e241921ddd25..14b2c9228dcb 100644 --- a/ports/stm32/boards/NUCLEO_F746ZG/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F746ZG/stm32f7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F756ZG/stm32f7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F756ZG/stm32f7xx_hal_conf.h index e241921ddd25..14b2c9228dcb 100644 --- a/ports/stm32/boards/NUCLEO_F756ZG/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F756ZG/stm32f7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h index e241921ddd25..14b2c9228dcb 100644 --- a/ports/stm32/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_F767ZI/stm32f7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_G474RE/stm32g4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_G474RE/stm32g4xx_hal_conf.h index 5e82fb4874d2..5aded589e7e7 100644 --- a/ports/stm32/boards/NUCLEO_G474RE/stm32g4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_G474RE/stm32g4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32G4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32G4XX_HAL_CONF_H -#include "boards/stm32g4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (24000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32g4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32G4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_H723ZG/stm32h7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_H723ZG/stm32h7xx_hal_conf.h index 45400cdcd734..311c1ff8015a 100644 --- a/ports/stm32/boards/NUCLEO_H723ZG/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_H723ZG/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_H743ZI/stm32h7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_H743ZI/stm32h7xx_hal_conf.h index 45400cdcd734..311c1ff8015a 100644 --- a/ports/stm32/boards/NUCLEO_H743ZI/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_H743ZI/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_L073RZ/stm32l0xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L073RZ/stm32l0xx_hal_conf.h index c88a7065103d..a2293de902fe 100644 --- a/ports/stm32/boards/NUCLEO_L073RZ/stm32l0xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_L073RZ/stm32l0xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L0XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L0XX_HAL_CONF_H -#include "boards/stm32l0xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -15,4 +13,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l0xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L0XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_L432KC/stm32l4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L432KC/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100755 --- a/ports/stm32/boards/NUCLEO_L432KC/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_L432KC/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_L452RE/stm32l4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L452RE/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100644 --- a/ports/stm32/boards/NUCLEO_L452RE/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_L452RE/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100755 --- a/ports/stm32/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_L476RG/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h b/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100644 --- a/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/NUCLEO_L4A6ZG/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/OLIMEX_E407/stm32f4xx_hal_conf.h b/ports/stm32/boards/OLIMEX_E407/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/OLIMEX_E407/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/OLIMEX_E407/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/OLIMEX_H407/stm32f4xx_hal_conf.h b/ports/stm32/boards/OLIMEX_H407/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/OLIMEX_H407/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/OLIMEX_H407/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/PYBD_SF2/stm32f7xx_hal_conf.h b/ports/stm32/boards/PYBD_SF2/stm32f7xx_hal_conf.h index 621b05c719e9..548f5b3f85a0 100644 --- a/ports/stm32/boards/PYBD_SF2/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/PYBD_SF2/stm32f7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/PYBLITEV10/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBLITEV10/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/PYBLITEV10/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/PYBLITEV10/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/PYBV10/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/PYBV11/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV11/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/PYBV11/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/PYBV11/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/PYBV3/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h b/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/PYBV4/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/stm32f4xx_hal_conf.h b/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/stm32f4xx_hal_conf.h index 9719157e55cd..21285f2e3360 100644 --- a/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (12000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32F411DISC/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F411DISC/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/STM32F411DISC/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/STM32F411DISC/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32F439/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F439/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/STM32F439/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/STM32F439/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h b/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h index de19251e0808..ddbeca131691 100644 --- a/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/STM32F4DISC/stm32f4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32F769DISC/stm32f7xx_hal_conf.h b/ports/stm32/boards/STM32F769DISC/stm32f7xx_hal_conf.h index 621b05c719e9..548f5b3f85a0 100644 --- a/ports/stm32/boards/STM32F769DISC/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/STM32F769DISC/stm32f7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32F7DISC/stm32f7xx_hal_conf.h b/ports/stm32/boards/STM32F7DISC/stm32f7xx_hal_conf.h index 621b05c719e9..548f5b3f85a0 100644 --- a/ports/stm32/boards/STM32F7DISC/stm32f7xx_hal_conf.h +++ b/ports/stm32/boards/STM32F7DISC/stm32f7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H -#include "boards/stm32f7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32H573I_DK/stm32h5xx_hal_conf.h b/ports/stm32/boards/STM32H573I_DK/stm32h5xx_hal_conf.h index 6b32ffb18508..a77b3a1c7063 100644 --- a/ports/stm32/boards/STM32H573I_DK/stm32h5xx_hal_conf.h +++ b/ports/stm32/boards/STM32H573I_DK/stm32h5xx_hal_conf.h @@ -10,10 +10,10 @@ #define LSE_VALUE (32768) #define EXTERNAL_CLOCK_VALUE (12288000) -#include "boards/stm32h5xx_hal_conf_base.h" - // Oscillator timeouts in ms #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32h5xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H5XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32H7B3I_DK/stm32h7xx_hal_conf.h b/ports/stm32/boards/STM32H7B3I_DK/stm32h7xx_hal_conf.h index 70c3246a890e..cad1a8576239 100644 --- a/ports/stm32/boards/STM32H7B3I_DK/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/STM32H7B3I_DK/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (24000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h b/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100644 --- a/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/STM32L476DISC/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/STM32L496GDISC/stm32l4xx_hal_conf.h b/ports/stm32/boards/STM32L496GDISC/stm32l4xx_hal_conf.h index fd380ab7357e..98ef4b371488 100644 --- a/ports/stm32/boards/STM32L496GDISC/stm32l4xx_hal_conf.h +++ b/ports/stm32/boards/STM32L496GDISC/stm32l4xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H -#include "boards/stm32l4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (8000000) #define LSE_VALUE (32768) @@ -17,4 +15,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32l4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H diff --git a/ports/stm32/boards/VCC_GND_F407VE/stm32f4xx_hal_conf.h b/ports/stm32/boards/VCC_GND_F407VE/stm32f4xx_hal_conf.h index fe2069fe1418..c22fb6177f5c 100644 --- a/ports/stm32/boards/VCC_GND_F407VE/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/VCC_GND_F407VE/stm32f4xx_hal_conf.h @@ -1,8 +1,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -12,4 +10,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/VCC_GND_F407ZG/stm32f4xx_hal_conf.h b/ports/stm32/boards/VCC_GND_F407ZG/stm32f4xx_hal_conf.h index fe2069fe1418..c22fb6177f5c 100644 --- a/ports/stm32/boards/VCC_GND_F407ZG/stm32f4xx_hal_conf.h +++ b/ports/stm32/boards/VCC_GND_F407ZG/stm32f4xx_hal_conf.h @@ -1,8 +1,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H -#include "boards/stm32f4xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -12,4 +10,6 @@ #define HSE_STARTUP_TIMEOUT (100) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32f4xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32F4XX_HAL_CONF_H diff --git a/ports/stm32/boards/VCC_GND_H743VI/stm32h7xx_hal_conf.h b/ports/stm32/boards/VCC_GND_H743VI/stm32h7xx_hal_conf.h index c4d148b0bbaf..c8f60c56055e 100644 --- a/ports/stm32/boards/VCC_GND_H743VI/stm32h7xx_hal_conf.h +++ b/ports/stm32/boards/VCC_GND_H743VI/stm32h7xx_hal_conf.h @@ -5,8 +5,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H -#include "boards/stm32h7xx_hal_conf_base.h" - // Oscillator values in Hz #define HSE_VALUE (25000000) #define LSE_VALUE (32768) @@ -16,4 +14,6 @@ #define HSE_STARTUP_TIMEOUT (5000) #define LSE_STARTUP_TIMEOUT (5000) +#include "boards/stm32h7xx_hal_conf_base.h" + #endif // MICROPY_INCLUDED_STM32H7XX_HAL_CONF_H diff --git a/ports/stm32/boards/stm32f0xx_hal_conf_base.h b/ports/stm32/boards/stm32f0xx_hal_conf_base.h index 70e6ccf758d3..d60fb9eaf7df 100644 --- a/ports/stm32/boards/stm32f0xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32f0xx_hal_conf_base.h @@ -26,31 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32F0XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32F0XX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32f0xx_hal_dma.h" -#include "stm32f0xx_hal_adc.h" -#include "stm32f0xx_hal_can.h" -#include "stm32f0xx_hal_cortex.h" -#include "stm32f0xx_hal_crc.h" -#include "stm32f0xx_hal_dac.h" -#include "stm32f0xx_hal_flash.h" -#include "stm32f0xx_hal_gpio.h" -#include "stm32f0xx_hal_i2c.h" -#include "stm32f0xx_hal_i2s.h" -#include "stm32f0xx_hal_iwdg.h" -#include "stm32f0xx_hal_pcd.h" -#include "stm32f0xx_hal_pwr.h" -#include "stm32f0xx_hal_rcc.h" -#include "stm32f0xx_hal_rtc.h" -#include "stm32f0xx_hal_spi.h" -#include "stm32f0xx_hal_tim.h" -#include "stm32f0xx_hal_uart.h" -#include "stm32f0xx_hal_usart.h" -#include "stm32f0xx_hal_wwdg.h" -#include "stm32f0xx_ll_adc.h" -#include "stm32f0xx_ll_rtc.h" -#include "stm32f0xx_ll_usart.h" - // Enable various HAL modules #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED @@ -87,6 +62,31 @@ #define USE_RTOS 0 #define USE_SPI_CRC 1 +// Include various HAL modules for convenience +#include "stm32f0xx_hal_dma.h" +#include "stm32f0xx_hal_adc.h" +#include "stm32f0xx_hal_can.h" +#include "stm32f0xx_hal_cortex.h" +#include "stm32f0xx_hal_crc.h" +#include "stm32f0xx_hal_dac.h" +#include "stm32f0xx_hal_flash.h" +#include "stm32f0xx_hal_gpio.h" +#include "stm32f0xx_hal_i2c.h" +#include "stm32f0xx_hal_i2s.h" +#include "stm32f0xx_hal_iwdg.h" +#include "stm32f0xx_hal_pcd.h" +#include "stm32f0xx_hal_pwr.h" +#include "stm32f0xx_hal_rcc.h" +#include "stm32f0xx_hal_rtc.h" +#include "stm32f0xx_hal_spi.h" +#include "stm32f0xx_hal_tim.h" +#include "stm32f0xx_hal_uart.h" +#include "stm32f0xx_hal_usart.h" +#include "stm32f0xx_hal_wwdg.h" +#include "stm32f0xx_ll_adc.h" +#include "stm32f0xx_ll_rtc.h" +#include "stm32f0xx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32f4xx_hal_conf_base.h b/ports/stm32/boards/stm32f4xx_hal_conf_base.h index d42f3ba19f4f..59d73a3028cd 100644 --- a/ports/stm32/boards/stm32f4xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32f4xx_hal_conf_base.h @@ -26,39 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32F4XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32F4XX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32f4xx_hal_dma.h" -#include "stm32f4xx_hal_adc.h" -#include "stm32f4xx_hal_can.h" -#include "stm32f4xx_hal_cortex.h" -#include "stm32f4xx_hal_crc.h" -#include "stm32f4xx_hal_dac.h" -#include "stm32f4xx_hal_dcmi.h" -#include "stm32f4xx_hal_eth.h" -#include "stm32f4xx_hal_flash.h" -#include "stm32f4xx_hal_gpio.h" -#include "stm32f4xx_hal_hash.h" -#include "stm32f4xx_hal_hcd.h" -#include "stm32f4xx_hal_i2c.h" -#include "stm32f4xx_hal_i2s.h" -#include "stm32f4xx_hal_iwdg.h" -#include "stm32f4xx_hal_mmc.h" -#include "stm32f4xx_hal_pcd.h" -#include "stm32f4xx_hal_pwr.h" -#include "stm32f4xx_hal_rcc.h" -#include "stm32f4xx_hal_rtc.h" -#include "stm32f4xx_hal_sd.h" -#include "stm32f4xx_hal_sdram.h" -#include "stm32f4xx_hal_spi.h" -#include "stm32f4xx_hal_tim.h" -#include "stm32f4xx_hal_uart.h" -#include "stm32f4xx_hal_usart.h" -#include "stm32f4xx_hal_wwdg.h" -#include "stm32f4xx_ll_adc.h" -#include "stm32f4xx_ll_pwr.h" -#include "stm32f4xx_ll_rtc.h" -#include "stm32f4xx_ll_usart.h" - // Enable various HAL modules #define HAL_ADC_MODULE_ENABLED #define HAL_CAN_MODULE_ENABLED @@ -101,6 +68,39 @@ #define PREFETCH_ENABLE 1 #define USE_RTOS 0 +// Include various HAL modules for convenience +#include "stm32f4xx_hal_dma.h" +#include "stm32f4xx_hal_adc.h" +#include "stm32f4xx_hal_can.h" +#include "stm32f4xx_hal_cortex.h" +#include "stm32f4xx_hal_crc.h" +#include "stm32f4xx_hal_dac.h" +#include "stm32f4xx_hal_dcmi.h" +#include "stm32f4xx_hal_eth.h" +#include "stm32f4xx_hal_flash.h" +#include "stm32f4xx_hal_gpio.h" +#include "stm32f4xx_hal_hash.h" +#include "stm32f4xx_hal_hcd.h" +#include "stm32f4xx_hal_i2c.h" +#include "stm32f4xx_hal_i2s.h" +#include "stm32f4xx_hal_iwdg.h" +#include "stm32f4xx_hal_mmc.h" +#include "stm32f4xx_hal_pcd.h" +#include "stm32f4xx_hal_pwr.h" +#include "stm32f4xx_hal_rcc.h" +#include "stm32f4xx_hal_rtc.h" +#include "stm32f4xx_hal_sd.h" +#include "stm32f4xx_hal_sdram.h" +#include "stm32f4xx_hal_spi.h" +#include "stm32f4xx_hal_tim.h" +#include "stm32f4xx_hal_uart.h" +#include "stm32f4xx_hal_usart.h" +#include "stm32f4xx_hal_wwdg.h" +#include "stm32f4xx_ll_adc.h" +#include "stm32f4xx_ll_pwr.h" +#include "stm32f4xx_ll_rtc.h" +#include "stm32f4xx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32f7xx_hal_conf_base.h b/ports/stm32/boards/stm32f7xx_hal_conf_base.h index efb15d471dcc..26908f2ebb38 100644 --- a/ports/stm32/boards/stm32f7xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32f7xx_hal_conf_base.h @@ -26,38 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32f7xx_hal_dma.h" -#include "stm32f7xx_hal_adc.h" -#include "stm32f7xx_hal_can.h" -#include "stm32f7xx_hal_cortex.h" -#include "stm32f7xx_hal_crc.h" -#include "stm32f7xx_hal_dac.h" -#include "stm32f7xx_hal_dcmi.h" -#include "stm32f7xx_hal_flash.h" -#include "stm32f7xx_hal_gpio.h" -#include "stm32f7xx_hal_hash.h" -#include "stm32f7xx_hal_hcd.h" -#include "stm32f7xx_hal_i2c.h" -#include "stm32f7xx_hal_i2s.h" -#include "stm32f7xx_hal_iwdg.h" -#include "stm32f7xx_hal_mmc.h" -#include "stm32f7xx_hal_pcd.h" -#include "stm32f7xx_hal_pwr.h" -#include "stm32f7xx_hal_rcc.h" -#include "stm32f7xx_hal_rtc.h" -#include "stm32f7xx_hal_sd.h" -#include "stm32f7xx_hal_sdram.h" -#include "stm32f7xx_hal_spi.h" -#include "stm32f7xx_hal_tim.h" -#include "stm32f7xx_hal_uart.h" -#include "stm32f7xx_hal_usart.h" -#include "stm32f7xx_hal_wwdg.h" -#include "stm32f7xx_ll_adc.h" -#include "stm32f7xx_ll_pwr.h" -#include "stm32f7xx_ll_rtc.h" -#include "stm32f7xx_ll_usart.h" - // Enable various HAL modules #define HAL_ADC_MODULE_ENABLED #define HAL_CAN_MODULE_ENABLED @@ -97,6 +65,38 @@ #define ART_ACCLERATOR_ENABLE 1 #define USE_RTOS 0 +// Include various HAL modules for convenience +#include "stm32f7xx_hal_dma.h" +#include "stm32f7xx_hal_adc.h" +#include "stm32f7xx_hal_can.h" +#include "stm32f7xx_hal_cortex.h" +#include "stm32f7xx_hal_crc.h" +#include "stm32f7xx_hal_dac.h" +#include "stm32f7xx_hal_dcmi.h" +#include "stm32f7xx_hal_flash.h" +#include "stm32f7xx_hal_gpio.h" +#include "stm32f7xx_hal_hash.h" +#include "stm32f7xx_hal_hcd.h" +#include "stm32f7xx_hal_i2c.h" +#include "stm32f7xx_hal_i2s.h" +#include "stm32f7xx_hal_iwdg.h" +#include "stm32f7xx_hal_mmc.h" +#include "stm32f7xx_hal_pcd.h" +#include "stm32f7xx_hal_pwr.h" +#include "stm32f7xx_hal_rcc.h" +#include "stm32f7xx_hal_rtc.h" +#include "stm32f7xx_hal_sd.h" +#include "stm32f7xx_hal_sdram.h" +#include "stm32f7xx_hal_spi.h" +#include "stm32f7xx_hal_tim.h" +#include "stm32f7xx_hal_uart.h" +#include "stm32f7xx_hal_usart.h" +#include "stm32f7xx_hal_wwdg.h" +#include "stm32f7xx_ll_adc.h" +#include "stm32f7xx_ll_pwr.h" +#include "stm32f7xx_ll_rtc.h" +#include "stm32f7xx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32g4xx_hal_conf_base.h b/ports/stm32/boards/stm32g4xx_hal_conf_base.h index 034d39653948..e6f24c21a494 100644 --- a/ports/stm32/boards/stm32g4xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32g4xx_hal_conf_base.h @@ -26,51 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32G4XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32G4XX_HAL_CONF_BASE_H -// Include various HAL modules for convenience - -#include "stm32g4xx_hal_rcc.h" -#include "stm32g4xx_hal_gpio.h" -#include "stm32g4xx_hal_dma.h" -#include "stm32g4xx_hal_cortex.h" -#include "stm32g4xx_hal_adc.h" -#include "stm32g4xx_hal_comp.h" -#include "stm32g4xx_hal_cordic.h" -#include "stm32g4xx_hal_crc.h" -#include "stm32g4xx_hal_cryp.h" -#include "stm32g4xx_hal_dac.h" -#include "stm32g4xx_hal_exti.h" -#include "stm32g4xx_hal_fdcan.h" -#include "stm32g4xx_hal_flash.h" -#include "stm32g4xx_hal_fmac.h" -#include "stm32g4xx_hal_hrtim.h" -#include "stm32g4xx_hal_irda.h" -#include "stm32g4xx_hal_iwdg.h" -#include "stm32g4xx_hal_i2c.h" -#include "stm32g4xx_hal_i2s.h" -#include "stm32g4xx_hal_lptim.h" -#include "stm32g4xx_hal_nand.h" -#include "stm32g4xx_hal_nor.h" -#include "stm32g4xx_hal_opamp.h" -#include "stm32g4xx_hal_pcd.h" -#include "stm32g4xx_hal_pwr.h" -#include "stm32g4xx_hal_qspi.h" -#include "stm32g4xx_hal_rng.h" -#include "stm32g4xx_hal_rtc.h" -#include "stm32g4xx_hal_sai.h" -#include "stm32g4xx_hal_smartcard.h" -#include "stm32g4xx_hal_smbus.h" -#include "stm32g4xx_hal_spi.h" -#include "stm32g4xx_hal_sram.h" -#include "stm32g4xx_hal_tim.h" -#include "stm32g4xx_hal_uart.h" -#include "stm32g4xx_hal_usart.h" -#include "stm32g4xx_hal_wwdg.h" - -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_rtc.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_lpuart.h" - #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED #define HAL_COMP_MODULE_ENABLED @@ -125,6 +80,49 @@ #define DATA_CACHE_ENABLE 1 #define USE_SPI_CRC 1 +// Include various HAL modules for convenience +#include "stm32g4xx_hal_rcc.h" +#include "stm32g4xx_hal_gpio.h" +#include "stm32g4xx_hal_dma.h" +#include "stm32g4xx_hal_cortex.h" +#include "stm32g4xx_hal_adc.h" +#include "stm32g4xx_hal_comp.h" +#include "stm32g4xx_hal_cordic.h" +#include "stm32g4xx_hal_crc.h" +#include "stm32g4xx_hal_cryp.h" +#include "stm32g4xx_hal_dac.h" +#include "stm32g4xx_hal_exti.h" +#include "stm32g4xx_hal_fdcan.h" +#include "stm32g4xx_hal_flash.h" +#include "stm32g4xx_hal_fmac.h" +#include "stm32g4xx_hal_hrtim.h" +#include "stm32g4xx_hal_irda.h" +#include "stm32g4xx_hal_iwdg.h" +#include "stm32g4xx_hal_i2c.h" +#include "stm32g4xx_hal_i2s.h" +#include "stm32g4xx_hal_lptim.h" +#include "stm32g4xx_hal_nand.h" +#include "stm32g4xx_hal_nor.h" +#include "stm32g4xx_hal_opamp.h" +#include "stm32g4xx_hal_pcd.h" +#include "stm32g4xx_hal_pwr.h" +#include "stm32g4xx_hal_qspi.h" +#include "stm32g4xx_hal_rng.h" +#include "stm32g4xx_hal_rtc.h" +#include "stm32g4xx_hal_sai.h" +#include "stm32g4xx_hal_smartcard.h" +#include "stm32g4xx_hal_smbus.h" +#include "stm32g4xx_hal_spi.h" +#include "stm32g4xx_hal_sram.h" +#include "stm32g4xx_hal_tim.h" +#include "stm32g4xx_hal_uart.h" +#include "stm32g4xx_hal_usart.h" +#include "stm32g4xx_hal_wwdg.h" +#include "stm32g4xx_ll_adc.h" +#include "stm32g4xx_ll_rtc.h" +#include "stm32g4xx_ll_usart.h" +#include "stm32g4xx_ll_lpuart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32h7xx_hal_conf_base.h b/ports/stm32/boards/stm32h7xx_hal_conf_base.h index 9c5ec8cb2c59..7882adf151c1 100644 --- a/ports/stm32/boards/stm32h7xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32h7xx_hal_conf_base.h @@ -26,39 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32H7XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32H7XX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32h7xx_hal_dma.h" -#include "stm32h7xx_hal_mdma.h" -#include "stm32h7xx_hal_adc.h" -#include "stm32h7xx_hal_cortex.h" -#include "stm32h7xx_hal_crc.h" -#include "stm32h7xx_hal_dac.h" -#include "stm32h7xx_hal_dcmi.h" -#include "stm32h7xx_hal_fdcan.h" -#include "stm32h7xx_hal_flash.h" -#include "stm32h7xx_hal_gpio.h" -#include "stm32h7xx_hal_hash.h" -#include "stm32h7xx_hal_hcd.h" -#include "stm32h7xx_hal_i2c.h" -#include "stm32h7xx_hal_i2s.h" -#include "stm32h7xx_hal_iwdg.h" -#include "stm32h7xx_hal_pcd.h" -#include "stm32h7xx_hal_pwr.h" -#include "stm32h7xx_hal_rcc.h" -#include "stm32h7xx_hal_rtc.h" -#include "stm32h7xx_hal_sd.h" -#include "stm32h7xx_hal_sdram.h" -#include "stm32h7xx_hal_spi.h" -#include "stm32h7xx_hal_tim.h" -#include "stm32h7xx_hal_uart.h" -#include "stm32h7xx_hal_usart.h" -#include "stm32h7xx_hal_wwdg.h" -#include "stm32h7xx_ll_adc.h" -#include "stm32h7xx_ll_lpuart.h" -#include "stm32h7xx_ll_pwr.h" -#include "stm32h7xx_ll_rtc.h" -#include "stm32h7xx_ll_usart.h" - // Enable various HAL modules #define HAL_ADC_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED @@ -98,6 +65,39 @@ #define USE_SD_TRANSCEIVER 0 #define USE_SPI_CRC 1 +// Include various HAL modules for convenience +#include "stm32h7xx_hal_dma.h" +#include "stm32h7xx_hal_mdma.h" +#include "stm32h7xx_hal_adc.h" +#include "stm32h7xx_hal_cortex.h" +#include "stm32h7xx_hal_crc.h" +#include "stm32h7xx_hal_dac.h" +#include "stm32h7xx_hal_dcmi.h" +#include "stm32h7xx_hal_fdcan.h" +#include "stm32h7xx_hal_flash.h" +#include "stm32h7xx_hal_gpio.h" +#include "stm32h7xx_hal_hash.h" +#include "stm32h7xx_hal_hcd.h" +#include "stm32h7xx_hal_i2c.h" +#include "stm32h7xx_hal_i2s.h" +#include "stm32h7xx_hal_iwdg.h" +#include "stm32h7xx_hal_pcd.h" +#include "stm32h7xx_hal_pwr.h" +#include "stm32h7xx_hal_rcc.h" +#include "stm32h7xx_hal_rtc.h" +#include "stm32h7xx_hal_sd.h" +#include "stm32h7xx_hal_sdram.h" +#include "stm32h7xx_hal_spi.h" +#include "stm32h7xx_hal_tim.h" +#include "stm32h7xx_hal_uart.h" +#include "stm32h7xx_hal_usart.h" +#include "stm32h7xx_hal_wwdg.h" +#include "stm32h7xx_ll_adc.h" +#include "stm32h7xx_ll_lpuart.h" +#include "stm32h7xx_ll_pwr.h" +#include "stm32h7xx_ll_rtc.h" +#include "stm32h7xx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32l0xx_hal_conf_base.h b/ports/stm32/boards/stm32l0xx_hal_conf_base.h index 7b569907e8d6..e33c0b2a1be1 100644 --- a/ports/stm32/boards/stm32l0xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32l0xx_hal_conf_base.h @@ -26,31 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32L0XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32L0XX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32l0xx_hal_dma.h" -#include "stm32l0xx_hal_adc.h" -#include "stm32l0xx_hal_cortex.h" -#include "stm32l0xx_hal_crc.h" -#include "stm32l0xx_hal_dac.h" -#include "stm32l0xx_hal_flash.h" -#include "stm32l0xx_hal_gpio.h" -#include "stm32l0xx_hal_i2c.h" -#include "stm32l0xx_hal_i2s.h" -#include "stm32l0xx_hal_iwdg.h" -#include "stm32l0xx_hal_pcd.h" -#include "stm32l0xx_hal_pwr.h" -#include "stm32l0xx_hal_rcc.h" -#include "stm32l0xx_hal_rtc.h" -#include "stm32l0xx_hal_spi.h" -#include "stm32l0xx_hal_tim.h" -#include "stm32l0xx_hal_uart.h" -#include "stm32l0xx_hal_usart.h" -#include "stm32l0xx_hal_wwdg.h" -#include "stm32l0xx_ll_adc.h" -#include "stm32l0xx_ll_lpuart.h" -#include "stm32l0xx_ll_rtc.h" -#include "stm32l0xx_ll_usart.h" - // Enable various HAL modules #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED @@ -89,6 +64,31 @@ #define USE_RTOS 0 #define USE_SPI_CRC 0 +// Include various HAL modules for convenience +#include "stm32l0xx_hal_dma.h" +#include "stm32l0xx_hal_adc.h" +#include "stm32l0xx_hal_cortex.h" +#include "stm32l0xx_hal_crc.h" +#include "stm32l0xx_hal_dac.h" +#include "stm32l0xx_hal_flash.h" +#include "stm32l0xx_hal_gpio.h" +#include "stm32l0xx_hal_i2c.h" +#include "stm32l0xx_hal_i2s.h" +#include "stm32l0xx_hal_iwdg.h" +#include "stm32l0xx_hal_pcd.h" +#include "stm32l0xx_hal_pwr.h" +#include "stm32l0xx_hal_rcc.h" +#include "stm32l0xx_hal_rtc.h" +#include "stm32l0xx_hal_spi.h" +#include "stm32l0xx_hal_tim.h" +#include "stm32l0xx_hal_uart.h" +#include "stm32l0xx_hal_usart.h" +#include "stm32l0xx_hal_wwdg.h" +#include "stm32l0xx_ll_adc.h" +#include "stm32l0xx_ll_lpuart.h" +#include "stm32l0xx_ll_rtc.h" +#include "stm32l0xx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32l1xx_hal_conf_base.h b/ports/stm32/boards/stm32l1xx_hal_conf_base.h index 5871e8a45a6f..d23453b27a68 100644 --- a/ports/stm32/boards/stm32l1xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32l1xx_hal_conf_base.h @@ -26,36 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32L1XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32L1XX_HAL_CONF_BASE_H -// Needs to be defined before ll_usb.h is included -#define HAL_PCD_MODULE_ENABLED - -// Include various HAL modules for convenience -#include "stm32l1xx_hal_rcc.h" -#include "stm32l1xx_hal_gpio.h" -#include "stm32l1xx_hal_dma.h" -#include "stm32l1xx_hal_cortex.h" -#include "stm32l1xx_hal_adc.h" -#include "stm32l1xx_hal_comp.h" -#include "stm32l1xx_hal_crc.h" -#include "stm32l1xx_hal_dac.h" -#include "stm32l1xx_hal_flash.h" -#include "stm32l1xx_hal_i2c.h" -#include "stm32l1xx_hal_iwdg.h" -#include "stm32l1xx_hal_pcd.h" -#include "stm32l1xx_hal_pwr.h" -#include "stm32l1xx_hal_rtc.h" -#include "stm32l1xx_hal_spi.h" -#include "stm32l1xx_hal_tim.h" -#include "stm32l1xx_hal_uart.h" -#include "stm32l1xx_hal_usart.h" -#include "stm32l1xx_hal_wwdg.h" -#include "stm32l1xx_hal_exti.h" -#include "stm32l1xx_ll_adc.h" -#include "stm32l1xx_ll_pwr.h" -#include "stm32l1xx_ll_rtc.h" -#include "stm32l1xx_ll_usart.h" -#include "stm32l1xx_ll_usb.h" - // Enable various HAL modules #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED @@ -67,6 +37,7 @@ #define HAL_FLASH_MODULE_ENABLED #define HAL_GPIO_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED +#define HAL_PCD_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED #define HAL_RTC_MODULE_ENABLED @@ -98,6 +69,33 @@ #define USE_SPI_CRC 0 #define USE_RTOS 0 +// Include various HAL modules for convenience +#include "stm32l1xx_hal_rcc.h" +#include "stm32l1xx_hal_gpio.h" +#include "stm32l1xx_hal_dma.h" +#include "stm32l1xx_hal_cortex.h" +#include "stm32l1xx_hal_adc.h" +#include "stm32l1xx_hal_comp.h" +#include "stm32l1xx_hal_crc.h" +#include "stm32l1xx_hal_dac.h" +#include "stm32l1xx_hal_flash.h" +#include "stm32l1xx_hal_i2c.h" +#include "stm32l1xx_hal_iwdg.h" +#include "stm32l1xx_hal_pcd.h" +#include "stm32l1xx_hal_pwr.h" +#include "stm32l1xx_hal_rtc.h" +#include "stm32l1xx_hal_spi.h" +#include "stm32l1xx_hal_tim.h" +#include "stm32l1xx_hal_uart.h" +#include "stm32l1xx_hal_usart.h" +#include "stm32l1xx_hal_wwdg.h" +#include "stm32l1xx_hal_exti.h" +#include "stm32l1xx_ll_adc.h" +#include "stm32l1xx_ll_pwr.h" +#include "stm32l1xx_ll_rtc.h" +#include "stm32l1xx_ll_usart.h" +#include "stm32l1xx_ll_usb.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32l4xx_hal_conf_base.h b/ports/stm32/boards/stm32l4xx_hal_conf_base.h index ce35dee28c1e..9ee895229f92 100644 --- a/ports/stm32/boards/stm32l4xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32l4xx_hal_conf_base.h @@ -26,39 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32L4XX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32L4XX_HAL_CONF_BASE_H -// Needs to be defined before ll_usb.h is included -#define HAL_PCD_MODULE_ENABLED - -// Include various HAL modules for convenience -#include "stm32l4xx_hal_dma.h" -#include "stm32l4xx_hal_adc.h" -#include "Legacy/stm32l4xx_hal_can_legacy.h" -#include "stm32l4xx_hal_cortex.h" -#include "stm32l4xx_hal_crc.h" -#include "stm32l4xx_hal_dac.h" -#include "stm32l4xx_hal_dcmi.h" -#include "stm32l4xx_hal_flash.h" -#include "stm32l4xx_hal_gpio.h" -#include "stm32l4xx_hal_hash.h" -#include "stm32l4xx_hal_hcd.h" -#include "stm32l4xx_hal_i2c.h" -#include "stm32l4xx_hal_iwdg.h" -#include "stm32l4xx_hal_pcd.h" -#include "stm32l4xx_hal_pwr.h" -#include "stm32l4xx_hal_rcc.h" -#include "stm32l4xx_hal_rtc.h" -#include "stm32l4xx_hal_sd.h" -#include "stm32l4xx_hal_spi.h" -#include "stm32l4xx_hal_tim.h" -#include "stm32l4xx_hal_uart.h" -#include "stm32l4xx_hal_usart.h" -#include "stm32l4xx_hal_wwdg.h" -#include "stm32l4xx_ll_adc.h" -#include "stm32l4xx_ll_lpuart.h" -#include "stm32l4xx_ll_rtc.h" -#include "stm32l4xx_ll_usart.h" -#include "stm32l4xx_ll_usb.h" - // Enable various HAL modules #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED @@ -74,6 +41,7 @@ #define HAL_HCD_MODULE_ENABLED #define HAL_I2C_MODULE_ENABLED #define HAL_IWDG_MODULE_ENABLED +#define HAL_PCD_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED #define HAL_RTC_MODULE_ENABLED @@ -100,6 +68,36 @@ #define USE_SPI_CRC 0 #define USE_RTOS 0 +// Include various HAL modules for convenience +#include "stm32l4xx_hal_dma.h" +#include "stm32l4xx_hal_adc.h" +#include "Legacy/stm32l4xx_hal_can_legacy.h" +#include "stm32l4xx_hal_cortex.h" +#include "stm32l4xx_hal_crc.h" +#include "stm32l4xx_hal_dac.h" +#include "stm32l4xx_hal_dcmi.h" +#include "stm32l4xx_hal_flash.h" +#include "stm32l4xx_hal_gpio.h" +#include "stm32l4xx_hal_hash.h" +#include "stm32l4xx_hal_hcd.h" +#include "stm32l4xx_hal_i2c.h" +#include "stm32l4xx_hal_iwdg.h" +#include "stm32l4xx_hal_pcd.h" +#include "stm32l4xx_hal_pwr.h" +#include "stm32l4xx_hal_rcc.h" +#include "stm32l4xx_hal_rtc.h" +#include "stm32l4xx_hal_sd.h" +#include "stm32l4xx_hal_spi.h" +#include "stm32l4xx_hal_tim.h" +#include "stm32l4xx_hal_uart.h" +#include "stm32l4xx_hal_usart.h" +#include "stm32l4xx_hal_wwdg.h" +#include "stm32l4xx_ll_adc.h" +#include "stm32l4xx_ll_lpuart.h" +#include "stm32l4xx_ll_rtc.h" +#include "stm32l4xx_ll_usart.h" +#include "stm32l4xx_ll_usb.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32wbxx_hal_conf_base.h b/ports/stm32/boards/stm32wbxx_hal_conf_base.h index 25eb4b93ecd2..79417d768faa 100644 --- a/ports/stm32/boards/stm32wbxx_hal_conf_base.h +++ b/ports/stm32/boards/stm32wbxx_hal_conf_base.h @@ -26,27 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32WBXX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32WBXX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32wbxx_hal_dma.h" -#include "stm32wbxx_hal_adc.h" -#include "stm32wbxx_hal_cortex.h" -#include "stm32wbxx_hal_flash.h" -#include "stm32wbxx_hal_gpio.h" -#include "stm32wbxx_hal_i2c.h" -#include "stm32wbxx_hal_pcd.h" -#include "stm32wbxx_hal_pwr.h" -#include "stm32wbxx_hal_rcc.h" -#include "stm32wbxx_hal_rtc.h" -#include "stm32wbxx_hal_spi.h" -#include "stm32wbxx_hal_tim.h" -#include "stm32wbxx_hal_uart.h" -#include "stm32wbxx_hal_usart.h" -#include "stm32wbxx_ll_adc.h" -#include "stm32wbxx_ll_hsem.h" -#include "stm32wbxx_ll_lpuart.h" -#include "stm32wbxx_ll_rtc.h" -#include "stm32wbxx_ll_usart.h" - // Enable various HAL modules #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED @@ -77,6 +56,27 @@ #define USE_SPI_CRC 0 #define USE_RTOS 0 +// Include various HAL modules for convenience +#include "stm32wbxx_hal_dma.h" +#include "stm32wbxx_hal_adc.h" +#include "stm32wbxx_hal_cortex.h" +#include "stm32wbxx_hal_flash.h" +#include "stm32wbxx_hal_gpio.h" +#include "stm32wbxx_hal_i2c.h" +#include "stm32wbxx_hal_pcd.h" +#include "stm32wbxx_hal_pwr.h" +#include "stm32wbxx_hal_rcc.h" +#include "stm32wbxx_hal_rtc.h" +#include "stm32wbxx_hal_spi.h" +#include "stm32wbxx_hal_tim.h" +#include "stm32wbxx_hal_uart.h" +#include "stm32wbxx_hal_usart.h" +#include "stm32wbxx_ll_adc.h" +#include "stm32wbxx_ll_hsem.h" +#include "stm32wbxx_ll_lpuart.h" +#include "stm32wbxx_ll_rtc.h" +#include "stm32wbxx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) diff --git a/ports/stm32/boards/stm32wlxx_hal_conf_base.h b/ports/stm32/boards/stm32wlxx_hal_conf_base.h index e98b0525bd1b..179f50465695 100644 --- a/ports/stm32/boards/stm32wlxx_hal_conf_base.h +++ b/ports/stm32/boards/stm32wlxx_hal_conf_base.h @@ -26,25 +26,6 @@ #ifndef MICROPY_INCLUDED_STM32WLXX_HAL_CONF_BASE_H #define MICROPY_INCLUDED_STM32WLXX_HAL_CONF_BASE_H -// Include various HAL modules for convenience -#include "stm32wlxx_hal_dma.h" -#include "stm32wlxx_hal_adc.h" -#include "stm32wlxx_hal_cortex.h" -#include "stm32wlxx_hal_flash.h" -#include "stm32wlxx_hal_gpio.h" -#include "stm32wlxx_hal_i2c.h" -#include "stm32wlxx_hal_pwr.h" -#include "stm32wlxx_hal_rcc.h" -#include "stm32wlxx_hal_rtc.h" -#include "stm32wlxx_hal_spi.h" -#include "stm32wlxx_hal_tim.h" -#include "stm32wlxx_hal_uart.h" -#include "stm32wlxx_hal_usart.h" -#include "stm32wlxx_ll_adc.h" -#include "stm32wlxx_ll_lpuart.h" -#include "stm32wlxx_ll_rtc.h" -#include "stm32wlxx_ll_usart.h" - // Enable various HAL modules #define HAL_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED @@ -72,6 +53,25 @@ #define USE_SPI_CRC 0 #define USE_RTOS 0 +// Include various HAL modules for convenience +#include "stm32wlxx_hal_dma.h" +#include "stm32wlxx_hal_adc.h" +#include "stm32wlxx_hal_cortex.h" +#include "stm32wlxx_hal_flash.h" +#include "stm32wlxx_hal_gpio.h" +#include "stm32wlxx_hal_i2c.h" +#include "stm32wlxx_hal_pwr.h" +#include "stm32wlxx_hal_rcc.h" +#include "stm32wlxx_hal_rtc.h" +#include "stm32wlxx_hal_spi.h" +#include "stm32wlxx_hal_tim.h" +#include "stm32wlxx_hal_uart.h" +#include "stm32wlxx_hal_usart.h" +#include "stm32wlxx_ll_adc.h" +#include "stm32wlxx_ll_lpuart.h" +#include "stm32wlxx_ll_rtc.h" +#include "stm32wlxx_ll_usart.h" + // HAL parameter assertions are disabled #define assert_param(expr) ((void)0) From 88564c1406a9572de8a92a4bebcdbf55f3f18ec5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 28 Sep 2023 15:33:56 +1000 Subject: [PATCH 08/78] stm32/uart: Generalise UART source clock calculation for H5 and H7 MCUs. This gets the calculation working properly for H5 MCUs, and fixes the switch statement to switch on csel&7 instead of csel&3. Signed-off-by: Damien George --- ports/stm32/Makefile | 1 + ports/stm32/boards/stm32h7xx_hal_conf_base.h | 1 + ports/stm32/uart.c | 63 +++++++++++--------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 475d8f1004f0..58dc76200666 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -404,6 +404,7 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ hal_tim.c \ hal_tim_ex.c \ hal_uart.c \ + ll_rcc.c \ ll_utils.c \ ) diff --git a/ports/stm32/boards/stm32h7xx_hal_conf_base.h b/ports/stm32/boards/stm32h7xx_hal_conf_base.h index 7882adf151c1..670dee383f81 100644 --- a/ports/stm32/boards/stm32h7xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32h7xx_hal_conf_base.h @@ -95,6 +95,7 @@ #include "stm32h7xx_ll_adc.h" #include "stm32h7xx_ll_lpuart.h" #include "stm32h7xx_ll_pwr.h" +#include "stm32h7xx_ll_rcc.h" #include "stm32h7xx_ll_rtc.h" #include "stm32h7xx_ll_usart.h" diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c index 1823596df16c..908361874d3f 100644 --- a/ports/stm32/uart.c +++ b/ports/stm32/uart.c @@ -837,48 +837,57 @@ uint32_t uart_get_source_freq(pyb_uart_obj_t *self) { uart_clk = LSE_VALUE; break; } - #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) + + #elif defined(STM32H5) || defined(STM32H7) + uint32_t csel; + unsigned int bus_pclk; + + #if defined(STM32H5) + if (1 <= self->uart_id && self->uart_id <= 10) { + csel = RCC->CCIPR1 >> ((self->uart_id - 1) * 3); + } else { + csel = RCC->CCIPR2 >> ((self->uart_id - 11) * 3); + } + bus_pclk = self->uart_id == 1 ? 2 : 1; + #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) if (self->uart_id == 1 || self->uart_id == 6 || self->uart_id == 9 || self->uart_id == 10) { csel = RCC->CDCCIP2R >> 3; + bus_pclk = 2; } else { csel = RCC->CDCCIP2R; + bus_pclk = 1; } - switch (csel & 3) { - case 0: - if (self->uart_id == 1 || self->uart_id == 6 || self->uart_id == 9 || self->uart_id == 10) { - uart_clk = HAL_RCC_GetPCLK2Freq(); - } else { - uart_clk = HAL_RCC_GetPCLK1Freq(); - } - break; - case 3: - uart_clk = HSI_VALUE; - break; - case 4: - uart_clk = CSI_VALUE; - break; - case 5: - uart_clk = LSE_VALUE; - break; - default: - break; - } - #elif defined(STM32H7) - uint32_t csel; + #else if (self->uart_id == 1 || self->uart_id == 6) { csel = RCC->D2CCIP2R >> 3; + bus_pclk = 2; } else { csel = RCC->D2CCIP2R; + bus_pclk = 1; } - switch (csel & 3) { + #endif + + switch (csel & 7) { case 0: - if (self->uart_id == 1 || self->uart_id == 6) { - uart_clk = HAL_RCC_GetPCLK2Freq(); - } else { + if (bus_pclk == 1) { uart_clk = HAL_RCC_GetPCLK1Freq(); + } else { + uart_clk = HAL_RCC_GetPCLK2Freq(); } break; + case 1: { + LL_PLL_ClocksTypeDef PLL_Clocks; + LL_RCC_GetPLL2ClockFreq(&PLL_Clocks); + uart_clk = PLL_Clocks.PLL_Q_Frequency; + break; + } + case 2: { + LL_PLL_ClocksTypeDef PLL_Clocks; + LL_RCC_GetPLL3ClockFreq(&PLL_Clocks); + uart_clk = PLL_Clocks.PLL_Q_Frequency; + break; + } case 3: uart_clk = HSI_VALUE; break; From 5dbd6fc70581e0264dbfc62a4313dca737124b5c Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 28 Sep 2023 17:31:54 +1000 Subject: [PATCH 09/78] stm32/dma: Remove unbalanced ). This was added by mistake in 9e0f934cdf195ca8d06ce51eb89f89e590984176 Signed-off-by: Damien George --- ports/stm32/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm32/dma.c b/ports/stm32/dma.c index 298670f00e99..36f4a678597d 100644 --- a/ports/stm32/dma.c +++ b/ports/stm32/dma.c @@ -161,7 +161,7 @@ static const DMA_InitTypeDef dma_init_struct_i2s = { static const DMA_InitTypeDef dma_init_struct_sdio = { #if defined(STM32F4) || defined(STM32F7) .Channel = 0, - #elif defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB)) || defined(STM32WL) + #elif defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL) .Request = 0, #endif .Direction = 0, From 52f76cf4fc1287b000e510a8ed50297bbdb4d4de Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 28 Sep 2023 14:37:29 +1000 Subject: [PATCH 10/78] tests/stress/bytecode_limit.py: Reverse order of cases. The PYBD_SF2 is right on the limit of being able to run this test and so it succeeds the first two cases and fails the next two with MemoryError. This causes it to SKIP, but that only works if it's the first thing printed. So reverse the order of the tests so it fails on the biggest one first. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/stress/bytecode_limit.py | 2 +- tests/stress/bytecode_limit.py.exp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/stress/bytecode_limit.py b/tests/stress/bytecode_limit.py index 8cca413cf277..ad090637f6a6 100644 --- a/tests/stress/bytecode_limit.py +++ b/tests/stress/bytecode_limit.py @@ -3,7 +3,7 @@ body = " with f()()() as a:\n try:\n f()()()\n except Exception:\n pass\n" # Test overflow of jump offset. -for n in (430, 431, 432, 433): +for n in (433, 432, 431, 430): try: exec("cond = 0\nif cond:\n" + body * n + "else:\n print('cond false')\n") except MemoryError: diff --git a/tests/stress/bytecode_limit.py.exp b/tests/stress/bytecode_limit.py.exp index 74ab06c09b67..1d892250b01e 100644 --- a/tests/stress/bytecode_limit.py.exp +++ b/tests/stress/bytecode_limit.py.exp @@ -1,5 +1,5 @@ -cond false -cond false RuntimeError RuntimeError +cond false +cond false [123] From 3695211576ed69671b98412ff5278265ab65e6bd Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 13:11:58 +1000 Subject: [PATCH 11/78] tests/float/float_format_ints.py: Put power-of-10 test in separate file. This test doesn't pass on builds with 30-bit floats (object repr C). Signed-off-by: Damien George --- tests/float/float_format_ints.py | 6 ------ tests/float/float_format_ints_power10.py | 8 ++++++++ tests/run-tests.py | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 tests/float/float_format_ints_power10.py diff --git a/tests/float/float_format_ints.py b/tests/float/float_format_ints.py index 0bf4baf12d0a..df4444166c5f 100644 --- a/tests/float/float_format_ints.py +++ b/tests/float/float_format_ints.py @@ -12,12 +12,6 @@ print(title, "with format", f_fmt, "gives", f_fmt.format(f)) print(title, "with format", g_fmt, "gives", g_fmt.format(f)) -# Check that powers of 10 (that fit in float32) format correctly. -for i in range(31): - # It works to 12 digits on all platforms *except* qemu-arm, where - # 10^11 comes out as 10000000820 or something. - print("{:.7g}".format(float("1e" + str(i)))) - # 16777215 is 2^24 - 1, the largest integer that can be completely held # in a float32. print("{:f}".format(16777215)) diff --git a/tests/float/float_format_ints_power10.py b/tests/float/float_format_ints_power10.py new file mode 100644 index 000000000000..98900c135b2e --- /dev/null +++ b/tests/float/float_format_ints_power10.py @@ -0,0 +1,8 @@ +# Test that integers format to exact values. +# This test requires at least 32-bit floats (won't work with 30-bit). + +# Check that powers of 10 (that fit in float32) format correctly. +for i in range(31): + # It works to 12 digits on all platforms *except* qemu-arm, where + # 10^11 comes out as 10000000820 or something. + print(i, "{:.7g}".format(float("1e" + str(i)))) diff --git a/tests/run-tests.py b/tests/run-tests.py index de886b8ae714..2d511c20ca7f 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -525,6 +525,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): ) # requires fp32, there's string_format_fp30.py instead skip_tests.add("float/bytes_construct.py") # requires fp32 skip_tests.add("float/bytearray_construct.py") # requires fp32 + skip_tests.add("float/float_format_ints_power10.py") # requires fp32 if upy_float_precision < 64: skip_tests.add("float/float_divmod.py") # tested by float/float_divmod_relaxed.py instead skip_tests.add("float/float2int_doubleprec_intbig.py") From a33766880e8fabfa421bee3252b486ebcfbde79b Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 13:13:12 +1000 Subject: [PATCH 12/78] tests/extmod/deflate_decompress.py: Skip test when not enough memory. Signed-off-by: Damien George --- tests/extmod/deflate_decompress.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/extmod/deflate_decompress.py b/tests/extmod/deflate_decompress.py index 29d3ec2d7110..3ac8880af263 100644 --- a/tests/extmod/deflate_decompress.py +++ b/tests/extmod/deflate_decompress.py @@ -6,6 +6,17 @@ print("SKIP") raise SystemExit +try: + # Check there's enough memory to deflate gzip streams. + # zlib.compress(b'', wbits=25) + empty_gzip = ( + b"\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00" + ) + deflate.DeflateIO(io.BytesIO(empty_gzip)).read() +except MemoryError: + print("SKIP") + raise SystemExit + # zlib.compress(b'micropython hello world hello world micropython', wbits=-9) data_raw = b'\xcb\xcdL.\xca/\xa8,\xc9\xc8\xcfS\xc8H\xcd\xc9\xc9W(\xcf/\xcaIAa\xe7"\xd4\x00\x00' # zlib.compress(b'micropython hello world hello world micropython', wbits=9) From a7e2a6d9f2b0bfe3e6955331a2e35bc260354fd6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 13:37:31 +1000 Subject: [PATCH 13/78] tests/extmod/ssl_cadata.py: Skip test on axtls. The axtls bindings don't support this. Signed-off-by: Damien George --- tests/extmod/ssl_cadata.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/extmod/ssl_cadata.py b/tests/extmod/ssl_cadata.py index a68cae1ecbb4..e66f6ca825ba 100644 --- a/tests/extmod/ssl_cadata.py +++ b/tests/extmod/ssl_cadata.py @@ -10,5 +10,9 @@ # Invalid cadata. try: ssl.wrap_socket(io.BytesIO(), cadata=b"!") +except TypeError: + # "cadata" keyword argument is not supported by axtls. + print("SKIP") + raise SystemExit except ValueError as er: print(repr(er)) From 7c88cdda49f98d76bc10b9d864fa1675acf46afc Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 13:53:55 +1000 Subject: [PATCH 14/78] tests/float/math_domain.py: Tweak test to also pass with obj-repr-C. Signed-off-by: Damien George --- tests/float/math_domain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/float/math_domain.py b/tests/float/math_domain.py index 26e883ea6487..b1273c6c11cf 100644 --- a/tests/float/math_domain.py +++ b/tests/float/math_domain.py @@ -28,7 +28,7 @@ ("radians", math.radians), ("degrees", math.degrees), ): - for x in (0, 1, 1.1, -1, -1.1, inf, -inf, nan): + for x in (0, 1, 1.12, -1, -1.12, inf, -inf, nan): try: ans = "%.4f" % f(x) except ValueError: From 62c3033ba6af8a498644716819ac91522d372305 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 15:28:42 +1000 Subject: [PATCH 15/78] tests/extmod/vfs_fat_finaliser.py: Tweak test so files are collected. Signed-off-by: Damien George --- tests/extmod/vfs_fat_finaliser.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py index b6c7dffb8295..a2cce7846c22 100644 --- a/tests/extmod/vfs_fat_finaliser.py +++ b/tests/extmod/vfs_fat_finaliser.py @@ -64,7 +64,7 @@ def ioctl(self, op, arg): # in turn allocate new qstrs and/or a new qstr pool). f = None n = None -names = ["x%d" % i for i in range(4)] +names = ["x%d" % i for i in range(5)] # Do a large number of single-block allocations to move the GC head forwards, # ensuring that the files are allocated from never-before-used blocks and @@ -74,12 +74,13 @@ def ioctl(self, op, arg): [] # Run the test: create files without closing them, run GC, then read back files. +# Only read back N-1 files because the last one may not be finalised due to +# references to it being left on the C stack. for n in names: f = vfs.open(n, "w") f.write(n) f = None # release f without closing - sorted([0, 1, 2, 3], key=lambda x: x) # use up Python and C stack so f is really gone -gc.collect() # should finalise all N files by closing them -for n in names: +gc.collect() # should finalise at least the first N-1 files by closing them +for n in names[:-1]: with vfs.open(n, "r") as f: print(f.read()) From 03a3af417e749860b2771642a738151aef830586 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 13:09:53 +1000 Subject: [PATCH 16/78] esp8266/boards: Make sure modespnow.o is placed in irom0. Signed-off-by: Damien George --- ports/esp8266/boards/esp8266_common.ld | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/esp8266/boards/esp8266_common.ld b/ports/esp8266/boards/esp8266_common.ld index 083e84d9afe5..ed8c6a7fe865 100644 --- a/ports/esp8266/boards/esp8266_common.ld +++ b/ports/esp8266/boards/esp8266_common.ld @@ -164,6 +164,7 @@ SECTIONS *machine_hspi.o(.literal*, .text*) *hspi.o(.literal*, .text*) *modesp.o(.literal* .text*) + *modespnow.o(.literal* .text*) *modos.o(.literal* .text*) *modlwip.o(.literal* .text*) *modsocket.o(.literal* .text*) From 58f63497e5ee4d7915ea23929dad7d59712b7c01 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 27 Sep 2023 13:36:25 +1000 Subject: [PATCH 17/78] extmod/modssl_axtls: Only close underlying socket once if it was used. To match the behaviour of the mbedtls implementation, and pass the ssl_basic.py test. Signed-off-by: Damien George --- extmod/modssl_axtls.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/extmod/modssl_axtls.c b/extmod/modssl_axtls.c index d169d89a2cfe..6cb999c13b69 100644 --- a/extmod/modssl_axtls.c +++ b/extmod/modssl_axtls.c @@ -208,7 +208,7 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t o->base.type = &ssl_socket_type; o->buf = NULL; o->bytes_left = 0; - o->sock = sock; + o->sock = MP_OBJ_NULL; o->blocking = true; uint32_t options = SSL_SERVER_VERIFY_LATER; @@ -262,6 +262,10 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t } } + // Populate the socket entry now that the SSLSocket is fully set up. + // This prevents closing the socket if an exception is raised above. + o->sock = sock; + return o; } @@ -348,11 +352,21 @@ STATIC mp_uint_t ssl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size STATIC mp_uint_t ssl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in); - if (request == MP_STREAM_CLOSE && self->ssl_sock != NULL) { + if (request == MP_STREAM_CLOSE) { + if (self->ssl_sock == NULL) { + // Already closed socket, do nothing. + return 0; + } ssl_free(self->ssl_sock); ssl_ctx_free(self->ssl_ctx); self->ssl_sock = NULL; } + + if (self->sock == MP_OBJ_NULL) { + // Underlying socket may be null if the constructor raised an exception. + return 0; + } + // Pass all requests down to the underlying socket return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode); } From 2fcd28f7138ed0573da80305bec825ec38fcb013 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 20 Sep 2023 17:29:12 +1000 Subject: [PATCH 18/78] py/mkrules.mk: Don't strip binary if STRIP variable is unset. This provides a way to build a non-DEBUG host binary that still has symbols and debug information. Document this for the unix port, and update a comment in the unix port Makefile. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/unix/Makefile | 4 ++-- ports/unix/README.md | 14 ++++++++++++++ py/mkrules.mk | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index eae02bf257c4..52ae8314eb4c 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -59,8 +59,8 @@ endif # Remove unused sections. COPT += -fdata-sections -ffunction-sections -# Always enable symbols -- They're occasionally useful, and don't make it into the -# final .bin/.hex/.dfu so the extra size doesn't matter. +# Note: Symbols and debug information will still be stripped from the final binary +# unless "DEBUG=1" or "STRIP=" is passed to make, see README.md for details. CFLAGS += -g ifndef DEBUG diff --git a/ports/unix/README.md b/ports/unix/README.md index a1af28996858..e15fd93b2312 100644 --- a/ports/unix/README.md +++ b/ports/unix/README.md @@ -72,3 +72,17 @@ deplibs`. To actually enable/disable use of dependencies, edit the `ports/unix/mpconfigport.mk` file, which has inline descriptions of the options. For example, to build the SSL module, `MICROPY_PY_SSL` should be set to 1. + +Debug Symbols +------------- + +By default, builds are stripped of symbols and debug information to save size. + +To build a debuggable version of the Unix port, there are two options + +1. Run `make [other arguments] DEBUG=1`. Note setting `DEBUG` also reduces the + optimisation level, so it's not a good option for builds that also want the + best performance. +2. Run `make [other arguments] STRIP=`. Note that the value of `STRIP` is + empty. This will skip the build step that strips symbols and debug + information, but changes nothing else in the build configuration. diff --git a/py/mkrules.mk b/py/mkrules.mk index a3ff85ef821b..ec36346b8afd 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -212,7 +212,9 @@ $(BUILD)/$(PROG): $(OBJ) # we may want to compile using Thumb, but link with non-Thumb libc. $(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS) ifndef DEBUG +ifdef STRIP $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $@ +endif endif $(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $@ From d83c1a43d4d31100f81bcd565236235efa9d1b90 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Tue, 26 Sep 2023 11:40:17 +0300 Subject: [PATCH 19/78] py: Change ifdef DEBUG_PRINT to if DEBUG_PRINT. Signed-off-by: Ihor Nehrutsa --- py/emitglue.c | 4 ++-- py/emitnative.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/py/emitglue.c b/py/emitglue.c index 95be7f661abe..6ec6d6b885d4 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -87,7 +87,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, mp_prof_extract_prelude(code, prelude); #endif - #ifdef DEBUG_PRINT + #if DEBUG_PRINT #if !(MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS) const size_t len = 0; #endif @@ -149,7 +149,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void rc->n_pos_args = n_pos_args; rc->type_sig = type_sig; - #ifdef DEBUG_PRINT + #if DEBUG_PRINT DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, n_pos_args, (uint)scope_flags); for (mp_uint_t i = 0; i < fun_len; i++) { if (i > 0 && i % 16 == 0) { diff --git a/py/emitnative.c b/py/emitnative.c index c6e61500999c..e6357b3f9f4a 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -745,7 +745,7 @@ STATIC void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { if (emit->pass > MP_PASS_SCOPE && emit->stack_size > emit->scope->stack_size) { emit->scope->stack_size = emit->stack_size; } - #ifdef DEBUG_PRINT + #if DEBUG_PRINT DEBUG_printf(" adjust_stack; stack_size=%d+%d; stack now:", emit->stack_size - stack_size_delta, stack_size_delta); for (int i = 0; i < emit->stack_size; i++) { stack_info_t *si = &emit->stack_info[i]; From 276bfa3146534f5b6a0130309f3b166fb2a77e25 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 28 Sep 2023 12:26:51 +1000 Subject: [PATCH 20/78] py/lexer: Add missing initialisation for fstring_args_idx. This was missed in 692d36d779192f32371f7f9daa845b566f26968d. Probably never noticed because everything enables `MICROPY_GC_CONSERVATIVE_CLEAR`, but found via ASAN thanks to @gwangmu & @chibinz. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- py/lexer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/py/lexer.c b/py/lexer.c index b22cc2eaeaec..6b28f2215227 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -846,6 +846,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) { vstr_init(&lex->vstr, 32); #if MICROPY_PY_FSTRINGS vstr_init(&lex->fstring_args, 0); + lex->fstring_args_idx = 0; #endif // store sentinel for first indentation level From 77ae0a0948d5c4de4efecefbba27f9aded9b79e2 Mon Sep 17 00:00:00 2001 From: Seon Rozenblum Date: Wed, 27 Sep 2023 20:38:35 +1000 Subject: [PATCH 21/78] esp32/boards: Fix VBAT voltage calculation for UM S3 boards. Signed-off-by: Seon Rozenblum --- ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py | 3 ++- ports/esp32/boards/UM_PROS3/modules/pros3.py | 3 ++- ports/esp32/boards/UM_TINYS3/modules/tinys3.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py index 1ba919ceaeeb..b6f486f3d811 100644 --- a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py +++ b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py @@ -65,8 +65,9 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V measuredvbat = adc.read() - measuredvbat /= 4095 # divide by 4095 as we are using the default ADC attenuation of 0dB + measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo return round(measuredvbat, 2) diff --git a/ports/esp32/boards/UM_PROS3/modules/pros3.py b/ports/esp32/boards/UM_PROS3/modules/pros3.py index 7f9590293618..4e5b2e9656ab 100644 --- a/ports/esp32/boards/UM_PROS3/modules/pros3.py +++ b/ports/esp32/boards/UM_PROS3/modules/pros3.py @@ -41,8 +41,9 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V measuredvbat = adc.read() - measuredvbat /= 4095 # divide by 4095 as we are using the default ADC attenuation of 0dB + measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo return round(measuredvbat, 2) diff --git a/ports/esp32/boards/UM_TINYS3/modules/tinys3.py b/ports/esp32/boards/UM_TINYS3/modules/tinys3.py index 06bbb5ff827c..6aa1f185f6ae 100644 --- a/ports/esp32/boards/UM_TINYS3/modules/tinys3.py +++ b/ports/esp32/boards/UM_TINYS3/modules/tinys3.py @@ -41,8 +41,9 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V measuredvbat = adc.read() - measuredvbat /= 4095 # divide by 4095 as we are using the default ADC attenuation of 0dB + measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo return round(measuredvbat, 2) From 79473691f2345bf343493143769e5730fe97cdf1 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 28 Sep 2023 14:57:51 +1000 Subject: [PATCH 22/78] {mimxrt,powerpc,samd}/mpconfigport: Don't override parse chunk alloc. This was copied from minimal/mpconfigport.h, but it doesn't make sense for general ports. Add a comment to minimal/mpconfigport.h to explain why it specifically overrides it. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/mimxrt/mpconfigport.h | 1 - ports/minimal/mpconfigport.h | 2 ++ ports/powerpc/mpconfigport.h | 1 - ports/samd/mpconfigport.h | 1 - 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index fb4acede5901..d1fe17ee10b5 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -42,7 +42,6 @@ uint32_t trng_random_u32(void); #else #define MICROPY_GC_STACK_ENTRY_TYPE uint16_t #endif -#define MICROPY_ALLOC_PARSE_CHUNK_INIT (32) #define MICROPY_ALLOC_PATH_MAX (256) // MicroPython emitters diff --git a/ports/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h index 0f50f8d389cd..56bef165facd 100644 --- a/ports/minimal/mpconfigport.h +++ b/ports/minimal/mpconfigport.h @@ -17,6 +17,8 @@ #define MICROPY_ENABLE_EXTERNAL_IMPORT (1) #define MICROPY_ALLOC_PATH_MAX (256) + +// Use the minimum headroom in the chunk allocator for parse nodes. #define MICROPY_ALLOC_PARSE_CHUNK_INIT (16) // type definitions for the specific machine diff --git a/ports/powerpc/mpconfigport.h b/ports/powerpc/mpconfigport.h index 084a461a4a73..06200a996901 100644 --- a/ports/powerpc/mpconfigport.h +++ b/ports/powerpc/mpconfigport.h @@ -38,7 +38,6 @@ #define MICROPY_QSTR_BYTES_IN_HASH (1) #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_ALLOC_PATH_MAX (256) -#define MICROPY_ALLOC_PARSE_CHUNK_INIT (16) #define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index c983d7e6d669..011119fd1171 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -34,7 +34,6 @@ // Memory allocation policies #define MICROPY_GC_STACK_ENTRY_TYPE uint16_t #define MICROPY_GC_ALLOC_THRESHOLD (0) -#define MICROPY_ALLOC_PARSE_CHUNK_INIT (32) #define MICROPY_ALLOC_PATH_MAX (256) #define MICROPY_QSTR_BYTES_IN_HASH (1) From cf32c2feb519367e1f6ca1d6ed146269022090aa Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 28 Sep 2023 15:08:50 +1000 Subject: [PATCH 23/78] ports: Restrict board.json to standard features. Applies to newly-added ARDUINO_PORTENTA_C33 and UM_NANOS3. Makes the list match the standard features defined in 24a6e951ec7696b8d18d95fe5da36f7e489913d0. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/esp32/boards/UM_NANOS3/board.json | 2 +- .../boards/ARDUINO_PORTENTA_C33/board.json | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ports/esp32/boards/UM_NANOS3/board.json b/ports/esp32/boards/UM_NANOS3/board.json index 2eb40ac3c9ef..b213a8ad6bd4 100644 --- a/ports/esp32/boards/UM_NANOS3/board.json +++ b/ports/esp32/boards/UM_NANOS3/board.json @@ -6,7 +6,7 @@ "features": [ "Battery Charging", "RGB LED", - "SPIRAM", + "External RAM", "WiFi", "BLE" ], diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/board.json b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/board.json index 18e6fe65e44d..4c4d4e4326b3 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/board.json +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/board.json @@ -4,13 +4,12 @@ ], "docs": "", "features": [ - "512KB SRAM", - "2MB Flash", - "16MB QSPI Flash", - "USB High Speed Phy", - "10/100 Ethernet Phy", - "ESP32 WiFi/BT Module", - "NXP SE050 crypto device" + "BLE", + "Ethernet", + "External Flash", + "Secure Element", + "USB-C", + "WiFi" ], "images": [ "ABX00074_01.iso_1000x750.jpg" From 88ecc78eb30aaea395c3e97ea097d6194a1f0baf Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 28 Sep 2023 15:26:23 +1000 Subject: [PATCH 24/78] tools/autobuild/build-downloads.py: Verify standard features. Defines the list of standard features and ensures that each board.json only uses those ones. This list can be extended, but needs to be a deliberate decision. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tools/autobuild/build-downloads.py | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tools/autobuild/build-downloads.py b/tools/autobuild/build-downloads.py index 0f532e8bf079..c03d98aa5dea 100755 --- a/tools/autobuild/build-downloads.py +++ b/tools/autobuild/build-downloads.py @@ -5,6 +5,42 @@ import os import sys +VALID_FEATURES = { + # Connectivity + "BLE", + "CAN", + "Ethernet", + "LoRa", + "USB", + "USB-C", + "WiFi", + # MCU features + "Dual-core", + "External Flash", + "External RAM", + # Form factor + "Feather", + # Connectors / sockets + "JST-PH", + "JST-SH", + "mikroBUS", + "microSD", + "SDCard", + # Sensors + "Environment Sensor", + "IMU", + # Other + "Audio Codec", + "Battery Charging", + "Camera", + "DAC", + "Display", + "Microphone", + "PoE", + "RGB LED", + "Secure Element", +} + def main(repo_path, output_path): boards_index = [] @@ -19,6 +55,16 @@ def main(repo_path, output_path): with open(board_json, "r") as f: blob = json.load(f) + features = set(blob.get("features", [])) + if not features.issubset(VALID_FEATURES): + print( + board_json, + "unknown features:", + features.difference(VALID_FEATURES), + file=sys.stderr, + ) + sys.exit(1) + # Use "id" if specified, otherwise default to board dir (e.g. "PYBV11"). # We allow boards to override ID for the historical build names. blob["id"] = blob.get("id", os.path.basename(board_dir)) From 58c2c503a93bde9b9a48c76151c6a52ff56ab4f9 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Fri, 11 Aug 2023 13:26:17 +0200 Subject: [PATCH 25/78] tools/mpremote: Add support for rfc2217, serial over TCP. Signed-off-by: Jos Verlinde --- docs/reference/mpremote.rst | 4 +++- tools/mpremote/mpremote/transport_serial.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst index b82672536025..08ef5d31ff57 100644 --- a/docs/reference/mpremote.rst +++ b/docs/reference/mpremote.rst @@ -100,6 +100,8 @@ The full list of supported commands are: command output) - ``port:``: connect to the device with the given path (the first column from the ``connect list`` command output + - ``rfc2217://:``: connect to the device using serial over TCP + (e.g. a networked serial port based on RFC2217) - any valid device name/path, to connect to that device **Note:** Instead of using the ``connect`` command, there are several @@ -109,7 +111,7 @@ The full list of supported commands are: **Note:** The ``auto`` option will only detect USB serial ports, i.e. a serial port that has an associated USB VID/PID (i.e. CDC/ACM or FTDI-style - devices). Other types of serial ports + devices). Other types of serial ports will not be auto-detected. .. _mpremote_command_disconnect: diff --git a/tools/mpremote/mpremote/transport_serial.py b/tools/mpremote/mpremote/transport_serial.py index 09025c309883..e04f5b4ac9ab 100644 --- a/tools/mpremote/mpremote/transport_serial.py +++ b/tools/mpremote/mpremote/transport_serial.py @@ -76,7 +76,9 @@ def __init__(self, device, baudrate=115200, wait=0, exclusive=True): delayed = False for attempt in range(wait + 1): try: - if os.name == "nt": + if device.startswith("rfc2217://"): + self.serial = serial.serial_for_url(device, **serial_kwargs) + elif os.name == "nt": self.serial = serial.Serial(**serial_kwargs) self.serial.port = device portinfo = list(serial.tools.list_ports.grep(device)) # type: ignore From 584c495d3201bbf01190cff673533bc405cee53f Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Fri, 22 Sep 2023 18:46:08 +0530 Subject: [PATCH 26/78] shared/netutils/dhcpserver: Reply on correct netif. The DHCP server broadcasts messages. They are being sent via the default netif which might be completely the wrong network. We want to send messages to the netif we got the original message from. Original author: [Peter Harper](https://github.com/peterharperuk) Source: https://github.com/raspberrypi/pico-examples/pull/392 Signed-off-by: Samveen --- shared/netutils/dhcpserver.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/shared/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c index 50cd69a1eb58..dca95507d3f0 100644 --- a/shared/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -118,7 +118,7 @@ static int dhcp_socket_bind(struct udp_pcb **udp, uint32_t ip, uint16_t port) { return udp_bind(*udp, &addr, port); } -static int dhcp_socket_sendto(struct udp_pcb **udp, const void *buf, size_t len, uint32_t ip, uint16_t port) { +static int dhcp_socket_sendto(struct udp_pcb **udp, struct netif *netif, const void *buf, size_t len, uint32_t ip, uint16_t port) { if (len > 0xffff) { len = 0xffff; } @@ -132,7 +132,12 @@ static int dhcp_socket_sendto(struct udp_pcb **udp, const void *buf, size_t len, ip_addr_t dest; IP4_ADDR(&dest, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); - err_t err = udp_sendto(*udp, p, &dest, port); + err_t err; + if (netif != NULL) { + err = udp_sendto_if(*udp, p, &dest, port, netif); + } else { + err = udp_sendto(*udp, p, &dest, port); + } pbuf_free(p); @@ -153,7 +158,7 @@ static uint8_t *opt_find(uint8_t *opt, uint8_t cmd) { return NULL; } -static void opt_write_n(uint8_t **opt, uint8_t cmd, size_t n, void *data) { +static void opt_write_n(uint8_t **opt, uint8_t cmd, size_t n, const void *data) { uint8_t *o = *opt; *o++ = cmd; *o++ = n; @@ -281,7 +286,8 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have multiple addresses opt_write_u32(&opt, DHCP_OPT_IP_LEASE_TIME, DEFAULT_LEASE_TIME_S); *opt++ = DHCP_OPT_END; - dhcp_socket_sendto(&d->udp, &dhcp_msg, opt - (uint8_t *)&dhcp_msg, 0xffffffff, PORT_DHCP_CLIENT); + struct netif *netif = ip_current_input_netif(); + dhcp_socket_sendto(&d->udp, netif, &dhcp_msg, opt - (uint8_t *)&dhcp_msg, 0xffffffff, PORT_DHCP_CLIENT); ignore_request: pbuf_free(p); From 3c2b2f7a4d790c66dbe723c5ed59ec18472baa6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Tue, 21 Feb 2023 07:11:14 +0000 Subject: [PATCH 27/78] rp2/modmachine: Fix lightsleep while wifi is powered off. While cyw43 is deinitialized, an interrupt occurs. That is handled with these lines: ports/rp2/mpnetworkport.c#L59-L61 and as pendsv is disabled while in network code, the poll function then just waits there. When deinit has finished, the poll func is executed, but skipped: src/cyw43_ctrl.c#L222-L225 this skips the `CYW43_POST_POLL_HOOK` which would re-enable interrupts, but also reset `cyw43_has_pending`. And in that state, the lightsleep code, will skip sleeping as it thinks there is a network packet pending to be handled. With this change applied, lightsleep works as expected when the wifi chip is enabled, and when it's powered off. --- ports/rp2/modmachine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 1efbb09312bf..35c938b54bd4 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -146,7 +146,7 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { uint32_t my_interrupts = save_and_disable_interrupts(); #if MICROPY_PY_NETWORK_CYW43 - if (cyw43_has_pending) { + if (cyw43_has_pending && cyw43_poll != NULL) { restore_interrupts(my_interrupts); return mp_const_none; } From dd8a69b5f2996800bcd193dbfdc2e3bf0fb52d65 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 20 Sep 2023 18:11:51 +1000 Subject: [PATCH 28/78] tests/README: Document ./run-internalbench.py. Signed-off-by: Angus Gratton --- tests/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/README.md b/tests/README.md index b0bff4872edf..c89930d0c088 100644 --- a/tests/README.md +++ b/tests/README.md @@ -147,3 +147,30 @@ the test runs, and the absolute difference value is unreliable. High error percentages are particularly common on PC builds, where the host OS may influence test run times. Increasing the `N` value may help average this out by running each test longer. + +## internal_bench + +The `internal_bench` directory contains a set of tests for benchmarking +different internal Python features. By default, tests are run on the (unix or +Windows) host, but the `--pyboard` option allows them to be run on an attached +board instead. + +Tests are grouped by the first part of the file name, and the test runner compares +output between each group of tests. + +The benchmarks measure the elapsed (wall time) for each test, according +to MicroPython's own time module. + +If run without any arguments, all test groups are run. Otherwise, it's possible +to manually specify which test cases to run. + +Example: + +``` +$ ./run-internalbench.py internal_bench/bytebuf-*.py +internal_bench/bytebuf: + 0.094s (+00.00%) internal_bench/bytebuf-1-inplace.py + 0.471s (+399.24%) internal_bench/bytebuf-2-join_map_bytes.py + 0.177s (+87.78%) internal_bench/bytebuf-3-bytarray_map.py +1 tests performed (3 individual testcases) +``` From b461d218d14cee9b5a1b3d2749ae14cbec1388a2 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 20 Sep 2023 18:12:11 +1000 Subject: [PATCH 29/78] tests/run-internalbench.py: Remove old CPython reference. At one point it was possible to internal_bench CPython vs MicroPython, but seemingly not any more. Signed-off-by: Angus Gratton --- tests/run-internalbench.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/run-internalbench.py b/tests/run-internalbench.py index 2cf7f3443bbc..c9f783e474c9 100755 --- a/tests/run-internalbench.py +++ b/tests/run-internalbench.py @@ -8,16 +8,11 @@ from glob import glob from collections import defaultdict -# Tests require at least CPython 3.3. If your default python3 executable -# is of lower version, you can point MICROPY_CPYTHON3 environment var -# to the correct executable. if os.name == "nt": - CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3.exe") MICROPYTHON = os.getenv( "MICROPY_MICROPYTHON", "../ports/windows/build-standard/micropython.exe" ) else: - CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3") MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/build-standard/micropython") From 6662d84faa25a5c64bd4f5e07bc548ceaa7f2fb5 Mon Sep 17 00:00:00 2001 From: Glenn Moloney Date: Thu, 7 Sep 2023 08:52:39 +1000 Subject: [PATCH 30/78] esp32/boards: Add bootloader rollback support for all builds. Add "CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y" to ports/esp32/boards/sdkconfig.base so that all micropython esp32 images support OTA rollback in the bootloader. These images can then be converted to OTA-capable images as required by user tools. Also remove CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y from board-specific sdkconfig files as this is now the default. Signed-off-by: Glenn Moloney --- ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board | 1 - ports/esp32/boards/ESP32_GENERIC/sdkconfig.ota | 1 - ports/esp32/boards/SIL_WESP32/sdkconfig.board | 1 - ports/esp32/boards/sdkconfig.base | 1 + 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board b/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board index 4d175f7ed77c..888e225763d4 100644 --- a/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board +++ b/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board @@ -17,6 +17,5 @@ CONFIG_TINYUSB_DESC_MANUFACTURER_STRING="Arduino" CONFIG_TINYUSB_DESC_PRODUCT_STRING="Nano ESP32" # compatibility with Espressif Arduino core -CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y CONFIG_ESP_ENABLE_COREDUMP_TO_FLASH=y diff --git a/ports/esp32/boards/ESP32_GENERIC/sdkconfig.ota b/ports/esp32/boards/ESP32_GENERIC/sdkconfig.ota index 4a164aa6f841..e3a1f81fd3c9 100644 --- a/ports/esp32/boards/ESP32_GENERIC/sdkconfig.ota +++ b/ports/esp32/boards/ESP32_GENERIC/sdkconfig.ota @@ -1,4 +1,3 @@ -CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4MiB-ota.csv" diff --git a/ports/esp32/boards/SIL_WESP32/sdkconfig.board b/ports/esp32/boards/SIL_WESP32/sdkconfig.board index be9e40c4c3ae..741a4db43909 100644 --- a/ports/esp32/boards/SIL_WESP32/sdkconfig.board +++ b/ports/esp32/boards/SIL_WESP32/sdkconfig.board @@ -13,7 +13,6 @@ CONFIG_ESP32_REV_MIN_1=y # OTA -CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16MiB-ota.csv" diff --git a/ports/esp32/boards/sdkconfig.base b/ports/esp32/boards/sdkconfig.base index 4b7c852332da..6526a803558e 100644 --- a/ports/esp32/boards/sdkconfig.base +++ b/ports/esp32/boards/sdkconfig.base @@ -14,6 +14,7 @@ CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR=y # Bootloader config CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y +CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y # Change default log level to "ERROR" (instead of "INFO") CONFIG_LOG_DEFAULT_LEVEL_INFO=n From d7f63f994f229610c44af9387cb8c9bad34c03fd Mon Sep 17 00:00:00 2001 From: dotnfc Date: Tue, 12 Sep 2023 17:15:27 +0800 Subject: [PATCH 31/78] esp32/main: Allow a board to override the MicroPython task stack size. This allows the MicroPython task stack size to be overridden by the mpconfigboard.h settings. Signed-off-by: dotnfc --- ports/esp32/main.c | 7 +++---- ports/esp32/mpconfigport.h | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 1420dd579c5d..4a9c0060b255 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -66,7 +66,6 @@ // MicroPython runs as a task under FreeRTOS #define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1) -#define MP_TASK_STACK_SIZE (16 * 1024) // Set the margin for detecting stack overflow, depending on the CPU architecture. #if CONFIG_IDF_TARGET_ESP32C3 @@ -87,7 +86,7 @@ int vprintf_null(const char *format, va_list ap) { void mp_task(void *pvParameter) { volatile uint32_t sp = (uint32_t)esp_cpu_get_sp(); #if MICROPY_PY_THREAD - mp_thread_init(pxTaskGetStackStart(NULL), MP_TASK_STACK_SIZE / sizeof(uintptr_t)); + mp_thread_init(pxTaskGetStackStart(NULL), MICROPY_TASK_STACK_SIZE / sizeof(uintptr_t)); #endif #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG usb_serial_jtag_init(); @@ -109,7 +108,7 @@ void mp_task(void *pvParameter) { soft_reset: // initialise the stack pointer for the main thread mp_stack_set_top((void *)sp); - mp_stack_set_limit(MP_TASK_STACK_SIZE - MP_TASK_STACK_LIMIT_MARGIN); + mp_stack_set_limit(MICROPY_TASK_STACK_SIZE - MP_TASK_STACK_LIMIT_MARGIN); gc_init(mp_task_heap, mp_task_heap + MP_TASK_HEAP_SIZE); mp_init(); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib)); @@ -206,7 +205,7 @@ void app_main(void) { MICROPY_BOARD_STARTUP(); // Create and transfer control to the MicroPython task. - xTaskCreatePinnedToCore(mp_task, "mp_task", MP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, MP_TASK_PRIORITY, &mp_main_task_handle, MP_TASK_COREID); + xTaskCreatePinnedToCore(mp_task, "mp_task", MICROPY_TASK_STACK_SIZE / sizeof(StackType_t), NULL, MP_TASK_PRIORITY, &mp_main_task_handle, MP_TASK_COREID); } void nlr_jump_fail(void *val) { diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index ae73e02e41a5..da26a78ae7b5 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -152,6 +152,11 @@ #define MICROPY_FATFS_MAX_SS (4096) #define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ +// task size +#ifndef MICROPY_TASK_STACK_SIZE +#define MICROPY_TASK_STACK_SIZE (16 * 1024) +#endif + #define MP_STATE_PORT MP_STATE_VM // type definitions for the specific machine From 61f331374da150f0d9f42d694d56b6b0dc9ee498 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 1 Sep 2023 16:02:29 +1000 Subject: [PATCH 32/78] stm32/usbd_msc_interface: Allow configuring the MSC inquiry response. This was previously hard-coded to "MicroPy" / "pyboard Flash" / "1.00". Now allow it to be overridden by a board. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/stm32/mpconfigboard_common.h | 15 +++++++++++++++ ports/stm32/usbd_msc_interface.c | 30 ++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index 611a08252d51..b6cc7f84db7e 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -256,6 +256,21 @@ #define MICROPY_HW_USB_INTERFACE_FS_STRING "Pyboard Interface" #endif +// Must be 8 bytes. +#ifndef MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING +#define MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING "MicroPy " +#endif + +// Must be 16 bytes. +#ifndef MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING +#define MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING "pyboard Flash " +#endif + +// Must be 4 bytes. +#ifndef MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING +#define MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING "1.00" +#endif + // Amount of incoming buffer space for each CDC instance. // This must be 2 or greater, and a power of 2. #ifndef MICROPY_HW_USB_CDC_RX_DATA_SIZE diff --git a/ports/stm32/usbd_msc_interface.c b/ports/stm32/usbd_msc_interface.c index cb1de9684155..a294a295b3eb 100644 --- a/ports/stm32/usbd_msc_interface.c +++ b/ports/stm32/usbd_msc_interface.c @@ -90,20 +90,17 @@ STATIC const uint8_t usbd_msc_vpd83[4] = { 0x00, 0x00, // page length (additional bytes beyond this entry) }; -STATIC const int8_t usbd_msc_inquiry_data[36] = { - 0x00, // peripheral qualifier; peripheral device type - 0x80, // 0x00 for a fixed drive, 0x80 for a removable drive - 0x02, // version - 0x02, // response data format - (STANDARD_INQUIRY_DATA_LEN - 5), // additional length - 0x00, // various flags - 0x00, // various flags - 0x00, // various flags - 'M', 'i', 'c', 'r', 'o', 'P', 'y', ' ', // Manufacturer : 8 bytes - 'p', 'y', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes - 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', - '1', '.', '0', '0', // Version : 4 Bytes -}; +STATIC const int8_t usbd_msc_inquiry_data[STANDARD_INQUIRY_DATA_LEN] = \ + "\x00" // peripheral qualifier; peripheral device type + "\x80" // 0x00 for a fixed drive, 0x80 for a removable drive + "\x02" // version + "\x02" // response data format + "\x1f" // 0x1f = (STANDARD_INQUIRY_DATA_LEN - 5) = 0x24 - 5 + "\x00\x00\x00" // various flags + MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING // 8 bytes + MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING // 16 bytes + MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING // 4 bytes +; // Set the logical units that will be exposed over MSC void usbd_msc_init_lu(size_t lu_n, const void *lu_data) { @@ -210,6 +207,11 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou return -1; } + // These strings must be padded to the expected length. (+1 here for null terminator). + MP_STATIC_ASSERT(sizeof(MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING) == 8 + 1); + MP_STATIC_ASSERT(sizeof(MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING) == 16 + 1); + MP_STATIC_ASSERT(sizeof(MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING) == 4 + 1); + uint8_t alloc_len = params[3] << 8 | params[4]; int len = MIN(sizeof(usbd_msc_inquiry_data), alloc_len); memcpy(data_out, usbd_msc_inquiry_data, len); From da6f1e1d1e2feb4b7aa4ee6c84e7e2c816d2bead Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 1 Sep 2023 16:03:27 +1000 Subject: [PATCH 33/78] rp2/msc_disk: Allow configuring the USB MSC inquiry response. This was previously hard-coded to "Micropy" / "Mass Storage" / "1.0". Now allow it to be overridden by a board. Also change "Micropy" to "MicroPy" and "1.0" to "1.00" to match stm32. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/rp2/msc_disk.c | 10 +++------- shared/tinyusb/tusb_config.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ports/rp2/msc_disk.c b/ports/rp2/msc_disk.c index 24bd51cec3f3..0937eeddf0d0 100644 --- a/ports/rp2/msc_disk.c +++ b/ports/rp2/msc_disk.c @@ -44,13 +44,9 @@ static bool ejected = false; // Invoked when received SCSI_CMD_INQUIRY // Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) { - const char vid[] = "Micropy"; - const char pid[] = "Mass Storage"; - const char rev[] = "1.0"; - - strncpy((char *)vendor_id, vid, 8); - strncpy((char *)product_id, pid, 16); - strncpy((char *)product_rev, rev, 4); + memcpy(vendor_id, MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING, MIN(strlen(MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING), 8)); + memcpy(product_id, MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING, MIN(strlen(MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING), 16)); + memcpy(product_rev, MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING, MIN(strlen(MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING), 4)); } // Invoked when received Test Unit Ready command. diff --git a/shared/tinyusb/tusb_config.h b/shared/tinyusb/tusb_config.h index 96e883fc8886..266cb88cc2fe 100644 --- a/shared/tinyusb/tusb_config.h +++ b/shared/tinyusb/tusb_config.h @@ -43,6 +43,18 @@ #define MICROPY_HW_USB_CDC_INTERFACE_STRING "Board CDC" #endif +#ifndef MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING +#define MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING "MicroPy" +#endif + +#ifndef MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING +#define MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING "Mass Storage" +#endif + +#ifndef MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING +#define MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING "1.00" +#endif + #ifndef CFG_TUSB_RHPORT0_MODE #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) #endif From 6a6a90507d0f7063ffe3b5b12ecf3855613a3b89 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 15 Sep 2023 15:07:18 +0200 Subject: [PATCH 34/78] stm32/boards/ARDUINO_GIGA: Update board config. Changes are: - Disable internal flash storage and use the external QSPI for storage. - Disable default bootloader entry mode. The bootloader entry function exists in board_init.c. - Remove OSC enable/disable macros (this board doesn't have an OSC). Signed-off-by: iabdalkader --- ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h index 29b61bd8ddd7..29f1e6140190 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h @@ -30,7 +30,7 @@ typedef unsigned int mp_uint_t; // must be pointer size // Flash storage config #define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1) -#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1) +#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0) #define MICROPY_BOARD_STARTUP GIGA_board_startup void GIGA_board_startup(void); @@ -38,6 +38,7 @@ void GIGA_board_startup(void); #define MICROPY_BOARD_EARLY_INIT GIGA_board_early_init void GIGA_board_early_init(void); +#define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0) #define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) GIGA_board_enter_bootloader() void GIGA_board_enter_bootloader(void); @@ -46,10 +47,6 @@ void GIGA_board_low_power(int mode); #define MICROPY_BOARD_ENTER_STOP GIGA_board_low_power(1); #define MICROPY_BOARD_ENTER_STANDBY GIGA_board_low_power(2); -void GIGA_board_osc_enable(int enable); -#define MICROPY_BOARD_OSC_ENABLE GIGA_board_osc_enable(1); -#define MICROPY_BOARD_OSC_DISABLE GIGA_board_osc_enable(0); - // PLL1 480MHz/48MHz SDMMC and FDCAN // USB and RNG are clocked from the HSI48 #define MICROPY_HW_CLK_PLLM (4) From 10f34b97d14dc3975fb021cd79d6ed95967e5a66 Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Wed, 6 Sep 2023 17:10:06 +0100 Subject: [PATCH 35/78] tests/multi_net/ssl_cert_rsa.py: Update test certificate. Update expired certificate, increase time validity period to five years and fix command arguments typos in commentaries. Signed-off-by: Carlos Gil --- tests/multi_net/ssl_cert_rsa.py | 197 ++++++++++++++++---------------- 1 file changed, 98 insertions(+), 99 deletions(-) diff --git a/tests/multi_net/ssl_cert_rsa.py b/tests/multi_net/ssl_cert_rsa.py index 872855edbaf2..6454ad83aafe 100644 --- a/tests/multi_net/ssl_cert_rsa.py +++ b/tests/multi_net/ssl_cert_rsa.py @@ -14,115 +14,114 @@ # testing/demonstration only. You should always generate your own key/cert. # To generate a new self-signed key/cert pair with openssl do: -# $ openssl req -x509 -newkey rsa:4096 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -node +# $ openssl req -x509 -newkey rsa:4096 -keyout rsa_key.pem -out rsa_cert.pem -days 1825 -nodes # # Convert them to DER format: # $ openssl rsa -in rsa_key.pem -out rsa_key.der -outform DER -# $ openssl x509 -in rsa_cert.pem -out rsa_key.der -outform DER +# $ openssl x509 -in rsa_cert.pem -out rsa_cert.der -outform DER # # Then convert to hex format, eg using binascii.hexlify(data). cert = binascii.unhexlify( - b"308205d7308203bfa003020102020900bc63b48a700c3d49300d06092a864886f70d01010b050030" - b"8181310b3009060355040613024155310c300a06035504080c03466f6f310c300a06035504070c03" - b"42617231143012060355040a0c0b4d6963726f507974686f6e310c300a060355040b0c03666f6f31" - b"16301406035504030c0d657370686f6d652e6c6f63616c311a301806092a864886f70d010901160b" - b"666f6f406261722e636f6d301e170d3232303731323138303031335a170d32333037313231383030" - b"31335a308181310b3009060355040613024155310c300a06035504080c03466f6f310c300a060355" - b"04070c0342617231143012060355040a0c0b4d6963726f507974686f6e310c300a060355040b0c03" - b"666f6f3116301406035504030c0d657370686f6d652e6c6f63616c311a301806092a864886f70d01" - b"0901160b666f6f406261722e636f6d30820222300d06092a864886f70d01010105000382020f0030" - b"82020a0282020100ce3c0f730ab34432ce605ab44d4ac0aafd8a6243133eab0dcc9d444ab7d9ff66" - b"a6815a101d2d3cbd72140afc34f8c3caedce16e9528350f3e0e56343f248507d82e41b51abb515cb" - b"f60e5a619f2dbca8684d174c3b0951e2c7ba576c7fb06453a3597755810a6a4c45eb0925c855ab53" - b"7785df46bf29145871330ff0641a101a24f0830c20bae865ba8bb32606caac4555812acf19f59553" - b"349ce70fb7ff63512f0444f8f41b973183eabf9679903087c6cd69dc3adcbe754dd0207ea57c50e9" - b"2d800bce6258d1618bb749d3fc01239b6d1af6d3f9cada3acbb312a1d85a59cfabd28b2e572c56a4" - b"818ce170ca2b781a04749c6239206c64ad9e057484143a4c52bdef6189c46405c1a9642489cb640a" - b"937adfc2687578dfa2b40ebafa05213642a1ccbc265557cd40de53324cff1bfba6f5c215f657b8f9" - b"f2260ab6293625d0e203bba975bc7ac6dff3e604c9b0d2a2a4ba5941c0dc8d2e0e9439c56447b404" - b"8c0e6cfb03517742ff6f7c2140a05954aa1e29247d1ae8bfd7db0db8dd45d095710fb78284ede285" - b"0fc0c21235406af83e6044addf9385316403e2a25442b9ffbfc7b01c6c9292e5a3531e6a48496c01" - b"6de1373334a52f01b7c6a0ece1261936788d2161c53a8985a0946d6d319225b230d96d055ea4692f" - b"eb71fdaf4b775ac9fbc38e1b943e6617cf61d33e930ab288a3ea4730b4f2784a8018e0dfc8a11e73" - b"0203010001a350304e301d0603551d0e04160414bc6048fe3cd278257e8b7c90dedbbce8369b20b8" - b"301f0603551d23041830168014bc6048fe3cd278257e8b7c90dedbbce8369b20b8300c0603551d13" - b"040530030101ff300d06092a864886f70d01010b0500038202010009238354b43379a3d2b56e928c" - b"ac8ea28e2c01cf8148e54c0bbd4055e2e57d578697d1e2c392f1fe3bc9211d4f27ed1be631e7547a" - b"6390d7f121a9e20a195fdda73f755188b16cf39714924a9686dd7cc749421335038c0640c2c6b15d" - b"f44d74d94a97285ee2a7b075ccc9d9d632e2a5906030cf59bde14ab10660b7cf47ec9d7ae2f35963" - b"454f76735a3dac12a4a4c907183e9ccf3e07d59484c182e67edc7c35ce15c7e1072fae8c9965a126" - b"1a1f31147d4af8d1ebf8ee7c142badfe67e31fb324a79a29bc94e89370b70d8cf7cd2b2aa427a49f" - b"77849891e7c4d5911f6fda52733a3c169b0188c2d9918f296dd8e234f8962f0db5e47c6159448045" - b"4e2d9a5850d4c696a0fb3b66534a4591c49dda8cc6f1b0008c625aa5e0091ecfbd51d9715c60b85e" - b"4e89d4a6cfabb2acdf81518eb61403b8f8767c5c00216f730e08f22959dff695a081cc726c4ab35a" - b"e3f6538a231f831a6e91206f3b691a94bdf95343ec02ef7aac42da2a70846cd5f13dd2955a5f1737" - b"a4c3c6c03b041d334c1dadd1e305f07c83b4b4e0509ec1d23e95f820290942eaaf8bea304cd5a505" - b"8fc0d4624ff1ffe1348e7bc54c756a12acb258eb5e7426fb062a82b88ec274c9c13b3eff8b010947" - b"62e166f490cd25b14e762db708785859a337d8fd0008fe602a90e2933cded3359e98ce3fbc041208" - b"66bd4d96d6b6f7f53def854d40021196b7a06b" + b"308205b53082039da00302010202090090195a9382cbcbef300d06092a864886f70d01010b050030" + b"71310b3009060355040613024155310c300a06035504080c03466f6f310c300a06035504070c0342" + b"617231143012060355040a0c0b4d6963726f507974686f6e31143012060355040b0c0b4d6963726f" + b"507974686f6e311a301806035504030c116d6963726f707974686f6e2e6c6f63616c301e170d3233" + b"303731353136323034395a170d3238303731333136323034395a3071310b30090603550406130241" + b"55310c300a06035504080c03466f6f310c300a06035504070c0342617231143012060355040a0c0b" + b"4d6963726f507974686f6e31143012060355040b0c0b4d6963726f507974686f6e311a3018060355" + b"04030c116d6963726f707974686f6e2e6c6f63616c30820222300d06092a864886f70d0101010500" + b"0382020f003082020a0282020100944fdb40b587af0cf7e9696c355d24a70936874e6a3bd2598166" + b"ce2495aaf9b4af01b54471f7cbf3626ae0720bf0bfd520507f79ec553c62898bfd2598385f56061b" + b"0e8f452625c82d3c83e2a0d070ab9be2db21faf88c58e4a61d62f8ff43960aa1ffdadaad41f7cb2e" + b"b337070a39f08ff9fe20c09b19926cbbc4a5154b796ff7e7ce11334e090d360c81072af08758f6cd" + b"7bad75bc7b95b6dcc801c85de81d72806ca3ce0782bfcbdffce707f9fb1572a7db0d74445dc32d5f" + b"bea12a3ab1d47edf668ebfa60ed8b51e654e76292e3894ee574ea851064956906aa8afe00e67664e" + b"110b5a6ff7db51f7944463cdd626ff2ec7886c229f4ca5985168f20f8f210972b5ff9181d4f3beb8" + b"914ec5b24a0953253b3d42ab55e98bd70cb25e7a24c603b27ec83e1ce31c90b728b47a5f606ff2a1" + b"0ff784a016894c28f7e71f51a78b0a7601bbbc8c1b132b04e567394a327a7aa4674e8e4c0bfaec4b" + b"eeccf0ed09d1660933d718a2f34ff91d79d875a73fbac07182a9531ca52bd360e2678f95ff9b4ba2" + b"1490d7456548364b2eb335c207d6e1e48ccd7d8cb43868a334c095bd9673be7403f3b69b545ee904" + b"a3f513d2b2a2dd46f06820cd394819551dd05d9b34a8a3238a521f6c1c3592f76d5ef29e181c60ee" + b"bcaf4c63098794c15d4f82e7425e75ff8f5430247ecc0e7f2983b715506012f187d54a7b6729bc61" + b"fa4d10a9f22b0203010001a350304e301d0603551d0e041604147a6d126931b58fa1c3dff3c9215f" + b"6202e61fa8da301f0603551d230418301680147a6d126931b58fa1c3dff3c9215f6202e61fa8da30" + b"0c0603551d13040530030101ff300d06092a864886f70d01010b0500038202010051b3a4834d2bf1" + b"95ac645bca61e95289eff38d80ab2ee732c6ebd1370781b66955a7583c78831f9fb7d8b236a1b5ff" + b"c9183b4e17225951e1fb2c39f7218af30ec3fd8e4f697e0d10ecd05eb14208535dc55bc1e25d8a43" + b"050670d4de3e4cb8c884e6cbb6b884320d496b354acf5258bcb0ddaefd065ee8fccbddf3a2bfa10d" + b"bfeb8ab6b2580b50f0678760599269b612f81ba1310bfcd39427fec49211769c514cdd0305081d8a" + b"11ebe705496d4dcc31ac9fab96a2d298ee4423789baffbfa0fa82ee1b5113f9cf597647a36640cad" + b"abf535205c322e16153d6ab04b0817f57d8a9a6ca2db2ab10986ae9eab343547e52c78a641868bb5" + b"e2981182fcc55d86cdc6aa8478b226318a3be72fb726dd0b90f30df810c4d6c6b5a0ecb3c6cc375b" + b"8d3d244a07d8517ad390929be7b75f679beb63d8c1028905af2383144a4ed560e45907d301846acc" + b"9dbec86bcdd7fbf8a805b59f359c8bd997f5eb7b8aea6f7a538f9663ec2c12e07d4b37650e92b783" + b"74356daee4a501eeb27fef79b472b2fcce4363a9ff4d80f96a3b47dc4c4ef380ef231d193a517071" + b"b31078fa9f9a80cfd943f7e99e4ed8548c9ea80fd845ecc2c89726be273fa8b36680d645998fd1e6" + b"2367638f4953e9af68531aedb2ee49dffaaed07a4a5b97551712058219ac6f8da71710949f761271" + b"5273a348dcce40c556bdab00a4ae3a7b23a5934ac88b7640df" ) key = binascii.unhexlify( - b"308209290201000282020100ce3c0f730ab34432ce605ab44d4ac0aafd8a6243133eab0dcc9d444a" - b"b7d9ff66a6815a101d2d3cbd72140afc34f8c3caedce16e9528350f3e0e56343f248507d82e41b51" - b"abb515cbf60e5a619f2dbca8684d174c3b0951e2c7ba576c7fb06453a3597755810a6a4c45eb0925" - b"c855ab537785df46bf29145871330ff0641a101a24f0830c20bae865ba8bb32606caac4555812acf" - b"19f59553349ce70fb7ff63512f0444f8f41b973183eabf9679903087c6cd69dc3adcbe754dd0207e" - b"a57c50e92d800bce6258d1618bb749d3fc01239b6d1af6d3f9cada3acbb312a1d85a59cfabd28b2e" - b"572c56a4818ce170ca2b781a04749c6239206c64ad9e057484143a4c52bdef6189c46405c1a96424" - b"89cb640a937adfc2687578dfa2b40ebafa05213642a1ccbc265557cd40de53324cff1bfba6f5c215" - b"f657b8f9f2260ab6293625d0e203bba975bc7ac6dff3e604c9b0d2a2a4ba5941c0dc8d2e0e9439c5" - b"6447b4048c0e6cfb03517742ff6f7c2140a05954aa1e29247d1ae8bfd7db0db8dd45d095710fb782" - b"84ede2850fc0c21235406af83e6044addf9385316403e2a25442b9ffbfc7b01c6c9292e5a3531e6a" - b"48496c016de1373334a52f01b7c6a0ece1261936788d2161c53a8985a0946d6d319225b230d96d05" - b"5ea4692feb71fdaf4b775ac9fbc38e1b943e6617cf61d33e930ab288a3ea4730b4f2784a8018e0df" - b"c8a11e73020301000102820201008efa0e8fe81c2e2cb6ed10152dfca4242750581d3e6b54f56524" - b"a6a2d2613cf2727efcec6cfddebd4c285f1148bc2a2936c28919cb0da502dea8c92fe2f9856bee61" - b"ac1aebdac838b5e66f7c7c799df07716f30ef362dbb5485884a180c8ce5539cb1db35699dce5f217" - b"27295d811f1ce7a115111c1823b5c90ce880f5352872a7a76282f6f1fd8a015136ab274c3d30783d" - b"eb6ad7096e33d826eafdf7c70398d5eab4d28f91cd3913c69c7a7ade9ef692b9f8292959be64dec4" - b"6ab2c291b41a6464004b5ddd4b93bfe41b37eedeef4ba2d16dcbb9c28b96f57fb96c20ed4a9471ff" - b"ae643b254f100f8c9702b5f67af6369e8d887f285e5d520c5aa5d3a79e5de96432e6d2e3dea68e58" - b"208c075fb119c6d3d4149b7e1247208d6b337c70272befc41d57f278618f1a82de337173346dc135" - b"4d80a7c9075af99dbb2a14733c06b71600c6677a6bb28c0e4fc63db622228047a2cb7474dc8141c3" - b"5f3a597c3e2bca9911d28eb9fd1a0c915e9f9c1cfd643d4fd8cac867f215380168ec37b8cfa28564" - b"e6288ab04a7d67ca44b4c8375214a7ffaa1e6be92c4b138fcfd6beaba251b31a50a6e2ef241c9554" - b"a1dc710b4acb63e749f5849e53d3f4915c6eb2a9a009bab04e932841ab34ae29eb000a08777d6399" - b"169c2dc3d7952df5bc2d06e90a32139c6a2793d3817e4feadac2ccac554d383a8d41569140c29168" - b"89220d3a5e410282010100fd603d18feef7aac61bda3b674a57ab38748bcde5c3efdba2279638f8e" - b"a413cc26b9dda0375c116a8798a295b2c283aaaad7cca0dbd9bb3322a9a815f6d0aa5fc4f9aff8fb" - b"da8ff914091ede7aefdb07a119c9b2e2b2bda776ac497060b8e88a82eb20c62f26f343566697726e" - b"71aa46fd4efad6f42fc8a478856324d72cbf5eb3918317162d6fc2cfd775969a2077759fa2c8220d" - b"acdc2ebb03ec39feed3f2b415449cbf40a7126bcf01d1068e3a45ec01181f2c68d7e05b4720bfe4a" - b"308e1648123c91214a5f8dfce58727c4cd9396a8b403b733a717449b2f1970db97a3b8467271ffa6" - b"e8c7cc9e2e1c0f789284ae9efe77eaac01131463c9c1329a1ba3530282010100d05ed6ab9b9fbdf7" - b"a0f5f91f68dc3bac5789332d6ece46103fb1ef109fc972fdc99edf3107a23d66d1cdfe6bdddfd1bb" - b"3952ccd10b5c20ad1b3e0aa6a51271ecf3a7ef2a65e029f5d77f238d1235b52a9dca3451c165d70a" - b"99cbaea5c610e5455979696db769191e7cf2db21f641959e4ba1c5c0aae260c724962b6ac2621d92" - b"e9df7adeb82b522d37b42cb454003bbe60d9915bf7737aeccf88c7ed1263a22f431a734e61fe7173" - b"a937ddf76ad2a79994c05238defc15f6846858e9edf27ae2a567c7c5c735ea5d2fbef65a2195bc05" - b"d82cbf06a477b29c84c92e8054c2bb25d8c6f19d43ef5fd1fce13c2cdbc361c39baec37b399200b3" - b"2d4a6798ba0b546102820101008e41492c4e7daff7368d1d6c64034067a94dca5461a0301e201add" - b"2e0d5ccb8cb435685bfa98e362572cf8236a10d191b187a568aee688b6c60050d1bc181d7fd57c86" - b"33195bf5b7576b637c6fb358dae8b52ccc15815affb99e334137dcb91a833475db2f4004164b5d20" - b"2c6c1bbf094a50dc7e70ec9f0ed067bb6944b1e7e3c897aaecfc53984add1c4ff5b525034cf3ca95" - b"e8a09aeba804f1c7e02be391b2bc641166c3e654eef5e72dba37d98f406f3fa520e41f2ea10f5574" - b"ac5984f75145378fefbfac1d07fff3f234fec698d55e746b1da18f6f7de24ec84ed7cb446d428820" - b"bef33c00693e6a0ef114b5d66e9fefa8ee059238df1ac37c87e7841ae7028201000721a7d139c34e" - b"da21cd295894db2cc3aa3f4cdc1a35bf1a2143f2bdabea56202f7d5b802f15b36a4875f76633b2cc" - b"57cf0f71691a2d6e04deb0d1e68031d06a5eb079b406c6944910b60e3e6ec81dca369a4c0e1c4363" - b"07bed9c4c171b4f453da4b187ba3d25a04bc1c07b9f2d6adcb3c256e4238d7049eec36a387c4dd5c" - b"cbc16b5fa62dc175cf8c5f83442cb7d153a3b6ee8daa3b6e929a4bc123f1042df1d6271a992d2b6b" - b"309d33074ac7822c304a72069e61ab590915e10862013dd24cdd825ec8fb17724cfc2c59fc1db825" - b"3641fece0ee9241b9dd5c198f0d575d0b7ebe26b3489b5b09edc3bcd366fd3110e83ce886c383d31" - b"feefe6e302cc2345210282010008f77a33d0081e9be3c1b1ac8b8e0eebb72df2eb69b95d2ed74935" - b"b9dab8e17023cc38465354023c5183b51a6a20288fbb2181172be1c2fdb8b444419454e5b37f7f3b" - b"df11e28cf4746b25534eb62f7e87bbbf28eda37024368b3897fbc661b40a93e04a183db9219c04a8" - b"7643edf5d8b5dbfe3d424e91d558d5e3e2fa02ce1984ee69fb8518470eee2e7db0e1df5ac4571f78" - b"a7a2529bc1fef5e32d46994869a8d8cc47869e174d84e7976be8ebb88f2ccb71a603a8bdb06af3eb" - b"2ddbd62082f40d7987e47f2e321eb5eb2a28fefab263409f89dc97ebc723a1b751418cdd3ea684ba" - b"8b17a330a306a6fbcf51ba83563aed85a4f886fff1a22423748d83798c" + b"308209280201000282020100944fdb40b587af0cf7e9696c355d24a70936874e6a3bd2598166ce24" + b"95aaf9b4af01b54471f7cbf3626ae0720bf0bfd520507f79ec553c62898bfd2598385f56061b0e8f" + b"452625c82d3c83e2a0d070ab9be2db21faf88c58e4a61d62f8ff43960aa1ffdadaad41f7cb2eb337" + b"070a39f08ff9fe20c09b19926cbbc4a5154b796ff7e7ce11334e090d360c81072af08758f6cd7bad" + b"75bc7b95b6dcc801c85de81d72806ca3ce0782bfcbdffce707f9fb1572a7db0d74445dc32d5fbea1" + b"2a3ab1d47edf668ebfa60ed8b51e654e76292e3894ee574ea851064956906aa8afe00e67664e110b" + b"5a6ff7db51f7944463cdd626ff2ec7886c229f4ca5985168f20f8f210972b5ff9181d4f3beb8914e" + b"c5b24a0953253b3d42ab55e98bd70cb25e7a24c603b27ec83e1ce31c90b728b47a5f606ff2a10ff7" + b"84a016894c28f7e71f51a78b0a7601bbbc8c1b132b04e567394a327a7aa4674e8e4c0bfaec4beecc" + b"f0ed09d1660933d718a2f34ff91d79d875a73fbac07182a9531ca52bd360e2678f95ff9b4ba21490" + b"d7456548364b2eb335c207d6e1e48ccd7d8cb43868a334c095bd9673be7403f3b69b545ee904a3f5" + b"13d2b2a2dd46f06820cd394819551dd05d9b34a8a3238a521f6c1c3592f76d5ef29e181c60eebcaf" + b"4c63098794c15d4f82e7425e75ff8f5430247ecc0e7f2983b715506012f187d54a7b6729bc61fa4d" + b"10a9f22b0203010001028202000b41080520013cc242299f0b4bfd5663aa6a4dd8206d8ba7a90f11" + b"036babfea8bc42e7eb5aae8ff656f87f3188406b7e13a6a815ab5e4867bdc236a25caba26857ac43" + b"ed9134b4d73cbf83ce759f7b7d3a25fbb4d76376dae3f6caf210ace60703a58951a51852922803d2" + b"2b91c82fdf563d85101d2d67c259a7e1e318fb922a71e85015b40beed9e6c90a1d6e1fb45586dcce" + b"ceb9c964a356ade82b6275e5c01e492a753f940852df788eab454aadc7d1dc74ddcf7dc493a3e4c9" + b"0557bbfe747e701b4b27b5c518a29dbcd8385525a1bb835e72a489096e15387e2f70b112c6bbd79e" + b"a97ae2562f7947cd2367635e25b5656a54aac7f1c892243dc135e5025a44d724884b244e8fe4abb4" + b"c67bbd2e652d5fc5942b55c24b7f642f65b9b6d37110a955c63eb4f26435be056effbd777f14db8d" + b"3d8073f7583b24656edb19911e1307101443a50717c32dbb80b6212e6f0ee43f629b1e718a958a5c" + b"fdcd99762f5bff821ac49b0e77c9d1426f8bb31142df030549330dde5cc92fa20d09744ceac6ae02" + b"fb354e9b930173e08488375f7c795b3b934c72b58a3353332d5129d56151b57a793d99868885ebd4" + b"aac11ca03e09f5b6bd9dda5322a0ab81e468839ea373ecd2b5ac4ffc99740581b35add07f83ff18e" + b"c2111555ead17783294b2330ad874bd966c1d60b44e5f379650910a8a05eb92cb7550191c13251f5" + b"0a11afa7510282010100c5a4aa380f6bdd4b4524deb44425aa7ef61039a46ad0d09e2ca2cd7fb757" + b"ff325f81eaf3a2e790afb3ffb0d71f3ffa52db1a24d3149839f03d1acfe33ef721fe310895986c5a" + b"fe88ceb82318ed540456b8aa7e07dc7b982345c4f040b1544bd2ee1e4cb0315bd8db3794ea93d705" + b"f41cc1c06badf72de36d2b4a4399846d6c851260e5044e9495be8225307edb97071bdea08c99ccfe" + b"54219f6a785db47864e03cf2851abcb62941d3efeea7cdf136d9e23845cf9ea0323b156c686c6d30" + b"1cbb5a8c7f1db23a998bf549874b2c13685b20d200d2d91be92c40480a0cca18c28f654dd644c60d" + b"e8e03824c0ff83e7cbfc44b2aa16ad537a09565ed4afbe63b8930282010100c01a5e6108420c3d2e" + b"ccd0b559e08680f47b3e7271ee4ea9bf4740cc5c418a53225778eddb716447b02d234909f8291581" + b"a45be0591952bacda55e774338962502c1d73f2d5383259aaa69f2603fde216ca9557d8b4e629888" + b"c697fec1aaf9f99ebd223c06399cc13cd21bd01e3660acc148ba841e5c89b3f8f04efac07f8072a5" + b"bacb4f5cfece528496bb35e906361efdb89a17fe4999f47508d5e48914ac651172ddc994993b4672" + b"7ec62810d6c204af4b5fd52ba4f8cb3c8720fbd469b219868e28294e60276bc2483e78d96a0edf29" + b"e237fe6f1660705d5cd3590c476e37c5d367b19bfb0a1c29ef296dfd3e9fabf5b37e1fb7357a3032" + b"c8a641b467d7090282010100bc6d55bf66ac6e69017dba38e0b38c4dc8a8055c845d9a5702b51ff8" + b"4042cbd1298f0201cf70b7d75b634d247aed92e9056c72692f3c46188d190fd35647648824154c11" + b"ea54025149cbf1e224f9b1bd4007836a594117f5a0e1b62fe72037bddc38d4e231dc9fedb79ae8dd" + b"93e5602b3e6905fff02536aaf0d7b78517e4fece0b8c872ac9040d93781e9e92832604a80462ca49" + b"234fe1c3c0695061fdd9be4aaeb08447ce5c590f2250a01629586bf3e421c424c1d576ae2fa99010" + b"b7346460165ed61de8bac782d0928e4313bd59037051e6691e85e692c2a22bbaafbe555742bca7a8" + b"1fae4933e332df317b7f3551c7e91211d6a33c38c4b85a4b46d769b3028201003884497a00a4f5d6" + b"d63af9b830fe06744ff926512345ba2ce49280f4debb858799d5e4450e4798fa2251d54cbabb20d3" + b"2bf5fff5cc20d01f173b6cc467a9713ae849c11adc29f2ae90874c6e3b74eed42494d90afb7e0f31" + b"d323a23a181e4636f345af99bb371df01805b49b11186c6ec6daafcd08e5aeb99d268e05e5b65d42" + b"dd914c194841cacfaa24726594edf7e43c3f204ea8c85c9bf806a66efb097302b514773dc41324c6" + b"400f1e1b5180ed49d58cb6600fdc143a2ecf8e9ba84d8451502de890e6771181f981a9a782475aa2" + b"bb3ecbbc76503e0530e28b676a5e6585d114b63021b4c4afae82a74cadb1cbe61a7e393ff975a942" + b"1edebb531f51618902820100214d9f1efa774b9d4e0a996442c2744560c84b133045b1af9241d60f" + b"c2f82043ac169dc9496ebb5f26b5cb8a6636c57d44e06843bf1f082be42fe5933a7ab7a6878dccf3" + b"58606a9fd6984ea525fe34f9e86f7bae33e707be0dec8fbef2deed253c822f6b812e7bd8c64bc302" + b"5c9a9e58811d30981a329f7b130148b0eb2ac62cec516942f7530963edab832bd0bacf344b183b9d" + b"ba9d54535dceff640f94d79599edf8dd0c32029950ede63f2f579b0d3c9a13c04df73fec03c4bcbe" + b"ff7ecf69ba082445673a263685475b91390963e2d42705ba89ff107e96bbb7a887daa016f282f1e6" + b"bdd7b9bb14579166f8c13be876cdef07e13c6ef08ff49d4207c7c7ff" ) From c854d0e3e1a05c06fadf997963932f2da5477a39 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 8 Sep 2023 21:11:13 +0200 Subject: [PATCH 36/78] examples/unix/machine_bios.py: Fix typo. Signed-off-by: Thomas --- examples/unix/machine_bios.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/unix/machine_bios.py b/examples/unix/machine_bios.py index 40aae4ccefe6..4644d3e2b2a9 100644 --- a/examples/unix/machine_bios.py +++ b/examples/unix/machine_bios.py @@ -1,5 +1,5 @@ # This example shows how to access Video BIOS memory area via machine.mem -# It requires root privilege and x86 legacy harfware (which has mentioned +# It requires root privilege and x86 legacy hardware (which has mentioned # Video BIOS at all). # It is expected to print 0xaa55, which is a signature at the start of # Video BIOS. From cfe6a11e39725f42ac3fffac138d2de1587fe756 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 14 Sep 2023 14:07:04 +1000 Subject: [PATCH 37/78] extmod/asyncio/event.py: Fix ThreadSafeFlag.ioctl return. iobase_ioctl expects that an ioctl method must return an integer, and will raise otherwise. This was tripping up aioble on Unix, where the new hybrid modselect.c implementation will attempt to extract a file descriptor from the pollable via ioctl(MP_STREAM_GET_FILENO). However, ThreadSafeFlag's ioctl only supported MP_STREAM_POLL, and returned None otherwise. This makes it return `-1` (to match tests/extmod/select_poll_custom.py). It should probably be `-22` (corresponding to MP_EINVAL), but the value is never checked, and MP_EINVAL can be a different value on different ports. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- extmod/asyncio/event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/asyncio/event.py b/extmod/asyncio/event.py index e0b41f732424..f11bb14e5840 100644 --- a/extmod/asyncio/event.py +++ b/extmod/asyncio/event.py @@ -49,7 +49,7 @@ def __init__(self): def ioctl(self, req, flags): if req == 3: # MP_STREAM_POLL return self.state * flags - return None + return -1 # Other requests are unsupported def set(self): self.state = 1 From fae83a6b4d0d7b3e4917fdeb9b7966a06161af54 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 14 Sep 2023 15:26:23 +1000 Subject: [PATCH 38/78] tests/extmod/asyncio_threadsafeflag.py: Update for unix select. 1. Remove the skip for detecting support for polling user-defined objects as this is always possible now on all ports. 2. Don't print when the scheduled task runs as the ordering of this relative to the other prints is dependent on other factors (e.g. if using the native emitter). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- tests/extmod/asyncio_threadsafeflag.py | 13 ------------- tests/extmod/asyncio_threadsafeflag.py.exp | 2 -- 2 files changed, 15 deletions(-) diff --git a/tests/extmod/asyncio_threadsafeflag.py b/tests/extmod/asyncio_threadsafeflag.py index 46da1b7b487a..e8798afcf5f5 100644 --- a/tests/extmod/asyncio_threadsafeflag.py +++ b/tests/extmod/asyncio_threadsafeflag.py @@ -16,17 +16,6 @@ raise SystemExit -try: - # Unix port can't select/poll on user-defined types. - import select - - poller = select.poll() - poller.register(asyncio.ThreadSafeFlag()) -except TypeError: - print("SKIP") - raise SystemExit - - async def task(id, flag): print("task", id) await flag.wait() @@ -34,9 +23,7 @@ async def task(id, flag): def set_from_schedule(flag): - print("schedule") flag.set() - print("schedule done") async def main(): diff --git a/tests/extmod/asyncio_threadsafeflag.py.exp b/tests/extmod/asyncio_threadsafeflag.py.exp index 757115ac4bdd..0c62eae9d096 100644 --- a/tests/extmod/asyncio_threadsafeflag.py.exp +++ b/tests/extmod/asyncio_threadsafeflag.py.exp @@ -9,8 +9,6 @@ yield task 2 set event yield -schedule -schedule done wait task task 2 done ---- From fbe58553c2696b18a95e1284b32d7292d49bc486 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 29 Sep 2023 16:15:30 +1000 Subject: [PATCH 39/78] extmod/btstack/btstack_hci_uart: Trigger a poll after UART data is sent. Prior to this commit, BTstack would only be notified of sent UART data when the mp_bluetooth_hci_poll() function was called for some other reason, eg because of incoming data over UART. This is highly suboptimal. With this commit, BTstack is now notified immediately after UART data has been sent out. This improves the multi_bluetooth/perf_gatt_char_write.py performance test by about a factor of 10x for write-without-response, and about 4x for write-with-response (tested on LEGO_HUB_NO6 as instance1). Signed-off-by: Damien George --- extmod/btstack/btstack_hci_uart.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extmod/btstack/btstack_hci_uart.c b/extmod/btstack/btstack_hci_uart.c index f945efc762cb..19cdfc4b9dae 100644 --- a/extmod/btstack/btstack_hci_uart.c +++ b/extmod/btstack/btstack_hci_uart.c @@ -36,6 +36,7 @@ #include "extmod/mpbthci.h" #include "extmod/btstack/btstack_hci_uart.h" +#include "mpbthciport.h" #include "mpbtstackport.h" #define HCI_TRACE (0) @@ -129,6 +130,10 @@ STATIC void btstack_uart_send_block(const uint8_t *buf, uint16_t len) { mp_bluetooth_hci_uart_write(buf, len); send_done = true; + + // Data has been written out synchronously on the UART, so trigger a poll which will + // then notify btstack (don't call send_handler here or it may call us recursively). + mp_bluetooth_hci_poll_now(); } STATIC int btstack_uart_get_supported_sleep_modes(void) { From 4b9c4591339ee2d903c393857f66a0ce0025aa95 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 5 Sep 2023 09:30:11 +0200 Subject: [PATCH 40/78] mimxrt/sdio: Add support for the 117x series. Signed-off-by: iabdalkader --- ports/mimxrt/sdio.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt/sdio.c b/ports/mimxrt/sdio.c index d97fef9e5129..2fa0f228fe3a 100644 --- a/ports/mimxrt/sdio.c +++ b/ports/mimxrt/sdio.c @@ -38,8 +38,14 @@ #if MICROPY_HW_SDIO_SDMMC == 1 #define SDMMC USDHC1 #define SDMMC_IRQn USDHC1_IRQn +#ifdef MIMXRT117x_SERIES +#define SDMMC_CLOCK_MUX kCLOCK_USDHC1_ClockRoot_MuxSysPll2Pfd2 +#define SDMMC_CLOCK_ROOT kCLOCK_Root_Usdhc1 +#else #define SDMMC_CLOCK_DIV kCLOCK_Usdhc1Div #define SDMMC_CLOCK_MUX kCLOCK_Usdhc1Mux +#define SDMMC_CLOCK_ROOT kCLOCK_Usdhc1ClkRoot +#endif #ifndef MICROPY_HW_SDIO_CLK_ALT #define MICROPY_HW_SDIO_CMD_ALT (0) #define MICROPY_HW_SDIO_CLK_ALT (0) @@ -51,8 +57,14 @@ #else #define SDMMC USDHC2 #define SDMMC_IRQn USDHC2_IRQn +#ifdef MIMXRT117x_SERIES +#define SDMMC_CLOCK_MUX kCLOCK_USDHC2_ClockRoot_MuxSysPll2Pfd2 +#define SDMMC_CLOCK_ROOT kCLOCK_Root_Usdhc2 +#else #define SDMMC_CLOCK_DIV kCLOCK_Usdhc2Div #define SDMMC_CLOCK_MUX kCLOCK_Usdhc2Mux +#define SDMMC_CLOCK_ROOT kCLOCK_Usdhc2ClkRoot +#endif #ifndef MICROPY_HW_SDIO_CLK_ALT #define MICROPY_HW_SDIO_CMD_ALT (6) #define MICROPY_HW_SDIO_CLK_ALT (6) @@ -95,7 +107,11 @@ typedef enum { } sdio_xfer_flags_t; static uint32_t sdio_base_clk(void) { - return CLOCK_GetSysPfdFreq(kCLOCK_Pfd0) / (CLOCK_GetDiv(kCLOCK_Usdhc1Div) + 1U); + #ifdef MIMXRT117x_SERIES + return CLOCK_GetRootClockFreq(SDMMC_CLOCK_ROOT); + #else + return CLOCK_GetClockRootFreq(SDMMC_CLOCK_ROOT); + #endif } static uint32_t sdio_response_type(uint32_t cmd) { @@ -144,19 +160,30 @@ void sdio_init(uint32_t irq_pri) { machine_pin_config(MICROPY_HW_SDIO_D2, PIN_MODE_ALT, PIN_PULL_UP_100K, PIN_DRIVE_6, 0, MICROPY_HW_SDIO_D2_ALT); machine_pin_config(MICROPY_HW_SDIO_D3, PIN_MODE_ALT, PIN_PULL_UP_100K, PIN_DRIVE_6, 0, MICROPY_HW_SDIO_D3_ALT); + #ifdef MIMXRT117x_SERIES + CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd2, 24); + + clock_root_config_t rootCfg = { 0 }; + rootCfg.mux = SDMMC_CLOCK_MUX; + rootCfg.div = 2; + CLOCK_SetRootClock(SDMMC_CLOCK_ROOT, &rootCfg); + #else // Configure PFD0 of PLL2 (system PLL) fractional divider to 24 resulting in: // with PFD0_clk = PLL2_clk * 18 / N // PFD0_clk = 528MHz * 18 / 24 = 396MHz CLOCK_InitSysPfd(kCLOCK_Pfd0, 24U); CLOCK_SetDiv(SDMMC_CLOCK_DIV, 1U); // USDHC_input_clk = PFD0_clk / 2 CLOCK_SetMux(SDMMC_CLOCK_MUX, 1U); // Select PFD0 as clock input for USDHC + #endif // Initialize USDHC const usdhc_config_t config = { .endianMode = kUSDHC_EndianModeLittle, .dataTimeout = 0xFU, + #ifndef MIMXRT117x_SERIES .readBurstLen = 0, .writeBurstLen = 0, + #endif .readWatermarkLevel = 128U, .writeWatermarkLevel = 128U, }; From 805c750164aed86db3875402bf26e7b12cbe85b1 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 5 Sep 2023 13:37:01 +0200 Subject: [PATCH 41/78] mimxrt/mimxrt_sdram: Allow boards to override the default SDRAM config. Signed-off-by: iabdalkader --- ports/mimxrt/mimxrt_sdram.c | 115 +++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 49 deletions(-) diff --git a/ports/mimxrt/mimxrt_sdram.c b/ports/mimxrt/mimxrt_sdram.c index c6c1776a554c..ea53daf5ca70 100644 --- a/ports/mimxrt/mimxrt_sdram.c +++ b/ports/mimxrt/mimxrt_sdram.c @@ -42,10 +42,51 @@ extern uint8_t __sdram_start; #define SDRAM_PIN_CONFIG (0xE1UL) #endif -void mimxrt_sdram_init(void) { +#ifndef MICROPY_HW_SDRAM_TIMING_TRC +#if defined(MIMXRT117x_SERIES) +#define MICROPY_HW_SDRAM_TIMING_TRC (60) +#define MICROPY_HW_SDRAM_TIMING_TRP (15) +#define MICROPY_HW_SDRAM_TIMING_TRCD (15) +#define MICROPY_HW_SDRAM_TIMING_TWR (2) +#define MICROPY_HW_SDRAM_TIMING_TRRD (2) +#define MICROPY_HW_SDRAM_TIMING_TXSR (70) +#define MICROPY_HW_SDRAM_TIMING_TRAS (42) +#define MICROPY_HW_SDRAM_TIMING_TREF (64 * 1000000 / 8192) // 64ms/8192 + +#define MICROPY_HW_SDRAM_CAS_LATENCY (kSEMC_LatencyThree) +#define MICROPY_HW_SDRAM_MEM_BUS_WIDTH (kSEMC_PortSize32Bit) +#define MICROPY_HW_SDRAM_COLUMN_BITS_NUM (kSEMC_SdramColunm_9bit) +#define MICROPY_HW_SDRAM_BURST_LENGTH (kSEMC_Sdram_BurstLen8) +#define MICROPY_HW_SDRAM_RBURST_LENGTH (1) +#define MICROPY_HW_SDRAM_DELAY_CHAIN (2) +#else +#define MICROPY_HW_SDRAM_TIMING_TRC (60) +#define MICROPY_HW_SDRAM_TIMING_TRP (18) +#define MICROPY_HW_SDRAM_TIMING_TRCD (18) +#define MICROPY_HW_SDRAM_TIMING_TWR (12) +#define MICROPY_HW_SDRAM_TIMING_TRRD (60) +#define MICROPY_HW_SDRAM_TIMING_TXSR (67) +#define MICROPY_HW_SDRAM_TIMING_TRAS (42) +#define MICROPY_HW_SDRAM_TIMING_TREF (64 * 1000000 / 8192) // 64ms/8192 + +#define MICROPY_HW_SDRAM_CAS_LATENCY (kSEMC_LatencyThree) +#define MICROPY_HW_SDRAM_MEM_BUS_WIDTH (kSEMC_PortSize16Bit) +#define MICROPY_HW_SDRAM_COLUMN_BITS_NUM (kSEMC_SdramColunm_9bit) +#define MICROPY_HW_SDRAM_BURST_LENGTH (kSEMC_Sdram_BurstLen1) +#define MICROPY_HW_SDRAM_RBURST_LENGTH (1) +#endif +#endif - #if !defined(MIMXRT117x_SERIES) +void mimxrt_sdram_init(void) { // Set Clocks + #if defined(MIMXRT117x_SERIES) + CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd1, 29); + + clock_root_config_t rootCfg = { 0 }; + rootCfg.mux = kCLOCK_SEMC_ClockRoot_MuxSysPll2Pfd1; + rootCfg.div = 2; + CLOCK_SetRootClock(kCLOCK_Root_Semc, &rootCfg); + #else CLOCK_InitSysPfd(kCLOCK_Pfd2, 29); // '29' PLL2 PFD2 frequency = 528MHz * 18 / 29 = 327.72MHz (with 528MHz = PLL2 frequency) CLOCK_SetMux(kCLOCK_SemcAltMux, 0); // '0' PLL2 PFD2 will be selected as alternative clock for SEMC root clock CLOCK_SetMux(kCLOCK_SemcMux, 1); // '1' SEMC alternative clock will be used as SEMC clock root @@ -137,7 +178,7 @@ void mimxrt_sdram_init(void) { IOMUXC_SetPinMux(MIMXRT_IOMUXC_SEMC_DQS, 1UL); IOMUXC_SetPinConfig(MIMXRT_IOMUXC_SEMC_DQS, SDRAM_PIN_CONFIG); - #if defined(MIMXRT117x_SERIES) + #if defined(MIMXRT_IOMUXC_SEMC_DATA16) // Data Pins 16..31 IOMUXC_SetPinMux(MIMXRT_IOMUXC_SEMC_DATA16, 0UL); IOMUXC_SetPinConfig(MIMXRT_IOMUXC_SEMC_DATA16, SDRAM_PIN_CONFIG); @@ -209,62 +250,38 @@ void mimxrt_sdram_init(void) { SEMC_Init(SEMC, &semc_cfg); #if defined(MIMXRT117x_SERIES) - uint32_t clock_freq = CLOCK_GetRootClockFreq(kCLOCK_Root_Semc); - - semc_sdram_config_t sdram_cfg = { - .csxPinMux = kSEMC_MUXCSX0, - .address = 0x80000000, - .memsize_kbytes = (MICROPY_HW_SDRAM_SIZE >> 10), - .portSize = kSEMC_PortSize32Bit, // two 16-bit SDRAMs make up 32-bit portsize - .burstLen = kSEMC_Sdram_BurstLen8, - .columnAddrBitNum = kSEMC_SdramColunm_9bit, - .casLatency = kSEMC_LatencyThree, - .tPrecharge2Act_Ns = 15, // tRP 15ns - .tAct2ReadWrite_Ns = 15, // tRCD 15ns - .tRefreshRecovery_Ns = 70, // Use the maximum of the (Trfc , Txsr). - .tWriteRecovery_Ns = 2, // tWR 2ns - .tCkeOff_Ns = 42, // The minimum cycle of SDRAM CLK off state. CKE is off in self refresh at a minimum period tRAS. - .tAct2Prechage_Ns = 40, // tRAS 40ns - .tSelfRefRecovery_Ns = 70, - .tRefresh2Refresh_Ns = 60, - .tAct2Act_Ns = 2, // tRC/tRDD 2ns - .tPrescalePeriod_Ns = 160 * (1000000000 / clock_freq), - .refreshPeriod_nsPerRow = 64 * 1000000 / 8192, // 64ms/8192 - .refreshUrgThreshold = sdram_cfg.refreshPeriod_nsPerRow, - .refreshBurstLen = 1, - .delayChain = 2, - }; - #else - uint32_t clock_freq = CLOCK_GetFreq(kCLOCK_SemcClk); + #endif + semc_sdram_config_t sdram_cfg = { .csxPinMux = kSEMC_MUXCSX0, .address = ((uint32_t)&__sdram_start), .memsize_kbytes = (MICROPY_HW_SDRAM_SIZE >> 10), // Right shift by 10 == division by 1024 - .portSize = kSEMC_PortSize16Bit, - .burstLen = kSEMC_Sdram_BurstLen1, - .columnAddrBitNum = kSEMC_SdramColunm_9bit, - .casLatency = kSEMC_LatencyThree, - .tPrecharge2Act_Ns = 18, // Trp 18ns - .tAct2ReadWrite_Ns = 18, // Trcd 18ns - .tRefreshRecovery_Ns = (60 + 67), - .tWriteRecovery_Ns = 12, // 12ns - .tCkeOff_Ns = 42, // The minimum cycle of SDRAM CLK off state. CKE is off in self refresh at a minimum period tRAS. - .tAct2Prechage_Ns = 42, // Tras 42ns - .tSelfRefRecovery_Ns = 67, - .tRefresh2Refresh_Ns = 60, - .tAct2Act_Ns = 60, - .tPrescalePeriod_Ns = 160 * (1000000000 / clock_freq), + .portSize = MICROPY_HW_SDRAM_MEM_BUS_WIDTH, + .burstLen = MICROPY_HW_SDRAM_BURST_LENGTH, + .columnAddrBitNum = MICROPY_HW_SDRAM_COLUMN_BITS_NUM, + .casLatency = MICROPY_HW_SDRAM_CAS_LATENCY, + .tPrecharge2Act_Ns = MICROPY_HW_SDRAM_TIMING_TRP, + .tAct2ReadWrite_Ns = MICROPY_HW_SDRAM_TIMING_TRCD, + .tRefreshRecovery_Ns = MICROPY_HW_SDRAM_TIMING_TXSR, + .tSelfRefRecovery_Ns = MICROPY_HW_SDRAM_TIMING_TXSR, + .tWriteRecovery_Ns = MICROPY_HW_SDRAM_TIMING_TWR, + .tCkeOff_Ns = MICROPY_HW_SDRAM_TIMING_TRAS, + .tAct2Prechage_Ns = MICROPY_HW_SDRAM_TIMING_TRAS, + .tRefresh2Refresh_Ns = MICROPY_HW_SDRAM_TIMING_TRC, + .tAct2Act_Ns = MICROPY_HW_SDRAM_TIMING_TRRD, .tIdleTimeout_Ns = 0UL, - .refreshPeriod_nsPerRow = 64 * 1000000 / 8192, // 64ms/8192 - .refreshUrgThreshold = 64 * 1000000 / 8192, // 64ms/8192 - .refreshBurstLen = 1 + .refreshPeriod_nsPerRow = MICROPY_HW_SDRAM_TIMING_TREF, + .refreshUrgThreshold = MICROPY_HW_SDRAM_TIMING_TREF, + .refreshBurstLen = MICROPY_HW_SDRAM_RBURST_LENGTH, + #ifdef MICROPY_HW_SDRAM_DELAY_CHAIN + .delayChain = MICROPY_HW_SDRAM_DELAY_CHAIN, + #endif + .tPrescalePeriod_Ns = 160 * (1000000000 / clock_freq), }; - #endif - (status_t)SEMC_ConfigureSDRAM(SEMC, kSEMC_SDRAM_CS0, &sdram_cfg, clock_freq); } From 9d1a1ed42d96965f3b410a0bb542118f99e69c1b Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 5 Sep 2023 14:14:00 +0200 Subject: [PATCH 42/78] mimxrt/Makefile: Enable the FSL USDHC for supported MCU series. Signed-off-by: iabdalkader --- ports/mimxrt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index d5bb7081b01a..d1ba9663c3ae 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -152,7 +152,7 @@ ifeq ($(MICROPY_HW_SDRAM_AVAIL),1) SRC_HAL_IMX_C += $(MCU_DIR)/drivers/fsl_semc.c endif -ifeq ($(MICROPY_PY_MACHINE_SDCARD),1) +ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES), MIMXRT1021 MIMXRT1052 MIMXRT1062 MIMXRT1064 MIMXRT1176)) SRC_HAL_IMX_C += $(MCU_DIR)/drivers/fsl_usdhc.c endif From 552b0bbe12a1e8a015d287e31f9cc615afa0a3b2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 5 Sep 2023 15:19:46 +0200 Subject: [PATCH 43/78] mimxrt: Remove SDCARD Makefile config option. This is option is no longer needed as a Makefile option as the USDHC driver is enabled for all supported series. Signed-off-by: iabdalkader --- ports/mimxrt/Makefile | 2 -- ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h | 1 + ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h | 1 + ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h | 1 + ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk | 1 - ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h | 1 + ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk | 1 - ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk | 1 - ports/mimxrt/boards/TEENSY40/mpconfigboard.mk | 1 - ports/mimxrt/boards/TEENSY41/mpconfigboard.mk | 1 - ports/mimxrt/machine_sdcard.c | 5 +++-- ports/mimxrt/mpconfigport.h | 3 +++ ports/mimxrt/sdcard.c | 2 ++ 20 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index d1ba9663c3ae..577cc9c1eea0 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -331,7 +331,6 @@ endif # Set default values for optional variables MICROPY_HW_SDRAM_AVAIL ?= 0 MICROPY_HW_SDRAM_SIZE ?= 0 -MICROPY_PY_MACHINE_SDCARD ?= 0 # Configure default compiler flags CFLAGS += \ @@ -351,7 +350,6 @@ CFLAGS += \ -DMICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE) \ -DMICROPY_HW_SDRAM_AVAIL=$(MICROPY_HW_SDRAM_AVAIL) \ -DMICROPY_HW_SDRAM_SIZE=$(MICROPY_HW_SDRAM_SIZE) \ - -DMICROPY_PY_MACHINE_SDCARD=$(MICROPY_PY_MACHINE_SDCARD) \ -DSPI_RETRY_TIMES=1000000 \ -DUART_RETRY_TIMES=1000000 \ -DXIP_BOOT_HEADER_ENABLE=1 \ diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h index 7d759df5e6f4..241567ab73f3 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -7,6 +7,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_NUM_PIN_IRQS (2 * 32) +#define MICROPY_HW_ENABLE_SDCARD (0) // Define mapping logical UART # to hardware UART # // LPUART1 on USB_DBG -> 0 diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk index 236db27c87db..a8f7add6d26a 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1011 MCU_VARIANT = MIMXRT1011DAE5A MICROPY_FLOAT_IMPL = single -MICROPY_PY_MACHINE_SDCARD = 0 MICROPY_HW_FLASH_TYPE ?= qspi_nor_flash MICROPY_HW_FLASH_SIZE ?= 0x800000 # 8MB diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h index 26811fdab8be..fc135c5e1b57 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h @@ -7,6 +7,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_NUM_PIN_IRQS (2 * 32) +#define MICROPY_HW_ENABLE_SDCARD (0) // Define mapping logical UART # to hardware UART # // LPUART1 on USB_DBG -> 0 diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk index 19db53c3f871..dd525859063d 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1011 MCU_VARIANT = MIMXRT1011DAE5A MICROPY_FLOAT_IMPL = single -MICROPY_PY_MACHINE_SDCARD = 0 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x1000000 # 16MB diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h index 655bb62c2783..f47bbf4fa138 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.h @@ -10,6 +10,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin)) #define MICROPY_HW_NUM_PIN_IRQS (3 * 32) +#define MICROPY_PY_MACHINE_SDCARD (0) // Define mapping logical UART # to hardware UART # // RX/TX HW-UART Logical UART diff --git a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk index ba7d61f6d4f0..34e5cdee5113 100644 --- a/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1015 MCU_VARIANT = MIMXRT1015DAF5A MICROPY_FLOAT_IMPL = single -MICROPY_PY_MACHINE_SDCARD = 0 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x1000000 # 16MB diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk index 547b88d57de4..c98843a1a3c3 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1021 MCU_VARIANT = MIMXRT1021DAG5A MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x800000 # 8MB diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk index 0cf2a348046e..ef7bbc8f56cb 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1052 MCU_VARIANT = MIMXRT1052DVL6B MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = qspi_hyper_flash MICROPY_HW_FLASH_SIZE = 0x4000000 # 64MB diff --git a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk index c2556a27248a..3af7cd231a2a 100644 --- a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1062 MCU_VARIANT = MIMXRT1062DVJ6A MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x800000 # 8MB diff --git a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk index d3ba752419e0..95cfb4585acc 100644 --- a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1064 MCU_VARIANT = MIMXRT1064DVL6A MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = internal MICROPY_HW_FLASH_SIZE = 0x400000 # 4MB diff --git a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk index 25747a52c6be..1488730f7c7c 100644 --- a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk @@ -3,7 +3,6 @@ MCU_VARIANT = MIMXRT1176DVMAA MCU_CORE = _cm7 MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE ?= qspi_nor_flash MICROPY_HW_FLASH_SIZE ?= 0x1000000 # 16MB MICROPY_HW_FLASH_RESERVED ?= 0x100000 # 1MB CM4 Code address space diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h index 9443bb373271..324cee9b14e9 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h +++ b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.h @@ -11,6 +11,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_NUM_PIN_IRQS (2 * 32) +#define MICROPY_PY_MACHINE_SDCARD (0) // Define mapping logical UART # to hardware UART # // LPUART1 on RX/TX -> 1 diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk index 135c43257c95..58429d298118 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk +++ b/ports/mimxrt/boards/OLIMEX_RT1010/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1011 MCU_VARIANT = MIMXRT1011DAE5A MICROPY_FLOAT_IMPL = single -MICROPY_PY_MACHINE_SDCARD ?= 0 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x200000 # 2MB MICROPY_HW_FLASH_RESERVED ?= 0x1000 # 4KB diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk index ca27dff55f3a..2cf7d33c6331 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1052 MCU_VARIANT = MIMXRT1052DVL6B MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x800000 # 8MB diff --git a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk index 4482c629f7dc..07f174944b79 100644 --- a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1062 MCU_VARIANT = MIMXRT1062DVJ6A MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x200000 # 2MB MICROPY_HW_FLASH_RESERVED ?= 0x1000 # 4KB diff --git a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk index cf07144668e1..b297448a307e 100755 --- a/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY41/mpconfigboard.mk @@ -2,7 +2,6 @@ MCU_SERIES = MIMXRT1062 MCU_VARIANT = MIMXRT1062DVJ6A MICROPY_FLOAT_IMPL = double -MICROPY_PY_MACHINE_SDCARD = 1 MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x800000 # 8MB MICROPY_HW_FLASH_RESERVED ?= 0x1000 # 4KB diff --git a/ports/mimxrt/machine_sdcard.c b/ports/mimxrt/machine_sdcard.c index 496eb9353388..b0bf8613c24a 100644 --- a/ports/mimxrt/machine_sdcard.c +++ b/ports/mimxrt/machine_sdcard.c @@ -24,11 +24,12 @@ * THE SOFTWARE. */ -#if MICROPY_PY_MACHINE_SDCARD - #include "py/runtime.h" #include "py/mperrno.h" #include "extmod/vfs.h" + +#if MICROPY_PY_MACHINE_SDCARD + #include "ticks.h" #if defined(MIMXRT1170x_SERIES) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index d1fe17ee10b5..feb6cb266078 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -87,6 +87,9 @@ uint32_t trng_random_u32(void); #ifndef MICROPY_PY_MACHINE_I2S #define MICROPY_PY_MACHINE_I2S (0) #endif +#ifndef MICROPY_PY_MACHINE_SDCARD +#define MICROPY_PY_MACHINE_SDCARD (1) +#endif #define MICROPY_PY_MACHINE_SOFTI2C (1) #define MICROPY_PY_MACHINE_SPI (1) #define MICROPY_PY_MACHINE_SOFTSPI (1) diff --git a/ports/mimxrt/sdcard.c b/ports/mimxrt/sdcard.c index 6dbd45303b63..ae52ed5d2cd0 100644 --- a/ports/mimxrt/sdcard.c +++ b/ports/mimxrt/sdcard.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#include "py/mphal.h" + #if MICROPY_PY_MACHINE_SDCARD #include "sdcard.h" From 361ca7d5ee8d661b72af749a02d988d580b89bc2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 6 Sep 2023 12:33:55 +0200 Subject: [PATCH 44/78] mimxrt/mpbthciport: Enable flow control for BT HCI UART. Signed-off-by: iabdalkader --- ports/mimxrt/mpbthciport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt/mpbthciport.c b/ports/mimxrt/mpbthciport.c index d8b384136452..2540abca42f5 100644 --- a/ports/mimxrt/mpbthciport.c +++ b/ports/mimxrt/mpbthciport.c @@ -85,13 +85,14 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) { mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(port), MP_OBJ_NEW_QSTR(MP_QSTR_baudrate), MP_OBJ_NEW_SMALL_INT(baudrate), + MP_OBJ_NEW_QSTR(MP_QSTR_flow), MP_OBJ_NEW_SMALL_INT(3), MP_OBJ_NEW_QSTR(MP_QSTR_timeout), MP_OBJ_NEW_SMALL_INT(200), MP_OBJ_NEW_QSTR(MP_QSTR_timeout_char), MP_OBJ_NEW_SMALL_INT(200), MP_OBJ_NEW_QSTR(MP_QSTR_txbuf), MP_OBJ_NEW_SMALL_INT(768), MP_OBJ_NEW_QSTR(MP_QSTR_rxbuf), MP_OBJ_NEW_SMALL_INT(768), }; - mp_bthci_uart = MP_OBJ_TYPE_GET_SLOT(&machine_uart_type, make_new)((mp_obj_t)&machine_uart_type, 1, 5, args); + mp_bthci_uart = MP_OBJ_TYPE_GET_SLOT(&machine_uart_type, make_new)((mp_obj_t)&machine_uart_type, 1, 6, args); MP_STATE_PORT(mp_bthci_uart) = mp_bthci_uart; // Start the HCI polling to process any initial events/packets. From 52e3da0a0bdb88a0eb869e8df03b66ab7f7a74ea Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 6 Sep 2023 14:53:17 +0200 Subject: [PATCH 45/78] mimxrt/mbedtls: Enable certificate validity time validation. Signed-off-by: iabdalkader --- ports/mimxrt/mbedtls/mbedtls_config.h | 9 +++++++ ports/mimxrt/mbedtls/mbedtls_port.c | 36 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ports/mimxrt/mbedtls/mbedtls_config.h b/ports/mimxrt/mbedtls/mbedtls_config.h index 4140bb514555..440498757085 100644 --- a/ports/mimxrt/mbedtls/mbedtls_config.h +++ b/ports/mimxrt/mbedtls/mbedtls_config.h @@ -26,6 +26,15 @@ #ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_H #define MICROPY_INCLUDED_MBEDTLS_CONFIG_H +// Enable mbedtls modules. +#define MBEDTLS_HAVE_TIME +#define MBEDTLS_HAVE_TIME_DATE + +// Time hook. +#include +extern time_t mimxrt_rtctime_seconds(time_t *timer); +#define MBEDTLS_PLATFORM_TIME_MACRO mimxrt_rtctime_seconds + // Set MicroPython-specific options. #define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1) diff --git a/ports/mimxrt/mbedtls/mbedtls_port.c b/ports/mimxrt/mbedtls/mbedtls_port.c index a9db174726ad..044de317f526 100644 --- a/ports/mimxrt/mbedtls/mbedtls_port.c +++ b/ports/mimxrt/mbedtls/mbedtls_port.c @@ -24,9 +24,16 @@ * THE SOFTWARE. */ +#include "py/runtime.h" + #ifdef MICROPY_SSL_MBEDTLS #include "mbedtls_config.h" +#if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE) +#include "fsl_snvs_lp.h" +#include "shared/timeutils/timeutils.h" +#endif + void trng_random_data(unsigned char *output, size_t len); int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) { @@ -38,4 +45,33 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t return 0; } +#if defined(MBEDTLS_HAVE_TIME) +time_t mimxrt_rtctime_seconds(time_t *timer) { + // Get date and date in CPython order. + snvs_lp_srtc_datetime_t date; + SNVS_LP_SRTC_GetDatetime(SNVS, &date); + return timeutils_seconds_since_epoch(date.year, date.month, date.day, date.hour, date.minute, date.second); +} +#endif + +#if defined(MBEDTLS_HAVE_TIME_DATE) +struct tm *gmtime(const time_t *timep) { + static struct tm tm; + timeutils_struct_time_t tm_buf = {0}; + timeutils_seconds_since_epoch_to_struct_time(*timep, &tm_buf); + + tm.tm_sec = tm_buf.tm_sec; + tm.tm_min = tm_buf.tm_min; + tm.tm_hour = tm_buf.tm_hour; + tm.tm_mday = tm_buf.tm_mday; + tm.tm_mon = tm_buf.tm_mon - 1; + tm.tm_year = tm_buf.tm_year - 1900; + tm.tm_wday = tm_buf.tm_wday; + tm.tm_yday = tm_buf.tm_yday; + tm.tm_isdst = -1; + + return &tm; +} +#endif + #endif From 0701341e7f68b9f0e83c7d61035f5f5f05b8c15b Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 5 Sep 2023 16:29:51 +0200 Subject: [PATCH 46/78] mimxrt/machine_uart: Set the UART clock to a fixed 40MHz value. There is a single UART clock for all devices, so switching it for one will affect all devices used at that time. This commit fixes that issue by keeping the clock at a fixed value. This fixed clock still supports the common baud rates between 300 and 921600 baud. Signed-off-by: robert-hh --- ports/mimxrt/boards/MIMXRT1011_clock_config.c | 2 +- ports/mimxrt/boards/MIMXRT1011_clock_config.h | 2 +- ports/mimxrt/boards/MIMXRT1015_clock_config.c | 2 +- ports/mimxrt/boards/MIMXRT1015_clock_config.h | 2 +- ports/mimxrt/boards/MIMXRT1021_clock_config.c | 2 +- ports/mimxrt/boards/MIMXRT1021_clock_config.h | 2 +- ports/mimxrt/boards/MIMXRT1052_clock_config.c | 2 +- ports/mimxrt/boards/MIMXRT1052_clock_config.h | 2 +- ports/mimxrt/boards/MIMXRT1062_clock_config.c | 2 +- ports/mimxrt/boards/MIMXRT1062_clock_config.h | 2 +- ports/mimxrt/boards/MIMXRT1064_clock_config.c | 2 +- ports/mimxrt/boards/MIMXRT1064_clock_config.h | 2 +- ports/mimxrt/machine_uart.c | 13 ------------- 13 files changed, 12 insertions(+), 25 deletions(-) diff --git a/ports/mimxrt/boards/MIMXRT1011_clock_config.c b/ports/mimxrt/boards/MIMXRT1011_clock_config.c index cc889d314a92..33e1ecfec87a 100644 --- a/ports/mimxrt/boards/MIMXRT1011_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1011_clock_config.c @@ -241,7 +241,7 @@ void BOARD_BootClockRUN(void) { CLOCK_DisableClock(kCLOCK_Lpuart3); CLOCK_DisableClock(kCLOCK_Lpuart4); /* Set UART_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_UartDiv, 0); + CLOCK_SetDiv(kCLOCK_UartDiv, 1); /* Set Uart clock source. */ CLOCK_SetMux(kCLOCK_UartMux, 0); /* Disable SPDIF clock gate. */ diff --git a/ports/mimxrt/boards/MIMXRT1011_clock_config.h b/ports/mimxrt/boards/MIMXRT1011_clock_config.h index 76f3df422f9d..145f3b50cb52 100644 --- a/ports/mimxrt/boards/MIMXRT1011_clock_config.h +++ b/ports/mimxrt/boards/MIMXRT1011_clock_config.h @@ -71,7 +71,7 @@ void BOARD_InitBootClocks(void); #define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL #define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL #define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL -#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 40000000UL #define BOARD_BOOTCLOCKRUN_USBPHY_CLK 0UL /*! @brief Usb1 PLL set for BOARD_BootClockRUN configuration. diff --git a/ports/mimxrt/boards/MIMXRT1015_clock_config.c b/ports/mimxrt/boards/MIMXRT1015_clock_config.c index 7cc91f95111d..331af4b9e81e 100644 --- a/ports/mimxrt/boards/MIMXRT1015_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1015_clock_config.c @@ -257,7 +257,7 @@ void BOARD_BootClockRUN(void) { CLOCK_DisableClock(kCLOCK_Lpuart3); CLOCK_DisableClock(kCLOCK_Lpuart4); /* Set UART_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_UartDiv, 0); + CLOCK_SetDiv(kCLOCK_UartDiv, 1); /* Set Uart clock source. */ CLOCK_SetMux(kCLOCK_UartMux, 0); /* Disable SPDIF clock gate. */ diff --git a/ports/mimxrt/boards/MIMXRT1015_clock_config.h b/ports/mimxrt/boards/MIMXRT1015_clock_config.h index 65944077e5ca..975ad52e0766 100644 --- a/ports/mimxrt/boards/MIMXRT1015_clock_config.h +++ b/ports/mimxrt/boards/MIMXRT1015_clock_config.h @@ -74,7 +74,7 @@ void BOARD_InitBootClocks(void); #define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL #define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL #define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL -#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 40000000UL #define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL /*! @brief Usb1 PLL set for BOARD_BootClockRUN configuration. diff --git a/ports/mimxrt/boards/MIMXRT1021_clock_config.c b/ports/mimxrt/boards/MIMXRT1021_clock_config.c index 1b8792dd2de0..f17e73beaebc 100644 --- a/ports/mimxrt/boards/MIMXRT1021_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1021_clock_config.c @@ -306,7 +306,7 @@ void BOARD_BootClockRUN(void) { CLOCK_DisableClock(kCLOCK_Lpuart7); CLOCK_DisableClock(kCLOCK_Lpuart8); /* Set UART_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_UartDiv, 0); + CLOCK_SetDiv(kCLOCK_UartDiv, 1); /* Set Uart clock source. */ CLOCK_SetMux(kCLOCK_UartMux, 0); /* Disable SPDIF clock gate. */ diff --git a/ports/mimxrt/boards/MIMXRT1021_clock_config.h b/ports/mimxrt/boards/MIMXRT1021_clock_config.h index 21d4e630ae30..6f7896bdc3fb 100644 --- a/ports/mimxrt/boards/MIMXRT1021_clock_config.h +++ b/ports/mimxrt/boards/MIMXRT1021_clock_config.h @@ -79,7 +79,7 @@ void BOARD_InitBootClocks(void); #define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL #define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL #define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL -#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 40000000UL #define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL #define BOARD_BOOTCLOCKRUN_USDHC1_CLK_ROOT 176000000UL #define BOARD_BOOTCLOCKRUN_USDHC2_CLK_ROOT 176000000UL diff --git a/ports/mimxrt/boards/MIMXRT1052_clock_config.c b/ports/mimxrt/boards/MIMXRT1052_clock_config.c index fa7450d487a6..bff43ae5e54b 100644 --- a/ports/mimxrt/boards/MIMXRT1052_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1052_clock_config.c @@ -311,7 +311,7 @@ void BOARD_BootClockRUN(void) { CLOCK_DisableClock(kCLOCK_Lpuart7); CLOCK_DisableClock(kCLOCK_Lpuart8); /* Set UART_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_UartDiv, 0); + CLOCK_SetDiv(kCLOCK_UartDiv, 1); /* Set Uart clock source. */ CLOCK_SetMux(kCLOCK_UartMux, 0); /* Disable LCDIF clock gate. */ diff --git a/ports/mimxrt/boards/MIMXRT1052_clock_config.h b/ports/mimxrt/boards/MIMXRT1052_clock_config.h index f213ac7e238d..358a6f03b366 100644 --- a/ports/mimxrt/boards/MIMXRT1052_clock_config.h +++ b/ports/mimxrt/boards/MIMXRT1052_clock_config.h @@ -83,7 +83,7 @@ void BOARD_InitBootClocks(void); #define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL #define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL #define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL -#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 40000000UL #define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL #define BOARD_BOOTCLOCKRUN_USBPHY2_CLK 0UL #define BOARD_BOOTCLOCKRUN_USDHC1_CLK_ROOT 198000000UL diff --git a/ports/mimxrt/boards/MIMXRT1062_clock_config.c b/ports/mimxrt/boards/MIMXRT1062_clock_config.c index 589ffb0b5831..f60797900d28 100644 --- a/ports/mimxrt/boards/MIMXRT1062_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1062_clock_config.c @@ -324,7 +324,7 @@ void BOARD_BootClockRUN(void) { CLOCK_DisableClock(kCLOCK_Lpuart7); CLOCK_DisableClock(kCLOCK_Lpuart8); /* Set UART_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_UartDiv, 0); + CLOCK_SetDiv(kCLOCK_UartDiv, 1); /* Set Uart clock source. */ CLOCK_SetMux(kCLOCK_UartMux, 0); /* Disable LCDIF clock gate. */ diff --git a/ports/mimxrt/boards/MIMXRT1062_clock_config.h b/ports/mimxrt/boards/MIMXRT1062_clock_config.h index 082202484771..0a6552664620 100644 --- a/ports/mimxrt/boards/MIMXRT1062_clock_config.h +++ b/ports/mimxrt/boards/MIMXRT1062_clock_config.h @@ -86,7 +86,7 @@ void BOARD_InitBootClocks(void); #define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL #define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL #define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL -#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 40000000UL #define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL #define BOARD_BOOTCLOCKRUN_USBPHY2_CLK 0UL #define BOARD_BOOTCLOCKRUN_USDHC1_CLK_ROOT 198000000UL diff --git a/ports/mimxrt/boards/MIMXRT1064_clock_config.c b/ports/mimxrt/boards/MIMXRT1064_clock_config.c index 56dd75d7fbf6..573b6a5c9a00 100644 --- a/ports/mimxrt/boards/MIMXRT1064_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1064_clock_config.c @@ -324,7 +324,7 @@ void BOARD_BootClockRUN(void) { CLOCK_DisableClock(kCLOCK_Lpuart7); CLOCK_DisableClock(kCLOCK_Lpuart8); /* Set UART_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_UartDiv, 0); + CLOCK_SetDiv(kCLOCK_UartDiv, 1); /* Set Uart clock source. */ CLOCK_SetMux(kCLOCK_UartMux, 0); /* Disable LCDIF clock gate. */ diff --git a/ports/mimxrt/boards/MIMXRT1064_clock_config.h b/ports/mimxrt/boards/MIMXRT1064_clock_config.h index 13bc925a105c..80ca030eb638 100644 --- a/ports/mimxrt/boards/MIMXRT1064_clock_config.h +++ b/ports/mimxrt/boards/MIMXRT1064_clock_config.h @@ -86,7 +86,7 @@ void BOARD_InitBootClocks(void); #define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL #define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL #define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL -#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 40000000UL #define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL #define BOARD_BOOTCLOCKRUN_USBPHY2_CLK 0UL #define BOARD_BOOTCLOCKRUN_USDHC1_CLK_ROOT 198000000UL diff --git a/ports/mimxrt/machine_uart.c b/ports/mimxrt/machine_uart.c index fba2b7fe3076..8e1505349ae2 100644 --- a/ports/mimxrt/machine_uart.c +++ b/ports/mimxrt/machine_uart.c @@ -153,24 +153,12 @@ static void machine_uart_ensure_active(machine_uart_obj_t *uart) { } } -#if !defined(MIMXRT117x_SERIES) -static inline void uart_set_clock_divider(uint32_t baudrate) { - // For baud rates < 460800 divide the clock by 10, supporting baud rates down to 50 baud. - if (baudrate >= 460800) { - CLOCK_SetDiv(kCLOCK_UartDiv, 0); - } else { - CLOCK_SetDiv(kCLOCK_UartDiv, 9); - } -} -#endif - void machine_uart_set_baudrate(mp_obj_t uart_in, uint32_t baudrate) { machine_uart_obj_t *uart = MP_OBJ_TO_PTR(uart_in); #if defined(MIMXRT117x_SERIES) // Use the Lpuart1 clock value, which is set for All UART devices. LPUART_SetBaudRate(uart->lpuart, baudrate, CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart1)); #else - uart_set_clock_divider(baudrate); LPUART_SetBaudRate(uart->lpuart, baudrate, CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot)); #endif } @@ -315,7 +303,6 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args // Use the Lpuart1 clock value, which is set for All UART devices. LPUART_Init(self->lpuart, &self->config, CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart1)); #else - uart_set_clock_divider(self->config.baudRate_Bps); LPUART_Init(self->lpuart, &self->config, CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot)); #endif LPUART_TransferCreateHandle(self->lpuart, &self->handle, LPUART_UserCallback, self); From abb44694d85bc8e139b9969f6d033d9fd946e641 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 6 Sep 2023 14:35:44 +0200 Subject: [PATCH 47/78] mimxrt/boards/MIMXRT1176_clock_config: Fix comments about UART clocks. No functional change, and pretty obvious. Signed-off-by: robert-hh --- ports/mimxrt/boards/MIMXRT1176_clock_config.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ports/mimxrt/boards/MIMXRT1176_clock_config.c b/ports/mimxrt/boards/MIMXRT1176_clock_config.c index ae02e30fa83b..b6845b989098 100644 --- a/ports/mimxrt/boards/MIMXRT1176_clock_config.c +++ b/ports/mimxrt/boards/MIMXRT1176_clock_config.c @@ -382,62 +382,62 @@ void BOARD_BootClockRUN(void) { rootCfg.div = 1; CLOCK_SetRootClock(kCLOCK_Root_Can3, &rootCfg); - /* Configure LPUART1 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART1 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART1_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart1, &rootCfg); - /* Configure LPUART2 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART2 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART2_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart2, &rootCfg); - /* Configure LPUART3 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART3 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART3_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart3, &rootCfg); - /* Configure LPUART4 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART4 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART4_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart4, &rootCfg); - /* Configure LPUART5 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART5 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART5_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart5, &rootCfg); - /* Configure LPUART6 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART6 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART6_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart6, &rootCfg); - /* Configure LPUART7 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART7 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART7_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart7, &rootCfg); - /* Configure LPUART8 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART8 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART8_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart8, &rootCfg); - /* Configure LPUART9 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART9 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART9_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart9, &rootCfg); - /* Configure LPUART10 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART10 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART10_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart10, &rootCfg); - /* Configure LPUART11 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART11 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART11_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart11, &rootCfg); - /* Configure LPUART12 using SYS_PLL3_PFD3_CLK */ + /* Configure LPUART12 using SYS_PLL2_PFD3_CLK */ rootCfg.mux = kCLOCK_LPUART12_ClockRoot_MuxSysPll2Pfd3; rootCfg.div = 4; CLOCK_SetRootClock(kCLOCK_Root_Lpuart12, &rootCfg); From 51ca23e4634788ddf8971de4d4b462bbeb4c7684 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 30 Sep 2023 08:17:33 +0200 Subject: [PATCH 48/78] mimxrt/boards: Fix naming of SD-card config option. Commit 552b0bbe12a1e8a015d287e31f9cc615afa0a3b2 did not define MICROPY_PY_MACHINE_SDCARD properly, and thus building the firmware failed. Signed-off-by: robert-hh --- ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h | 2 +- ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h index 241567ab73f3..784373c93947 100644 --- a/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h +++ b/ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.h @@ -7,7 +7,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_NUM_PIN_IRQS (2 * 32) -#define MICROPY_HW_ENABLE_SDCARD (0) +#define MICROPY_PY_MACHINE_SDCARD (0) // Define mapping logical UART # to hardware UART # // LPUART1 on USB_DBG -> 0 diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h index fc135c5e1b57..a616fbec64a5 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.h @@ -7,7 +7,7 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_NUM_PIN_IRQS (2 * 32) -#define MICROPY_HW_ENABLE_SDCARD (0) +#define MICROPY_PY_MACHINE_SDCARD (0) // Define mapping logical UART # to hardware UART # // LPUART1 on USB_DBG -> 0 From 6482eb142c6d9b88b3897356d00399226056c603 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 30 Sep 2023 08:27:22 +0200 Subject: [PATCH 49/78] mimxrt/mpbthciport: Allow disabling UART flow control for BLE. Not all boards or BLE extensions have the flow control signals for BLE available at suitable pins. Actually none of the Adafruit extensions match for flow control. For consistency with the previous behaviour it is enabled by default. Signed-off-by: robert-hh --- ports/mimxrt/mpbthciport.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt/mpbthciport.c b/ports/mimxrt/mpbthciport.c index 2540abca42f5..4325655e5740 100644 --- a/ports/mimxrt/mpbthciport.c +++ b/ports/mimxrt/mpbthciport.c @@ -36,6 +36,10 @@ #if MICROPY_PY_BLUETOOTH +#ifndef MICROPY_HW_BLE_UART_FLOW_CONTROL +#define MICROPY_HW_BLE_UART_FLOW_CONTROL (3) +#endif + #define DEBUG_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__) #define ERROR_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__) @@ -85,7 +89,7 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) { mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(port), MP_OBJ_NEW_QSTR(MP_QSTR_baudrate), MP_OBJ_NEW_SMALL_INT(baudrate), - MP_OBJ_NEW_QSTR(MP_QSTR_flow), MP_OBJ_NEW_SMALL_INT(3), + MP_OBJ_NEW_QSTR(MP_QSTR_flow), MP_OBJ_NEW_SMALL_INT(MICROPY_HW_BLE_UART_FLOW_CONTROL), MP_OBJ_NEW_QSTR(MP_QSTR_timeout), MP_OBJ_NEW_SMALL_INT(200), MP_OBJ_NEW_QSTR(MP_QSTR_timeout_char), MP_OBJ_NEW_SMALL_INT(200), MP_OBJ_NEW_QSTR(MP_QSTR_txbuf), MP_OBJ_NEW_SMALL_INT(768), From 4e5611c55a4a82805ae972f8f9bc10ac2110ea19 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Mon, 18 Sep 2023 22:10:10 +0200 Subject: [PATCH 50/78] mimxrt/machine_rtc: Improve the RTC init at boot. By clearing the tamper bits and enabling access to the registers for all code, just in case that this was set. It keeps the clock running on battery and the calibration setting. Signed-off-by: robert-hh --- ports/mimxrt/Makefile | 1 + ports/mimxrt/machine_rtc.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 577cc9c1eea0..f44518a8aa13 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -137,6 +137,7 @@ SRC_HAL_IMX_C += \ $(MCU_DIR)/drivers/fsl_pit.c \ $(MCU_DIR)/drivers/fsl_pwm.c \ $(MCU_DIR)/drivers/fsl_sai.c \ + $(MCU_DIR)/drivers/fsl_snvs_hp.c \ $(MCU_DIR)/drivers/fsl_snvs_lp.c \ $(MCU_DIR)/drivers/fsl_wdog.c \ $(MCU_DIR)/system_$(MCU_SERIES)$(MCU_CORE).c \ diff --git a/ports/mimxrt/machine_rtc.c b/ports/mimxrt/machine_rtc.c index 702c1b903e50..54a19dacb433 100644 --- a/ports/mimxrt/machine_rtc.c +++ b/ports/mimxrt/machine_rtc.c @@ -30,6 +30,7 @@ #include "modmachine.h" #include "ticks.h" #include "fsl_snvs_lp.h" +#include "fsl_snvs_hp.h" typedef struct _machine_rtc_obj_t { mp_obj_base_t base; @@ -41,6 +42,12 @@ STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; // Start the RTC Timer. void machine_rtc_start(void) { + // Enable Non-Privileged Software Access + SNVS->HPCOMR |= SNVS_HPCOMR_NPSWA_EN_MASK; + // Do a basic init. + SNVS_LP_Init(SNVS); + // Disable all external Tamper + SNVS_LP_DisableAllExternalTamper(SNVS); SNVS_LP_SRTC_StartTimer(SNVS); // If the date is not set, set it to a more recent start date, From 1660c787956968c6a2cc19919d16014ddcbdd4ed Mon Sep 17 00:00:00 2001 From: vsfos Date: Sat, 30 Sep 2023 02:41:00 +0800 Subject: [PATCH 51/78] unix/main: Fix memory leakage if MICROPY_USE_READLINE is disabled. --- ports/unix/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/unix/main.c b/ports/unix/main.c index b065706ba65a..47973df8df2e 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -296,10 +296,10 @@ STATIC int do_repl(void) { } int ret = execute_from_lexer(LEX_SRC_STR, line, MP_PARSE_SINGLE_INPUT, true); + free(line); if (ret & FORCED_EXIT) { return ret; } - free(line); } #endif From 2772b88f6a57257bdf27d9eecbccdb98e4820a42 Mon Sep 17 00:00:00 2001 From: Wanlin Wang Date: Sat, 30 Sep 2023 17:48:25 +0800 Subject: [PATCH 52/78] rp2/README: Fix name of RPI_PICO_W board. Signed-off-by: Wanlin Wang --- ports/rp2/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/rp2/README.md b/ports/rp2/README.md index 3f152b8181f9..e22fb3093d72 100644 --- a/ports/rp2/README.md +++ b/ports/rp2/README.md @@ -40,9 +40,9 @@ called `firmware.uf2`. If you are using a different board other than a Rasoberry Pi Pico, then you should pass the board name to the build; e.g. for Raspberry Pi Pico W: - $ make BOARD=PICO_W submodules - $ make BOARD=PICO_W clean - $ make BOARD=PICO_W + $ make BOARD=RPI_PICO_W submodules + $ make BOARD=RPI_PICO_W clean + $ make BOARD=RPI_PICO_W ## Deploying firmware to the device From da193c42f6c767fe0c185e50598a48c95b562327 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 1 Oct 2023 16:33:27 +0200 Subject: [PATCH 53/78] ports: Rename Arduino board LED pins to be consistent. Signed-off-by: iabdalkader --- ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv | 6 +++--- ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv | 6 +++--- ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h | 6 +++--- ports/stm32/boards/ARDUINO_GIGA/pins.csv | 6 +++--- ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h | 6 +++--- ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv | 6 +++--- ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h | 6 +++--- ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv index 195d4d54ca37..1e6379a07b8b 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv @@ -147,6 +147,6 @@ D5,P210 LED1,P107 LED2,P400 LED3,P800 -LED_R,P107 -LED_G,P400 -LED_B,P800 +LED_RED,P107 +LED_GREEN,P400 +LED_BLUE,P800 diff --git a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv index 1e42a4f8def2..47d9b5b04326 100644 --- a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv +++ b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv @@ -19,9 +19,9 @@ A2,GPIO28 A3,GPIO29 SDA,GPIO12 SCL,GPIO13 -LEDR,EXT_GPIO0 -LEDG,EXT_GPIO1 -LEDB,EXT_GPIO2 +LED_RED,EXT_GPIO0 +LED_GREEN,EXT_GPIO1 +LED_BLUE,EXT_GPIO2 D18,EXT_GPIO3 D19,EXT_GPIO4 D20,EXT_GPIO5 diff --git a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h index 29f1e6140190..a9b8cbfc7b52 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.h @@ -184,9 +184,9 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_USRSW_PRESSED (1) // LEDs -#define MICROPY_HW_LED1 (pyb_pin_LEDR) // red -#define MICROPY_HW_LED2 (pyb_pin_LEDG) // green -#define MICROPY_HW_LED3 (pyb_pin_LEDB) // yellow +#define MICROPY_HW_LED1 (pyb_pin_LED_RED) // red +#define MICROPY_HW_LED2 (pyb_pin_LED_GREEN) // green +#define MICROPY_HW_LED3 (pyb_pin_LED_BLUE) // yellow #define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin)) diff --git a/ports/stm32/boards/ARDUINO_GIGA/pins.csv b/ports/stm32/boards/ARDUINO_GIGA/pins.csv index c27b5d8cd4f0..91c5c6d58616 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/pins.csv +++ b/ports/stm32/boards/ARDUINO_GIGA/pins.csv @@ -179,9 +179,9 @@ UART6_RX,PC7 BOOT0,BOOT0 DAC1,PA4 DAC2,PA5 -LEDR,PI12 -LEDG,PJ13 -LEDB,PE3 +LED_RED,PI12 +LED_GREEN,PJ13 +LED_BLUE,PE3 I2C1_SDA,PB9 I2C1_SCL,PB8 I2C2_SDA,PB11 diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h index 276288d287cb..7cb3d85d3ddf 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.h @@ -180,9 +180,9 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_CAN_IS_RESERVED(id) (id != PYB_CAN_1) // LEDs -#define MICROPY_HW_LED1 (pyb_pin_LEDR) // red -#define MICROPY_HW_LED2 (pyb_pin_LEDG) // green -#define MICROPY_HW_LED3 (pyb_pin_LEDB) // yellow +#define MICROPY_HW_LED1 (pyb_pin_LED_RED) // red +#define MICROPY_HW_LED2 (pyb_pin_LED_GREEN) // green +#define MICROPY_HW_LED3 (pyb_pin_LED_BLUE) // yellow #define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin)) diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv b/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv index c092965aafe9..8ff21e645331 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv @@ -180,9 +180,9 @@ BOOT0,BOOT0 OSCEN,PH1 DAC1,-PA4 DAC2,-PA5 -LEDR,PE3 -LEDG,PC13 -LEDB,-PF4 +LED_RED,PE3 +LED_GREEN,PC13 +LED_BLUE,-PF4 I2C1_SCL,PB8 I2C1_SDA,PB9 I2C2_SCL,PF1 diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h index 452ec00d7098..349ca9e0010c 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h @@ -177,9 +177,9 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_USRSW_PRESSED (1) // LEDs -#define MICROPY_HW_LED1 (pyb_pin_LEDR) // red -#define MICROPY_HW_LED2 (pyb_pin_LEDG) // green -#define MICROPY_HW_LED3 (pyb_pin_LEDB) // yellow +#define MICROPY_HW_LED1 (pyb_pin_LED_RED) // red +#define MICROPY_HW_LED2 (pyb_pin_LED_GREEN) // green +#define MICROPY_HW_LED3 (pyb_pin_LED_BLUE) // yellow #define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin)) diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv b/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv index 6ab00f02ec40..ea8710b25f84 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv @@ -203,9 +203,9 @@ BOOT0,BOOT0 OSCEN,PH1 DAC1,PA4 DAC2,-PA5 -LEDR,PK5 -LEDG,PK6 -LEDB,PK7 +LED_RED,PK5 +LED_GREEN,PK6 +LED_BLUE,PK7 I2C1_SDA,PB7 I2C1_SCL,PB6 I2C3_SDA,PH8 From a93ebd0e0368a44f92322d0dbf45bab49165a891 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Fri, 22 Sep 2023 18:00:36 +0000 Subject: [PATCH 54/78] docs: Add requirements.txt file with dependencies for Sphinx. Signed-off-by: Jos Verlinde --- .github/workflows/docs.yml | 2 +- docs/develop/gettingstarted.rst | 2 +- docs/requirements.txt | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index afc3166f3d65..a0105d6ca60e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -17,6 +17,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 - name: Install Python packages - run: pip install Sphinx + run: pip install -r docs/requirements.txt - name: Build docs run: make -C docs/ html diff --git a/docs/develop/gettingstarted.rst b/docs/develop/gettingstarted.rst index 34ca1c9c63e6..a17a320671f5 100644 --- a/docs/develop/gettingstarted.rst +++ b/docs/develop/gettingstarted.rst @@ -245,7 +245,7 @@ that you use a virtual environment: $ python3 -m venv env $ source env/bin/activate - $ pip install sphinx + $ pip install -r docs/requirements.txt Navigate to the ``docs`` directory: diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 000000000000..824e9799c773 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,2 @@ +sphinx~=7.2.6 +sphinxcontrib.jquery==4.1 From 977dc9a369af2d51455c87c1978a5b4598702d35 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Mon, 11 Jul 2022 15:23:20 +1000 Subject: [PATCH 55/78] extmod/asyncio/stream.py: Fix cancellation handling of start_server. The following code: server = await asyncio.start_server(...) async with server: ... code that raises ... would lose the original exception because the server's task would not have had a chance to be scheduled yet, and so awaiting the task in wait_closed would raise the cancellation instead of the original exception. Additionally, ensures that explicitly cancelling the parent task delivers the cancellation correctly (previously was masked by the server loop), now this only happens if the server was closed, not when the task was cancelled. Signed-off-by: Jim Mussared --- extmod/asyncio/stream.py | 26 ++++++++++++-- tests/net_hosted/asyncio_start_server.py | 38 ++++++++++++++++++++ tests/net_hosted/asyncio_start_server.py.exp | 18 ++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/extmod/asyncio/stream.py b/extmod/asyncio/stream.py index c47c48cf0982..5547bfbd51e7 100644 --- a/extmod/asyncio/stream.py +++ b/extmod/asyncio/stream.py @@ -127,20 +127,30 @@ async def __aexit__(self, exc_type, exc, tb): await self.wait_closed() def close(self): + # Note: the _serve task must have already started by now due to the sleep + # in start_server, so `state` won't be clobbered at the start of _serve. + self.state = True self.task.cancel() async def wait_closed(self): await self.task async def _serve(self, s, cb): + self.state = False # Accept incoming connections while True: try: yield core._io_queue.queue_read(s) - except core.CancelledError: - # Shutdown server + except core.CancelledError as er: + # The server task was cancelled, shutdown server and close socket. s.close() - return + if self.state: + # If the server was explicitly closed, ignore the cancellation. + return + else: + # Otherwise e.g. the parent task was cancelled, propagate + # cancellation. + raise er try: s2, addr = s.accept() except: @@ -167,6 +177,16 @@ async def start_server(cb, host, port, backlog=5): # Create and return server object and task. srv = Server() srv.task = core.create_task(srv._serve(s, cb)) + try: + # Ensure that the _serve task has been scheduled so that it gets to + # handle cancellation. + await core.sleep_ms(0) + except core.CancelledError as er: + # If the parent task is cancelled during this first sleep, then + # we will leak the task and it will sit waiting for the socket, so + # cancel it. + srv.task.cancel() + raise er return srv diff --git a/tests/net_hosted/asyncio_start_server.py b/tests/net_hosted/asyncio_start_server.py index 316221898112..e76faf7edb6a 100644 --- a/tests/net_hosted/asyncio_start_server.py +++ b/tests/net_hosted/asyncio_start_server.py @@ -22,6 +22,44 @@ async def test(): print("sleep") await asyncio.sleep(0) + # Test that cancellation works before the server starts if + # the subsequent code raises. + print("create server3") + server3 = await asyncio.start_server(None, "0.0.0.0", 8000) + try: + async with server3: + raise OSError + except OSError as er: + print("OSError") + + # Test that closing doesn't raise CancelledError. + print("create server4") + server4 = await asyncio.start_server(None, "0.0.0.0", 8000) + server4.close() + await server4.wait_closed() + print("server4 closed") + + # Test that cancelling the task will still raise CancelledError, checking + # edge cases around how many times the tasks have been re-scheduled by + # sleep. + async def task(n): + print("create task server", n) + srv = await asyncio.start_server(None, "0.0.0.0", 8000) + await srv.wait_closed() + # This should be unreachable. + print("task finished") + + for num_sleep in range(0, 5): + print("sleep", num_sleep) + t = asyncio.create_task(task(num_sleep)) + for _ in range(num_sleep): + await asyncio.sleep(0) + t.cancel() + try: + await t + except asyncio.CancelledError: + print("CancelledError") + print("done") diff --git a/tests/net_hosted/asyncio_start_server.py.exp b/tests/net_hosted/asyncio_start_server.py.exp index 0fb8e6a63b07..58982a108ce1 100644 --- a/tests/net_hosted/asyncio_start_server.py.exp +++ b/tests/net_hosted/asyncio_start_server.py.exp @@ -2,4 +2,22 @@ create server1 create server2 OSError sleep +create server3 +OSError +create server4 +server4 closed +sleep 0 +CancelledError +sleep 1 +create task server 1 +CancelledError +sleep 2 +create task server 2 +CancelledError +sleep 3 +create task server 3 +CancelledError +sleep 4 +create task server 4 +CancelledError done From 379b583b2fbff7772884f199ddb0d70fb8b86090 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 20 Sep 2023 14:41:01 +0200 Subject: [PATCH 56/78] drivers/esp_hosted: Fix pin IRQ. This patch reinstalls the pin IRQ handler on WiFi init, as some ports disable/remove pin IRQs on soft-reboot, or deinit the pins. Signed-off-by: iabdalkader --- drivers/esp-hosted/esp_hosted_hal.c | 86 ++++++++++++++---------- drivers/esp-hosted/esp_hosted_hal.h | 1 + drivers/esp-hosted/esp_hosted_internal.h | 2 - drivers/esp-hosted/esp_hosted_wifi.c | 4 ++ 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/drivers/esp-hosted/esp_hosted_hal.c b/drivers/esp-hosted/esp_hosted_hal.c index d8e2e6ece495..85cacc0a1bf2 100644 --- a/drivers/esp-hosted/esp_hosted_hal.c +++ b/drivers/esp-hosted/esp_hosted_hal.c @@ -41,12 +41,9 @@ #include "esp_hosted_hal.h" #include "esp_hosted_wifi.h" -#ifndef MICROPY_HW_WIFI_IRQ -#define MICROPY_HW_WIFI_IRQ MICROPY_HW_WIFI_HANDSHAKE -#endif +extern void mod_network_poll_events(void); STATIC mp_obj_t esp_hosted_pin_irq_callback(mp_obj_t self_in) { - extern void mod_network_poll_events(void); mod_network_poll_events(); return mp_const_none; } @@ -64,34 +61,16 @@ MP_WEAK int esp_hosted_hal_init(uint32_t mode) { mp_hal_pin_input(MICROPY_HW_WIFI_HANDSHAKE); mp_hal_pin_input(MICROPY_HW_WIFI_DATAREADY); - // Enable Pin-IRQ for the handshake PIN to call esp_hosted_wifi_poll() - mp_obj_t irq_rising_attr[2]; - mp_load_method_maybe((mp_obj_t)MICROPY_HW_WIFI_IRQ, MP_QSTR_IRQ_RISING, irq_rising_attr); - - if (irq_rising_attr[0] != MP_OBJ_NULL && irq_rising_attr[1] == MP_OBJ_NULL) { // value for IRQ rising found - mp_obj_t pin_args[] = { - NULL, // Method pointer - (mp_obj_t)MICROPY_HW_WIFI_IRQ, // Pin object - (mp_obj_t)&esp_hosted_pin_irq_callback_obj, // Callback function object - NULL, // The Rising edge value is set below. - mp_const_true, // Hard IRQ, since the actual polling is scheduled. - }; - pin_args[3] = irq_rising_attr[0]; - mp_load_method_maybe((mp_obj_t)MICROPY_HW_WIFI_IRQ, MP_QSTR_irq, pin_args); - if (pin_args[0] != MP_OBJ_NULL && pin_args[1] != MP_OBJ_NULL) { - mp_call_method_n_kw(3, 0, pin_args); - } - } - // Initialize SPI. mp_obj_t args[] = { MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_ID), MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_BAUDRATE), + MP_OBJ_NEW_QSTR(MP_QSTR_phase), MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_NEW_QSTR(MP_QSTR_polarity), MP_OBJ_NEW_SMALL_INT(1), }; MP_STATE_PORT(mp_wifi_spi) = - MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)((mp_obj_t)&machine_spi_type, 2, 1, args); + MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)((mp_obj_t)&machine_spi_type, 2, 2, args); // SPI might change the direction/mode of CS pin, // set it to GPIO again just in case. @@ -101,16 +80,8 @@ MP_WEAK int esp_hosted_hal_init(uint32_t mode) { } MP_WEAK int esp_hosted_hal_deinit(void) { - // Disable Pin-IRQ for the handshake PIN - mp_obj_t pin_args[] = { - NULL, // Method pointer - (mp_obj_t)MICROPY_HW_WIFI_IRQ, // Pin object - mp_const_none // Set to None - }; - mp_load_method_maybe((mp_obj_t)MICROPY_HW_WIFI_IRQ, MP_QSTR_irq, pin_args); - if (pin_args[0] && pin_args[1]) { - mp_call_method_n_kw(1, 0, pin_args); - } + // Disable pin IRQ. + esp_hosted_hal_irq_enable(false); // Remove all network interfaces and reset wifi state. esp_hosted_wifi_deinit(); @@ -134,6 +105,43 @@ MP_WEAK int esp_hosted_hal_deinit(void) { return 0; } +MP_WEAK void esp_hosted_hal_irq_enable(bool enable) { + #ifdef MICROPY_HW_WIFI_IRQ_PIN + // Disable Pin-IRQ for the handshake PIN + mp_obj_t pin_args[] = { + NULL, // Method pointer + (mp_obj_t)MICROPY_HW_WIFI_IRQ_PIN, // Pin object + mp_const_none // Set to None + }; + mp_load_method_maybe((mp_obj_t)MICROPY_HW_WIFI_IRQ_PIN, MP_QSTR_irq, pin_args); + if (pin_args[0] && pin_args[1]) { + mp_call_method_n_kw(1, 0, pin_args); + } + + if (enable) { + // Enable Pin-IRQ for the handshake PIN to call esp_hosted_wifi_poll() + mp_obj_t irq_rising_attr[2]; + mp_load_method_maybe((mp_obj_t)MICROPY_HW_WIFI_IRQ_PIN, MP_QSTR_IRQ_RISING, irq_rising_attr); + + if (irq_rising_attr[0] != MP_OBJ_NULL && irq_rising_attr[1] == MP_OBJ_NULL) { + // value for IRQ rising found + mp_obj_t pin_args[] = { + NULL, // Method pointer + (mp_obj_t)MICROPY_HW_WIFI_IRQ_PIN, // Pin object + (mp_obj_t)&esp_hosted_pin_irq_callback_obj, // Callback function object + NULL, // The Rising edge value is set below. + mp_const_true, // Hard IRQ, since the actual polling is scheduled. + }; + pin_args[3] = irq_rising_attr[0]; + mp_load_method_maybe((mp_obj_t)MICROPY_HW_WIFI_IRQ_PIN, MP_QSTR_irq, pin_args); + if (pin_args[0] != MP_OBJ_NULL && pin_args[1] != MP_OBJ_NULL) { + mp_call_method_n_kw(3, 0, pin_args); + } + } + } + #endif +} + MP_WEAK int esp_hosted_hal_atomic_enter(void) { #if MICROPY_ENABLE_SCHEDULER mp_sched_lock(); @@ -149,7 +157,7 @@ MP_WEAK int esp_hosted_hal_atomic_exit(void) { } MP_WEAK bool esp_hosted_hal_data_ready(void) { - return mp_hal_pin_read(MICROPY_HW_WIFI_DATAREADY) && mp_hal_pin_read(MICROPY_HW_WIFI_HANDSHAKE); + return mp_hal_pin_read(MICROPY_HW_WIFI_DATAREADY); } MP_WEAK int esp_hosted_hal_spi_transfer(const uint8_t *tx_buf, uint8_t *rx_buf, uint32_t size) { @@ -158,7 +166,8 @@ MP_WEAK int esp_hosted_hal_spi_transfer(const uint8_t *tx_buf, uint8_t *rx_buf, // Wait for handshake pin to go high. for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(1)) { - if (mp_hal_pin_read(MICROPY_HW_WIFI_HANDSHAKE)) { + if (mp_hal_pin_read(MICROPY_HW_WIFI_HANDSHAKE) && + (rx_buf == NULL || mp_hal_pin_read(MICROPY_HW_WIFI_DATAREADY))) { break; } if ((mp_hal_ticks_ms() - start) >= 1000) { @@ -171,6 +180,11 @@ MP_WEAK int esp_hosted_hal_spi_transfer(const uint8_t *tx_buf, uint8_t *rx_buf, mp_hal_delay_us(10); spi_proto->transfer(mp_wifi_spi, size, tx_buf, rx_buf); mp_hal_pin_write(MICROPY_HW_WIFI_SPI_CS, 1); + mp_hal_delay_us(100); + + if (esp_hosted_hal_data_ready()) { + mod_network_poll_events(); + } return 0; } diff --git a/drivers/esp-hosted/esp_hosted_hal.h b/drivers/esp-hosted/esp_hosted_hal.h index abf060c8935e..0bc7db928235 100644 --- a/drivers/esp-hosted/esp_hosted_hal.h +++ b/drivers/esp-hosted/esp_hosted_hal.h @@ -68,6 +68,7 @@ typedef enum { // Note A default machine-based implementation is provided in esp_hosted_hal.c. int esp_hosted_hal_init(uint32_t mode); int esp_hosted_hal_deinit(void); +void esp_hosted_hal_irq_enable(bool enable); bool esp_hosted_hal_data_ready(void); int esp_hosted_hal_atomic_enter(void); int esp_hosted_hal_atomic_exit(void); diff --git a/drivers/esp-hosted/esp_hosted_internal.h b/drivers/esp-hosted/esp_hosted_internal.h index f57cd210a18a..ff8377e6745e 100644 --- a/drivers/esp-hosted/esp_hosted_internal.h +++ b/drivers/esp-hosted/esp_hosted_internal.h @@ -29,8 +29,6 @@ #ifndef MICROPY_INCLUDED_DRIVERS_ESP_HOSTED_INTERNAL_H #define MICROPY_INCLUDED_DRIVERS_ESP_HOSTED_INTERNAL_H -#define ESP_HOSTED_DEBUG (0) - #define ESP_FRAME_MAX_SIZE (1600) #define ESP_FRAME_MAX_PAYLOAD (ESP_FRAME_MAX_SIZE - sizeof(esp_header_t)) #define ESP_FRAME_FLAGS_FRAGMENT (1 << 0) diff --git a/drivers/esp-hosted/esp_hosted_wifi.c b/drivers/esp-hosted/esp_hosted_wifi.c index 3cc153205c97..d1b6333aa012 100644 --- a/drivers/esp-hosted/esp_hosted_wifi.c +++ b/drivers/esp-hosted/esp_hosted_wifi.c @@ -476,6 +476,10 @@ int esp_hosted_wifi_init(uint32_t itf) { esp_hosted_netif_init(&esp_state, itf); info_printf("esp_hosted_init() initialized itf %lu\n", itf); } + + // Re/enable IRQ pin. + esp_hosted_hal_irq_enable(true); + return 0; } From a43e13c67be565a1d053e745fb96c9a31b9f2c41 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 20 Sep 2023 14:44:51 +0200 Subject: [PATCH 57/78] drivers/esp-hosted: Fix MTU size. The maximum SPI frame payload is 1600 - header_size. Signed-off-by: iabdalkader --- drivers/esp-hosted/esp_hosted_netif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/esp-hosted/esp_hosted_netif.c b/drivers/esp-hosted/esp_hosted_netif.c index b471c3ad4c20..da911f3d6210 100644 --- a/drivers/esp-hosted/esp_hosted_netif.c +++ b/drivers/esp-hosted/esp_hosted_netif.c @@ -51,7 +51,7 @@ static err_t netif_struct_init(struct netif *netif) { netif->linkoutput = esp_hosted_netif_output; netif->output = etharp_output; - netif->mtu = 1500; + netif->mtu = ESP_FRAME_MAX_PAYLOAD; netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; esp_hosted_wifi_get_mac(netif->name[1] - '0', netif->hwaddr); netif->hwaddr_len = sizeof(netif->hwaddr); From 279e2561f2abfae1fdf2b4b8a37bf228d499e4ba Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 20 Sep 2023 14:43:52 +0200 Subject: [PATCH 58/78] drivers/esp_hosted_hal: Add support for WiFI LED activity indicator. Signed-off-by: iabdalkader --- drivers/esp-hosted/esp_hosted_hal.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/esp-hosted/esp_hosted_hal.c b/drivers/esp-hosted/esp_hosted_hal.c index 85cacc0a1bf2..4c3ecad130b7 100644 --- a/drivers/esp-hosted/esp_hosted_hal.c +++ b/drivers/esp-hosted/esp_hosted_hal.c @@ -37,6 +37,9 @@ #include "modmachine.h" #include "extmod/machine_spi.h" #include "mpconfigboard.h" +#ifdef MICROPY_HW_WIFI_LED +#include "led.h" +#endif #include "esp_hosted_hal.h" #include "esp_hosted_wifi.h" @@ -44,6 +47,9 @@ extern void mod_network_poll_events(void); STATIC mp_obj_t esp_hosted_pin_irq_callback(mp_obj_t self_in) { + #ifdef MICROPY_HW_WIFI_LED + led_toggle(MICROPY_HW_WIFI_LED); + #endif mod_network_poll_events(); return mp_const_none; } From 5c8099003c5db6c398efa611f041f8280e7a32e3 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 20 Sep 2023 14:59:28 +0200 Subject: [PATCH 59/78] renesas-ra/boards/ARDUINO_PORTENTA_C33: Update WiFi config. Changes are: - Enable IRQ on WiFi data ready pin. - Fix WiFi SPI clock (an exact 30MHz is not possible). - Update WiFi pins. Signed-off-by: iabdalkader --- .../ARDUINO_PORTENTA_C33/mpconfigboard.h | 3 ++- .../ARDUINO_PORTENTA_C33/ra_gen/common_data.c | 24 +++++++++++++++++++ .../ARDUINO_PORTENTA_C33/ra_gen/common_data.h | 12 +++++++++- .../ARDUINO_PORTENTA_C33/ra_gen/pin_data.c | 2 ++ .../ARDUINO_PORTENTA_C33/ra_gen/vector_data.c | 2 ++ .../ARDUINO_PORTENTA_C33/ra_gen/vector_data.h | 4 +++- 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h index ed19f60e9ea6..aa1e28ab9d09 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h @@ -98,9 +98,10 @@ void PORTENTA_C33_board_enter_bootloader(void); // WiFi config. #define MICROPY_HW_WIFI_SPI_ID (1) #define MICROPY_HW_WIFI_SPI_CS (pin_P104) -#define MICROPY_HW_WIFI_SPI_BAUDRATE (30 * 1000 * 1000) +#define MICROPY_HW_WIFI_SPI_BAUDRATE (25 * 1000 * 1000) #define MICROPY_HW_WIFI_DATAREADY (pin_P803) #define MICROPY_HW_WIFI_HANDSHAKE (pin_P806) +#define MICROPY_HW_WIFI_IRQ_PIN (MICROPY_HW_WIFI_DATAREADY) // ESP hosted control pins #define MICROPY_HW_ESP_HOSTED_RESET (pin_P804) diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.c b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.c index 50a3f6046b1c..edc031ea9075 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.c +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.c @@ -1,5 +1,29 @@ /* generated common source file - do not edit */ #include "common_data.h" +icu_instance_ctrl_t g_external_irq1_ctrl; +const external_irq_cfg_t g_external_irq1_cfg = +{ .channel = 2, + .trigger = EXTERNAL_IRQ_TRIG_RISING, + .filter_enable = false, + .pclk_div = EXTERNAL_IRQ_PCLK_DIV_BY_64, + .p_callback = NULL, + /** If NULL then do not add & */ + #if defined(NULL) + .p_context = NULL, + #else + .p_context = &NULL, + #endif + .p_extend = NULL, + .ipl = (12), + #if defined(VECTOR_NUMBER_ICU_IRQ2) + .irq = VECTOR_NUMBER_ICU_IRQ2, + #else + .irq = FSP_INVALID_VECTOR, + #endif +}; +/* Instance structure to use this module. */ +const external_irq_instance_t g_external_irq1 = +{ .p_ctrl = &g_external_irq1_ctrl, .p_cfg = &g_external_irq1_cfg, .p_api = &g_external_irq_on_icu }; sce_instance_ctrl_t sce_ctrl; const sce_cfg_t sce_cfg = { .lifecycle = SCE_SSD }; diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.h b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.h index 0f5a143ff6a7..3573218160fc 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.h +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/common_data.h @@ -3,12 +3,22 @@ #define COMMON_DATA_H_ #include #include "bsp_api.h" -#include "r_sce.h" #include "r_icu.h" #include "r_external_irq_api.h" +#include "r_sce.h" #include "r_ioport.h" #include "bsp_pin_cfg.h" FSP_HEADER +/** External IRQ on ICU Instance. */ +extern const external_irq_instance_t g_external_irq1; + +/** Access the ICU instance using these structures when calling API functions directly (::p_api is not used). */ +extern icu_instance_ctrl_t g_external_irq1_ctrl; +extern const external_irq_cfg_t g_external_irq1_cfg; + +#ifndef NULL +void NULL(external_irq_callback_args_t *p_args); +#endif extern sce_instance_ctrl_t sce_ctrl; extern const sce_cfg_t sce_cfg; /** External IRQ on ICU Instance. */ diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/pin_data.c b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/pin_data.c index 895f662f2731..ac0f7b5ddf11 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/pin_data.c +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/pin_data.c @@ -34,6 +34,8 @@ const ioport_pin_cfg_t g_bsp_pin_cfg_data[] = | (uint32_t)IOPORT_PERIPHERAL_SCI1_3_5_7_9) }, { .pin = BSP_IO_PORT_06_PIN_07, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, + { .pin = BSP_IO_PORT_08_PIN_03, .pin_cfg = ((uint32_t)IOPORT_CFG_IRQ_ENABLE + | (uint32_t)IOPORT_CFG_PORT_DIRECTION_INPUT) }, { .pin = BSP_IO_PORT_10_PIN_00, .pin_cfg = ((uint32_t)IOPORT_CFG_PERIPHERAL_PIN | (uint32_t)IOPORT_PERIPHERAL_SCI0_2_4_6_8) }, }; diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.c b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.c index ea8b0511ba17..cb4da4cf340d 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.c +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.c @@ -33,6 +33,7 @@ BSP_DONT_REMOVE const fsp_vector_t g_vector_table[BSP_ICU_VECTOR_MAX_ENTRIES] BS [26] = spi_txi_isr, /* SPI1 TXI (Transmit buffer empty) */ [27] = spi_tei_isr, /* SPI1 TEI (Transmission complete event) */ [28] = spi_eri_isr, /* SPI1 ERI (Error) */ + [29] = r_icu_isr, /* ICU IRQ2 (External pin interrupt 2) */ }; const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENTRIES] = { @@ -65,5 +66,6 @@ const bsp_interrupt_event_t g_interrupt_event_link_select[BSP_ICU_VECTOR_MAX_ENT [26] = BSP_PRV_IELS_ENUM(EVENT_SPI1_TXI), /* SPI1 TXI (Transmit buffer empty) */ [27] = BSP_PRV_IELS_ENUM(EVENT_SPI1_TEI), /* SPI1 TEI (Transmission complete event) */ [28] = BSP_PRV_IELS_ENUM(EVENT_SPI1_ERI), /* SPI1 ERI (Error) */ + [29] = BSP_PRV_IELS_ENUM(EVENT_ICU_IRQ2), /* ICU IRQ2 (External pin interrupt 2) */ }; #endif diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.h b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.h index 2342dbbab1a4..c5ccb9e3cfdc 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.h +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/ra_gen/vector_data.h @@ -6,7 +6,7 @@ extern "C" { #endif /* Number of interrupts allocated */ #ifndef VECTOR_DATA_IRQ_COUNT -#define VECTOR_DATA_IRQ_COUNT (29) +#define VECTOR_DATA_IRQ_COUNT (30) #endif /* ISR prototypes */ void sci_uart_rxi_isr(void); @@ -92,6 +92,8 @@ void spi_eri_isr(void); #define SPI1_TEI_IRQn ((IRQn_Type)27) /* SPI1 TEI (Transmission complete event) */ #define VECTOR_NUMBER_SPI1_ERI ((IRQn_Type)28) /* SPI1 ERI (Error) */ #define SPI1_ERI_IRQn ((IRQn_Type)28) /* SPI1 ERI (Error) */ +#define VECTOR_NUMBER_ICU_IRQ2 ((IRQn_Type)29) /* ICU IRQ2 (External pin interrupt 2) */ +#define ICU_IRQ2_IRQn ((IRQn_Type)29) /* ICU IRQ2 (External pin interrupt 2) */ #ifdef __cplusplus } #endif From 9d5d2e8cf71321b4ba41bad127bf0ea0ff24ccbf Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 20 Sep 2023 15:03:44 +0200 Subject: [PATCH 60/78] renesas-ra: Tune lwip buffers and timing to improve network performance. Signed-off-by: iabdalkader --- ports/renesas-ra/lwip_inc/lwipopts.h | 14 ++++++++------ ports/renesas-ra/mpnetworkport.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ports/renesas-ra/lwip_inc/lwipopts.h b/ports/renesas-ra/lwip_inc/lwipopts.h index 036da9bcef24..f7dc80cc3863 100644 --- a/ports/renesas-ra/lwip_inc/lwipopts.h +++ b/ports/renesas-ra/lwip_inc/lwipopts.h @@ -42,12 +42,14 @@ extern uint32_t rng_read(void); #define LWIP_RAND() rng_read() -// lwip takes 26700 bytes -#define MEM_SIZE (8000) -#define TCP_MSS (800) -#define TCP_WND (8 * TCP_MSS) -#define TCP_SND_BUF (8 * TCP_MSS) -#define MEMP_NUM_TCP_SEG (32) +#define MEM_SIZE (16 * 1024) +#define TCP_MSS (1460) +#define TCP_OVERSIZE (TCP_MSS) +#define TCP_WND (8 * TCP_MSS) +#define TCP_SND_BUF (8 * TCP_MSS) +#define TCP_SND_QUEUELEN (2 * (TCP_SND_BUF / TCP_MSS)) +#define TCP_QUEUE_OOSEQ (1) +#define MEMP_NUM_TCP_SEG (2 * TCP_SND_QUEUELEN) typedef uint32_t sys_prot_t; diff --git a/ports/renesas-ra/mpnetworkport.c b/ports/renesas-ra/mpnetworkport.c index 2bc6bf439980..8e16c2b1b4f8 100644 --- a/ports/renesas-ra/mpnetworkport.c +++ b/ports/renesas-ra/mpnetworkport.c @@ -67,8 +67,8 @@ void mod_network_lwip_init(void) { timer_started = false; } // Start poll timer. - soft_timer_static_init(&network_timer, SOFT_TIMER_MODE_PERIODIC, 128, network_timer_callback); - soft_timer_reinsert(&network_timer, 128); + soft_timer_static_init(&network_timer, SOFT_TIMER_MODE_PERIODIC, 50, network_timer_callback); + soft_timer_reinsert(&network_timer, 50); timer_started = true; } #endif // MICROPY_PY_LWIP From cf490a70917a1b2d38ba9b58e763e0837d0f7ca7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 3 Oct 2023 11:24:50 +1100 Subject: [PATCH 61/78] all: Fix various spelling mistakes found by codespell 2.2.6. Signed-off-by: Damien George --- docs/library/espnow.rst | 2 +- docs/library/wm8960.rst | 2 +- docs/reference/glossary.rst | 2 +- examples/hwapi/README.md | 2 +- extmod/modbluetooth.c | 2 +- extmod/nimble/modbluetooth_nimble.c | 2 +- ports/cc3200/application.lds | 2 +- ports/cc3200/fatfs/src/drivers/sd_diskio.c | 2 +- ports/nrf/Makefile | 2 +- ports/nrf/drivers/bluetooth/ble_drv.c | 2 +- ports/stm32/Makefile | 2 +- ports/stm32/timer.c | 2 +- ports/teensy/Makefile | 2 +- ports/teensy/timer.c | 2 +- py/formatfloat.c | 2 +- py/mkrules.mk | 2 +- py/mpconfig.h | 6 +++--- py/obj.c | 2 +- pyproject.toml | 2 +- tools/pydfu.py | 2 +- 20 files changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/library/espnow.rst b/docs/library/espnow.rst index f344983700a1..f0b592dffc8a 100644 --- a/docs/library/espnow.rst +++ b/docs/library/espnow.rst @@ -287,7 +287,7 @@ after reboot/reset). This reduces the reliability of receiving ESP-NOW messages .. method:: ESPNow.irecv([timeout_ms]) - Works like `ESPNow.recv()` but will re-use internal bytearrays to store the + Works like `ESPNow.recv()` but will reuse internal bytearrays to store the return values: ``[mac, msg]``, so that no new memory is allocated on each call. diff --git a/docs/library/wm8960.rst b/docs/library/wm8960.rst index add003630eb8..5abfb6a8a011 100644 --- a/docs/library/wm8960.rst +++ b/docs/library/wm8960.rst @@ -251,7 +251,7 @@ controlling its operation: .. method:: WM8960.expand_3d(level) - Enable Stereo 3D exansion. *level* is a number between 0 and 15. + Enable Stereo 3D expansion. *level* is a number between 0 and 15. A value of 0 disables the expansion. .. method:: WM8960.mono(active) diff --git a/docs/reference/glossary.rst b/docs/reference/glossary.rst index d039bf7132f3..efaa8f607f72 100644 --- a/docs/reference/glossary.rst +++ b/docs/reference/glossary.rst @@ -32,7 +32,7 @@ Glossary callee-owned tuple This is a MicroPython-specific construct where, for efficiency - reasons, some built-in functions or methods may re-use the same + reasons, some built-in functions or methods may reuse the same underlying tuple object to return data. This avoids having to allocate a new tuple for every call, and reduces heap fragmentation. Programs should not hold references to callee-owned tuples and instead only diff --git a/examples/hwapi/README.md b/examples/hwapi/README.md index a1b0c5642a2f..929ef425fd49 100644 --- a/examples/hwapi/README.md +++ b/examples/hwapi/README.md @@ -3,7 +3,7 @@ This directory shows the best practices for using MicroPython hardware API across various boards, with the aim to enable writing portable applications, which would work from a board to board, from a system to another systems. This is inherently a hard problem, because hardware is different from one -board type to another, and even from examplar of board to another. For +board type to another, and even from exemplar of board to another. For example, if your app requires an external LED, one user may connect it to one GPIO pin, while another user may find it much more convenient to use another pin. This of course applies to relays, buzzers, sensors, etc. diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 7b13f9556c4f..3417df7a27fd 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -504,7 +504,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character // How many descriptors in the flattened list per characteristic. uint8_t *num_descriptors = m_new(uint8_t, len); - // Inititally allocate enough room for the number of characteristics. + // Initially allocate enough room for the number of characteristics. // Will be grown to accommodate descriptors as necessary. *num_handles = len; *handles = m_new(uint16_t, *num_handles); diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index e23ffbf0f981..5e3e38ea67f1 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -1856,7 +1856,7 @@ int mp_bluetooth_l2cap_recvinto(uint16_t conn_handle, uint16_t cid, uint8_t *buf // re-enable receiving yet (as we need to complete the rest of IRQ handler first). if (!chan->irq_in_progress) { // We've already given the channel a new mbuf in l2cap_channel_event above, so - // re-use that mbuf in the call to ble_l2cap_recv_ready. This will just + // reuse that mbuf in the call to ble_l2cap_recv_ready. This will just // give the channel more credits. struct os_mbuf *sdu_rx = chan->chan->coc_rx.sdu; assert(sdu_rx); diff --git a/ports/cc3200/application.lds b/ports/cc3200/application.lds index 3f5e72f8bd65..2d7dd0462130 100644 --- a/ports/cc3200/application.lds +++ b/ports/cc3200/application.lds @@ -83,7 +83,7 @@ SECTIONS } > SRAM /* place here functions that are only called during boot up, */ - /* that way, we can re-use this area for the MicroPython heap */ + /* that way, we can reuse this area for the MicroPython heap */ .boot : { . = ALIGN(8); diff --git a/ports/cc3200/fatfs/src/drivers/sd_diskio.c b/ports/cc3200/fatfs/src/drivers/sd_diskio.c index 329ae04b9910..e370ba538fd0 100644 --- a/ports/cc3200/fatfs/src/drivers/sd_diskio.c +++ b/ports/cc3200/fatfs/src/drivers/sd_diskio.c @@ -363,7 +363,7 @@ DRESULT sd_disk_read (BYTE* pBuffer, DWORD ulSectorNumber, UINT SectorCount) { //***************************************************************************** // -//! Wrties sector(s) to the disk drive. +//! Writes sector(s) to the disk drive. //! //! //! This function writes specified number of sectors to the drive diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 5e9e31ad0140..284b82281b24 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -536,7 +536,7 @@ SRC_QSTR += $(SRC_C) $(SRC_SHARED_C) $(DRIVERS_SRC_C) $(SRC_BOARD_MODULES) # SRC_QSTR SRC_QSTR_AUTO_DEPS += -# Making OBJ use an order-only depenedency on the generated pins.h file +# Making OBJ use an order-only dependency on the generated pins.h file # has the side effect of making the pins.h file before we actually compile # any of the objects. The normal dependency generation will deal with the # case when pins.h is modified. But when it doesn't exist, we don't know diff --git a/ports/nrf/drivers/bluetooth/ble_drv.c b/ports/nrf/drivers/bluetooth/ble_drv.c index 078c7d995bc0..b1caa187d5fc 100644 --- a/ports/nrf/drivers/bluetooth/ble_drv.c +++ b/ports/nrf/drivers/bluetooth/ble_drv.c @@ -942,7 +942,7 @@ static void sd_evt_handler(uint32_t evt_id) { break; } #if MICROPY_HW_USB_CDC - // Farward SOC events to USB CDC driver. + // Forward SOC events to USB CDC driver. usb_cdc_sd_event_handler(evt_id); #endif } diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 58dc76200666..dcfc8dfd5413 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -664,7 +664,7 @@ SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) # SRC_QSTR SRC_QSTR_AUTO_DEPS += $(GEN_CDCINF_HEADER) -# Making OBJ use an order-only depenedency on the generated pins.h file +# Making OBJ use an order-only dependency on the generated pins.h file # has the side effect of making the pins.h file before we actually compile # any of the objects. The normal dependency generation will deal with the # case when pins.h is modified. But when it doesn't exist, we don't know diff --git a/ports/stm32/timer.c b/ports/stm32/timer.c index 5f2e213a0aa2..c15b84fe54f9 100644 --- a/ports/stm32/timer.c +++ b/ports/stm32/timer.c @@ -605,7 +605,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// - `mode` can be one of: /// - `Timer.UP` - configures the timer to count from 0 to ARR (default) /// - `Timer.DOWN` - configures the timer to count from ARR down to 0. -/// - `Timer.CENTER` - confgures the timer to count from 0 to ARR and +/// - `Timer.CENTER` - configures the timer to count from 0 to ARR and /// then back down to 0. /// /// - `div` can be one of 1, 2, or 4. Divides the timer clock to determine diff --git a/ports/teensy/Makefile b/ports/teensy/Makefile index 70331c5dc704..8f55e4bcba61 100644 --- a/ports/teensy/Makefile +++ b/ports/teensy/Makefile @@ -214,7 +214,7 @@ SRC_QSTR += $(SRC_C) $(STM_SRC_C) $(SHARED_SRC_C) # SRC_QSTR SRC_QSTR_AUTO_DEPS += -# Making OBJ use an order-only depenedency on the generated pins.h file +# Making OBJ use an order-only dependency on the generated pins.h file # has the side effect of making the pins.h file before we actually compile # any of the objects. The normal dependency generation will deal with the # case when pins.h is modified. But when it doesn't exist, we don't know diff --git a/ports/teensy/timer.c b/ports/teensy/timer.c index 56d25e331240..da18d6f4f510 100644 --- a/ports/teensy/timer.c +++ b/ports/teensy/timer.c @@ -225,7 +225,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// /// - `mode` can be one of: /// - `Timer.UP` - configures the timer to count from 0 to MOD (default) -/// - `Timer.CENTER` - confgures the timer to count from 0 to MOD and +/// - `Timer.CENTER` - configures the timer to count from 0 to MOD and /// then back down to 0. /// /// - `callback` - as per Timer.callback() diff --git a/py/formatfloat.c b/py/formatfloat.c index 050d3a9dfb6c..7cd471018da9 100644 --- a/py/formatfloat.c +++ b/py/formatfloat.c @@ -230,7 +230,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch } } else { // Build positive exponent. - // We don't modify f at this point to avoid innaccuracies from + // We don't modify f at this point to avoid inaccuracies from // scaling it. Instead, we find the product of powers of 10 // that is not greater than it, and use that to start the // mantissa. diff --git a/py/mkrules.mk b/py/mkrules.mk index ec36346b8afd..421e638c22b3 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -22,7 +22,7 @@ endif # QSTR generation uses the same CFLAGS, with these modifications. QSTR_GEN_FLAGS = -DNO_QSTR -# Note: := to force evalulation immediately. +# Note: := to force evaluation immediately. QSTR_GEN_CFLAGS := $(CFLAGS) QSTR_GEN_CFLAGS += $(QSTR_GEN_FLAGS) QSTR_GEN_CXXFLAGS := $(CXXFLAGS) diff --git a/py/mpconfig.h b/py/mpconfig.h index 433d6e50def2..9a7eb1b15d05 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1136,7 +1136,7 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_RANGE_BINOP (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif -// Support for callling next() with second argument +// Support for calling next() with second argument #ifndef MICROPY_PY_BUILTINS_NEXT2 #define MICROPY_PY_BUILTINS_NEXT2 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif @@ -1155,13 +1155,13 @@ typedef double mp_float_t; #define MICROPY_PY_ALL_SPECIAL_METHODS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// Whether to support all inplace arithmetic operarion methods +// Whether to support all inplace arithmetic operation methods // (__imul__, etc.) #ifndef MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS #define MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) #endif -// Whether to support reverse arithmetic operarion methods +// Whether to support reverse arithmetic operation methods // (__radd__, etc.). Additionally gated by // MICROPY_PY_ALL_SPECIAL_METHODS. #ifndef MICROPY_PY_REVERSE_SPECIAL_METHODS diff --git a/py/obj.c b/py/obj.c index 64c52eeb76c1..d013eb3d02cf 100644 --- a/py/obj.c +++ b/py/obj.c @@ -286,7 +286,7 @@ mp_obj_t mp_obj_equal_not_equal(mp_binary_op_t op, mp_obj_t o1, mp_obj_t o2) { o2 = temp; } - // equality not implemented, so fall back to pointer conparison + // equality not implemented, so fall back to pointer comparison return (o1 == o2) ? local_true : local_false; } diff --git a/pyproject.toml b/pyproject.toml index e3d70385c3f5..96e2e3a890ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ line-length = 99 [tool.codespell] count = "" ignore-regex = '\b[A-Z]{3}\b' -ignore-words-list = "ans,asend,deques,dout,extint,hsi,iput,mis,numer,technic,ure" +ignore-words-list = "ans,asend,deques,dout,extint,hsi,iput,mis,numer,shft,technic,ure" quiet-level = 3 skip = """ */build*,\ diff --git a/tools/pydfu.py b/tools/pydfu.py index a9da3a0f83fb..e1e4074a6baf 100755 --- a/tools/pydfu.py +++ b/tools/pydfu.py @@ -8,7 +8,7 @@ DFU, without requiring dfu-util. See app note AN3156 for a description of the DFU protocol. -See document UM0391 for a dscription of the DFuse file. +See document UM0391 for a description of the DFuse file. """ from __future__ import print_function From d6c55a40fe611201ae5a56e1738da443862911db Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 3 Oct 2023 12:09:44 +1100 Subject: [PATCH 62/78] top: Update .git-blame-ignore-revs for latest spelling fix commit. Signed-off-by: Damien George --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 6f84de6f60ea..637f2ec3d1eb 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,6 @@ +# all: Fix various spelling mistakes found by codespell 2.2.6. +cf490a70917a1b2d38ba9b58e763e0837d0f7ca7 + # all: Fix spelling mistakes based on codespell check. b1229efbd1509654dec6053865ab828d769e29db From b329fdcb7394f7a30cb81c48e04ba3d557d29396 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 29 Sep 2023 22:49:49 +1000 Subject: [PATCH 63/78] extmod/modnetwork: Increase max hostname length to 32. This changes from the previous limit of 15 characters. Although DHCP and mDNS allow for up to 63, ESP32 and ESP8266 only allow 32, so this seems like a reasonable limit to enforce across all ports (and avoids wasting the additional memory). Also clarifies that `MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN` does not include the null terminator (which was unclear before). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- docs/library/network.rst | 5 +++++ extmod/modnetwork.c | 6 +++--- extmod/modnetwork.h | 6 ++++-- extmod/network_cyw43.c | 2 +- ports/esp32/network_wlan.c | 2 +- ports/esp8266/network_wlan.c | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/library/network.rst b/docs/library/network.rst index a14d6192ea06..cc508842942a 100644 --- a/docs/library/network.rst +++ b/docs/library/network.rst @@ -188,6 +188,11 @@ The following are functions available in the network module. during connection. For this reason, you must set the hostname before activating/connecting your network interfaces. + The length of the hostname is limited to 32 characters. + :term:`MicroPython ports ` may choose to set a lower + limit for memory reasons. If the given name does not fit, a `ValueError` + is raised. + The default hostname is typically the name of the board. .. function:: phy_mode([mode]) diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index 7c1b91de45d0..378b45b9c81d 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -35,7 +35,7 @@ #if MICROPY_PY_NETWORK #include "shared/netutils/netutils.h" -#include "modnetwork.h" +#include "extmod/modnetwork.h" #if MICROPY_PY_NETWORK_CYW43 // So that CYW43_LINK_xxx constants are available to MICROPY_PORT_NETWORK_INTERFACES. @@ -56,7 +56,7 @@ char mod_network_country_code[2] = "XX"; #error "MICROPY_PY_NETWORK_HOSTNAME_DEFAULT must be set in mpconfigport.h or mpconfigboard.h" #endif -char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN] = MICROPY_PY_NETWORK_HOSTNAME_DEFAULT; +char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1] = MICROPY_PY_NETWORK_HOSTNAME_DEFAULT; #ifdef MICROPY_PORT_NETWORK_INTERFACES @@ -122,7 +122,7 @@ STATIC mp_obj_t network_hostname(size_t n_args, const mp_obj_t *args) { } else { size_t len; const char *str = mp_obj_str_get_data(args[0], &len); - if (len >= MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { + if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { mp_raise_ValueError(NULL); } strcpy(mod_network_hostname, str); diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index e775612fe7b1..e9769e309b2b 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -56,10 +56,12 @@ extern char mod_network_country_code[2]; #ifndef MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN -#define MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN (16) +// Doesn't include the null terminator. +#define MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN (32) #endif -extern char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN]; +// This is a null-terminated string. +extern char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; #if MICROPY_PY_LWIP struct netif; diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index 168bd3d52b52..f26a835c16d5 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -500,7 +500,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map // TODO: Deprecated. Use network.hostname(name) instead. size_t len; const char *str = mp_obj_str_get_data(e->value, &len); - if (len >= MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { + if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { mp_raise_ValueError(NULL); } strcpy(mod_network_hostname, str); diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index 58af9f3bc333..f06143bf76d5 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -524,7 +524,7 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_ // TODO: Deprecated. Use network.hostname(name) instead. size_t len; const char *str = mp_obj_str_get_data(kwargs->table[i].value, &len); - if (len >= MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { + if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { mp_raise_ValueError(NULL); } strcpy(mod_network_hostname, str); diff --git a/ports/esp8266/network_wlan.c b/ports/esp8266/network_wlan.c index 348d7f63550c..012cc970b276 100644 --- a/ports/esp8266/network_wlan.c +++ b/ports/esp8266/network_wlan.c @@ -404,7 +404,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs // TODO: Deprecated. Use network.hostname(name) instead. size_t len; const char *str = mp_obj_str_get_data(kwargs->table[i].value, &len); - if (len >= MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { + if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { mp_raise_ValueError(NULL); } strcpy(mod_network_hostname, str); From 65a3ce39a31e5ed7e5634c6905ca981039f42cb3 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 3 Oct 2023 13:32:48 +1100 Subject: [PATCH 64/78] extmod/modnetwork: Forward if.config(hostname) to network.hostname. This removes the duplicate code in cyw43, esp32, esp8266 that implements the same logic as network.hostname. Renames the `mod_network_hostname` (where we store the hostname value in `.data`) to `mod_network_hostname_data` to make way for calling the shared function `mod_network_hostname`. And uses memcpy for mod_network_hostname_data, because the length of source is already known and removes reliance on string data being null-terminated. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- extmod/modnetwork.c | 11 ++++++----- extmod/modnetwork.h | 7 ++++++- extmod/network_cyw43.c | 9 ++------- ports/esp32/network_wlan.c | 15 +++++---------- ports/esp8266/network_wlan.c | 13 ++++--------- ports/mimxrt/cyw43_configport.h | 2 +- ports/mimxrt/eth.c | 2 +- ports/rp2/cyw43_configport.h | 2 +- ports/stm32/cyw43_configport.h | 2 +- ports/stm32/eth.c | 2 +- 10 files changed, 28 insertions(+), 37 deletions(-) diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index 378b45b9c81d..f5734af9b5af 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -56,7 +56,7 @@ char mod_network_country_code[2] = "XX"; #error "MICROPY_PY_NETWORK_HOSTNAME_DEFAULT must be set in mpconfigport.h or mpconfigboard.h" #endif -char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1] = MICROPY_PY_NETWORK_HOSTNAME_DEFAULT; +char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1] = MICROPY_PY_NETWORK_HOSTNAME_DEFAULT; #ifdef MICROPY_PORT_NETWORK_INTERFACES @@ -116,20 +116,21 @@ STATIC mp_obj_t network_country(size_t n_args, const mp_obj_t *args) { // TODO: Non-static to allow backwards-compatible pyb.country. MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, network_country); -STATIC mp_obj_t network_hostname(size_t n_args, const mp_obj_t *args) { +mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { - return mp_obj_new_str(mod_network_hostname, strlen(mod_network_hostname)); + return mp_obj_new_str(mod_network_hostname_data, strlen(mod_network_hostname_data)); } else { size_t len; const char *str = mp_obj_str_get_data(args[0], &len); if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { mp_raise_ValueError(NULL); } - strcpy(mod_network_hostname, str); + memcpy(mod_network_hostname_data, str, len); + mod_network_hostname_data[len] = 0; return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_hostname_obj, 0, 1, network_hostname); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_hostname_obj, 0, 1, mod_network_hostname); STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) }, diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index e9769e309b2b..e3239c2a05fc 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -61,7 +61,12 @@ extern char mod_network_country_code[2]; #endif // This is a null-terminated string. -extern char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; +extern char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; + +// To support backwards-compatible (esp32, esp8266, cyw43) +// `if.config(hostname=...)` to forward directly to the implementation of +// `network.hostname(...)`. +mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args); #if MICROPY_PY_LWIP struct netif; diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index f26a835c16d5..834f09eae956 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -422,7 +422,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map } case MP_QSTR_hostname: { // TODO: Deprecated. Use network.hostname() instead. - return mp_obj_new_str(mod_network_hostname, strlen(mod_network_hostname)); + return mod_network_hostname(0, NULL); } default: mp_raise_ValueError(MP_ERROR_TEXT("unknown config param")); @@ -498,12 +498,7 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map } case MP_QSTR_hostname: { // TODO: Deprecated. Use network.hostname(name) instead. - size_t len; - const char *str = mp_obj_str_get_data(e->value, &len); - if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { - mp_raise_ValueError(NULL); - } - strcpy(mod_network_hostname, str); + mod_network_hostname(1, &e->value); break; } default: diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index f06143bf76d5..e1d16b4191d6 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -169,8 +169,8 @@ static void network_wlan_ip_event_handler(void *event_handler_arg, esp_event_bas if (!mdns_initialised) { mdns_init(); #if MICROPY_HW_ENABLE_MDNS_RESPONDER - mdns_hostname_set(mod_network_hostname); - mdns_instance_name_set(mod_network_hostname); + mdns_hostname_set(mod_network_hostname_data); + mdns_instance_name_set(mod_network_hostname_data); #endif mdns_initialised = true; } @@ -305,7 +305,7 @@ STATIC mp_obj_t network_wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp esp_exceptions(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_sta_config)); } - esp_exceptions(esp_netif_set_hostname(wlan_sta_obj.netif, mod_network_hostname)); + esp_exceptions(esp_netif_set_hostname(wlan_sta_obj.netif, mod_network_hostname_data)); wifi_sta_reconnects = 0; // connect to the WiFi AP @@ -522,12 +522,7 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_ case MP_QSTR_hostname: case MP_QSTR_dhcp_hostname: { // TODO: Deprecated. Use network.hostname(name) instead. - size_t len; - const char *str = mp_obj_str_get_data(kwargs->table[i].value, &len); - if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { - mp_raise_ValueError(NULL); - } - strcpy(mod_network_hostname, str); + mod_network_hostname(1, &kwargs->table[i].value); break; } case MP_QSTR_max_clients: { @@ -630,7 +625,7 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_ case MP_QSTR_dhcp_hostname: { // TODO: Deprecated. Use network.hostname() instead. req_if = ESP_IF_WIFI_STA; - val = mp_obj_new_str(mod_network_hostname, strlen(mod_network_hostname)); + val = mod_network_hostname(0, NULL); break; } case MP_QSTR_max_clients: { diff --git a/ports/esp8266/network_wlan.c b/ports/esp8266/network_wlan.c index 012cc970b276..b0e6b3aeb175 100644 --- a/ports/esp8266/network_wlan.c +++ b/ports/esp8266/network_wlan.c @@ -152,7 +152,7 @@ STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k error_check(wifi_station_set_config(&config), "Cannot set STA config"); } - wifi_station_set_hostname(mod_network_hostname); + wifi_station_set_hostname(mod_network_hostname_data); error_check(wifi_station_connect(), "Cannot connect to AP"); @@ -402,12 +402,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs case MP_QSTR_hostname: case MP_QSTR_dhcp_hostname: { // TODO: Deprecated. Use network.hostname(name) instead. - size_t len; - const char *str = mp_obj_str_get_data(kwargs->table[i].value, &len); - if (len > MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN) { - mp_raise_ValueError(NULL); - } - strcpy(mod_network_hostname, str); + mod_network_hostname(1, &kwargs->table[i].value); break; } case MP_QSTR_protocol: { @@ -481,9 +476,9 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs break; case MP_QSTR_hostname: case MP_QSTR_dhcp_hostname: { - req_if = STATION_IF; // TODO: Deprecated. Use network.hostname() instead. - val = mp_obj_new_str(mod_network_hostname, strlen(mod_network_hostname)); + req_if = STATION_IF; + val = mod_network_hostname(0, NULL); break; } case MP_QSTR_protocol: { diff --git a/ports/mimxrt/cyw43_configport.h b/ports/mimxrt/cyw43_configport.h index 5f9685647405..f1cfc86cb067 100644 --- a/ports/mimxrt/cyw43_configport.h +++ b/ports/mimxrt/cyw43_configport.h @@ -61,7 +61,7 @@ #define CYW43_THREAD_EXIT MICROPY_PY_LWIP_EXIT #define CYW43_THREAD_LOCK_CHECK -#define CYW43_HOST_NAME mod_network_hostname +#define CYW43_HOST_NAME mod_network_hostname_data #define CYW43_SDPCM_SEND_COMMON_WAIT __WFI(); #define CYW43_DO_IOCTL_WAIT __WFI(); diff --git a/ports/mimxrt/eth.c b/ports/mimxrt/eth.c index d0df7610cc27..befccca1cd66 100644 --- a/ports/mimxrt/eth.c +++ b/ports/mimxrt/eth.c @@ -559,7 +559,7 @@ STATIC void eth_lwip_init(eth_t *self) { n->name[0] = 'e'; n->name[1] = (self == ð_instance0 ? '0' : '1'); netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, eth_netif_init, ethernet_input); - netif_set_hostname(n, mod_network_hostname); + netif_set_hostname(n, mod_network_hostname_data); netif_set_default(n); netif_set_up(n); diff --git a/ports/rp2/cyw43_configport.h b/ports/rp2/cyw43_configport.h index 0c4a032100e8..929d83537b5b 100644 --- a/ports/rp2/cyw43_configport.h +++ b/ports/rp2/cyw43_configport.h @@ -48,7 +48,7 @@ #define CYW43_THREAD_EXIT MICROPY_PY_LWIP_EXIT #define CYW43_THREAD_LOCK_CHECK -#define CYW43_HOST_NAME mod_network_hostname +#define CYW43_HOST_NAME mod_network_hostname_data #define CYW43_SDPCM_SEND_COMMON_WAIT \ if (get_core_num() == 0) { \ diff --git a/ports/stm32/cyw43_configport.h b/ports/stm32/cyw43_configport.h index f2a880603ab0..1ea1ebde17ea 100644 --- a/ports/stm32/cyw43_configport.h +++ b/ports/stm32/cyw43_configport.h @@ -62,7 +62,7 @@ #define CYW43_THREAD_EXIT MICROPY_PY_LWIP_EXIT #define CYW43_THREAD_LOCK_CHECK -#define CYW43_HOST_NAME mod_network_hostname +#define CYW43_HOST_NAME mod_network_hostname_data #define CYW43_SDPCM_SEND_COMMON_WAIT __WFI(); #define CYW43_DO_IOCTL_WAIT __WFI(); diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index 0feacdae2d50..b01eee3f2b4a 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -737,7 +737,7 @@ STATIC void eth_lwip_init(eth_t *self) { n->name[0] = 'e'; n->name[1] = '0'; netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, eth_netif_init, ethernet_input); - netif_set_hostname(n, mod_network_hostname); + netif_set_hostname(n, mod_network_hostname_data); netif_set_default(n); netif_set_up(n); From 1cd61149e4328154110d4b1e38bcbecdcc0ec386 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Tue, 3 Oct 2023 12:21:50 +0200 Subject: [PATCH 65/78] esp32/boards/ARDUINO_NANO_ESP32: Use Arduino USB IDs. The IDF-provided version of TinyUSB defaults to Espressif's standard VID:PID unless specific sdkconfig options are present. The numbers already defined for the CUSTOM_* config options were ignored otherwise. Signed-off-by: Luca Burelli --- ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board b/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board index 888e225763d4..d586dd4ce40d 100644 --- a/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board +++ b/ports/esp32/boards/ARDUINO_NANO_ESP32/sdkconfig.board @@ -11,6 +11,8 @@ CONFIG_SPIRAM_IGNORE_NOTFOUND= CONFIG_LWIP_LOCAL_HOSTNAME="nano-esp32" +CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID=n +CONFIG_TINYUSB_DESC_USE_DEFAULT_PID=n CONFIG_TINYUSB_DESC_CUSTOM_VID=0x2341 CONFIG_TINYUSB_DESC_CUSTOM_PID=0x056B CONFIG_TINYUSB_DESC_MANUFACTURER_STRING="Arduino" From 92717a95c048932e1085ff34ca799835515e442b Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 4 Oct 2023 15:44:25 +1100 Subject: [PATCH 66/78] tools/metrics.py: Fix esp32 and esp8266 board names after renaming. Signed-off-by: Damien George --- tools/metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/metrics.py b/tools/metrics.py index 95156e3012d0..9c5ed1d7d5a6 100755 --- a/tools/metrics.py +++ b/tools/metrics.py @@ -64,8 +64,8 @@ def __init__(self, name, dir, output, make_flags=None): "n": PortData("unix nanbox", "unix", "build-nanbox/micropython", "VARIANT=nanbox"), "s": PortData("stm32", "stm32", "build-PYBV10/firmware.elf", "BOARD=PYBV10"), "c": PortData("cc3200", "cc3200", "build/WIPY/release/application.axf", "BTARGET=application"), - "8": PortData("esp8266", "esp8266", "build-GENERIC/firmware.elf"), - "3": PortData("esp32", "esp32", "build-GENERIC/micropython.elf"), + "8": PortData("esp8266", "esp8266", "build-ESP8266_GENERIC/firmware.elf"), + "3": PortData("esp32", "esp32", "build-ESP32_GENERIC/micropython.elf"), "x": PortData("mimxrt", "mimxrt", "build-TEENSY40/firmware.elf"), "e": PortData("renesas-ra", "renesas-ra", "build-EK_RA6M2/firmware.elf"), "r": PortData("nrf", "nrf", "build-PCA10040/firmware.elf"), From cac666f38cbce488a12c4fdcd28c2bb9d084368e Mon Sep 17 00:00:00 2001 From: stijn Date: Tue, 3 Oct 2023 13:12:42 +0200 Subject: [PATCH 67/78] extmod/vfs_posix_file: Fix flush handling in msvc builds. Flushing console output in msvc builds always fails because that output is not buffered so don't propagate that as an error (in a simlar way as was done in 1c047742 for macOS). Signed-off-by: stijn --- extmod/vfs_posix_file.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 488593230c74..81a608d2b66c 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -153,11 +153,14 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_ switch (request) { case MP_STREAM_FLUSH: { int ret; - // fsync(stdin/stdout/stderr) may fail with EINVAL (or ENOTSUP on macos), - // but don't propagate that error out. Because data is not buffered by - // us, and stdin/out/err.flush() should just be a no-op. - #ifdef __APPLE__ + // fsync(stdin/stdout/stderr) may fail with EINVAL (or ENOTSUP on macos or EBADF + // on windows), because the OS doesn't buffer these except for instance when they + // are redirected from/to file, but don't propagate that error out. Because data + // is not buffered by us, and stdin/out/err.flush() should just be a no-op. + #if defined(__APPLE__) #define VFS_POSIX_STREAM_STDIO_ERR_CATCH (err == EINVAL || err == ENOTSUP) + #elif defined(_MSC_VER) + #define VFS_POSIX_STREAM_STDIO_ERR_CATCH (err == EINVAL || err == EBADF) #else #define VFS_POSIX_STREAM_STDIO_ERR_CATCH (err == EINVAL) #endif From 5aec051f9f0e1be9750ca4f08478275f298087a3 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 3 Oct 2023 17:51:55 +0200 Subject: [PATCH 68/78] stm32/i2c: Add support for I2C4 on H7 MCUs. The current code assumes all I2Cs are on the same peripheral bus, which is not true for I2C4 and the same goes for the clock enable code. Signed-off-by: iabdalkader --- ports/stm32/i2c.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c index 65271b352525..42aba2eccbe5 100644 --- a/ports/stm32/i2c.c +++ b/ports/stm32/i2c.c @@ -285,8 +285,17 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) { STATIC uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C]; +static uint32_t i2c_get_id(i2c_t *i2c) { + #if defined(STM32H7) + if (i2c == I2C4) { + return 3; + } + #endif + return ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); +} + int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t freq, uint16_t timeout_ms) { - uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); + uint32_t i2c_id = i2c_get_id(i2c); // Init pins if (!mp_hal_pin_config_alt(scl, MP_HAL_PIN_MODE_ALT_OPEN_DRAIN, MP_HAL_PIN_PULL_UP, AF_FN_I2C, i2c_id + 1)) { @@ -300,9 +309,22 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr i2c_timeout_ms[i2c_id] = timeout_ms; // Enable I2C peripheral clock - RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id; - volatile uint32_t tmp = RCC->APB1ENR; // delay after RCC clock enable + volatile uint32_t tmp; (void)tmp; + switch (i2c_id) { + case 0: + case 1: + case 2: + RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id; + tmp = RCC->APB1ENR; // delay after RCC clock enable + break; + #if defined(STM32H7) + case 3: + RCC->APB4ENR |= RCC_APB4ENR_I2C4EN; + tmp = RCC->APB4ENR; // delay after RCC clock enable + break; + #endif + } // Initialise I2C peripheral i2c->CR1 = 0; @@ -340,7 +362,8 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr } STATIC int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) { - uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); + uint32_t i2c_id = i2c_get_id(i2c); + uint32_t t0 = HAL_GetTick(); while (i2c->CR2 & mask) { if (HAL_GetTick() - t0 >= i2c_timeout_ms[i2c_id]) { @@ -352,7 +375,8 @@ STATIC int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) { } STATIC int i2c_wait_isr_set(i2c_t *i2c, uint32_t mask) { - uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); + uint32_t i2c_id = i2c_get_id(i2c); + uint32_t t0 = HAL_GetTick(); while (!(i2c->ISR & mask)) { if (HAL_GetTick() - t0 >= i2c_timeout_ms[i2c_id]) { From 5d53783a461ff648c37a14f2e30dd468f293bebb Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 5 Oct 2023 11:20:05 +1100 Subject: [PATCH 69/78] lib/cyw43-driver: Update driver to latest version v1.0.2. Includes more error checking, and a fix to handle buffer overflow when getting STA MACs. Signed-off-by: Damien George --- lib/cyw43-driver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cyw43-driver b/lib/cyw43-driver index 8ef38a6d32c5..2ab0db6e1fe9 160000 --- a/lib/cyw43-driver +++ b/lib/cyw43-driver @@ -1 +1 @@ -Subproject commit 8ef38a6d32c54f850bff8f189bdca19ded33792a +Subproject commit 2ab0db6e1fe9265fa9802a95f7f4d60b7f0d655a From 342ebcb41d14197b1a2424bac8ff131ddf8e841d Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 5 Oct 2023 11:21:34 +1100 Subject: [PATCH 70/78] lib/micropython-lib: Update submodule to latest. Signed-off-by: Damien George --- lib/micropython-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micropython-lib b/lib/micropython-lib index c11361176527..e025c843b60e 160000 --- a/lib/micropython-lib +++ b/lib/micropython-lib @@ -1 +1 @@ -Subproject commit c113611765278b2fc8dcf8b2f2c3513b35a69b39 +Subproject commit e025c843b60e93689f0f991d753010bb5bd6a722 From 040a96d00eaec0990541debc0310a6ff56d082d0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 5 Oct 2023 14:04:45 +1100 Subject: [PATCH 71/78] docs,tools: Change remaining "urequests" references to "requests". Signed-off-by: Damien George --- docs/esp32/quickref.rst | 2 +- tools/manifestfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst index 5be737fa2d76..e03a5ffbc9d2 100644 --- a/docs/esp32/quickref.rst +++ b/docs/esp32/quickref.rst @@ -101,7 +101,7 @@ A useful function for connecting to your local WiFi network is:: print('network config:', wlan.ifconfig()) Once the network is established the :mod:`socket ` module can be used -to create and use TCP/UDP sockets as usual, and the ``urequests`` module for +to create and use TCP/UDP sockets as usual, and the ``requests`` module for convenient HTTP requests. After a call to ``wlan.connect()``, the device will by default retry to connect diff --git a/tools/manifestfile.py b/tools/manifestfile.py index 3b613d9e1dca..295170c34cab 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -106,7 +106,7 @@ def __init__(self, is_require=False): self.stdlib = False # Allows a python-ecosys package to be annotated with the - # corresponding name in PyPI. e.g. micropython-lib/urequests is based + # corresponding name in PyPI. e.g. micropython-lib/requests is based # on pypi/requests. self.pypi = None # For a micropython package, this is the name that we will publish it From d81cf0b9e39dd0526ccbf6c131e62cd8fb33f3e9 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 5 Oct 2023 13:09:40 +1100 Subject: [PATCH 72/78] rp2/CMakeLists: Enable debug symbols in all builds. Allows using gdb, addr2line, etc. on a "release" ELF file. No impact to .bin or .uf2 size, only the .elf will get bigger. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/rp2/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 7718697b438f..fae4cda75633 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -406,6 +406,7 @@ target_include_directories(${MICROPY_TARGET} PRIVATE target_compile_options(${MICROPY_TARGET} PRIVATE -Wall -Werror + -g # always include debug information in the ELF ) target_link_options(${MICROPY_TARGET} PRIVATE From f0f173ff5c09ae1bd4edee72ef3ec67a96b87279 Mon Sep 17 00:00:00 2001 From: Glenn Moloney Date: Wed, 4 Oct 2023 13:51:41 +1100 Subject: [PATCH 73/78] esp32/boards/manifest.py: Freeze aioespnow into firmware by default. Also remove corresponding commented line from esp8266/boards/manifest.py. It doesn't have enough flash to have this frozen by default. Signed-off-by: Glenn Moloney --- ports/esp32/boards/manifest.py | 2 +- ports/esp8266/boards/manifest.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/esp32/boards/manifest.py b/ports/esp32/boards/manifest.py index 290d98c4e499..135e2c4d2dfa 100644 --- a/ports/esp32/boards/manifest.py +++ b/ports/esp32/boards/manifest.py @@ -5,7 +5,7 @@ require("bundle-networking") # Require some micropython-lib modules. -# require("aioespnow") +require("aioespnow") require("dht") require("ds18x20") require("neopixel") diff --git a/ports/esp8266/boards/manifest.py b/ports/esp8266/boards/manifest.py index 17f58feac88a..10fa6da2796e 100644 --- a/ports/esp8266/boards/manifest.py +++ b/ports/esp8266/boards/manifest.py @@ -1,5 +1,4 @@ freeze("$(PORT_DIR)/modules") -# require("aioespnow") require("bundle-networking") require("dht") require("ds18x20") From c2e9a6f2a566ce4e1045f3ab93969a1b43543c6c Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 5 Oct 2023 13:25:55 +1100 Subject: [PATCH 74/78] esp8266/boards/ESP8266_GENERIC: Remove urllib from the 2MiB manifest. No other network-enabled board has urllib.urequest frozen in to the firmware, and esp8266 is relatively low on flash, so remove this module. And (u)requests is already included by bundle-networking. Signed-off-by: Damien George --- ports/esp8266/boards/ESP8266_GENERIC/manifest_2MiB.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ports/esp8266/boards/ESP8266_GENERIC/manifest_2MiB.py b/ports/esp8266/boards/ESP8266_GENERIC/manifest_2MiB.py index fd9c41dc5423..e4f44b43b99d 100644 --- a/ports/esp8266/boards/ESP8266_GENERIC/manifest_2MiB.py +++ b/ports/esp8266/boards/ESP8266_GENERIC/manifest_2MiB.py @@ -10,10 +10,6 @@ # micropython-lib: file utilities require("upysh") -# micropython-lib: requests -require("urequests") -require("urllib.urequest") - # micropython-lib: umqtt require("umqtt.simple") require("umqtt.robust") From 6f76d1c7fa28c4bcb94a1fa33e3cca1ba8c8cdfd Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 5 Oct 2023 16:32:19 +1100 Subject: [PATCH 75/78] rp2: Implement time.time_ns with time_us_64 so it has us resolution. Currently on rp2 the time.time_ns() function has only seconds resolution. This commit makes it have microsecond resolution, by using the output of time_us_64() instead of the RTC. Tested that it does not drift from the RTC over long periods of time. Signed-off-by: Damien George --- ports/rp2/machine_rtc.c | 2 ++ ports/rp2/main.c | 1 + ports/rp2/mphalport.c | 25 +++++++++++++++++++++++-- ports/rp2/mphalport.h | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ports/rp2/machine_rtc.c b/ports/rp2/machine_rtc.c index a9d3426cf838..25d65eda6989 100644 --- a/ports/rp2/machine_rtc.c +++ b/ports/rp2/machine_rtc.c @@ -58,6 +58,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s rtc_init(); datetime_t t = { .month = 1, .day = 1 }; rtc_set_datetime(&t); + mp_hal_time_ns_set_from_rtc(); } // return constant object return (mp_obj_t)&machine_rtc_obj; @@ -104,6 +105,7 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { if (!rtc_set_datetime(&t)) { mp_raise_OSError(MP_EINVAL); } + mp_hal_time_ns_set_from_rtc(); } return mp_const_none; diff --git a/ports/rp2/main.c b/ports/rp2/main.c index ff0384b95292..72b243a5984c 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -106,6 +106,7 @@ int main(int argc, char **argv) { }; rtc_init(); rtc_set_datetime(&t); + mp_hal_time_ns_set_from_rtc(); // Initialise stack extents and GC heap. mp_stack_set_top(&__StackTop); diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index 52d55198b7dc..d1bba43642e3 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -39,6 +39,10 @@ #include "lib/cyw43-driver/src/cyw43.h" #endif +// This needs to be added to the result of time_us_64() to get the number of +// microseconds since the Epoch. +STATIC uint64_t time_us_64_offset_from_epoch; + #if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC #ifndef MICROPY_HW_STDIN_BUFFER_LEN @@ -176,11 +180,28 @@ void mp_hal_delay_ms(mp_uint_t ms) { } } -uint64_t mp_hal_time_ns(void) { +void mp_hal_time_ns_set_from_rtc(void) { + // Delay at least one RTC clock cycle so it's registers have updated with the most + // recent time settings. + sleep_us(23); + + // Sample RTC and time_us_64() as close together as possible, so the offset + // calculated for the latter can be as accurate as possible. datetime_t t; rtc_get_datetime(&t); + uint64_t us = time_us_64(); + + // Calculate the difference between the RTC Epoch seconds and time_us_64(). uint64_t s = timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec); - return s * 1000000000ULL; + time_us_64_offset_from_epoch = (uint64_t)s * 1000000ULL - us; +} + +uint64_t mp_hal_time_ns(void) { + // The RTC only has seconds resolution, so instead use time_us_64() to get a more + // precise measure of Epoch time. Both these "clocks" are clocked from the same + // source so they remain synchronised, and only differ by a fixed offset (calculated + // in mp_hal_time_ns_set_from_rtc). + return (time_us_64_offset_from_epoch + time_us_64()) * 1000ULL; } // Generate a random locally administered MAC address (LAA) diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index 8b4a5b609377..95e7cba2c542 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -39,6 +39,7 @@ extern int mp_interrupt_char; extern ringbuf_t stdin_ringbuf; void mp_hal_set_interrupt_char(int c); +void mp_hal_time_ns_set_from_rtc(void); static inline void mp_hal_delay_us(mp_uint_t us) { sleep_us(us); From e00a144008f368df878c12606fdbf651af2a1dc0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 6 Oct 2023 10:32:07 +1100 Subject: [PATCH 76/78] all: Bump version to 1.21.0. Signed-off-by: Damien George --- py/mpconfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/mpconfig.h b/py/mpconfig.h index 9a7eb1b15d05..eb3a0eb7368a 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -28,7 +28,7 @@ // Current version of MicroPython #define MICROPY_VERSION_MAJOR 1 -#define MICROPY_VERSION_MINOR 20 +#define MICROPY_VERSION_MINOR 21 #define MICROPY_VERSION_MICRO 0 // Combined version as a 32-bit number for convenience From 69e34b6b6bdf45bc1111777c46839a8b5fcb30bd Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Wed, 4 Oct 2023 11:20:47 +1100 Subject: [PATCH 77/78] all: Switch to new preview build versioning scheme. See https://github.com/micropython/micropython/issues/12127 for details. Previously at the point when a release is made, we update mpconfig.h and set a git tag. i.e. the version increments at the release. Now the version increments immediately after the release. The workflow is: 1. Final commit in the cycle updates mpconfig.h to set (X, Y, 0, 0) (i.e. clear the pre-release state). 2. This commit is tagged "vX.Y.0". 3. First commit for the new cycle updates mpconfig.h to set (X, Y+1, 0, 1) (i.e. increment the minor version, set the pre-release state). 4. This commit is tagged "vX.Y+1.0-preview". The idea is that a nightly build is actually a "preview" of the _next_ release. i.e. any documentation describing the current release may not actually match the nightly build. So we use "preview" as our semver pre-release identifier. Changes in this commit: - Add MICROPY_VERSION_PRERELEASE to mpconfig.h to allow indicating that this is not a release version. - Remove unused MICROPY_VERSION integer. - Append "-preview" to MICROPY_VERSION_STRING when the pre-release state is set. - Update py/makeversionhdr.py to no longer generate MICROPY_GIT_HASH. - Remove the one place MICROPY_GIT_HASH was used (it can use MICROPY_GIT_TAG instead). - Update py/makeversionhdr.py to also understand MICROPY_VERSION_PRERELEASE in mpconfig.h. - Update py/makeversionhdr.py to convert the git-describe output into semver-compatible "X.Y.Z-preview.N.gHASH". - Update autobuild.sh to generate filenames using the new scheme. - Update remove_old_firmware.py to match new scheme. - Update mpremote's pyproject.toml to handle the "-preview" suffix in the tag. setuptools_scm maps to this "rc0" to match PEP440. - Fix docs heading where it incorrectly said "vvX.Y.Z" for release docs. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- docs/conf.py | 4 +- docs/templates/layout.html | 2 +- ports/cc3200/tools/update-wipy.py | 4 +- py/makeversionhdr.py | 91 +++++++++++++------------- py/modsys.c | 20 ++++-- py/mpconfig.h | 32 +++++---- tools/autobuild/autobuild.sh | 14 +++- tools/autobuild/remove_old_firmware.py | 22 ++++--- tools/mpremote/pyproject.toml | 7 +- 9 files changed, 117 insertions(+), 79 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0dbbfe0f706c..49ddd22be980 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,10 +21,12 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('.')) -# The members of the html_context dict are available inside topindex.html +# The MICROPY_VERSION env var should be "vX.Y.Z" (or unset). micropy_version = os.getenv('MICROPY_VERSION') or 'latest' micropy_all_versions = (os.getenv('MICROPY_ALL_VERSIONS') or 'latest').split(',') url_pattern = '%s/en/%%s' % (os.getenv('MICROPY_URL_PREFIX') or '/',) + +# The members of the html_context dict are available inside topindex.html html_context = { 'cur_version':micropy_version, 'all_versions':[ diff --git a/docs/templates/layout.html b/docs/templates/layout.html index 8563f02af00a..21dab5eb42f1 100644 --- a/docs/templates/layout.html +++ b/docs/templates/layout.html @@ -9,7 +9,7 @@ {% if is_release %}

- This is the v{{ release }} version of the MicroPython + This is the {{ release }} version of the MicroPython documentation. The latest development version of this page may be more current.

diff --git a/ports/cc3200/tools/update-wipy.py b/ports/cc3200/tools/update-wipy.py index 7f5527a52bb5..e37f3a0b0912 100644 --- a/ports/cc3200/tools/update-wipy.py +++ b/ports/cc3200/tools/update-wipy.py @@ -152,9 +152,9 @@ def find_tag(tag): with open(tag_file_path) as tag_file: for line in tag_file: bline = bytes(line, "ascii") - if b"MICROPY_GIT_HASH" in bline: + if b"MICROPY_GIT_TAG" in bline: bline = ( - bline.lstrip(b"#define MICROPY_GIT_HASH ") + bline.lstrip(b"#define MICROPY_GIT_TAG ") .replace(b'"', b"") .replace(b"\r", b"") .replace(b"\n", b"") diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index e682a4e139cc..2030bb02c4cd 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -13,6 +13,14 @@ import subprocess +# The MicroPython repository tags a release commit as "vX.Y.Z", and the commit +# immediately following as "vX.(Y+1).Z-preview". +# This function will return: +# "vX.Y.Z" -- building at the release commit +# "vX.Y.Z-preview" -- building at the first commit in the next cycle +# "vX.Y.Z-preview.N.gHASH" -- building at any subsequent commit in the cycle +# "vX.Y.Z-preview.N.gHASH.dirty" -- building at any subsequent commit in the cycle +# with local changes def get_version_info_from_git(repo_path): # Python 2.6 doesn't have check_output, so check for that try: @@ -29,47 +37,33 @@ def get_version_info_from_git(repo_path): stderr=subprocess.STDOUT, universal_newlines=True, ).strip() - except subprocess.CalledProcessError as er: - if er.returncode == 128: - # git exit code of 128 means no repository found - return None - git_tag = "" - except OSError: - return None - try: - git_hash = subprocess.check_output( - ["git", "rev-parse", "--short", "HEAD"], - cwd=repo_path, - stderr=subprocess.STDOUT, - universal_newlines=True, - ).strip() + # Turn git-describe's output into semver compatible (dot-separated + # identifiers inside the prerelease field). + git_tag = git_tag.split("-", 1) + if len(git_tag) == 1: + return git_tag[0] + else: + return git_tag[0] + "-" + git_tag[1].replace("-", ".") except subprocess.CalledProcessError: - git_hash = "unknown" - except OSError: return None - - try: - # Check if there are any modified files. - subprocess.check_call( - ["git", "diff", "--no-ext-diff", "--quiet", "--exit-code"], - cwd=repo_path, - stderr=subprocess.STDOUT, - ) - # Check if there are any staged files. - subprocess.check_call( - ["git", "diff-index", "--cached", "--quiet", "HEAD", "--"], - cwd=repo_path, - stderr=subprocess.STDOUT, - ) - except subprocess.CalledProcessError: - git_hash += "-dirty" except OSError: return None - return git_tag, git_hash - +# When building from a source tarball (or any situation where the git repo +# isn't available), this function will use the info in mpconfig.h as a +# fallback. The release commit sets MICROPY_VERSION_PRERELEASE to 0, and the +# commit immediately following increments MICROPY_VERSION_MINOR and sets +# MICROPY_VERSION_PRERELEASE back to 1. +# This function will return: +# "vX.Y.Z" -- building at the release commit +# "vX.Y.Z-preview" -- building at any other commit def get_version_info_from_mpconfig(repo_path): + print( + "makeversionhdr.py: Warning: No git repo or tag info available, falling back to mpconfig.h version info.", + file=sys.stderr, + ) + with open(os.path.join(repo_path, "py", "mpconfig.h")) as f: for line in f: if line.startswith("#define MICROPY_VERSION_MAJOR "): @@ -78,21 +72,30 @@ def get_version_info_from_mpconfig(repo_path): ver_minor = int(line.strip().split()[2]) elif line.startswith("#define MICROPY_VERSION_MICRO "): ver_micro = int(line.strip().split()[2]) - git_tag = "v%d.%d.%d" % (ver_major, ver_minor, ver_micro) - return git_tag, "" + elif line.startswith("#define MICROPY_VERSION_PRERELEASE "): + ver_prerelease = int(line.strip().split()[2]) + git_tag = "v%d.%d.%d%s" % ( + ver_major, + ver_minor, + ver_micro, + "-preview" if ver_prerelease else "", + ) + return git_tag return None def make_version_header(repo_path, filename): - info = None + git_tag = None if "MICROPY_GIT_TAG" in os.environ: - info = [os.environ["MICROPY_GIT_TAG"], os.environ["MICROPY_GIT_HASH"]] - if info is None: - info = get_version_info_from_git(repo_path) - if info is None: - info = get_version_info_from_mpconfig(repo_path) + git_tag = os.environ["MICROPY_GIT_TAG"] + if git_tag is None: + git_tag = get_version_info_from_git(repo_path) + if git_tag is None: + git_tag = get_version_info_from_mpconfig(repo_path) - git_tag, git_hash = info + if not git_tag: + print("makeversionhdr.py: Error: No version information available.") + sys.exit(1) build_date = datetime.date.today() if "SOURCE_DATE_EPOCH" in os.environ: @@ -104,11 +107,9 @@ def make_version_header(repo_path, filename): file_data = """\ // This file was generated by py/makeversionhdr.py #define MICROPY_GIT_TAG "%s" -#define MICROPY_GIT_HASH "%s" #define MICROPY_BUILD_DATE "%s" """ % ( git_tag, - git_hash, build_date.strftime("%Y-%m-%d"), ) diff --git a/py/modsys.c b/py/modsys.c index 38105ee21894..e40542467b32 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -59,16 +59,24 @@ const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adap STATIC const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); // version_info - Python language version that this implementation conforms to, as a tuple of ints -#define I(n) MP_OBJ_NEW_SMALL_INT(n) -// TODO: CPython is now at 5-element array, but save 2 els so far... -STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3), I(4), I(0)}}; +// TODO: CPython is now at 5-element array (major, minor, micro, releaselevel, serial), but save 2 els so far... +STATIC const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; // sys.implementation object // this holds the MicroPython version -STATIC const mp_obj_tuple_t mp_sys_implementation_version_info_obj = { +STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { {&mp_type_tuple}, - 3, - { I(MICROPY_VERSION_MAJOR), I(MICROPY_VERSION_MINOR), I(MICROPY_VERSION_MICRO) } + 4, + { + MP_ROM_INT(MICROPY_VERSION_MAJOR), + MP_ROM_INT(MICROPY_VERSION_MINOR), + MP_ROM_INT(MICROPY_VERSION_MICRO), + #if MICROPY_VERSION_PRERELEASE + MP_ROM_QSTR(MP_QSTR_preview), + #else + MP_ROM_QSTR(MP_QSTR_), + #endif + } }; STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); #if MICROPY_PERSISTENT_CODE_LOAD diff --git a/py/mpconfig.h b/py/mpconfig.h index eb3a0eb7368a..a36f9658fbdd 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -26,22 +26,32 @@ #ifndef MICROPY_INCLUDED_PY_MPCONFIG_H #define MICROPY_INCLUDED_PY_MPCONFIG_H -// Current version of MicroPython +// Current version of MicroPython. This is used by sys.implementation.version +// as well as a fallback to generate MICROPY_GIT_TAG if the git repo or tags +// are unavailable. #define MICROPY_VERSION_MAJOR 1 -#define MICROPY_VERSION_MINOR 21 +#define MICROPY_VERSION_MINOR 22 #define MICROPY_VERSION_MICRO 0 - -// Combined version as a 32-bit number for convenience -#define MICROPY_VERSION ( \ - MICROPY_VERSION_MAJOR << 16 \ - | MICROPY_VERSION_MINOR << 8 \ - | MICROPY_VERSION_MICRO) - -// String version -#define MICROPY_VERSION_STRING \ +#define MICROPY_VERSION_PRERELEASE 1 + +// Combined version as a 32-bit number for convenience to allow version +// comparison. Doesn't include prerelease state. +// e.g. #if MICROPY_VERSION < MICROPY_MAKE_VERSION(1, 22, 0) +#define MICROPY_MAKE_VERSION(major, minor, patch) (major << 16 | minor << 8 | patch) +#define MICROPY_VERSION MICROPY_MAKE_VERSION(MICROPY_VERSION_MAJOR, MICROPY_VERSION_MINOR, MICROPY_VERSION_MICRO) + +// String version. This is only used directly for platform.platform and +// os.uname().release. All other version info available in the firmware (e.g. +// the REPL banner) comes from MICROPY_GIT_TAG. +#define MICROPY_VERSION_STRING_BASE \ MP_STRINGIFY(MICROPY_VERSION_MAJOR) "." \ MP_STRINGIFY(MICROPY_VERSION_MINOR) "." \ MP_STRINGIFY(MICROPY_VERSION_MICRO) +#if MICROPY_VERSION_PRERELEASE +#define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE "-preview" +#else +#define MICROPY_VERSION_STRING MICROPY_VERSION_STRING_BASE +#endif // This file contains default configuration settings for MicroPython. // You can override any of the options below using mpconfigport.h file diff --git a/tools/autobuild/autobuild.sh b/tools/autobuild/autobuild.sh index e1f2287ee597..7854945bbee0 100755 --- a/tools/autobuild/autobuild.sh +++ b/tools/autobuild/autobuild.sh @@ -54,9 +54,19 @@ pushd ${MICROPY_AUTOBUILD_MICROPYTHON_REPO} make -C mpy-cross # make the firmware tag +# final filename will be <-VARIANT>--v.ext +# where SEMVER is vX.Y.Z or vX.Y.Z-preview.N.gHASH or vX.Y.Z-preview.N.gHASH.dirty FW_DATE=$(date '+%Y%m%d') -FW_GIT="$(git describe --dirty || echo unknown)" -FW_TAG="-$FW_DATE-unstable-$FW_GIT" +# same logic as makeversionhdr.py, convert git-describe output into semver-compatible +FW_GIT_TAG="$(git describe --tags --dirty --always --match 'v[1-9].*')" +FW_SEMVER_MAJOR_MINOR_PATCH="$(echo $FW_GIT_TAG | cut -d'-' -f1)" +FW_SEMVER_PRERELEASE="$(echo $FW_GIT_TAG | cut -s -d'-' -f2-)" +if [ -z "$FW_SEMVER_PRERELEASE" ]; then + FW_SEMVER="$FW_SEMVER_MAJOR_MINOR_PATCH" +else + FW_SEMVER="$FW_SEMVER_MAJOR_MINOR_PATCH-$(echo $FW_SEMVER_PRERELEASE | tr - .)" +fi +FW_TAG="-$FW_DATE-$FW_SEMVER" # build new firmware cd ports/cc3200 diff --git a/tools/autobuild/remove_old_firmware.py b/tools/autobuild/remove_old_firmware.py index e9d2e8aae8e9..a6203531c766 100755 --- a/tools/autobuild/remove_old_firmware.py +++ b/tools/autobuild/remove_old_firmware.py @@ -14,7 +14,7 @@ def main(): # SSH to get list of existing files. p = subprocess.run( - ["ssh", ssh_machine, "find", ssh_firmware_dir, "-name", "\\*-unstable-v\\*"], + ["ssh", ssh_machine, "find", ssh_firmware_dir, "-name", "\\*-preview.\\*"], capture_output=True, ) if p.returncode != 0: @@ -26,31 +26,33 @@ def main(): boards = {} for file in all_files: m = re.match( - rb"([a-z/.]+)/([A-Za-z0-9_-]+)-(20[0-9]{6})-unstable-(v[0-9.-]+-g[0-9a-f]+).", + rb"([a-z/.]+)/([A-Za-z0-9_-]+)-(20[0-9]{6})-(v[0-9.]+)-preview.([0-9]+).g[0-9a-f]+.", file, ) if not m: continue - dir, board, date, version = m.groups() + dir, board, date, version, ncommits = m.groups() if board not in boards: boards[board] = {} - if (date, version) not in boards[board]: - boards[board][(date, version)] = [] - boards[board][(date, version)].append(file) + if (date, version, ncommits) not in boards[board]: + boards[board][(date, version, ncommits)] = [] + boards[board][(date, version, ncommits)].append(file) # Collect files to remove based on date and version. remove = [] for board in boards.values(): - filelist = [(date, version, files) for (date, version), files in board.items()] + filelist = [ + (date, version, ncommits, files) for (date, version, ncommits), files in board.items() + ] filelist.sort(reverse=True) keep = [] - for date, version, files in filelist: - if keep and version == keep[-1]: + for date, version, ncommits, files in filelist: + if keep and (version, ncommits) == keep[-1]: remove.extend(files) elif len(keep) >= NUM_KEEP_PER_BOARD: remove.extend(files) else: - keep.append(version) + keep.append((version, ncommits)) if DEBUG: all_files.sort(reverse=True) diff --git a/tools/mpremote/pyproject.toml b/tools/mpremote/pyproject.toml index b01385c3d578..746b40bfdd18 100644 --- a/tools/mpremote/pyproject.toml +++ b/tools/mpremote/pyproject.toml @@ -36,9 +36,14 @@ mpremote = "mpremote.main:main" [tool.hatch.metadata.hooks.requirements_txt] files = ["requirements.txt"] +# This will be PEP-440 normalised into either: +# mpremote-X.Y.Z (on vX.Y.Z release tag) +# mpremote-X.Y.Zrc0 (on vX.Y.Z-preview tag, i.e. first commit in the cycle) +# mpremote-X.Y.Zrc0.postN+gHASH (N commits past vX.Y.Z-preview tag) +# mpremote-X.Y.Zrc0.postN+gHASH.dDATE (N commits past vX.Y.Z-preview tag, dirty) [tool.hatch.version] source = "vcs" -tag-pattern = "(?Pv(\\d+).(\\d+).(\\d+))" +tag-pattern = "(?Pv(\\d+).(\\d+).(\\d+)(-preview)?)" raw-options = { root = "../..", version_scheme = "post-release" } [tool.hatch.build] From 5232847771903e9022c8c67a436b0562e4530602 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 6 Oct 2023 15:57:15 +1100 Subject: [PATCH 78/78] README.md: Update CI badges. - Fix URL for the unix badge. - Add stm32 CI badge. - Add docs CI badge (linking to the documentation) - Make docs CI run on push (so we get a badge generated). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- .github/workflows/docs.yml | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index a0105d6ca60e..e0b6fdaba038 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,6 +1,7 @@ name: Build docs on: + push: pull_request: paths: - docs/** diff --git a/README.md b/README.md index 6482899b251d..e6c0a09b8b55 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CI badge](https://github.com/micropython/micropython/workflows/unix%20port/badge.svg)](https://github.com/micropython/micropython/actions?query=branch%3Amaster+event%3Apush) [![codecov](https://codecov.io/gh/micropython/micropython/branch/master/graph/badge.svg?token=I92PfD05sD)](https://codecov.io/gh/micropython/micropython) +[![Unix CI badge](https://github.com/micropython/micropython/actions/workflows/ports_unix.yml/badge.svg)](https://github.com/micropython/micropython/actions?query=branch%3Amaster+event%3Apush) [![STM32 CI badge](https://github.com/micropython/micropython/actions/workflows/ports_stm32.yml/badge.svg)](https://github.com/micropython/micropython/actions?query=branch%3Amaster+event%3Apush) [![Docs CI badge](https://github.com/micropython/micropython/actions/workflows/docs.yml/badge.svg)](https://docs.micropython.org/) [![codecov](https://codecov.io/gh/micropython/micropython/branch/master/graph/badge.svg?token=I92PfD05sD)](https://codecov.io/gh/micropython/micropython) The MicroPython project =======================