diff --git a/docs/psoc6/quickref.rst b/docs/psoc6/quickref.rst index 7a81c18f63323..efe397d597fee 100644 --- a/docs/psoc6/quickref.rst +++ b/docs/psoc6/quickref.rst @@ -426,6 +426,7 @@ Methods ^^^^^^^ All the methods(functions) given in :ref:`machine.SPI ` class have been implemented in this port + ADC (analog to digital conversion) ---------------------------------- diff --git a/ports/esp32/boards/GENERIC_OTA/sdkconfig.board b/ports/esp32/boards/GENERIC_OTA/sdkconfig.board index d314860cc9378..7ff939aa991f2 100644 --- a/ports/esp32/boards/GENERIC_OTA/sdkconfig.board +++ b/ports/esp32/boards/GENERIC_OTA/sdkconfig.board @@ -1,3 +1,6 @@ CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-ota.csv" + +# Reduce firmware size to fit in the OTA partition. +CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y diff --git a/ports/esp32/main_esp32/idf_component.yml b/ports/esp32/main_esp32/idf_component.yml new file mode 100644 index 0000000000000..8be21ed2fbe87 --- /dev/null +++ b/ports/esp32/main_esp32/idf_component.yml @@ -0,0 +1,5 @@ +## IDF Component Manager Manifest File +dependencies: + espressif/mdns: "~1.1.0" + idf: + version: ">=5.0.2" diff --git a/ports/esp32/main_esp32c3/idf_component.yml b/ports/esp32/main_esp32c3/idf_component.yml new file mode 100644 index 0000000000000..8be21ed2fbe87 --- /dev/null +++ b/ports/esp32/main_esp32c3/idf_component.yml @@ -0,0 +1,5 @@ +## IDF Component Manager Manifest File +dependencies: + espressif/mdns: "~1.1.0" + idf: + version: ">=5.0.2" diff --git a/ports/esp32/main_esp32s2/idf_component.yml b/ports/esp32/main_esp32s2/idf_component.yml index fe3213bd26af2..69e27bf8b54bc 100644 --- a/ports/esp32/main_esp32s2/idf_component.yml +++ b/ports/esp32/main_esp32s2/idf_component.yml @@ -1,5 +1,6 @@ ## IDF Component Manager Manifest File dependencies: + espressif/mdns: "~1.1.0" + espressif/esp_tinyusb: "~1.0.0" idf: version: ">=5.0.2" - espressif/esp_tinyusb: "~1.0.0" diff --git a/ports/esp32/main_esp32s3/idf_component.yml b/ports/esp32/main_esp32s3/idf_component.yml index fe3213bd26af2..69e27bf8b54bc 100644 --- a/ports/esp32/main_esp32s3/idf_component.yml +++ b/ports/esp32/main_esp32s3/idf_component.yml @@ -1,5 +1,6 @@ ## IDF Component Manager Manifest File dependencies: + espressif/mdns: "~1.1.0" + espressif/esp_tinyusb: "~1.0.0" idf: version: ">=5.0.2" - espressif/esp_tinyusb: "~1.0.0" diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 7484fce786c74..ba1fe096f6946 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -58,6 +58,10 @@ #define MDNS_QUERY_TIMEOUT_MS (5000) #define MDNS_LOCAL_SUFFIX ".local" +#ifndef NO_QSTR +#include "mdns.h" +#endif + enum { SOCKET_STATE_NEW, SOCKET_STATE_CONNECTED, diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index b18681bb572df..e97980c36f467 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -221,11 +221,11 @@ typedef long mp_off_t; #endif #ifndef MICROPY_HW_ENABLE_MDNS_QUERIES -#define MICROPY_HW_ENABLE_MDNS_QUERIES (0) +#define MICROPY_HW_ENABLE_MDNS_QUERIES (1) #endif #ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER -#define MICROPY_HW_ENABLE_MDNS_RESPONDER (0) +#define MICROPY_HW_ENABLE_MDNS_RESPONDER (1) #endif #ifndef MICROPY_BOARD_STARTUP diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index cfedd898cdf24..3c88f8db8682a 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -42,6 +42,10 @@ #include "esp_wifi.h" #include "esp_log.h" +#ifndef NO_QSTR +#include "mdns.h" +#endif + #if MICROPY_PY_NETWORK_WLAN #if (WIFI_MODE_STA & WIFI_MODE_AP != WIFI_MODE_NULL || WIFI_MODE_STA | WIFI_MODE_AP != WIFI_MODE_APSTA) diff --git a/ports/psoc6/modules/machine/modmachine.h b/ports/psoc6/modules/machine/modmachine.h index 9794fd9892b5a..5d1f9980cc647 100644 --- a/ports/psoc6/modules/machine/modmachine.h +++ b/ports/psoc6/modules/machine/modmachine.h @@ -14,7 +14,6 @@ extern const mp_obj_type_t machine_spi_type; extern const mp_obj_type_t machine_adc_type; extern const mp_obj_type_t machine_adcblock_type; - /* Note: the static functions' prototypes in the .c file cannot be declared here since they are static. The static type in those functions come from MPY hence should stay that way. */ diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index d5030b7e46da2..81a48249e89d3 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -404,7 +404,7 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ ll_utils.c \ ) -ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l4 wb)) +ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l1 l4 wb)) HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ hal_pcd.c \ hal_pcd_ex.c \ diff --git a/ports/stm32/boards/NUCLEO_L152RE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L152RE/mpconfigboard.h index 3609955893fe1..5b83a980ce164 100644 --- a/ports/stm32/boards/NUCLEO_L152RE/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_L152RE/mpconfigboard.h @@ -7,6 +7,7 @@ #define MICROPY_HW_RTC_USE_LSE (1) #define MICROPY_HW_ENABLE_SERVO (1) #define MICROPY_HW_ENABLE_DAC (1) +#define MICROPY_HW_ENABLE_USB (0) // HSE is 8MHz, HSI is 16MHz CPU freq set to 32MHz // Default source for the clock is HSI. @@ -72,3 +73,11 @@ #define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_low(pin)) #define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_1 + +// USB config +#if MICROPY_HW_ENABLE_USB +#if MICROPY_HW_CLK_USE_HSI +#error STM32L152RE cannot use USB feature with HSI clock. Use HSE. +#endif +#define MICROPY_HW_USB_FS (1) +#endif diff --git a/ports/stm32/boards/stm32l1xx_hal_conf_base.h b/ports/stm32/boards/stm32l1xx_hal_conf_base.h index b839fd29f0a3d..5871e8a45a6f2 100644 --- a/ports/stm32/boards/stm32l1xx_hal_conf_base.h +++ b/ports/stm32/boards/stm32l1xx_hal_conf_base.h @@ -26,6 +26,9 @@ #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" @@ -38,6 +41,7 @@ #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" @@ -50,6 +54,7 @@ #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 diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index 1869b984dab0a..69fe8f4f54a83 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -387,7 +387,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsle STATIC mp_obj_t machine_reset_cause(void) { return MP_OBJ_NEW_SMALL_INT(reset_cause); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); +MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); #if MICROPY_PY_MACHINE diff --git a/ports/stm32/modmachine.h b/ports/stm32/modmachine.h index 0c776280b416c..28d9c699d63fc 100644 --- a/ports/stm32/modmachine.h +++ b/ports/stm32/modmachine.h @@ -29,7 +29,6 @@ #include "py/obj.h" extern const mp_obj_type_t machine_adc_type; -extern const mp_obj_type_t machine_timer_type; extern const mp_obj_type_t machine_i2c_type; extern const mp_obj_type_t machine_i2s_type; extern const mp_obj_type_t machine_spi_type; @@ -49,6 +48,7 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj); MP_DECLARE_CONST_FUN_OBJ_0(machine_idle_obj); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj); +MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_cause_obj); MP_DECLARE_CONST_FUN_OBJ_0(machine_disable_irq_obj); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj); diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index 8f2a6e530a540..149d2ae73a636 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -586,7 +586,7 @@ // Whether the USB peripheral is device-only, or multiple OTG // For STM32G0 and STM32H5 the USB peripheral supports device and host mode, // but otherwise acts like a non-multi-OTG peripheral. -#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L0) || defined(STM32L432xx) || defined(STM32WB) +#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L0) || defined(STM32L1) || defined(STM32L432xx) || defined(STM32WB) #define MICROPY_HW_USB_IS_MULTI_OTG (0) #else #define MICROPY_HW_USB_IS_MULTI_OTG (1) diff --git a/ports/stm32/powerctrlboot.c b/ports/stm32/powerctrlboot.c index 149c34ae63ec4..51b740a809031 100644 --- a/ports/stm32/powerctrlboot.c +++ b/ports/stm32/powerctrlboot.c @@ -389,22 +389,7 @@ void SystemClock_Config(void) { powerctrl_config_systick(); #if MICROPY_HW_ENABLE_USB - // Enable the 48MHz internal oscillator - RCC->CRRCR |= RCC_CRRCR_HSI48ON; RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; - SYSCFG->CFGR3 |= SYSCFG_CFGR3_ENREF_HSI48; - while (!(RCC->CRRCR & RCC_CRRCR_HSI48RDY)) { - // Wait for HSI48 to be ready - } - - // Select RC48 as HSI48 for USB and RNG - RCC->CCIPR |= RCC_CCIPR_HSI48SEL; - - // Synchronise HSI48 with 1kHz USB SoF - __HAL_RCC_CRS_CLK_ENABLE(); - CRS->CR = 0x20 << CRS_CR_TRIM_Pos; - CRS->CFGR = 2 << CRS_CFGR_SYNCSRC_Pos | 0x22 << CRS_CFGR_FELIM_Pos - | __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000) << CRS_CFGR_RELOAD_Pos; #endif // Disable the Debug Module in low-power mode due to prevent diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index 84c05602b57b7..483537b649379 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -320,7 +320,7 @@ void USB_IRQHandler(void) { } #endif -#elif defined(STM32G4) || defined(STM32WB) +#elif defined(STM32G4) || defined(STM32L1) || defined(STM32WB) #if MICROPY_HW_USB_FS void USB_LP_IRQHandler(void) { diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c index 94d62f7625a57..c3b8544417d0b 100644 --- a/ports/stm32/usb.c +++ b/ports/stm32/usb.c @@ -59,7 +59,7 @@ #endif // Maximum number of endpoints (excluding EP0) -#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L0) || defined(STM32WB) +#if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L0) || defined(STM32L1) || defined(STM32WB) #define MAX_ENDPOINT(dev_id) (7) #elif defined(STM32L4) #define MAX_ENDPOINT(dev_id) (5) diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index 9f187fc08b57a..5d9e7177de564 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -75,6 +75,16 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { mp_hal_pin_config(pin_A12, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0); mp_hal_pin_config_speed(pin_A12, GPIO_SPEED_FREQ_VERY_HIGH); + #elif defined(STM32L1) + + // STM32L1 doesn't have an alternate function for USB. + // To be disconnected from all peripherals, put in input mode. + + mp_hal_pin_config(pin_A11, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0); + mp_hal_pin_config_speed(pin_A11, GPIO_SPEED_FREQ_VERY_HIGH); + mp_hal_pin_config(pin_A12, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0); + mp_hal_pin_config_speed(pin_A12, GPIO_SPEED_FREQ_VERY_HIGH); + #else // Other MCUs have an alternate function for GPIO's to be in USB mode. @@ -149,7 +159,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { #elif defined(STM32L432xx) NVIC_SetPriority(USB_FS_IRQn, IRQ_PRI_OTG_FS); HAL_NVIC_EnableIRQ(USB_FS_IRQn); - #elif defined(STM32G4) || defined(STM32WB) + #elif defined(STM32G4) || defined(STM32L1) || defined(STM32WB) NVIC_SetPriority(USB_LP_IRQn, IRQ_PRI_OTG_FS); HAL_NVIC_EnableIRQ(USB_LP_IRQn); #else @@ -708,6 +718,24 @@ void USBD_LL_Delay(uint32_t Delay) { HAL_Delay(Delay); } +#if defined(STM32L1) +/** + * @brief Software Device Connection + * @param hpcd: PCD handle + * @param state: Connection state (0: disconnected / 1: connected) + * @retval None + */ +void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) { + if (state == 1) { + /* DP Pull-Down is Internal */ + __HAL_SYSCFG_USBPULLUP_ENABLE(); + } else { + /* DP Pull-Down is Internal */ + __HAL_SYSCFG_USBPULLUP_DISABLE(); + } +} +#endif + #endif // MICROPY_HW_USB_FS || MICROPY_HW_USB_HS /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/