summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2021-12-04 14:40:32 +0800
committersakumisu <[email protected]>2021-12-04 14:40:32 +0800
commitaac9ca00f8115b1ab59f012033a5898580f2d359 (patch)
tree316799a52ebbcfe0588fc91dd6f623413da64479
parentc3cc88d95f4ec4c1cd1ecc322a19d508580daba8 (diff)
add usb config for stm32
-rw-r--r--demo/stm32/stm32f103c8t6/Core/Src/stm32f1xx_it.c19
-rw-r--r--demo/stm32/stm32f103c8t6/MDK-ARM/stm32f103c8t6.uvoptx2
-rw-r--r--port/stm32/usb_dc_hal.c27
-rw-r--r--port/stm32/usb_dc_nohal.c30
-rw-r--r--port/stm32/usbd_config.h29
5 files changed, 70 insertions, 37 deletions
diff --git a/demo/stm32/stm32f103c8t6/Core/Src/stm32f1xx_it.c b/demo/stm32/stm32f103c8t6/Core/Src/stm32f1xx_it.c
index 336b1c7b..b9e6a918 100644
--- a/demo/stm32/stm32f103c8t6/Core/Src/stm32f1xx_it.c
+++ b/demo/stm32/stm32f103c8t6/Core/Src/stm32f1xx_it.c
@@ -202,17 +202,16 @@ void SysTick_Handler(void)
/**
* @brief This function handles USB low priority or CAN RX0 interrupts.
*/
- void USB_LP_CAN1_RX0_IRQHandler(void)
- {
- /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 0 */
- extern void USBD_IRQHandler(void);
- /* USER CODE END USB_LP_CAN1_RX0_IRQn 0 */
- USBD_IRQHandler();
- //HAL_PCD_IRQHandler(&hpcd_USB_FS);
- /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 1 */
+//void USB_LP_CAN1_RX0_IRQHandler(void)
+//{
+///* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 0 */
- /* USER CODE END USB_LP_CAN1_RX0_IRQn 1 */
- }
+///* USER CODE END USB_LP_CAN1_RX0_IRQn 0 */
+// HAL_PCD_IRQHandler(&hpcd_USB_FS);
+///* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 1 */
+
+///* USER CODE END USB_LP_CAN1_RX0_IRQn 1 */
+//}
/* USER CODE BEGIN 1 */
diff --git a/demo/stm32/stm32f103c8t6/MDK-ARM/stm32f103c8t6.uvoptx b/demo/stm32/stm32f103c8t6/MDK-ARM/stm32f103c8t6.uvoptx
index cc4f0569..6ad5caa0 100644
--- a/demo/stm32/stm32f103c8t6/MDK-ARM/stm32f103c8t6.uvoptx
+++ b/demo/stm32/stm32f103c8t6/MDK-ARM/stm32f103c8t6.uvoptx
@@ -496,7 +496,7 @@
<Group>
<GroupName>Drivers/CMSIS</GroupName>
- <tvExp>0</tvExp>
+ <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
diff --git a/port/stm32/usb_dc_hal.c b/port/stm32/usb_dc_hal.c
index 442770ea..ae818168 100644
--- a/port/stm32/usb_dc_hal.c
+++ b/port/stm32/usb_dc_hal.c
@@ -1,11 +1,5 @@
#include "usbd_core.h"
-#ifdef STM32F1
-#include "stm32f1xx_hal.h" //chanage this header for different soc
-#elif defined(STM32F4)
-#include "stm32f4xx_hal.h" //chanage this header for different soc
-#elif defined(STM32H7)
-#include "stm32h7xx_hal.h" //chanage this header for different soc
-#endif
+#include "usbd_config.h"
#ifndef USB_NUM_BIDIR_ENDPOINTS
#define USB_NUM_BIDIR_ENDPOINTS 6
@@ -18,28 +12,27 @@
extern PCD_HandleTypeDef hpcd_USB_FS;
#define PCD_HANDLE &hpcd_USB_FS
#else
+
+#ifdef CONFIG_USB_HS
+
#ifndef USB_RAM_SIZE
#define USB_RAM_SIZE 4096
#endif
-#ifdef CONFIG_USB_HS
extern PCD_HandleTypeDef hpcd_USB_OTG_HS;
#define PCD_HANDLE &hpcd_USB_OTG_HS
+
#else
+
+#ifndef USB_RAM_SIZE
+#define USB_RAM_SIZE 1280
+#endif
extern PCD_HandleTypeDef hpcd_USB_OTG_HS;
#define PCD_HANDLE &hpcd_USB_OTG_HS
//extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
//#define PCD_HANDLE &hpcd_USB_OTG_FS
#endif
#endif
-/*
- * USB and USB_OTG_FS are defined in STM32Cube HAL and allows to distinguish
- * between two kind of USB DC. STM32 F0, F3, L0 and G4 series support USB device
- * controller. STM32 F4 and F7 series support USB_OTG_FS device controller.
- * STM32 F1 and L4 series support either USB or USB_OTG_FS device controller.
- *
- * WARNING: Don't mix USB defined in STM32Cube HAL and CONFIG_USB from Zephyr
- * Kconfig system.
- */
+
#ifdef USB
#define EP0_MPS 64U
diff --git a/port/stm32/usb_dc_nohal.c b/port/stm32/usb_dc_nohal.c
index 7089de24..5e8f70f8 100644
--- a/port/stm32/usb_dc_nohal.c
+++ b/port/stm32/usb_dc_nohal.c
@@ -1,19 +1,31 @@
#include "usbd_core.h"
-#ifdef STM32F1
-#include "stm32f1xx_hal.h" //chanage this header for different soc
-#elif defined(STM32F4)
-#include "stm32f4xx_hal.h" //chanage this header for different soc
-#elif defined(STM32H7)
-#include "stm32h7xx_hal.h" //chanage this header for different soc
+#include "usbd_config.h"
+
+#ifndef USB_NUM_BIDIR_ENDPOINTS
+#define USB_NUM_BIDIR_ENDPOINTS 8
#endif
+#ifdef USB
#ifndef USB_RAM_SIZE
#define USB_RAM_SIZE 512
#endif
-#ifndef USB_NUM_BIDIR_ENDPOINTS
-#define USB_NUM_BIDIR_ENDPOINTS 8
+#define USB_BTABLE_SIZE (8 * USB_NUM_BIDIR_ENDPOINTS)
+#else
+
+#ifdef CONFIG_USB_HS
+
+#ifndef USB_RAM_SIZE
+#define USB_RAM_SIZE 4096
#endif
+#else
+#ifndef USB_RAM_SIZE
+#define USB_RAM_SIZE 1280
+#endif
+
+#endif
+
+#endif
/* Endpoint state */
struct usb_dc_ep_state {
/** Endpoint max packet size */
@@ -47,7 +59,7 @@ int usb_dc_init(void)
memset(&usb_dc_cfg, 0, sizeof(struct usb_dc_config_priv));
#ifdef USB
usb_dc_cfg.Instance = USB;
- usb_dc_cfg.pma_offset = 64;
+ usb_dc_cfg.pma_offset = USB_BTABLE_SIZE;
usb_dc_cfg.Init.speed = PCD_SPEED_FULL;
#elif defined(USB_OTG_FS) || defined(USB_OTG_HS)
#ifdef CONFIG_USB_HS
diff --git a/port/stm32/usbd_config.h b/port/stm32/usbd_config.h
new file mode 100644
index 00000000..7e3f6998
--- /dev/null
+++ b/port/stm32/usbd_config.h
@@ -0,0 +1,29 @@
+#ifndef __USBD_CONFIG_H__
+#define __USBD_CONFIG_H__
+
+#if defined(STM32F0)
+#include "stm32f0xx.h"
+#elif defined(STM32F1)
+#include "stm32f1xx.h"
+#elif STM32F3
+#include "stm32f3xx.h"
+#elif defined(STM32F4)
+#include "stm32f4xx.h"
+#elif defined(STM32H7)
+#include "stm32h7xx.h"
+#endif
+
+/*other do not process,users need to modify byself*/
+#if defined(STM32F0)
+#define USBD_IRQHandler USB_IRQHandler
+#elif defined(STM32F1) || defined(STM32F3)
+#define USBD_IRQHandler USB_LP_CAN1_RX0_IRQHandler
+#else
+#ifdef CONFIG_USB_HS
+#define USBD_IRQHandler OTG_HS_IRQHandler
+#else
+#define USBD_IRQHandler OTG_FS_IRQHandler
+#endif
+#endif
+
+#endif \ No newline at end of file