stm32/usbd: Introduce MICROPY_HW_USB_IS_MULTI_OTG to simplify USB config
This is an internal config value that is enabled for MCUs that have multiple OTG instances, to simplify #if configuration of the USB code.
This commit is contained in:
parent
ba607809f2
commit
bf733c27bb
|
@ -287,6 +287,13 @@
|
|||
#define MICROPY_HW_MAX_CAN (1)
|
||||
#endif
|
||||
|
||||
// Whether the USB peripheral is device-only, or multiple OTG
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
#define MICROPY_HW_USB_IS_MULTI_OTG (0)
|
||||
#else
|
||||
#define MICROPY_HW_USB_IS_MULTI_OTG (1)
|
||||
#endif
|
||||
|
||||
// Configure maximum number of CDC VCP interfaces, and whether MSC/HID are supported
|
||||
#ifndef MICROPY_HW_USB_CDC_NUM
|
||||
#define MICROPY_HW_USB_CDC_NUM (1)
|
||||
|
|
|
@ -142,7 +142,7 @@ int8_t usbd_cdc_control(usbd_cdc_state_t *cdc_in, uint8_t cmd, uint8_t* pbuf, ui
|
|||
// configure its serial port (in most cases to disable local echo)
|
||||
cdc->connect_state = USBD_CDC_CONNECT_STATE_CONNECTING;
|
||||
usbd_cdc_connect_tx_timer = 8; // wait for 8 SOF IRQs
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
USB->CNTR |= USB_CNTR_SOFM;
|
||||
#else
|
||||
PCD_HandleTypeDef *hpcd = cdc->base.usbd->pdev->pData;
|
||||
|
@ -219,7 +219,7 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
|
|||
--usbd_cdc_connect_tx_timer;
|
||||
} else {
|
||||
usbd_cdc_msc_hid_state_t *usbd = ((USBD_HandleTypeDef*)hpcd->pData)->pClassData;
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
USB->CNTR &= ~USB_CNTR_SOFM;
|
||||
#else
|
||||
hpcd->Instance->GINTMSK &= ~USB_OTG_GINTMSK_SOFM;
|
||||
|
|
|
@ -44,8 +44,8 @@ PCD_HandleTypeDef pcd_fs_handle;
|
|||
PCD_HandleTypeDef pcd_hs_handle;
|
||||
#endif
|
||||
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
// The STM32L0xx has a single USB device-only instance
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
// The MCU has a single USB device-only instance
|
||||
#define USB_OTG_FS USB
|
||||
#endif
|
||||
|
||||
|
@ -92,7 +92,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
|
|||
#endif
|
||||
|
||||
// Enable USB FS Clocks
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
__HAL_RCC_USB_CLK_ENABLE();
|
||||
#else
|
||||
__USB_OTG_FS_CLK_ENABLE();
|
||||
|
@ -195,7 +195,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
|
|||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) {
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
__HAL_RCC_USB_CLK_DISABLE();
|
||||
#else
|
||||
|
||||
|
@ -379,7 +379,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev, int high_speed) {
|
|||
pcd_fs_handle.Init.lpm_enable = DISABLE;
|
||||
pcd_fs_handle.Init.battery_charging_enable = DISABLE;
|
||||
#endif
|
||||
#if !defined(STM32L0) && !defined(STM32WB)
|
||||
#if MICROPY_HW_USB_IS_MULTI_OTG
|
||||
pcd_fs_handle.Init.use_dedicated_ep1 = 0;
|
||||
pcd_fs_handle.Init.dma_enable = 0;
|
||||
#if !defined(MICROPY_HW_USB_VBUS_DETECT_PIN)
|
||||
|
@ -396,7 +396,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev, int high_speed) {
|
|||
// Initialize LL Driver
|
||||
HAL_PCD_Init(&pcd_fs_handle);
|
||||
|
||||
#if defined(STM32L0) || defined(STM32WB)
|
||||
#if !MICROPY_HW_USB_IS_MULTI_OTG
|
||||
// We have 512 16-bit words it total to use here (when using PCD_SNG_BUF)
|
||||
HAL_PCDEx_PMAConfig(&pcd_fs_handle, 0x00, PCD_SNG_BUF, 64); // EP0
|
||||
HAL_PCDEx_PMAConfig(&pcd_fs_handle, 0x80, PCD_SNG_BUF, 128); // EP0
|
||||
|
|
Loading…
Reference in New Issue