Skip to content

Commit 6e0d2fc

Browse files
committed
[bsp/stm32l496zg] add cherryusb port and fix rtconfig.py
1 parent eb346c3 commit 6e0d2fc

File tree

7 files changed

+25
-223
lines changed

7 files changed

+25
-223
lines changed

bsp/stm32/stm32f407-rt-spark/board/ports/cherryusb/cherryusb.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,20 @@
77
* Date Author Notes
88
* 2025-01-17 Supperthomas first version
99
*/
10-
#include <stm32f4xx.h>
10+
#include "board.h"
1111
#include "rtthread.h"
1212
#include "drv_config.h"
1313

14+
static PCD_HandleTypeDef hpcd_USB_OTG_FS;
1415
void usb_dc_low_level_init(uint8_t busid)
1516
{
16-
GPIO_InitTypeDef GPIO_InitStruct = {0};
17-
18-
__HAL_RCC_GPIOA_CLK_ENABLE();
19-
/**USB_OTG_FS GPIO Configuration
20-
PA11 ------> USB_OTG_FS_DM
21-
PA12 ------> USB_OTG_FS_DP
22-
*/
23-
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
24-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
25-
GPIO_InitStruct.Pull = GPIO_NOPULL;
26-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
27-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
28-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
29-
30-
/* Peripheral clock enable */
31-
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
32-
/* USB_OTG_FS interrupt Init */
33-
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
34-
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
17+
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
18+
HAL_PCD_MspInit(&hpcd_USB_OTG_FS);
3519
}
3620

3721
void usb_dc_low_level_deinit(uint8_t busid)
3822
{
39-
/* Peripheral clock disable */
40-
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
41-
42-
/**USB_OTG_FS GPIO Configuration
43-
PA11 ------> USB_OTG_FS_DM
44-
PA12 ------> USB_OTG_FS_DP
45-
*/
46-
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
47-
48-
/* USB_OTG_FS interrupt DeInit */
49-
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
23+
HAL_PCD_MspDeInit(&hpcd_USB_OTG_FS);
5024
}
5125

5226
#ifdef RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM

bsp/stm32/stm32f407-rt-spark/rtconfig.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
PLATFORM = 'gcc'
2020
EXEC_PATH = r'C:\Users\XXYYZZ'
2121
elif CROSS_TOOL == 'keil':
22-
PLATFORM = 'armcc'
22+
PLATFORM = 'armclang' #KEIL AC6
23+
#PLATFORM = 'armcc' #KEIL AC5
2324
EXEC_PATH = r'C:/Keil_v5'
2425
elif CROSS_TOOL == 'iar':
2526
PLATFORM = 'iccarm'
@@ -28,7 +29,7 @@
2829
PLATFORM = 'llvm-arm'
2930
EXEC_PATH = r'D:\Progrem\LLVMEmbeddedToolchainForArm-17.0.1-Windows-x86_64\bin'
3031

31-
if os.getenv('RTT_EXEC_PATH'):
32+
if os.getenv('RTT_EXEC_PATH') and CROSS_TOOL == 'gcc':
3233
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
3334

3435
BUILD = 'debug'

bsp/stm32/stm32l496-st-nucleo/board/CubeMX_Config/Inc/stm32l4xx_it.h

Lines changed: 0 additions & 70 deletions
This file was deleted.

bsp/stm32/stm32l496-st-nucleo/board/CubeMX_Config/STM32L496ZG.ioc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ NVIC.ForceEnableDMAVector=true
100100
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
101101
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
102102
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
103+
NVIC.OTG_FS_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
103104
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
104105
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
105106
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false

bsp/stm32/stm32l496-st-nucleo/board/CubeMX_Config/Src/stm32l4xx_hal_msp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,9 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
805805
{
806806
HAL_PWREx_EnableVddUSB();
807807
}
808+
/* USB_OTG_FS interrupt Init */
809+
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
810+
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
808811
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
809812

810813
/* USER CODE END USB_OTG_FS_MspInit 1 */
@@ -850,6 +853,9 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
850853
{
851854
HAL_PWREx_DisableVddUSB();
852855
}
856+
857+
/* USB_OTG_FS interrupt DeInit */
858+
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
853859
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
854860

855861
/* USER CODE END USB_OTG_FS_MspDeInit 1 */

bsp/stm32/stm32l496-st-nucleo/board/cherryusb/cherryusb.c

Lines changed: 7 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -7,131 +7,20 @@
77
* Date Author Notes
88
* 2025-01-17 Supperthomas first version
99
*/
10-
#include <stm32l4xx.h>
10+
#include "board.h"
1111
#include "rtthread.h"
1212
#include "drv_config.h"
13-
#include "usb_config.h"
13+
14+
static PCD_HandleTypeDef hpcd_USB_OTG_FS;
1415
void usb_dc_low_level_init(uint8_t busid)
1516
{
16-
#define USB_OverCurrent_Pin GPIO_PIN_5
17-
#define USB_OverCurrent_GPIO_Port GPIOG
18-
#define USB_PowerSwitchOn_Pin GPIO_PIN_6
19-
#define USB_PowerSwitchOn_GPIO_Port GPIOG
20-
#define STLK_RX_Pin GPIO_PIN_7
21-
#define STLK_RX_GPIO_Port GPIOG
22-
#define STLK_TX_Pin GPIO_PIN_8
23-
#define STLK_TX_GPIO_Port GPIOG
24-
#define USB_SOF_Pin GPIO_PIN_8
25-
#define USB_SOF_GPIO_Port GPIOA
26-
#define USB_VBUS_Pin GPIO_PIN_9
27-
#define USB_VBUS_GPIO_Port GPIOA
28-
#define USB_ID_Pin GPIO_PIN_10
29-
#define USB_ID_GPIO_Port GPIOA
30-
#define USB_DM_Pin GPIO_PIN_11
31-
#define USB_DM_GPIO_Port GPIOA
32-
#define USB_DP_Pin GPIO_PIN_12
33-
#define USB_DP_GPIO_Port GPIOA
34-
GPIO_InitTypeDef GPIO_InitStruct = {0};
35-
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
36-
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
37-
38-
/* USER CODE END USB_OTG_FS_MspInit 0 */
39-
40-
/** Initializes the peripherals clock
41-
*/
42-
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
43-
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
44-
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
45-
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
46-
PeriphClkInit.PLLSAI1.PLLSAI1N = 24;
47-
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV2;
48-
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
49-
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
50-
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;
51-
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
52-
{
53-
//Error_Handler();
54-
}
55-
56-
__HAL_RCC_GPIOA_CLK_ENABLE();
57-
/**USB_OTG_FS GPIO Configuration
58-
PA8 ------> USB_OTG_FS_SOF
59-
PA9 ------> USB_OTG_FS_VBUS
60-
PA10 ------> USB_OTG_FS_ID
61-
PA11 ------> USB_OTG_FS_DM
62-
PA12 ------> USB_OTG_FS_DP
63-
*/
64-
GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
65-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
66-
GPIO_InitStruct.Pull = GPIO_NOPULL;
67-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
68-
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
69-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
70-
71-
GPIO_InitStruct.Pin = USB_VBUS_Pin;
72-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
73-
GPIO_InitStruct.Pull = GPIO_NOPULL;
74-
HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
75-
76-
/* Peripheral clock enable */
77-
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
78-
79-
/* Enable VDDUSB */
80-
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
81-
{
82-
__HAL_RCC_PWR_CLK_ENABLE();
83-
HAL_PWREx_EnableVddUSB();
84-
__HAL_RCC_PWR_CLK_DISABLE();
85-
}
86-
else
87-
{
88-
HAL_PWREx_EnableVddUSB();
89-
}
90-
/* USB_OTG_FS interrupt Init */
91-
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
92-
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
93-
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
94-
95-
/* USER CODE END USB_OTG_FS_MspInit 1 */
96-
17+
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
18+
HAL_PCD_MspInit(&hpcd_USB_OTG_FS);
9719
}
9820

9921
void usb_dc_low_level_deinit(uint8_t busid)
10022
{
101-
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
102-
103-
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
104-
/* Peripheral clock disable */
105-
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
106-
107-
/**USB_OTG_FS GPIO Configuration
108-
PA8 ------> USB_OTG_FS_SOF
109-
PA9 ------> USB_OTG_FS_VBUS
110-
PA10 ------> USB_OTG_FS_ID
111-
PA11 ------> USB_OTG_FS_DM
112-
PA12 ------> USB_OTG_FS_DP
113-
*/
114-
HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
115-
|USB_DP_Pin);
116-
117-
/* Disable VDDUSB */
118-
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
119-
{
120-
__HAL_RCC_PWR_CLK_ENABLE();
121-
HAL_PWREx_DisableVddUSB();
122-
__HAL_RCC_PWR_CLK_DISABLE();
123-
}
124-
else
125-
{
126-
HAL_PWREx_DisableVddUSB();
127-
}
128-
129-
/* USB_OTG_FS interrupt DeInit */
130-
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
131-
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
132-
133-
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
134-
23+
HAL_PCD_MspDeInit(&hpcd_USB_OTG_FS);
13524
}
13625

13726
#ifdef RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM
@@ -154,7 +43,7 @@ MSH_CMD_EXPORT(cherry_usb_cdc_send, send the cdc data for test)
15443
#endif
15544

15645
#ifdef USBD_IRQ_HANDLER
157-
void USBD_IRQ_HANDLER(void)
46+
void USBD_IRQ_HANDLER(void)
15847
{
15948
extern void USBD_IRQHandler(uint8_t busid);
16049
USBD_IRQHandler(0);

bsp/stm32/stm32l496-st-nucleo/rtconfig.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
PLATFORM = 'gcc'
2020
EXEC_PATH = r'.'
2121
elif CROSS_TOOL == 'keil':
22-
PLATFORM = 'armcc'
22+
PLATFORM = 'armclang' #KEIL A6
23+
#PLATFORM = 'armcc' #KEIL A5
2324
EXEC_PATH = r'C:/Keil_v5'
2425
elif CROSS_TOOL == 'iar':
2526
PLATFORM = 'iccarm'
2627
EXEC_PATH = r'C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3'
2728

28-
if os.getenv('RTT_EXEC_PATH'):
29+
if os.getenv('RTT_EXEC_PATH') and CROSS_TOOL == 'gcc':
2930
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
3031

3132
BUILD = 'debug'

0 commit comments

Comments
 (0)