1 /*
2  * Copyright (c) 2025, sakumisu
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include "usbd_core.h"
7 
8 #if __has_include("stm32f0xx_hal.h")
9 #include "stm32f0xx_hal.h"
10 #elif __has_include("stm32f1xx_hal.h")
11 #include "stm32f1xx_hal.h"
12 #elif __has_include("stm32f3xx_hal.h")
13 #include "stm32f3xx_hal.h"
14 #elif __has_include("stm32g0xx_hal.h")
15 #include "stm32g0xx_hal.h"
16 #elif __has_include("stm32g4xx_hal.h")
17 #include "stm32g4xx_hal.h"
18 #elif __has_include("stm32l0xx_hal.h")
19 #include "stm32l0xx_hal.h"
20 #elif __has_include("stm32l1xx_hal.h")
21 #include "stm32l1xx_hal.h"
22 #elif __has_include("stm32l4xx_hal.h")
23 #include "stm32l4xx_hal.h"
24 #elif __has_include("stm32l5xx_hal.h")
25 #include "stm32l5xx_hal.h"
26 #endif
27 
28 #if !defined(HAL_PCD_MODULE_ENABLED)
29 #error please define HAL_PCD_MODULE_ENABLED in stm32xxx_hal_conf.h
30 #endif
31 
32 #ifndef CONFIG_USBDEV_FSDEV_PMA_ACCESS
33 #error "please define CONFIG_USBDEV_FSDEV_PMA_ACCESS in usb_config.h"
34 #endif
35 
36 #if CONFIG_USBDEV_FSDEV_PMA_ACCESS != PMA_ACCESS
37 #error "CONFIG_USBDEV_FSDEV_PMA_ACCESS must be equal PMA_ACCESS"
38 #endif
39 
40 struct fsdev_instance {
41     USB_TypeDef *Instance;
42 };
43 
44 static struct fsdev_instance g_fsdev_instance;
45 
usb_dc_low_level_init(uint8_t busid)46 void usb_dc_low_level_init(uint8_t busid)
47 {
48     g_fsdev_instance.Instance = (USB_TypeDef *)g_usbdev_bus[busid].reg_base;
49     HAL_PCD_MspInit((PCD_HandleTypeDef *)&g_fsdev_instance);
50 }
51 
usb_dc_low_level_deinit(uint8_t busid)52 void usb_dc_low_level_deinit(uint8_t busid)
53 {
54     g_fsdev_instance.Instance = (USB_TypeDef *)g_usbdev_bus[busid].reg_base;
55     HAL_PCD_MspDeInit((PCD_HandleTypeDef *)&g_fsdev_instance);
56 }
57 
USB_IRQHandler(void)58 void USB_IRQHandler(void)
59 {
60     USBD_IRQHandler(0);
61 }
62 
USB_LP_IRQHandler(void)63 void USB_LP_IRQHandler(void)
64 {
65     USBD_IRQHandler(0);
66 }