Skip to content

Commit

Permalink
Merge branch 'ports-psoc6-main' into psoc6-machine-adc
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhitaR-IFX committed Jul 12, 2023
2 parents 1dfd731 + 5edc41a commit 955a94a
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 27 deletions.
1 change: 1 addition & 0 deletions docs/psoc6/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ Methods
^^^^^^^
All the methods(functions) given in :ref:`machine.SPI <machine.SPI>` class have been implemented in this port


ADC (analog to digital conversion)
----------------------------------

Expand Down
3 changes: 3 additions & 0 deletions ports/esp32/boards/GENERIC_OTA/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions ports/esp32/main_esp32/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## IDF Component Manager Manifest File
dependencies:
espressif/mdns: "~1.1.0"
idf:
version: ">=5.0.2"
5 changes: 5 additions & 0 deletions ports/esp32/main_esp32c3/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## IDF Component Manager Manifest File
dependencies:
espressif/mdns: "~1.1.0"
idf:
version: ">=5.0.2"
3 changes: 2 additions & 1 deletion ports/esp32/main_esp32s2/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion ports/esp32/main_esp32s3/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions ports/esp32/modsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ports/esp32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ports/esp32/network_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion ports/psoc6/modules/machine/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 9 additions & 0 deletions ports/stm32/boards/NUCLEO_L152RE/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions ports/stm32/boards/stm32l1xx_hal_conf_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/mpconfigboard_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions ports/stm32/powerctrlboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/stm32_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion ports/stm32/usbd_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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****/

0 comments on commit 955a94a

Please sign in to comment.