feat:add erpc usb cdc interface
This commit is contained in:
parent
d8053c532a
commit
8063250f66
69
.config
69
.config
@ -172,7 +172,7 @@ CONFIG_RT_USING_HEAP=y
|
|||||||
# end of Memory Management
|
# end of Memory Management
|
||||||
|
|
||||||
CONFIG_RT_USING_DEVICE=y
|
CONFIG_RT_USING_DEVICE=y
|
||||||
# CONFIG_RT_USING_DEVICE_OPS is not set
|
CONFIG_RT_USING_DEVICE_OPS=y
|
||||||
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
||||||
# CONFIG_RT_USING_THREADSAFE_PRINTF is not set
|
# CONFIG_RT_USING_THREADSAFE_PRINTF is not set
|
||||||
CONFIG_RT_USING_CONSOLE=y
|
CONFIG_RT_USING_CONSOLE=y
|
||||||
@ -236,7 +236,7 @@ CONFIG_RT_USING_SERIAL=y
|
|||||||
CONFIG_RT_USING_SERIAL_V1=y
|
CONFIG_RT_USING_SERIAL_V1=y
|
||||||
# CONFIG_RT_USING_SERIAL_V2 is not set
|
# CONFIG_RT_USING_SERIAL_V2 is not set
|
||||||
CONFIG_RT_SERIAL_USING_DMA=y
|
CONFIG_RT_SERIAL_USING_DMA=y
|
||||||
CONFIG_RT_SERIAL_RB_BUFSZ=1024
|
CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||||
# CONFIG_RT_USING_SERIAL_BYPASS is not set
|
# CONFIG_RT_USING_SERIAL_BYPASS is not set
|
||||||
# CONFIG_RT_USING_CAN is not set
|
# CONFIG_RT_USING_CAN is not set
|
||||||
# CONFIG_RT_USING_CPUTIME is not set
|
# CONFIG_RT_USING_CPUTIME is not set
|
||||||
@ -275,7 +275,60 @@ CONFIG_RT_USING_SPI=y
|
|||||||
CONFIG_RT_USING_PIN=y
|
CONFIG_RT_USING_PIN=y
|
||||||
CONFIG_RT_USING_KTIME=y
|
CONFIG_RT_USING_KTIME=y
|
||||||
# CONFIG_RT_USING_HWTIMER is not set
|
# CONFIG_RT_USING_HWTIMER is not set
|
||||||
# CONFIG_RT_USING_CHERRYUSB is not set
|
CONFIG_RT_USING_CHERRYUSB=y
|
||||||
|
CONFIG_RT_CHERRYUSB_DEVICE=y
|
||||||
|
CONFIG_RT_CHERRYUSB_DEVICE_SPEED_FS=y
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_SPEED_HS is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_SPEED_AUTO is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CUSTOM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_FSDEV_ST is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_FSDEV_CUSTOM is not set
|
||||||
|
CONFIG_RT_CHERRYUSB_DEVICE_DWC2_ST=y
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_ESP is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_KENDRYTE is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_AT is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_HC is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_NATION is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_GD is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DWC2_CUSTOM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MUSB_ES is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MUSB_SUNXI is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MUSB_BK is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MUSB_SIFLI is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MUSB_CUSTOM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CHIPIDEA_MCX is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_KINETIS_MCX is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_KINETIS_MM32 is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_KINETIS_CUSTOM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_BL is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_HPM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_AIC is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_RP2040 is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CH32 is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_PUSB2 is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_NRF5X is not set
|
||||||
|
CONFIG_RT_CHERRYUSB_DEVICE_CDC_ACM=y
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_HID is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MSC is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_AUDIO is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_VIDEO is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CDC_RNDIS is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CDC_ECM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CDC_NCM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_MTP is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_ADB is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_DFU is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_CDC_ACM_CHARDEV is not set
|
||||||
|
CONFIG_CONFIG_USBDEV_REQUEST_BUFFER_LEN=1024
|
||||||
|
CONFIG_CONFIG_USBDEV_MSC_MAX_BUFSIZE=1024
|
||||||
|
# CONFIG_CONFIG_USBDEV_RNDIS_USING_LWIP is not set
|
||||||
|
# CONFIG_CONFIG_USBDEV_CDC_ECM_USING_LWIP is not set
|
||||||
|
CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_NONE=y
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1 is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC is not set
|
||||||
|
# CONFIG_RT_CHERRYUSB_HOST is not set
|
||||||
# end of Device Drivers
|
# end of Device Drivers
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -324,7 +377,7 @@ CONFIG_PTHREAD_NUM_MAX=8
|
|||||||
CONFIG_RT_USING_CPLUSPLUS=y
|
CONFIG_RT_USING_CPLUSPLUS=y
|
||||||
# CONFIG_RT_USING_CPLUSPLUS11 is not set
|
# CONFIG_RT_USING_CPLUSPLUS11 is not set
|
||||||
# CONFIG_RT_USING_CPP_WRAPPER is not set
|
# CONFIG_RT_USING_CPP_WRAPPER is not set
|
||||||
# CONFIG_RT_USING_CPP_EXCEPTIONS is not set
|
CONFIG_RT_USING_CPP_EXCEPTIONS=y
|
||||||
# end of C/C++ and POSIX layer
|
# end of C/C++ and POSIX layer
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -585,6 +638,7 @@ CONFIG_RT_USING_CPLUSPLUS=y
|
|||||||
#
|
#
|
||||||
# tools packages
|
# tools packages
|
||||||
#
|
#
|
||||||
|
# CONFIG_PKG_USING_VECTOR is not set
|
||||||
# CONFIG_PKG_USING_CMBACKTRACE is not set
|
# CONFIG_PKG_USING_CMBACKTRACE is not set
|
||||||
# CONFIG_PKG_USING_MCOREDUMP is not set
|
# CONFIG_PKG_USING_MCOREDUMP is not set
|
||||||
# CONFIG_PKG_USING_EASYFLASH is not set
|
# CONFIG_PKG_USING_EASYFLASH is not set
|
||||||
@ -1079,6 +1133,7 @@ CONFIG_PKG_STM32H7_CMSIS_DRIVER_VER="latest"
|
|||||||
# CONFIG_PKG_USING_IST8310 is not set
|
# CONFIG_PKG_USING_IST8310 is not set
|
||||||
# CONFIG_PKG_USING_ST7789_SPI is not set
|
# CONFIG_PKG_USING_ST7789_SPI is not set
|
||||||
# CONFIG_PKG_USING_ISOTP_C is not set
|
# CONFIG_PKG_USING_ISOTP_C is not set
|
||||||
|
# CONFIG_PKG_USING_IKUNLED is not set
|
||||||
# CONFIG_PKG_USING_SPI_TOOLS is not set
|
# CONFIG_PKG_USING_SPI_TOOLS is not set
|
||||||
# end of peripheral libraries and drivers
|
# end of peripheral libraries and drivers
|
||||||
|
|
||||||
@ -1441,6 +1496,7 @@ CONFIG_BSP_SCB_ENABLE_I_CACHE=y
|
|||||||
# CONFIG_BSP_SCB_ENABLE_D_CACHE is not set
|
# CONFIG_BSP_SCB_ENABLE_D_CACHE is not set
|
||||||
CONFIG_BSP_ENABLE_FPU=y
|
CONFIG_BSP_ENABLE_FPU=y
|
||||||
CONFIG_BSP_USING_GPIO=y
|
CONFIG_BSP_USING_GPIO=y
|
||||||
|
# CONFIG_BSP_USING_USBD is not set
|
||||||
CONFIG_BSP_USING_UART=y
|
CONFIG_BSP_USING_UART=y
|
||||||
CONFIG_BSP_STM32_UART_V1_TX_TIMEOUT=6000
|
CONFIG_BSP_STM32_UART_V1_TX_TIMEOUT=6000
|
||||||
CONFIG_BSP_USING_UART1=y
|
CONFIG_BSP_USING_UART1=y
|
||||||
@ -1476,9 +1532,10 @@ CONFIG_BSP_USING_ERPC=y
|
|||||||
CONFIG_ERPC_USING_RTT=y
|
CONFIG_ERPC_USING_RTT=y
|
||||||
CONFIG_ERPC_MODE=y
|
CONFIG_ERPC_MODE=y
|
||||||
CONFIG_ERPC_MODE_SERVER=y
|
CONFIG_ERPC_MODE_SERVER=y
|
||||||
CONFIG_ERPC_MODE_CLIENT=y
|
# CONFIG_ERPC_MODE_CLIENT is not set
|
||||||
CONFIG_ERPC_TRANSPORTS=y
|
CONFIG_ERPC_TRANSPORTS=y
|
||||||
# CONFIG_ERPC_TRANSPORTS_SPI is not set
|
# CONFIG_ERPC_TRANSPORTS_SPI is not set
|
||||||
CONFIG_ERPC_TRANSPORTS_UART=y
|
# CONFIG_ERPC_TRANSPORTS_UART is not set
|
||||||
# CONFIG_ERPC_TRANSPORTS_TCP is not set
|
# CONFIG_ERPC_TRANSPORTS_TCP is not set
|
||||||
|
CONFIG_ERPC_TRANSPORTS_USB_CDC=y
|
||||||
# end of Third Packages Drivers
|
# end of Third Packages Drivers
|
||||||
|
|||||||
120
CMakeLists.txt
120
CMakeLists.txt
@ -13,7 +13,7 @@ SET(CMAKE_ASM_FLAGS " -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard
|
|||||||
SET(CMAKE_C_COMPILER_WORKS TRUE)
|
SET(CMAKE_C_COMPILER_WORKS TRUE)
|
||||||
|
|
||||||
SET(CMAKE_CXX_COMPILER "C:/tool/rtthread/env-windows/tools/bin/../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-g++.exe")
|
SET(CMAKE_CXX_COMPILER "C:/tool/rtthread/env-windows/tools/bin/../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-g++.exe")
|
||||||
SET(CMAKE_CXX_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections")
|
SET(CMAKE_CXX_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g")
|
||||||
SET(CMAKE_CXX_COMPILER_WORKS TRUE)
|
SET(CMAKE_CXX_COMPILER_WORKS TRUE)
|
||||||
|
|
||||||
SET(CMAKE_OBJCOPY "C:/tool/rtthread/env-windows/tools/bin/../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-objcopy.exe")
|
SET(CMAKE_OBJCOPY "C:/tool/rtthread/env-windows/tools/bin/../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-objcopy.exe")
|
||||||
@ -36,6 +36,7 @@ INCLUDE_DIRECTORIES(
|
|||||||
applications/erpc/proto/generated
|
applications/erpc/proto/generated
|
||||||
board
|
board
|
||||||
board/CubeMX_Config/Inc
|
board/CubeMX_Config/Inc
|
||||||
|
board/ports/usb
|
||||||
libraries/HAL_Drivers/CMSIS/Include
|
libraries/HAL_Drivers/CMSIS/Include
|
||||||
packages/erpc-1.14.0/erpc_c
|
packages/erpc-1.14.0/erpc_c
|
||||||
packages/erpc-1.14.0/erpc_c/config
|
packages/erpc-1.14.0/erpc_c/config
|
||||||
@ -52,6 +53,23 @@ INCLUDE_DIRECTORIES(
|
|||||||
rt-thread/components/drivers/phy
|
rt-thread/components/drivers/phy
|
||||||
rt-thread/components/drivers/smp_call
|
rt-thread/components/drivers/smp_call
|
||||||
rt-thread/components/drivers/spi
|
rt-thread/components/drivers/spi
|
||||||
|
rt-thread/components/drivers/usb/cherryusb
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/common
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/core
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/hub
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/cdc
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/msc
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/hid
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/audio
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/video
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/wireless
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/midi
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/adb
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/dfu
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/vendor/net
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/vendor/serial
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/vendor/wifi
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/osal
|
||||||
rt-thread/components/finsh
|
rt-thread/components/finsh
|
||||||
rt-thread/components/libc/compilers/common/include
|
rt-thread/components/libc/compilers/common/include
|
||||||
rt-thread/components/libc/compilers/newlib
|
rt-thread/components/libc/compilers/newlib
|
||||||
@ -84,17 +102,25 @@ ADD_DEFINITIONS(
|
|||||||
# Library source files
|
# Library source files
|
||||||
SET(RT_APP_ERPC_SOURCES
|
SET(RT_APP_ERPC_SOURCES
|
||||||
applications/erpc/service/src/erpc_server_main.cpp
|
applications/erpc/service/src/erpc_server_main.cpp
|
||||||
|
applications/erpc/proto/generated/head_service_interface.cpp
|
||||||
applications/erpc/common/src/erpc_error_handler.cpp
|
applications/erpc/common/src/erpc_error_handler.cpp
|
||||||
applications/erpc/service/src/head_service_impl.cpp
|
applications/erpc/service/src/head_service_impl.cpp
|
||||||
applications/erpc/proto/generated/head_service_server.cpp
|
applications/erpc/proto/generated/head_service_server.cpp
|
||||||
applications/erpc/client/src/erpc_client_main.cpp
|
|
||||||
applications/erpc/proto/generated/head_service_interface.cpp
|
|
||||||
applications/erpc/proto/generated/head_service_client.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_APPLICATIONS_SOURCES
|
SET(RT_APPLICATIONS_SOURCES
|
||||||
applications/servo.c
|
|
||||||
applications/main.c
|
applications/main.c
|
||||||
|
applications/servo.c
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(RT_CHERRYUSB_SOURCES
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/osal/usb_osal_rtthread.c
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/class/cdc/usbd_cdc_acm.c
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/platform/rtthread/usb_check.c
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/platform/rtthread/usb_msh.c
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/port/dwc2/usb_glue_st.c
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/core/usbd_core.c
|
||||||
|
rt-thread/components/drivers/usb/cherryusb/port/dwc2/usb_dc_dwc2.c
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_COMPILER_SOURCES
|
SET(RT_COMPILER_SOURCES
|
||||||
@ -108,8 +134,8 @@ SET(RT_COMPILER_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_CPP_SOURCES
|
SET(RT_CPP_SOURCES
|
||||||
rt-thread/components/libc/cplusplus/cxx_crt.cpp
|
|
||||||
rt-thread/components/libc/cplusplus/cxx_crt_init.c
|
rt-thread/components/libc/cplusplus/cxx_crt_init.c
|
||||||
|
rt-thread/components/libc/cplusplus/cxx_crt.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_DEVICEDRIVERS_SOURCES
|
SET(RT_DEVICEDRIVERS_SOURCES
|
||||||
@ -132,7 +158,8 @@ SET(RT_DEVICEDRIVERS_SOURCES
|
|||||||
SET(RT_DRIVERS_SOURCES
|
SET(RT_DRIVERS_SOURCES
|
||||||
board/CubeMX_Config/Src/stm32h7xx_hal_msp.c
|
board/CubeMX_Config/Src/stm32h7xx_hal_msp.c
|
||||||
board/board.c
|
board/board.c
|
||||||
board/ports/qspi_flash_init.c
|
board/ports/usb/usb_cdc_char_device.c
|
||||||
|
board/ports/usb/usb_cdc_init.c
|
||||||
libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h750xx.s
|
libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h750xx.s
|
||||||
libraries/HAL_Drivers/drivers/drv_gpio.c
|
libraries/HAL_Drivers/drivers/drv_gpio.c
|
||||||
libraries/HAL_Drivers/drivers/drv_spi.c
|
libraries/HAL_Drivers/drivers/drv_spi.c
|
||||||
@ -141,31 +168,28 @@ SET(RT_DRIVERS_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_ERPC_SOURCES
|
SET(RT_ERPC_SOURCES
|
||||||
packages/erpc-1.14.0/erpc_c/setup/erpc_setup_mbf_dynamic.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/setup/erpc_server_setup.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_server.cpp
|
packages/erpc-1.14.0/erpc_c/infra/erpc_server.cpp
|
||||||
packages/erpc-1.14.0/erpc_c/setup/erpc_setup_mbf_static.cpp
|
packages/erpc-1.14.0/erpc_c/port/erpc_port_rtt.cpp
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_simple_server.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/setup/erpc_setup_serial.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_pre_post_action.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_message_buffer.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_basic_codec.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_framed_transport.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_client_manager.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/transports/erpc_serial_transport.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_message_loggers.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/port/erpc_threading_pthreads.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_transport_arbitrator.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_arbitrated_client_manager.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/transports/erpc_inter_thread_buffer_transport.cpp
|
|
||||||
packages/erpc-1.14.0/erpc_c/infra/erpc_crc16.cpp
|
packages/erpc-1.14.0/erpc_c/infra/erpc_crc16.cpp
|
||||||
packages/erpc-1.14.0/erpc_c/setup/erpc_arbitrated_client_setup.cpp
|
packages/erpc-1.14.0/erpc_c/infra/erpc_simple_server.cpp
|
||||||
packages/erpc-1.14.0/erpc_c/setup/erpc_client_setup.cpp
|
packages/erpc-1.14.0/erpc_c/transports/erpc_usb_cdc_transport.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/infra/erpc_message_loggers.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/setup/erpc_server_setup.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/infra/erpc_transport_arbitrator.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/infra/erpc_framed_transport.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/infra/erpc_message_buffer.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/transports/erpc_inter_thread_buffer_transport.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/infra/erpc_basic_codec.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/setup/erpc_setup_mbf_static.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/setup/erpc_setup_usb_cdc.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/infra/erpc_pre_post_action.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/setup/erpc_setup_mbf_dynamic.cpp
|
||||||
|
packages/erpc-1.14.0/erpc_c/port/erpc_threading_pthreads.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_FINSH_SOURCES
|
SET(RT_FINSH_SOURCES
|
||||||
rt-thread/components/finsh/cmd.c
|
|
||||||
rt-thread/components/finsh/msh.c
|
rt-thread/components/finsh/msh.c
|
||||||
|
rt-thread/components/finsh/cmd.c
|
||||||
rt-thread/components/finsh/msh_parse.c
|
rt-thread/components/finsh/msh_parse.c
|
||||||
rt-thread/components/finsh/shell.c
|
rt-thread/components/finsh/shell.c
|
||||||
)
|
)
|
||||||
@ -189,17 +213,17 @@ SET(RT_KERNEL_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_KLIBC_SOURCES
|
SET(RT_KLIBC_SOURCES
|
||||||
rt-thread/src/klibc/rt_vsscanf.c
|
|
||||||
rt-thread/src/klibc/rt_vsnprintf_tiny.c
|
rt-thread/src/klibc/rt_vsnprintf_tiny.c
|
||||||
rt-thread/src/klibc/kerrno.c
|
rt-thread/src/klibc/rt_vsscanf.c
|
||||||
rt-thread/src/klibc/kstdio.c
|
|
||||||
rt-thread/src/klibc/kstring.c
|
rt-thread/src/klibc/kstring.c
|
||||||
|
rt-thread/src/klibc/kstdio.c
|
||||||
|
rt-thread/src/klibc/kerrno.c
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_KTIME_SOURCES
|
SET(RT_KTIME_SOURCES
|
||||||
|
rt-thread/components/drivers/ktime/src/cputimer.c
|
||||||
rt-thread/components/drivers/ktime/src/hrtimer.c
|
rt-thread/components/drivers/ktime/src/hrtimer.c
|
||||||
rt-thread/components/drivers/ktime/src/boottime.c
|
rt-thread/components/drivers/ktime/src/boottime.c
|
||||||
rt-thread/components/drivers/ktime/src/cputimer.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_LIBCPU_SOURCES
|
SET(RT_LIBCPU_SOURCES
|
||||||
@ -212,30 +236,30 @@ SET(RT_LIBCPU_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_LIBRARIES_SOURCES
|
SET(RT_LIBRARIES_SOURCES
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cec.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_comp.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cec.c
|
||||||
|
libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sram.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_comp.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp_ex.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp_ex.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c
|
||||||
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
|
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
|
||||||
libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sram.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c
|
|
||||||
libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(RT_POSIX_SOURCES
|
SET(RT_POSIX_SOURCES
|
||||||
@ -276,6 +300,7 @@ SET(RT_COMPILER_LIBS
|
|||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
ADD_LIBRARY(rtt_app_erpc OBJECT ${RT_APP_ERPC_SOURCES})
|
ADD_LIBRARY(rtt_app_erpc OBJECT ${RT_APP_ERPC_SOURCES})
|
||||||
|
ADD_LIBRARY(rtt_CherryUSB OBJECT ${RT_CHERRYUSB_SOURCES})
|
||||||
ADD_LIBRARY(rtt_Compiler OBJECT ${RT_COMPILER_SOURCES})
|
ADD_LIBRARY(rtt_Compiler OBJECT ${RT_COMPILER_SOURCES})
|
||||||
ADD_LIBRARY(rtt_CPP OBJECT ${RT_CPP_SOURCES})
|
ADD_LIBRARY(rtt_CPP OBJECT ${RT_CPP_SOURCES})
|
||||||
ADD_LIBRARY(rtt_DeviceDrivers OBJECT ${RT_DEVICEDRIVERS_SOURCES})
|
ADD_LIBRARY(rtt_DeviceDrivers OBJECT ${RT_DEVICEDRIVERS_SOURCES})
|
||||||
@ -303,6 +328,7 @@ TARGET_LINK_LIBRARIES(rtt_Compiler INTERFACE ${RT_COMPILER_LIBS})
|
|||||||
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${RT_APPLICATIONS_SOURCES})
|
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${RT_APPLICATIONS_SOURCES})
|
||||||
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}.elf
|
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}.elf
|
||||||
rtt_app_erpc
|
rtt_app_erpc
|
||||||
|
rtt_CherryUSB
|
||||||
rtt_Compiler
|
rtt_Compiler
|
||||||
rtt_CPP
|
rtt_CPP
|
||||||
rtt_DeviceDrivers
|
rtt_DeviceDrivers
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -28,6 +28,14 @@ int32_t add(int32_t a, int32_t b)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t sum_i32(const list_int32_1_t * arr)
|
||||||
|
{
|
||||||
|
int64_t result;
|
||||||
|
result = s_demo_client->sum_i32(arr);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void initdemo_client(erpc_client_t client)
|
void initdemo_client(erpc_client_t client)
|
||||||
{
|
{
|
||||||
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC
|
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -25,11 +25,14 @@ enum _demo_ids
|
|||||||
{
|
{
|
||||||
kdemo_service_id = 1,
|
kdemo_service_id = 1,
|
||||||
kdemo_add_id = 1,
|
kdemo_add_id = 1,
|
||||||
|
kdemo_sum_i32_id = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
//! @name demo
|
//! @name demo
|
||||||
//@{
|
//@{
|
||||||
int32_t add(int32_t a, int32_t b);
|
int32_t add(int32_t a, int32_t b);
|
||||||
|
|
||||||
|
int64_t sum_i32(const list_int32_1_t * arr);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
#endif // ERPC_FUNCTIONS_DEFINITIONS
|
#endif // ERPC_FUNCTIONS_DEFINITIONS
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -28,6 +28,14 @@ class demo_server: public demo_interface
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t sum_i32(const list_int32_1_t * arr)
|
||||||
|
{
|
||||||
|
int64_t result;
|
||||||
|
result = ::sum_i32(arr);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ERPC_MANUALLY_CONSTRUCTED_STATIC(demo_service, s_demo_service);
|
ERPC_MANUALLY_CONSTRUCTED_STATIC(demo_service, s_demo_service);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -26,11 +26,14 @@ enum _demo_ids
|
|||||||
{
|
{
|
||||||
kdemo_service_id = 1,
|
kdemo_service_id = 1,
|
||||||
kdemo_add_id = 1,
|
kdemo_add_id = 1,
|
||||||
|
kdemo_sum_i32_id = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
//! @name demo
|
//! @name demo
|
||||||
//@{
|
//@{
|
||||||
int32_t add(int32_t a, int32_t b);
|
int32_t add(int32_t a, int32_t b);
|
||||||
|
|
||||||
|
int64_t sum_i32(const list_int32_1_t * arr);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -20,6 +20,26 @@ using namespace erpc;
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace erpcShim;
|
using namespace erpcShim;
|
||||||
|
|
||||||
|
//! @brief Function to write struct list_int32_1_t
|
||||||
|
static void write_list_int32_1_t_struct(erpc::Codec * codec, const list_int32_1_t * data);
|
||||||
|
|
||||||
|
|
||||||
|
// Write struct list_int32_1_t function implementation
|
||||||
|
static void write_list_int32_1_t_struct(erpc::Codec * codec, const list_int32_1_t * data)
|
||||||
|
{
|
||||||
|
if(NULL == data)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
codec->startWriteList(data->elementsCount);
|
||||||
|
for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount)
|
||||||
|
{
|
||||||
|
codec->write(data->elements[listCount]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
demo_client::demo_client(ClientManager *manager)
|
demo_client::demo_client(ClientManager *manager)
|
||||||
@ -88,6 +108,69 @@ int32_t demo_client::add(int32_t a, int32_t b)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if (err != kErpcStatus_Success)
|
||||||
|
{
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// demo interface sum_i32 function client shim.
|
||||||
|
int64_t demo_client::sum_i32(const list_int32_1_t * arr)
|
||||||
|
{
|
||||||
|
erpc_status_t err = kErpcStatus_Success;
|
||||||
|
|
||||||
|
int64_t result;
|
||||||
|
|
||||||
|
#if ERPC_PRE_POST_ACTION
|
||||||
|
pre_post_action_cb preCB = m_clientManager->getPreCB();
|
||||||
|
if (preCB)
|
||||||
|
{
|
||||||
|
preCB();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Get a new request.
|
||||||
|
RequestContext request = m_clientManager->createRequest(false);
|
||||||
|
|
||||||
|
// Encode the request.
|
||||||
|
Codec * codec = request.getCodec();
|
||||||
|
|
||||||
|
if (codec == NULL)
|
||||||
|
{
|
||||||
|
err = kErpcStatus_MemoryError;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
codec->startWriteMessage(message_type_t::kInvocationMessage, m_serviceId, m_sum_i32Id, request.getSequence());
|
||||||
|
|
||||||
|
write_list_int32_1_t_struct(codec, arr);
|
||||||
|
|
||||||
|
// Send message to server
|
||||||
|
// Codec status is checked inside this function.
|
||||||
|
m_clientManager->performRequest(request);
|
||||||
|
|
||||||
|
codec->read(result);
|
||||||
|
|
||||||
|
err = codec->getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispose of the request.
|
||||||
|
m_clientManager->releaseRequest(request);
|
||||||
|
|
||||||
|
// Invoke error handler callback function
|
||||||
|
m_clientManager->callErrorHandler(err, m_sum_i32Id);
|
||||||
|
|
||||||
|
#if ERPC_PRE_POST_ACTION
|
||||||
|
pre_post_action_cb postCB = m_clientManager->getPostCB();
|
||||||
|
if (postCB)
|
||||||
|
{
|
||||||
|
postCB();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (err != kErpcStatus_Success)
|
if (err != kErpcStatus_Success)
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -24,6 +24,8 @@ class demo_client: public demo_interface
|
|||||||
|
|
||||||
virtual int32_t add(int32_t a, int32_t b);
|
virtual int32_t add(int32_t a, int32_t b);
|
||||||
|
|
||||||
|
virtual int64_t sum_i32(const list_int32_1_t * arr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
erpc::ClientManager *m_clientManager;
|
erpc::ClientManager *m_clientManager;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -27,6 +27,17 @@ extern "C"
|
|||||||
#if !defined(ERPC_TYPE_DEFINITIONS_ERPCSHIM)
|
#if !defined(ERPC_TYPE_DEFINITIONS_ERPCSHIM)
|
||||||
#define ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
#define ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
||||||
|
|
||||||
|
// Aliases data types declarations
|
||||||
|
typedef struct list_int32_1_t list_int32_1_t;
|
||||||
|
|
||||||
|
// Structures/unions data types declarations
|
||||||
|
struct list_int32_1_t
|
||||||
|
{
|
||||||
|
int32_t * elements;
|
||||||
|
uint32_t elementsCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
#endif // ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -22,6 +22,17 @@
|
|||||||
#if !defined(ERPC_TYPE_DEFINITIONS_ERPCSHIM)
|
#if !defined(ERPC_TYPE_DEFINITIONS_ERPCSHIM)
|
||||||
#define ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
#define ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
||||||
|
|
||||||
|
// Aliases data types declarations
|
||||||
|
typedef struct list_int32_1_t list_int32_1_t;
|
||||||
|
|
||||||
|
// Structures/unions data types declarations
|
||||||
|
struct list_int32_1_t
|
||||||
|
{
|
||||||
|
int32_t * elements;
|
||||||
|
uint32_t elementsCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
#endif // ERPC_TYPE_DEFINITIONS_ERPCSHIM
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -20,10 +20,13 @@ class demo_interface
|
|||||||
public:
|
public:
|
||||||
static const uint8_t m_serviceId = 1;
|
static const uint8_t m_serviceId = 1;
|
||||||
static const uint8_t m_addId = 1;
|
static const uint8_t m_addId = 1;
|
||||||
|
static const uint8_t m_sum_i32Id = 2;
|
||||||
|
|
||||||
virtual ~demo_interface(void);
|
virtual ~demo_interface(void);
|
||||||
|
|
||||||
virtual int32_t add(int32_t a, int32_t b) = 0;
|
virtual int32_t add(int32_t a, int32_t b) = 0;
|
||||||
|
|
||||||
|
virtual int64_t sum_i32(const list_int32_1_t * arr) = 0;
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
} // erpcShim
|
} // erpcShim
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -25,6 +25,42 @@ extern bool nestingDetection;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//! @brief Function to read struct list_int32_1_t
|
||||||
|
static void read_list_int32_1_t_struct(erpc::Codec * codec, list_int32_1_t * data);
|
||||||
|
|
||||||
|
|
||||||
|
// Read struct list_int32_1_t function implementation
|
||||||
|
static void read_list_int32_1_t_struct(erpc::Codec * codec, list_int32_1_t * data)
|
||||||
|
{
|
||||||
|
if(NULL == data)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
codec->startReadList(data->elementsCount);
|
||||||
|
data->elements = (int32_t *) erpc_malloc(data->elementsCount * sizeof(int32_t));
|
||||||
|
if ((data->elements == NULL) && (data->elementsCount > 0))
|
||||||
|
{
|
||||||
|
codec->updateStatus(kErpcStatus_MemoryError);
|
||||||
|
}
|
||||||
|
for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount)
|
||||||
|
{
|
||||||
|
codec->read(data->elements[listCount]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @brief Function to free space allocated inside struct list_int32_1_t
|
||||||
|
static void free_list_int32_1_t_struct(list_int32_1_t * data);
|
||||||
|
|
||||||
|
|
||||||
|
// Free space allocated inside struct list_int32_1_t function implementation
|
||||||
|
static void free_list_int32_1_t_struct(list_int32_1_t * data)
|
||||||
|
{
|
||||||
|
erpc_free(data->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
demo_service::demo_service(demo_interface *_demo_interface)
|
demo_service::demo_service(demo_interface *_demo_interface)
|
||||||
: erpc::Service(demo_interface::m_serviceId)
|
: erpc::Service(demo_interface::m_serviceId)
|
||||||
@ -54,6 +90,12 @@ erpc_status_t demo_service::handleInvocation(uint32_t methodId, uint32_t sequenc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case demo_interface::m_sum_i32Id:
|
||||||
|
{
|
||||||
|
erpcStatus = sum_i32_shim(codec, messageFactory, transport, sequence);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
erpcStatus = kErpcStatus_InvalidArgument;
|
erpcStatus = kErpcStatus_InvalidArgument;
|
||||||
@ -110,3 +152,58 @@ erpc_status_t demo_service::add_shim(Codec * codec, MessageBufferFactory *messag
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server shim for sum_i32 of demo interface.
|
||||||
|
erpc_status_t demo_service::sum_i32_shim(Codec * codec, MessageBufferFactory *messageFactory, Transport * transport, uint32_t sequence)
|
||||||
|
{
|
||||||
|
erpc_status_t err = kErpcStatus_Success;
|
||||||
|
|
||||||
|
list_int32_1_t *arr = NULL;
|
||||||
|
arr = (list_int32_1_t *) erpc_malloc(sizeof(list_int32_1_t));
|
||||||
|
if (arr == NULL)
|
||||||
|
{
|
||||||
|
codec->updateStatus(kErpcStatus_MemoryError);
|
||||||
|
}
|
||||||
|
int64_t result;
|
||||||
|
|
||||||
|
// startReadMessage() was already called before this shim was invoked.
|
||||||
|
|
||||||
|
read_list_int32_1_t_struct(codec, arr);
|
||||||
|
|
||||||
|
err = codec->getStatus();
|
||||||
|
if (err == kErpcStatus_Success)
|
||||||
|
{
|
||||||
|
// Invoke the actual served function.
|
||||||
|
#if ERPC_NESTED_CALLS_DETECTION
|
||||||
|
nestingDetection = true;
|
||||||
|
#endif
|
||||||
|
result = m_handler->sum_i32(arr);
|
||||||
|
#if ERPC_NESTED_CALLS_DETECTION
|
||||||
|
nestingDetection = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// preparing MessageBuffer for serializing data
|
||||||
|
err = messageFactory->prepareServerBufferForSend(codec->getBufferRef(), transport->reserveHeaderSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == kErpcStatus_Success)
|
||||||
|
{
|
||||||
|
// preparing codec for serializing data
|
||||||
|
codec->reset(transport->reserveHeaderSize());
|
||||||
|
|
||||||
|
// Build response message.
|
||||||
|
codec->startWriteMessage(message_type_t::kReplyMessage, demo_interface::m_serviceId, demo_interface::m_sum_i32Id, sequence);
|
||||||
|
|
||||||
|
codec->write(result);
|
||||||
|
|
||||||
|
err = codec->getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arr)
|
||||||
|
{
|
||||||
|
free_list_int32_1_t_struct(arr);
|
||||||
|
}
|
||||||
|
erpc_free(arr);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated by erpcgen 1.14.0 on Wed Dec 24 14:07:39 2025.
|
* Generated by erpcgen 1.14.0 on Wed Dec 31 16:10:10 2025.
|
||||||
*
|
*
|
||||||
* AUTOGENERATED - DO NOT EDIT
|
* AUTOGENERATED - DO NOT EDIT
|
||||||
*/
|
*/
|
||||||
@ -41,6 +41,9 @@ private:
|
|||||||
demo_interface *m_handler;
|
demo_interface *m_handler;
|
||||||
/*! @brief Server shim for add of demo interface. */
|
/*! @brief Server shim for add of demo interface. */
|
||||||
erpc_status_t add_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, erpc::Transport * transport, uint32_t sequence);
|
erpc_status_t add_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, erpc::Transport * transport, uint32_t sequence);
|
||||||
|
|
||||||
|
/*! @brief Server shim for sum_i32 of demo interface. */
|
||||||
|
erpc_status_t sum_i32_shim(erpc::Codec * codec, erpc::MessageBufferFactory *messageFactory, erpc::Transport * transport, uint32_t sequence);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // erpcShim
|
} // erpcShim
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
interface demo {
|
interface demo {
|
||||||
add(int32 a, int32 b) -> int32
|
add(int32 a, int32 b) -> int32;
|
||||||
|
sum_i32(list<int32> arr) -> int64;
|
||||||
};
|
};
|
||||||
@ -18,6 +18,7 @@ public:
|
|||||||
|
|
||||||
// 实现你 .erpc 里定义的方法(这里只举例 add)
|
// 实现你 .erpc 里定义的方法(这里只举例 add)
|
||||||
int32_t add(int32_t a, int32_t b) override;
|
int32_t add(int32_t a, int32_t b) override;
|
||||||
|
int64_t sum_i32(const list_int32_1_t* arr) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include "erpc_server_setup.h"
|
#include "erpc_server_setup.h"
|
||||||
#include "erpc_transport_setup.h"
|
#include "erpc_transport_setup.h"
|
||||||
#include "erpc_mbf_setup.h"
|
#include "erpc_mbf_setup.h"
|
||||||
|
#include "erpc_usb_cdc_transport.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include "erpc/proto/generated/head_service_server.hpp"
|
#include "erpc/proto/generated/head_service_server.hpp"
|
||||||
@ -48,7 +49,14 @@ static void erpc_server_entry(void *parameter)
|
|||||||
rt_kprintf("[erpc] server init on %s, %d\r\n", ERPC_SERVER_UART_NAME, ERPC_UART_BAUD);
|
rt_kprintf("[erpc] server init on %s, %d\r\n", ERPC_SERVER_UART_NAME, ERPC_UART_BAUD);
|
||||||
|
|
||||||
// 1) transport
|
// 1) transport
|
||||||
erpc_transport_t transport = erpc_transport_serial_init(ERPC_SERVER_UART_NAME,ERPC_UART_BAUD);
|
static serial_port_usb_cdc_config_t cfg = {
|
||||||
|
.dev_name = "cdc0",
|
||||||
|
.rx_wait_ms = -1,
|
||||||
|
.tx_wait_ms = 2000,
|
||||||
|
};
|
||||||
|
|
||||||
|
erpc_transport_t transport = erpc_transport_usb_cdc_init(NULL, NULL, &cfg, NULL, 0);
|
||||||
|
// erpc_transport_t transport = erpc_transport_serial_init(ERPC_SERVER_UART_NAME,ERPC_UART_BAUD);
|
||||||
// erpc_transport_t transport = erpc_transport_cmsis_uart_init(ERPC_SERVER_UART_NAME);
|
// erpc_transport_t transport = erpc_transport_cmsis_uart_init(ERPC_SERVER_UART_NAME);
|
||||||
if (!transport)
|
if (!transport)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,10 +8,20 @@
|
|||||||
|
|
||||||
int32_t HeadServiceImpl::add(int32_t a, int32_t b)
|
int32_t HeadServiceImpl::add(int32_t a, int32_t b)
|
||||||
{
|
{
|
||||||
int32_t r = a + b;
|
return a + b;
|
||||||
rt_tick_t now = rt_tick_get();
|
// rt_tick_t now = rt_tick_get();
|
||||||
rt_uint32_t ms = (rt_uint32_t)((rt_uint64_t)now * 1000 / RT_TICK_PER_SECOND);
|
// rt_uint32_t ms = (rt_uint32_t)((rt_uint64_t)now * 1000 / RT_TICK_PER_SECOND);
|
||||||
rt_kprintf("[%lu ms] [erpc service] add(%ld,%ld)=%ld\r\n",
|
// rt_kprintf("[%lu ms] [erpc service] add(%ld,%ld)=%ld\r\n",
|
||||||
(unsigned long)ms, (long)a, (long)b, (long)r);
|
// (unsigned long)ms, (long)a, (long)b, (long)r);
|
||||||
return r;
|
// return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t HeadServiceImpl::sum_i32(const list_int32_1_t* arr)
|
||||||
|
{
|
||||||
|
int64_t sum = 0;
|
||||||
|
for (int i = 0; i < arr->elementsCount; ++i)
|
||||||
|
{
|
||||||
|
sum+= arr->elements[i];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,17 +32,10 @@ int main(void)
|
|||||||
rt_thread_mdelay(100);
|
rt_thread_mdelay(100);
|
||||||
// rt_kprintf("Hello RT-Thread!\n");
|
// rt_kprintf("Hello RT-Thread!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
static inline int dwt_init(void)
|
|
||||||
{
|
|
||||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
|
||||||
DWT->CYCCNT = 0;
|
|
||||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_APP_EXPORT(dwt_init);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -14,41 +14,42 @@ Mcu.CPN=STM32H750XBH6
|
|||||||
Mcu.Family=STM32H7
|
Mcu.Family=STM32H7
|
||||||
Mcu.IP0=CORTEX_M7
|
Mcu.IP0=CORTEX_M7
|
||||||
Mcu.IP1=DEBUG
|
Mcu.IP1=DEBUG
|
||||||
Mcu.IP10=USART3
|
Mcu.IP10=USB_DEVICE
|
||||||
|
Mcu.IP11=USB_OTG_FS
|
||||||
Mcu.IP2=MEMORYMAP
|
Mcu.IP2=MEMORYMAP
|
||||||
Mcu.IP3=NVIC
|
Mcu.IP3=NVIC
|
||||||
Mcu.IP4=QUADSPI
|
Mcu.IP4=QUADSPI
|
||||||
Mcu.IP5=RCC
|
Mcu.IP5=RCC
|
||||||
Mcu.IP6=SPI5
|
Mcu.IP6=SYS
|
||||||
Mcu.IP7=SYS
|
Mcu.IP7=USART1
|
||||||
Mcu.IP8=USART1
|
Mcu.IP8=USART2
|
||||||
Mcu.IP9=USART2
|
Mcu.IP9=USART3
|
||||||
Mcu.IPNb=11
|
Mcu.IPNb=12
|
||||||
Mcu.Name=STM32H750XBHx
|
Mcu.Name=STM32H750XBHx
|
||||||
Mcu.Package=TFBGA240
|
Mcu.Package=TFBGA240
|
||||||
Mcu.Pin0=PD5
|
Mcu.Pin0=PD5
|
||||||
Mcu.Pin1=PD6
|
Mcu.Pin1=PD6
|
||||||
Mcu.Pin10=PH0-OSC_IN (PH0)
|
Mcu.Pin10=PG6
|
||||||
Mcu.Pin11=PK0
|
Mcu.Pin11=PH1-OSC_OUT (PH1)
|
||||||
Mcu.Pin12=PF6
|
Mcu.Pin12=PH0-OSC_IN (PH0)
|
||||||
Mcu.Pin13=PF7
|
Mcu.Pin13=PF7
|
||||||
Mcu.Pin14=PF8
|
Mcu.Pin14=PF8
|
||||||
Mcu.Pin15=PF10
|
Mcu.Pin15=PF10
|
||||||
Mcu.Pin16=PF9
|
Mcu.Pin16=PF9
|
||||||
Mcu.Pin17=PJ10
|
Mcu.Pin17=PE9
|
||||||
Mcu.Pin18=PE9
|
Mcu.Pin18=PD9
|
||||||
Mcu.Pin19=PD9
|
Mcu.Pin19=PD8
|
||||||
Mcu.Pin2=PA14 (JTCK/SWCLK)
|
Mcu.Pin2=PA14 (JTCK/SWCLK)
|
||||||
Mcu.Pin20=PD8
|
Mcu.Pin20=VP_SYS_VS_Systick
|
||||||
Mcu.Pin21=VP_SYS_VS_Systick
|
Mcu.Pin21=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
|
||||||
Mcu.Pin22=VP_MEMORYMAP_VS_MEMORYMAP
|
Mcu.Pin22=VP_MEMORYMAP_VS_MEMORYMAP
|
||||||
Mcu.Pin3=PC15-OSC32_OUT (OSC32_OUT)
|
Mcu.Pin3=PC15-OSC32_OUT (OSC32_OUT)
|
||||||
Mcu.Pin4=PC14-OSC32_IN (OSC32_IN)
|
Mcu.Pin4=PC14-OSC32_IN (OSC32_IN)
|
||||||
Mcu.Pin5=PA13 (JTMS/SWDIO)
|
Mcu.Pin5=PA13 (JTMS/SWDIO)
|
||||||
Mcu.Pin6=PA10
|
Mcu.Pin6=PA10
|
||||||
Mcu.Pin7=PA9
|
Mcu.Pin7=PA9
|
||||||
Mcu.Pin8=PG6
|
Mcu.Pin8=PA12
|
||||||
Mcu.Pin9=PH1-OSC_OUT (PH1)
|
Mcu.Pin9=PA11
|
||||||
Mcu.PinsNb=23
|
Mcu.PinsNb=23
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
@ -61,7 +62,8 @@ NVIC.ForceEnableDMAVector=true
|
|||||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.OTG_FS_IRQn=true\:5\:0\:true\:false\:true\:true\:true\:true
|
||||||
|
NVIC.PendSV_IRQn=true\:0\:0\:true\:false\:true\:false\:false\:false
|
||||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||||
@ -69,6 +71,16 @@ NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
|||||||
PA10.Locked=true
|
PA10.Locked=true
|
||||||
PA10.Mode=Asynchronous
|
PA10.Mode=Asynchronous
|
||||||
PA10.Signal=USART1_RX
|
PA10.Signal=USART1_RX
|
||||||
|
PA11.GPIOParameters=GPIO_Speed,GPIO_PuPd
|
||||||
|
PA11.GPIO_PuPd=GPIO_PULLUP
|
||||||
|
PA11.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||||
|
PA11.Mode=Device_Only
|
||||||
|
PA11.Signal=USB_OTG_FS_DM
|
||||||
|
PA12.GPIOParameters=GPIO_Speed,GPIO_PuPd
|
||||||
|
PA12.GPIO_PuPd=GPIO_PULLUP
|
||||||
|
PA12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||||
|
PA12.Mode=Device_Only
|
||||||
|
PA12.Signal=USB_OTG_FS_DP
|
||||||
PA13\ (JTMS/SWDIO).Mode=Serial_Wire
|
PA13\ (JTMS/SWDIO).Mode=Serial_Wire
|
||||||
PA13\ (JTMS/SWDIO).Signal=DEBUG_JTMS-SWDIO
|
PA13\ (JTMS/SWDIO).Signal=DEBUG_JTMS-SWDIO
|
||||||
PA14\ (JTCK/SWCLK).Mode=Serial_Wire
|
PA14\ (JTCK/SWCLK).Mode=Serial_Wire
|
||||||
@ -92,30 +104,23 @@ PD9.Mode=Asynchronous
|
|||||||
PD9.Signal=USART3_RX
|
PD9.Signal=USART3_RX
|
||||||
PE9.Locked=true
|
PE9.Locked=true
|
||||||
PE9.Signal=S_TIM1_CH1
|
PE9.Signal=S_TIM1_CH1
|
||||||
PF10.Mode=Single Bank 1
|
PF10.Mode=Single Bank 1 2IOs
|
||||||
PF10.Signal=QUADSPI_CLK
|
PF10.Signal=QUADSPI_CLK
|
||||||
PF6.Mode=Single Bank 1
|
|
||||||
PF6.Signal=QUADSPI_BK1_IO3
|
|
||||||
PF7.Locked=true
|
PF7.Locked=true
|
||||||
PF7.Mode=Single Bank 1
|
|
||||||
PF7.Signal=QUADSPI_BK1_IO2
|
PF7.Signal=QUADSPI_BK1_IO2
|
||||||
PF8.Locked=true
|
PF8.Locked=true
|
||||||
PF8.Mode=Single Bank 1
|
PF8.Mode=Single Bank 1 2IOs
|
||||||
PF8.Signal=QUADSPI_BK1_IO0
|
PF8.Signal=QUADSPI_BK1_IO0
|
||||||
PF9.Locked=true
|
PF9.Locked=true
|
||||||
PF9.Mode=Single Bank 1
|
PF9.Mode=Single Bank 1 2IOs
|
||||||
PF9.Signal=QUADSPI_BK1_IO1
|
PF9.Signal=QUADSPI_BK1_IO1
|
||||||
PG6.Locked=true
|
PG6.Locked=true
|
||||||
PG6.Mode=Single Bank 1
|
PG6.Mode=Single Bank 1 2IOs
|
||||||
PG6.Signal=QUADSPI_BK1_NCS
|
PG6.Signal=QUADSPI_BK1_NCS
|
||||||
PH0-OSC_IN\ (PH0).Mode=HSE-External-Oscillator
|
PH0-OSC_IN\ (PH0).Mode=HSE-External-Oscillator
|
||||||
PH0-OSC_IN\ (PH0).Signal=RCC_OSC_IN
|
PH0-OSC_IN\ (PH0).Signal=RCC_OSC_IN
|
||||||
PH1-OSC_OUT\ (PH1).Mode=HSE-External-Oscillator
|
PH1-OSC_OUT\ (PH1).Mode=HSE-External-Oscillator
|
||||||
PH1-OSC_OUT\ (PH1).Signal=RCC_OSC_OUT
|
PH1-OSC_OUT\ (PH1).Signal=RCC_OSC_OUT
|
||||||
PJ10.Mode=TX_Only_Simplex_Unidirect_Master
|
|
||||||
PJ10.Signal=SPI5_MOSI
|
|
||||||
PK0.Mode=TX_Only_Simplex_Unidirect_Master
|
|
||||||
PK0.Signal=SPI5_SCK
|
|
||||||
PinOutPanel.CurrentBGAView=Top
|
PinOutPanel.CurrentBGAView=Top
|
||||||
PinOutPanel.RotationAngle=0
|
PinOutPanel.RotationAngle=0
|
||||||
ProjectManager.AskForMigrate=true
|
ProjectManager.AskForMigrate=true
|
||||||
@ -150,14 +155,14 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=false
|
ProjectManager.UnderRoot=false
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_QUADSPI_Init-QUADSPI-false-HAL-true,5-MX_SPI5_Init-SPI5-false-HAL-true,6-MX_USART2_UART_Init-USART2-false-HAL-true,7-MX_USART3_UART_Init-USART3-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_USART3_UART_Init-USART3-false-HAL-true,6-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||||
QUADSPI.ChipSelectHighTime=QSPI_CS_HIGH_TIME_5_CYCLE
|
QUADSPI.ChipSelectHighTime=QSPI_CS_HIGH_TIME_5_CYCLE
|
||||||
QUADSPI.ClockPrescaler=5
|
QUADSPI.ClockPrescaler=5
|
||||||
QUADSPI.FifoThreshold=4
|
QUADSPI.FifoThreshold=4
|
||||||
QUADSPI.FlashSize=22
|
QUADSPI.FlashSize=22
|
||||||
QUADSPI.IPParameters=ClockPrescaler,FifoThreshold,SampleShifting,FlashSize,ChipSelectHighTime
|
QUADSPI.IPParameters=ClockPrescaler,FifoThreshold,SampleShifting,FlashSize,ChipSelectHighTime
|
||||||
QUADSPI.SampleShifting=QSPI_SAMPLE_SHIFTING_HALFCYCLE
|
QUADSPI.SampleShifting=QSPI_SAMPLE_SHIFTING_HALFCYCLE
|
||||||
RCC.ADCFreq_Value=129000000
|
RCC.ADCFreq_Value=50390625
|
||||||
RCC.AHB12Freq_Value=240000000
|
RCC.AHB12Freq_Value=240000000
|
||||||
RCC.AHB4Freq_Value=240000000
|
RCC.AHB4Freq_Value=240000000
|
||||||
RCC.APB1Freq_Value=120000000
|
RCC.APB1Freq_Value=120000000
|
||||||
@ -174,20 +179,21 @@ RCC.D1PPRE=RCC_APB3_DIV2
|
|||||||
RCC.D2PPRE1=RCC_APB1_DIV2
|
RCC.D2PPRE1=RCC_APB1_DIV2
|
||||||
RCC.D2PPRE2=RCC_APB2_DIV2
|
RCC.D2PPRE2=RCC_APB2_DIV2
|
||||||
RCC.D3PPRE=RCC_APB4_DIV2
|
RCC.D3PPRE=RCC_APB4_DIV2
|
||||||
RCC.DFSDMACLkFreq_Value=480000000
|
RCC.DFSDMACLkFreq_Value=48000000
|
||||||
RCC.DFSDMFreq_Value=120000000
|
RCC.DFSDMFreq_Value=120000000
|
||||||
RCC.DIVM1=4
|
RCC.DIVM1=5
|
||||||
RCC.DIVN1=60
|
RCC.DIVN1=192
|
||||||
RCC.DIVP1Freq_Value=480000000
|
RCC.DIVP1Freq_Value=480000000
|
||||||
RCC.DIVP2Freq_Value=129000000
|
RCC.DIVP2Freq_Value=50390625
|
||||||
RCC.DIVP3Freq_Value=129000000
|
RCC.DIVP3Freq_Value=50390625
|
||||||
RCC.DIVQ1Freq_Value=480000000
|
RCC.DIVQ1=20
|
||||||
RCC.DIVQ2Freq_Value=129000000
|
RCC.DIVQ1Freq_Value=48000000
|
||||||
RCC.DIVQ3Freq_Value=129000000
|
RCC.DIVQ2Freq_Value=50390625
|
||||||
|
RCC.DIVQ3Freq_Value=50390625
|
||||||
RCC.DIVR1Freq_Value=480000000
|
RCC.DIVR1Freq_Value=480000000
|
||||||
RCC.DIVR2Freq_Value=129000000
|
RCC.DIVR2Freq_Value=50390625
|
||||||
RCC.DIVR3Freq_Value=129000000
|
RCC.DIVR3Freq_Value=50390625
|
||||||
RCC.FDCANFreq_Value=480000000
|
RCC.FDCANFreq_Value=48000000
|
||||||
RCC.FMCFreq_Value=240000000
|
RCC.FMCFreq_Value=240000000
|
||||||
RCC.FamilyName=M
|
RCC.FamilyName=M
|
||||||
RCC.HCLK3ClockFreq_Value=240000000
|
RCC.HCLK3ClockFreq_Value=240000000
|
||||||
@ -196,27 +202,29 @@ RCC.HPRE=RCC_HCLK_DIV2
|
|||||||
RCC.HRTIMFreq_Value=240000000
|
RCC.HRTIMFreq_Value=240000000
|
||||||
RCC.I2C123Freq_Value=120000000
|
RCC.I2C123Freq_Value=120000000
|
||||||
RCC.I2C4Freq_Value=120000000
|
RCC.I2C4Freq_Value=120000000
|
||||||
RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVN1,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HPRE,HRTIMFreq_Value,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLL2FRACN,PLL3FRACN,PLLFRACN,QSPIFreq_Value,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value
|
RCC.IPParameters=ADCFreq_Value,AHB12Freq_Value,AHB4Freq_Value,APB1Freq_Value,APB2Freq_Value,APB3Freq_Value,APB4Freq_Value,AXIClockFreq_Value,CECFreq_Value,CKPERFreq_Value,CortexFreq_Value,CpuClockFreq_Value,D1CPREFreq_Value,D1PPRE,D2PPRE1,D2PPRE2,D3PPRE,DFSDMACLkFreq_Value,DFSDMFreq_Value,DIVM1,DIVN1,DIVP1Freq_Value,DIVP2Freq_Value,DIVP3Freq_Value,DIVQ1,DIVQ1Freq_Value,DIVQ2Freq_Value,DIVQ3Freq_Value,DIVR1Freq_Value,DIVR2Freq_Value,DIVR3Freq_Value,FDCANFreq_Value,FMCFreq_Value,FamilyName,HCLK3ClockFreq_Value,HCLKFreq_Value,HPRE,HRTIMFreq_Value,I2C123Freq_Value,I2C4Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPTIM345Freq_Value,LPUART1Freq_Value,LTDCFreq_Value,MCO1PinFreq_Value,MCO2PinFreq_Value,PLL2FRACN,PLL3FRACN,PLLFRACN,PLLSourceVirtual,QSPIFreq_Value,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SAI23Freq_Value,SAI4AFreq_Value,SAI4BFreq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SPI123Freq_Value,SPI45Freq_Value,SPI6Freq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,Tim1OutputFreq_Value,Tim2OutputFreq_Value,TraceFreq_Value,USART16Freq_Value,USART234578Freq_Value,USBFreq_Value,VCO1OutputFreq_Value,VCO2OutputFreq_Value,VCO3OutputFreq_Value,VCOInput1Freq_Value,VCOInput2Freq_Value,VCOInput3Freq_Value
|
||||||
RCC.LPTIM1Freq_Value=120000000
|
RCC.LPTIM1Freq_Value=120000000
|
||||||
RCC.LPTIM2Freq_Value=120000000
|
RCC.LPTIM2Freq_Value=120000000
|
||||||
RCC.LPTIM345Freq_Value=120000000
|
RCC.LPTIM345Freq_Value=120000000
|
||||||
RCC.LPUART1Freq_Value=120000000
|
RCC.LPUART1Freq_Value=120000000
|
||||||
RCC.LTDCFreq_Value=129000000
|
RCC.LTDCFreq_Value=50390625
|
||||||
|
RCC.LockedElements=AHBOutput
|
||||||
RCC.MCO1PinFreq_Value=64000000
|
RCC.MCO1PinFreq_Value=64000000
|
||||||
RCC.MCO2PinFreq_Value=480000000
|
RCC.MCO2PinFreq_Value=480000000
|
||||||
RCC.PLL2FRACN=0
|
RCC.PLL2FRACN=0
|
||||||
RCC.PLL3FRACN=0
|
RCC.PLL3FRACN=0
|
||||||
RCC.PLLFRACN=0
|
RCC.PLLFRACN=0
|
||||||
|
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||||
RCC.QSPIFreq_Value=240000000
|
RCC.QSPIFreq_Value=240000000
|
||||||
RCC.RNGFreq_Value=48000000
|
RCC.RNGFreq_Value=48000000
|
||||||
RCC.RTCFreq_Value=32000
|
RCC.RTCFreq_Value=32000
|
||||||
RCC.SAI1Freq_Value=480000000
|
RCC.SAI1Freq_Value=48000000
|
||||||
RCC.SAI23Freq_Value=480000000
|
RCC.SAI23Freq_Value=48000000
|
||||||
RCC.SAI4AFreq_Value=480000000
|
RCC.SAI4AFreq_Value=48000000
|
||||||
RCC.SAI4BFreq_Value=480000000
|
RCC.SAI4BFreq_Value=48000000
|
||||||
RCC.SDMMCFreq_Value=480000000
|
RCC.SDMMCFreq_Value=48000000
|
||||||
RCC.SPDIFRXFreq_Value=480000000
|
RCC.SPDIFRXFreq_Value=48000000
|
||||||
RCC.SPI123Freq_Value=480000000
|
RCC.SPI123Freq_Value=48000000
|
||||||
RCC.SPI45Freq_Value=120000000
|
RCC.SPI45Freq_Value=120000000
|
||||||
RCC.SPI6Freq_Value=120000000
|
RCC.SPI6Freq_Value=120000000
|
||||||
RCC.SWPMI1Freq_Value=120000000
|
RCC.SWPMI1Freq_Value=120000000
|
||||||
@ -227,28 +235,32 @@ RCC.Tim2OutputFreq_Value=240000000
|
|||||||
RCC.TraceFreq_Value=480000000
|
RCC.TraceFreq_Value=480000000
|
||||||
RCC.USART16Freq_Value=120000000
|
RCC.USART16Freq_Value=120000000
|
||||||
RCC.USART234578Freq_Value=120000000
|
RCC.USART234578Freq_Value=120000000
|
||||||
RCC.USBFreq_Value=480000000
|
RCC.USBFreq_Value=48000000
|
||||||
RCC.VCO1OutputFreq_Value=960000000
|
RCC.VCO1OutputFreq_Value=960000000
|
||||||
RCC.VCO2OutputFreq_Value=258000000
|
RCC.VCO2OutputFreq_Value=100781250
|
||||||
RCC.VCO3OutputFreq_Value=258000000
|
RCC.VCO3OutputFreq_Value=100781250
|
||||||
RCC.VCOInput1Freq_Value=16000000
|
RCC.VCOInput1Freq_Value=5000000
|
||||||
RCC.VCOInput2Freq_Value=2000000
|
RCC.VCOInput2Freq_Value=781250
|
||||||
RCC.VCOInput3Freq_Value=2000000
|
RCC.VCOInput3Freq_Value=781250
|
||||||
SH.S_TIM1_CH1.0=TIM1_CH1
|
SH.S_TIM1_CH1.0=TIM1_CH1
|
||||||
SH.S_TIM1_CH1.ConfNb=1
|
SH.S_TIM1_CH1.ConfNb=1
|
||||||
SPI5.CalculateBaudRate=60.0 MBits/s
|
|
||||||
SPI5.Direction=SPI_DIRECTION_2LINES_TXONLY
|
|
||||||
SPI5.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
|
||||||
SPI5.Mode=SPI_MODE_MASTER
|
|
||||||
SPI5.VirtualType=VM_MASTER
|
|
||||||
USART1.IPParameters=VirtualMode-Asynchronous
|
USART1.IPParameters=VirtualMode-Asynchronous
|
||||||
USART1.VirtualMode-Asynchronous=VM_ASYNC
|
USART1.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
USART2.IPParameters=VirtualMode-Asynchronous
|
USART2.IPParameters=VirtualMode-Asynchronous
|
||||||
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
USART3.IPParameters=VirtualMode-Asynchronous
|
USART3.IPParameters=VirtualMode-Asynchronous
|
||||||
USART3.VirtualMode-Asynchronous=VM_ASYNC
|
USART3.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
|
USB_DEVICE.CLASS_NAME_FS=CDC
|
||||||
|
USB_DEVICE.IPParameters=VirtualMode-CDC_FS,VirtualModeFS,CLASS_NAME_FS
|
||||||
|
USB_DEVICE.VirtualMode-CDC_FS=Cdc
|
||||||
|
USB_DEVICE.VirtualModeFS=Cdc_FS
|
||||||
|
USB_OTG_FS.IPParameters=VirtualMode,dma_enable
|
||||||
|
USB_OTG_FS.VirtualMode=Device_Only
|
||||||
|
USB_OTG_FS.dma_enable=ENABLE
|
||||||
VP_MEMORYMAP_VS_MEMORYMAP.Mode=CurAppReg
|
VP_MEMORYMAP_VS_MEMORYMAP.Mode=CurAppReg
|
||||||
VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
||||||
VP_SYS_VS_Systick.Mode=SysTick
|
VP_SYS_VS_Systick.Mode=SysTick
|
||||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||||
|
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
|
||||||
|
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
|
||||||
board=custom
|
board=custom
|
||||||
|
|||||||
@ -0,0 +1,444 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file stm32h7xx_hal_pcd.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file of PCD HAL module.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef STM32H7xx_HAL_PCD_H
|
||||||
|
#define STM32H7xx_HAL_PCD_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx_ll_usb.h"
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
|
||||||
|
/** @addtogroup STM32H7xx_HAL_Driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup PCD
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
/** @defgroup PCD_Exported_Types PCD Exported Types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief PCD State structure definition
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
HAL_PCD_STATE_RESET = 0x00,
|
||||||
|
HAL_PCD_STATE_READY = 0x01,
|
||||||
|
HAL_PCD_STATE_ERROR = 0x02,
|
||||||
|
HAL_PCD_STATE_BUSY = 0x03,
|
||||||
|
HAL_PCD_STATE_TIMEOUT = 0x04
|
||||||
|
} PCD_StateTypeDef;
|
||||||
|
|
||||||
|
/* Device LPM suspend state */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LPM_L0 = 0x00, /* on */
|
||||||
|
LPM_L1 = 0x01, /* LPM L1 sleep */
|
||||||
|
LPM_L2 = 0x02, /* suspend */
|
||||||
|
LPM_L3 = 0x03, /* off */
|
||||||
|
} PCD_LPM_StateTypeDef;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
PCD_LPM_L0_ACTIVE = 0x00, /* on */
|
||||||
|
PCD_LPM_L1_ACTIVE = 0x01, /* LPM L1 sleep */
|
||||||
|
} PCD_LPM_MsgTypeDef;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
PCD_BCD_ERROR = 0xFF,
|
||||||
|
PCD_BCD_CONTACT_DETECTION = 0xFE,
|
||||||
|
PCD_BCD_STD_DOWNSTREAM_PORT = 0xFD,
|
||||||
|
PCD_BCD_CHARGING_DOWNSTREAM_PORT = 0xFC,
|
||||||
|
PCD_BCD_DEDICATED_CHARGING_PORT = 0xFB,
|
||||||
|
PCD_BCD_DISCOVERY_COMPLETED = 0x00,
|
||||||
|
|
||||||
|
} PCD_BCD_MsgTypeDef;
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
|
||||||
|
typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
|
||||||
|
typedef USB_OTG_EPTypeDef PCD_EPTypeDef;
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief PCD Handle Structure definition
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
typedef struct __PCD_HandleTypeDef
|
||||||
|
#else
|
||||||
|
typedef struct
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
PCD_TypeDef *Instance; /*!< Register base address */
|
||||||
|
PCD_InitTypeDef Init; /*!< PCD required parameters */
|
||||||
|
__IO uint8_t USB_Address; /*!< USB Address */
|
||||||
|
PCD_EPTypeDef IN_ep[16]; /*!< IN endpoint parameters */
|
||||||
|
PCD_EPTypeDef OUT_ep[16]; /*!< OUT endpoint parameters */
|
||||||
|
HAL_LockTypeDef Lock; /*!< PCD peripheral status */
|
||||||
|
__IO PCD_StateTypeDef State; /*!< PCD communication state */
|
||||||
|
__IO uint32_t ErrorCode; /*!< PCD Error code */
|
||||||
|
uint32_t Setup[12]; /*!< Setup packet buffer */
|
||||||
|
PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */
|
||||||
|
uint32_t BESL;
|
||||||
|
uint32_t FrameNumber; /*!< Store Current Frame number */
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t lpm_active; /*!< Enable or disable the Link Power Management .
|
||||||
|
This parameter can be set to ENABLE or DISABLE */
|
||||||
|
|
||||||
|
uint32_t battery_charging_active; /*!< Enable or disable Battery charging.
|
||||||
|
This parameter can be set to ENABLE or DISABLE */
|
||||||
|
void *pData; /*!< Pointer to upper stack Handler */
|
||||||
|
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
void (* SOFCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD SOF callback */
|
||||||
|
void (* SetupStageCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Setup Stage callback */
|
||||||
|
void (* ResetCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Reset callback */
|
||||||
|
void (* SuspendCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Suspend callback */
|
||||||
|
void (* ResumeCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Resume callback */
|
||||||
|
void (* ConnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Connect callback */
|
||||||
|
void (* DisconnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Disconnect callback */
|
||||||
|
|
||||||
|
void (* DataOutStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data OUT Stage callback */
|
||||||
|
void (* DataInStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data IN Stage callback */
|
||||||
|
void (* ISOOUTIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO OUT Incomplete callback */
|
||||||
|
void (* ISOINIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO IN Incomplete callback */
|
||||||
|
void (* BCDCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); /*!< USB OTG PCD BCD callback */
|
||||||
|
void (* LPMCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); /*!< USB OTG PCD LPM callback */
|
||||||
|
|
||||||
|
void (* MspInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp Init callback */
|
||||||
|
void (* MspDeInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp DeInit callback */
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
} PCD_HandleTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Include PCD HAL Extended module */
|
||||||
|
#include "stm32h7xx_hal_pcd_ex.h"
|
||||||
|
|
||||||
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
/** @defgroup PCD_Exported_Constants PCD Exported Constants
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup PCD_Speed PCD Speed
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define PCD_SPEED_HIGH USBD_HS_SPEED
|
||||||
|
#define PCD_SPEED_HIGH_IN_FULL USBD_HSINFS_SPEED
|
||||||
|
#define PCD_SPEED_FULL USBD_FS_SPEED
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup PCD_PHY_Module PCD PHY Module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define PCD_PHY_ULPI 1U
|
||||||
|
#define PCD_PHY_EMBEDDED 2U
|
||||||
|
#define PCD_PHY_UTMI 3U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup PCD_Error_Code_definition PCD Error Code definition
|
||||||
|
* @brief PCD Error Code definition
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
#define HAL_PCD_ERROR_INVALID_CALLBACK (0x00000010U) /*!< Invalid Callback error */
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported macros -----------------------------------------------------------*/
|
||||||
|
/** @defgroup PCD_Exported_Macros PCD Exported Macros
|
||||||
|
* @brief macros to handle interrupts and specific clock configurations
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
|
||||||
|
#define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
|
||||||
|
|
||||||
|
#define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) \
|
||||||
|
((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
#define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
|
||||||
|
#define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
|
||||||
|
|
||||||
|
#define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) \
|
||||||
|
*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= ~(USB_OTG_PCGCCTL_STOPCLK)
|
||||||
|
|
||||||
|
#define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) \
|
||||||
|
*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
|
||||||
|
|
||||||
|
#define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) \
|
||||||
|
((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE)) & 0x10U)
|
||||||
|
|
||||||
|
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI_D1->IMR2 |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
|
||||||
|
#define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI_D1->IMR2 &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
|
||||||
|
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI_D1->IMR2 |= (USB_OTG_FS_WAKEUP_EXTI_LINE)
|
||||||
|
#define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI_D1->IMR2 &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
/** @addtogroup PCD_Exported_Functions PCD Exported Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Initialization/de-initialization functions ********************************/
|
||||||
|
/** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
/** @defgroup HAL_PCD_Callback_ID_enumeration_definition HAL USB OTG PCD Callback ID enumeration definition
|
||||||
|
* @brief HAL USB OTG PCD Callback ID enumeration definition
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
HAL_PCD_SOF_CB_ID = 0x01, /*!< USB PCD SOF callback ID */
|
||||||
|
HAL_PCD_SETUPSTAGE_CB_ID = 0x02, /*!< USB PCD Setup Stage callback ID */
|
||||||
|
HAL_PCD_RESET_CB_ID = 0x03, /*!< USB PCD Reset callback ID */
|
||||||
|
HAL_PCD_SUSPEND_CB_ID = 0x04, /*!< USB PCD Suspend callback ID */
|
||||||
|
HAL_PCD_RESUME_CB_ID = 0x05, /*!< USB PCD Resume callback ID */
|
||||||
|
HAL_PCD_CONNECT_CB_ID = 0x06, /*!< USB PCD Connect callback ID */
|
||||||
|
HAL_PCD_DISCONNECT_CB_ID = 0x07, /*!< USB PCD Disconnect callback ID */
|
||||||
|
|
||||||
|
HAL_PCD_MSPINIT_CB_ID = 0x08, /*!< USB PCD MspInit callback ID */
|
||||||
|
HAL_PCD_MSPDEINIT_CB_ID = 0x09 /*!< USB PCD MspDeInit callback ID */
|
||||||
|
|
||||||
|
} HAL_PCD_CallbackIDTypeDef;
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup HAL_PCD_Callback_pointer_definition HAL USB OTG PCD Callback pointer definition
|
||||||
|
* @brief HAL USB OTG PCD Callback pointer definition
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef void (*pPCD_CallbackTypeDef)(PCD_HandleTypeDef *hpcd); /*!< pointer to a common USB OTG PCD callback function */
|
||||||
|
typedef void (*pPCD_DataOutStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data OUT Stage callback */
|
||||||
|
typedef void (*pPCD_DataInStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data IN Stage callback */
|
||||||
|
typedef void (*pPCD_IsoOutIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO OUT Incomplete callback */
|
||||||
|
typedef void (*pPCD_IsoInIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO IN Incomplete callback */
|
||||||
|
typedef void (*pPCD_LpmCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); /*!< pointer to USB OTG PCD LPM callback */
|
||||||
|
typedef void (*pPCD_BcdCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); /*!< pointer to USB OTG PCD BCD callback */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID,
|
||||||
|
pPCD_CallbackTypeDef pCallback);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd,
|
||||||
|
pPCD_DataOutStageCallbackTypeDef pCallback);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd,
|
||||||
|
pPCD_DataInStageCallbackTypeDef pCallback);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd,
|
||||||
|
pPCD_IsoOutIncpltCallbackTypeDef pCallback);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd,
|
||||||
|
pPCD_IsoInIncpltCallbackTypeDef pCallback);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterBcdCallback(PCD_HandleTypeDef *hpcd, pPCD_BcdCallbackTypeDef pCallback);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterBcdCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCD_RegisterLpmCallback(PCD_HandleTypeDef *hpcd, pPCD_LpmCallbackTypeDef pCallback);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_UnRegisterLpmCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* I/O operation functions ***************************************************/
|
||||||
|
/* Non-Blocking mode: Interrupt */
|
||||||
|
/** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
||||||
|
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
||||||
|
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
||||||
|
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Peripheral Control functions **********************************************/
|
||||||
|
/** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_EP_Abort(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
HAL_StatusTypeDef HAL_PCD_SetTestMode(const PCD_HandleTypeDef *hpcd, uint8_t testmode);
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef const *hpcd, uint8_t ep_addr);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Peripheral State functions ************************************************/
|
||||||
|
/** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef const *hpcd);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private constants ---------------------------------------------------------*/
|
||||||
|
/** @defgroup PCD_Private_Constants PCD Private Constants
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/** @defgroup USB_EXTI_Line_Interrupt USB EXTI line interrupt
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
#define USB_OTG_FS_WAKEUP_EXTI_LINE (0x1U << 12) /*!< USB FS EXTI Line WakeUp Interrupt */
|
||||||
|
#define USB_OTG_HS_WAKEUP_EXTI_LINE (0x1U << 11) /*!< USB HS EXTI Line WakeUp Interrupt */
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
#ifndef USB_OTG_DOEPINT_OTEPSPR
|
||||||
|
#define USB_OTG_DOEPINT_OTEPSPR (0x1UL << 5) /*!< Status Phase Received interrupt */
|
||||||
|
#endif /* defined USB_OTG_DOEPINT_OTEPSPR */
|
||||||
|
|
||||||
|
#ifndef USB_OTG_DOEPMSK_OTEPSPRM
|
||||||
|
#define USB_OTG_DOEPMSK_OTEPSPRM (0x1UL << 5) /*!< Setup Packet Received interrupt mask */
|
||||||
|
#endif /* defined USB_OTG_DOEPMSK_OTEPSPRM */
|
||||||
|
|
||||||
|
#ifndef USB_OTG_DOEPINT_NAK
|
||||||
|
#define USB_OTG_DOEPINT_NAK (0x1UL << 13) /*!< NAK interrupt */
|
||||||
|
#endif /* defined USB_OTG_DOEPINT_NAK */
|
||||||
|
|
||||||
|
#ifndef USB_OTG_DOEPMSK_NAKM
|
||||||
|
#define USB_OTG_DOEPMSK_NAKM (0x1UL << 13) /*!< OUT Packet NAK interrupt mask */
|
||||||
|
#endif /* defined USB_OTG_DOEPMSK_NAKM */
|
||||||
|
|
||||||
|
#ifndef USB_OTG_DOEPINT_STPKTRX
|
||||||
|
#define USB_OTG_DOEPINT_STPKTRX (0x1UL << 15) /*!< Setup Packet Received interrupt */
|
||||||
|
#endif /* defined USB_OTG_DOEPINT_STPKTRX */
|
||||||
|
|
||||||
|
#ifndef USB_OTG_DOEPMSK_NYETM
|
||||||
|
#define USB_OTG_DOEPMSK_NYETM (0x1UL << 14) /*!< Setup Packet Received interrupt mask */
|
||||||
|
#endif /* defined USB_OTG_DOEPMSK_NYETM */
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
/* Private macros ------------------------------------------------------------*/
|
||||||
|
/** @defgroup PCD_Private_Macros PCD Private Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* STM32H7xx_HAL_PCD_H */
|
||||||
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file stm32h7xx_hal_spi_ex.h
|
* @file stm32h7xx_hal_pcd_ex.h
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @brief Header file of SPI HAL Extended module.
|
* @brief Header file of PCD HAL Extension module.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
@ -17,68 +17,51 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
#ifndef STM32H7xx_HAL_SPI_EX_H
|
#ifndef STM32H7xx_HAL_PCD_EX_H
|
||||||
#define STM32H7xx_HAL_SPI_EX_H
|
#define STM32H7xx_HAL_PCD_EX_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "stm32h7xx_hal_def.h"
|
#include "stm32h7xx_hal_def.h"
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
/** @addtogroup STM32H7xx_HAL_Driver
|
/** @addtogroup STM32H7xx_HAL_Driver
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @addtogroup SPIEx
|
/** @addtogroup PCDEx
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/** @defgroup SPIEx_Exported_Types SPIEx Exported Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/** @defgroup SPIEx_Exported_Constants SPIEx Exported Constants
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Exported macros -----------------------------------------------------------*/
|
/* Exported macros -----------------------------------------------------------*/
|
||||||
/** @defgroup SPIEx_Exported_Macros SPIEx Extended Exported Macros
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Exported functions --------------------------------------------------------*/
|
/* Exported functions --------------------------------------------------------*/
|
||||||
/** @addtogroup SPIEx_Exported_Functions
|
/** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
/** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
|
||||||
/* Initialization and de-initialization functions ****************************/
|
|
||||||
/* IO operation functions *****************************************************/
|
|
||||||
/** @addtogroup SPIEx_Exported_Functions_Group1
|
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi);
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
HAL_StatusTypeDef HAL_SPIEx_EnableLockConfiguration(SPI_HandleTypeDef *hspi);
|
HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size);
|
||||||
HAL_StatusTypeDef HAL_SPIEx_ConfigureUnderrun(SPI_HandleTypeDef *hspi, uint32_t UnderrunDetection,
|
HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size);
|
||||||
uint32_t UnderrunBehaviour);
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd);
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd);
|
||||||
|
void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd);
|
||||||
|
|
||||||
|
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg);
|
||||||
|
void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -91,9 +74,14 @@ HAL_StatusTypeDef HAL_SPIEx_ConfigureUnderrun(SPI_HandleTypeDef *hspi, uint32_t
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif /* STM32H7xx_HAL_SPI_EX_H */
|
|
||||||
|
#endif /* STM32H7xx_HAL_PCD_EX_H */
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,578 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file stm32h7xx_ll_usb.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file of USB Low Layer HAL module.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef STM32H7xx_LL_USB_H
|
||||||
|
#define STM32H7xx_LL_USB_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx_hal_def.h"
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
/** @addtogroup STM32H7xx_HAL_Driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup USB_LL
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
#ifndef HAL_USB_TIMEOUT
|
||||||
|
#define HAL_USB_TIMEOUT 0xF000000U
|
||||||
|
#endif /* define HAL_USB_TIMEOUT */
|
||||||
|
|
||||||
|
#ifndef HAL_USB_CURRENT_MODE_MAX_DELAY_MS
|
||||||
|
#define HAL_USB_CURRENT_MODE_MAX_DELAY_MS 200U
|
||||||
|
#endif /* define HAL_USB_CURRENT_MODE_MAX_DELAY_MS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USB Mode definition
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
USB_DEVICE_MODE = 0,
|
||||||
|
USB_HOST_MODE = 1,
|
||||||
|
USB_DRD_MODE = 2
|
||||||
|
} USB_ModeTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief URB States definition
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
URB_IDLE = 0,
|
||||||
|
URB_DONE,
|
||||||
|
URB_NOTREADY,
|
||||||
|
URB_NYET,
|
||||||
|
URB_ERROR,
|
||||||
|
URB_STALL
|
||||||
|
} USB_URBStateTypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Host channel States definition
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
HC_IDLE = 0,
|
||||||
|
HC_XFRC,
|
||||||
|
HC_HALTED,
|
||||||
|
HC_ACK,
|
||||||
|
HC_NAK,
|
||||||
|
HC_NYET,
|
||||||
|
HC_STALL,
|
||||||
|
HC_XACTERR,
|
||||||
|
HC_BBLERR,
|
||||||
|
HC_DATATGLERR
|
||||||
|
} USB_HCStateTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USB Instance Initialization Structure definition
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t dev_endpoints; /*!< Device Endpoints number.
|
||||||
|
This parameter depends on the used USB core.
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
|
||||||
|
|
||||||
|
uint8_t Host_channels; /*!< Host Channels number.
|
||||||
|
This parameter Depends on the used USB core.
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
|
||||||
|
|
||||||
|
uint8_t dma_enable; /*!< USB DMA state.
|
||||||
|
If DMA is not supported this parameter shall be set by default to zero */
|
||||||
|
|
||||||
|
uint8_t speed; /*!< USB Core speed.
|
||||||
|
This parameter can be any value of @ref PCD_Speed/HCD_Speed
|
||||||
|
(HCD_SPEED_xxx, HCD_SPEED_xxx) */
|
||||||
|
|
||||||
|
uint8_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */
|
||||||
|
|
||||||
|
uint8_t phy_itface; /*!< Select the used PHY interface.
|
||||||
|
This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module */
|
||||||
|
|
||||||
|
uint8_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
|
||||||
|
|
||||||
|
uint8_t low_power_enable; /*!< Enable or disable the low Power Mode. */
|
||||||
|
|
||||||
|
uint8_t lpm_enable; /*!< Enable or disable Link Power Management. */
|
||||||
|
|
||||||
|
uint8_t battery_charging_enable; /*!< Enable or disable Battery charging. */
|
||||||
|
|
||||||
|
uint8_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */
|
||||||
|
|
||||||
|
uint8_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */
|
||||||
|
|
||||||
|
uint8_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */
|
||||||
|
|
||||||
|
} USB_CfgTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t num; /*!< Endpoint number
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
|
||||||
|
|
||||||
|
uint8_t is_in; /*!< Endpoint direction
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint8_t is_stall; /*!< Endpoint stall condition
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint8_t is_iso_incomplete; /*!< Endpoint isoc condition
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint8_t type; /*!< Endpoint type
|
||||||
|
This parameter can be any value of @ref USB_LL_EP_Type */
|
||||||
|
|
||||||
|
uint8_t data_pid_start; /*!< Initial data PID
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint32_t maxpacket; /*!< Endpoint Max packet size
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
|
||||||
|
|
||||||
|
uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
|
||||||
|
|
||||||
|
uint32_t xfer_len; /*!< Current transfer length */
|
||||||
|
|
||||||
|
uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
|
||||||
|
|
||||||
|
uint8_t even_odd_frame; /*!< IFrame parity
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint16_t tx_fifo_num; /*!< Transmission FIFO number
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
|
||||||
|
|
||||||
|
uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address */
|
||||||
|
|
||||||
|
uint32_t xfer_size; /*!< requested transfer size */
|
||||||
|
} USB_EPTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t dev_addr; /*!< USB device address.
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 255 */
|
||||||
|
|
||||||
|
uint8_t ch_num; /*!< Host channel number.
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
|
||||||
|
|
||||||
|
uint8_t ep_num; /*!< Endpoint number.
|
||||||
|
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
|
||||||
|
|
||||||
|
uint8_t ep_is_in; /*!< Endpoint direction
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint8_t speed; /*!< USB Host Channel speed.
|
||||||
|
This parameter can be any value of @ref HCD_Device_Speed:
|
||||||
|
(HCD_DEVICE_SPEED_xxx) */
|
||||||
|
|
||||||
|
uint8_t do_ping; /*!< Enable or disable the use of the PING protocol for HS mode. */
|
||||||
|
uint8_t do_ssplit; /*!< Enable start split transaction in HS mode. */
|
||||||
|
uint8_t do_csplit; /*!< Enable complete split transaction in HS mode. */
|
||||||
|
uint8_t ep_ss_schedule; /*!< Enable periodic endpoint start split schedule . */
|
||||||
|
uint32_t iso_splt_xactPos; /*!< iso split transfer transaction position. */
|
||||||
|
|
||||||
|
uint8_t hub_port_nbr; /*!< USB HUB port number */
|
||||||
|
uint8_t hub_addr; /*!< USB HUB address */
|
||||||
|
|
||||||
|
uint8_t ep_type; /*!< Endpoint Type.
|
||||||
|
This parameter can be any value of @ref USB_LL_EP_Type */
|
||||||
|
|
||||||
|
uint16_t max_packet; /*!< Endpoint Max packet size.
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
|
||||||
|
|
||||||
|
uint8_t data_pid; /*!< Initial data PID.
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint8_t *xfer_buff; /*!< Pointer to transfer buffer. */
|
||||||
|
|
||||||
|
uint32_t XferSize; /*!< OTG Channel transfer size. */
|
||||||
|
|
||||||
|
uint32_t xfer_len; /*!< Current transfer length. */
|
||||||
|
|
||||||
|
uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */
|
||||||
|
|
||||||
|
uint8_t toggle_in; /*!< IN transfer current toggle flag.
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint8_t toggle_out; /*!< OUT transfer current toggle flag
|
||||||
|
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
|
||||||
|
|
||||||
|
uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address. */
|
||||||
|
|
||||||
|
uint32_t ErrCnt; /*!< Host channel error count. */
|
||||||
|
uint32_t NyetErrCnt; /*!< Complete Split NYET Host channel error count. */
|
||||||
|
|
||||||
|
USB_URBStateTypeDef urb_state; /*!< URB state.
|
||||||
|
This parameter can be any value of @ref USB_URBStateTypeDef */
|
||||||
|
|
||||||
|
USB_HCStateTypeDef state; /*!< Host Channel state.
|
||||||
|
This parameter can be any value of @ref USB_HCStateTypeDef */
|
||||||
|
} USB_HCTypeDef;
|
||||||
|
|
||||||
|
typedef USB_ModeTypeDef USB_OTG_ModeTypeDef;
|
||||||
|
typedef USB_CfgTypeDef USB_OTG_CfgTypeDef;
|
||||||
|
typedef USB_EPTypeDef USB_OTG_EPTypeDef;
|
||||||
|
typedef USB_URBStateTypeDef USB_OTG_URBStateTypeDef;
|
||||||
|
typedef USB_HCStateTypeDef USB_OTG_HCStateTypeDef;
|
||||||
|
typedef USB_HCTypeDef USB_OTG_HCTypeDef;
|
||||||
|
|
||||||
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/** @defgroup PCD_Exported_Constants PCD Exported Constants
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
/** @defgroup USB_OTG_CORE VERSION ID
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USB_OTG_CORE_ID_300A 0x4F54300AU
|
||||||
|
#define USB_OTG_CORE_ID_310A 0x4F54310AU
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_Core_Mode_ USB Core Mode
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USB_OTG_MODE_DEVICE 0U
|
||||||
|
#define USB_OTG_MODE_HOST 1U
|
||||||
|
#define USB_OTG_MODE_DRD 2U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_Core_Speed USB Low Layer Core Speed
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USB_OTG_SPEED_HIGH 0U
|
||||||
|
#define USB_OTG_SPEED_HIGH_IN_FULL 1U
|
||||||
|
#define USB_OTG_SPEED_FULL 3U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_Core_PHY USB Low Layer Core PHY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USB_OTG_ULPI_PHY 1U
|
||||||
|
#define USB_OTG_EMBEDDED_PHY 2U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_Turnaround_Timeout Turnaround Timeout Value
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#ifndef USBD_HS_TRDT_VALUE
|
||||||
|
#define USBD_HS_TRDT_VALUE 9U
|
||||||
|
#endif /* USBD_HS_TRDT_VALUE */
|
||||||
|
#ifndef USBD_FS_TRDT_VALUE
|
||||||
|
#define USBD_FS_TRDT_VALUE 5U
|
||||||
|
#define USBD_DEFAULT_TRDT_VALUE 9U
|
||||||
|
#endif /* USBD_HS_TRDT_VALUE */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_Core_MPS USB Low Layer Core MPS
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USB_OTG_HS_MAX_PACKET_SIZE 512U
|
||||||
|
#define USB_OTG_FS_MAX_PACKET_SIZE 64U
|
||||||
|
#define USB_OTG_MAX_EP0_SIZE 64U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_Core_PHY_Frequency USB Low Layer Core PHY Frequency
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1)
|
||||||
|
#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1)
|
||||||
|
#define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1)
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_CORE_Frame_Interval USB Low Layer Core Frame Interval
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DCFG_FRAME_INTERVAL_80 0U
|
||||||
|
#define DCFG_FRAME_INTERVAL_85 1U
|
||||||
|
#define DCFG_FRAME_INTERVAL_90 2U
|
||||||
|
#define DCFG_FRAME_INTERVAL_95 3U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
/** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define EP_MPS_64 0U
|
||||||
|
#define EP_MPS_32 1U
|
||||||
|
#define EP_MPS_16 2U
|
||||||
|
#define EP_MPS_8 3U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_EP_Type USB Low Layer EP Type
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define EP_TYPE_CTRL 0U
|
||||||
|
#define EP_TYPE_ISOC 1U
|
||||||
|
#define EP_TYPE_BULK 2U
|
||||||
|
#define EP_TYPE_INTR 3U
|
||||||
|
#define EP_TYPE_MSK 3U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_EP_Speed USB Low Layer EP Speed
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define EP_SPEED_LOW 0U
|
||||||
|
#define EP_SPEED_FULL 1U
|
||||||
|
#define EP_SPEED_HIGH 2U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_CH_PID_Type USB Low Layer Channel PID Type
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HC_PID_DATA0 0U
|
||||||
|
#define HC_PID_DATA2 1U
|
||||||
|
#define HC_PID_DATA1 2U
|
||||||
|
#define HC_PID_SETUP 3U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL Device Speed
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USBD_HS_SPEED 0U
|
||||||
|
#define USBD_HSINFS_SPEED 1U
|
||||||
|
#define USBH_HS_SPEED 0U
|
||||||
|
#define USBD_FS_SPEED 2U
|
||||||
|
#define USBH_FSLS_SPEED 1U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
/** @defgroup USB_LL_STS_Defines USB Low Layer STS Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define STS_GOUT_NAK 1U
|
||||||
|
#define STS_DATA_UPDT 2U
|
||||||
|
#define STS_XFER_COMP 3U
|
||||||
|
#define STS_SETUP_COMP 4U
|
||||||
|
#define STS_SETUP_UPDT 6U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_HCFG_SPEED_Defines USB Low Layer HCFG Speed Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HCFG_30_60_MHZ 0U
|
||||||
|
#define HCFG_48_MHZ 1U
|
||||||
|
#define HCFG_6_MHZ 2U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_HFIR_Defines USB Low Layer frame interval Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HFIR_6_MHZ 6000U
|
||||||
|
#define HFIR_60_MHZ 60000U
|
||||||
|
#define HFIR_48_MHZ 48000U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_LL_HPRT0_PRTSPD_SPEED_Defines USB Low Layer HPRT0 PRTSPD Speed Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HPRT0_PRTSPD_HIGH_SPEED 0U
|
||||||
|
#define HPRT0_PRTSPD_FULL_SPEED 1U
|
||||||
|
#define HPRT0_PRTSPD_LOW_SPEED 2U
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define HCCHAR_CTRL 0U
|
||||||
|
#define HCCHAR_ISOC 1U
|
||||||
|
#define HCCHAR_BULK 2U
|
||||||
|
#define HCCHAR_INTR 3U
|
||||||
|
|
||||||
|
#define GRXSTS_PKTSTS_IN 2U
|
||||||
|
#define GRXSTS_PKTSTS_IN_XFER_COMP 3U
|
||||||
|
#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U
|
||||||
|
#define GRXSTS_PKTSTS_CH_HALTED 7U
|
||||||
|
|
||||||
|
#define CLEAR_INTERRUPT_MASK 0xFFFFFFFFU
|
||||||
|
|
||||||
|
#define HC_MAX_PKT_CNT 256U
|
||||||
|
#define ISO_SPLT_MPS 188U
|
||||||
|
|
||||||
|
#define HCSPLT_BEGIN 1U
|
||||||
|
#define HCSPLT_MIDDLE 2U
|
||||||
|
#define HCSPLT_END 3U
|
||||||
|
#define HCSPLT_FULL 4U
|
||||||
|
|
||||||
|
#define TEST_J 1U
|
||||||
|
#define TEST_K 2U
|
||||||
|
#define TEST_SE0_NAK 3U
|
||||||
|
#define TEST_PACKET 4U
|
||||||
|
#define TEST_FORCE_EN 5U
|
||||||
|
|
||||||
|
#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE)
|
||||||
|
#define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE)
|
||||||
|
|
||||||
|
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE))
|
||||||
|
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)(USBx_BASE\
|
||||||
|
+ USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||||
|
|
||||||
|
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE\
|
||||||
|
+ USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||||
|
|
||||||
|
#define USBx_DFIFO(i) *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
|
||||||
|
|
||||||
|
#define USBx_HOST ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE))
|
||||||
|
#define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)(USBx_BASE\
|
||||||
|
+ USB_OTG_HOST_CHANNEL_BASE\
|
||||||
|
+ ((i) * USB_OTG_HOST_CHANNEL_SIZE)))
|
||||||
|
|
||||||
|
|
||||||
|
#define EP_ADDR_MSK 0xFU
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
/** @defgroup USB_LL_Exported_Macros USB Low Layer Exported Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
#define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
|
||||||
|
#define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
|
||||||
|
|
||||||
|
#define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
|
||||||
|
#define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
/** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
|
||||||
|
HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
|
||||||
|
HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed);
|
||||||
|
HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTypeDef mode);
|
||||||
|
HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed);
|
||||||
|
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num);
|
||||||
|
HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep, uint8_t dma);
|
||||||
|
HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
|
||||||
|
uint8_t ch_ep_num, uint16_t len, uint8_t dma);
|
||||||
|
|
||||||
|
void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
|
||||||
|
HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
|
||||||
|
HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address);
|
||||||
|
HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, uint8_t dma, const uint8_t *psetup);
|
||||||
|
uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx);
|
||||||
|
uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum);
|
||||||
|
uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
|
||||||
|
uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
|
||||||
|
void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
|
||||||
|
|
||||||
|
HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
|
||||||
|
HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq);
|
||||||
|
HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state);
|
||||||
|
uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx);
|
||||||
|
uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx);
|
||||||
|
HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
|
||||||
|
uint8_t epnum, uint8_t dev_address, uint8_t speed,
|
||||||
|
uint8_t ep_type, uint16_t mps);
|
||||||
|
HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx,
|
||||||
|
USB_OTG_HCTypeDef *hc, uint8_t dma);
|
||||||
|
|
||||||
|
uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num);
|
||||||
|
HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num);
|
||||||
|
HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* STM32H7xx_LL_USB_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,341 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file stm32h7xx_hal_pcd_ex.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief PCD Extended HAL module driver.
|
||||||
|
* This file provides firmware functions to manage the following
|
||||||
|
* functionalities of the USB Peripheral Controller:
|
||||||
|
* + Extended features functions
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32H7xx_HAL_Driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup PCDEx PCDEx
|
||||||
|
* @brief PCD Extended HAL module driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAL_PCD_MODULE_ENABLED
|
||||||
|
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
/* Private types -------------------------------------------------------------*/
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
/* Private constants ---------------------------------------------------------*/
|
||||||
|
/* Private macros ------------------------------------------------------------*/
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
/* Exported functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
|
||||||
|
* @brief PCDEx control functions
|
||||||
|
*
|
||||||
|
@verbatim
|
||||||
|
===============================================================================
|
||||||
|
##### Extended features functions #####
|
||||||
|
===============================================================================
|
||||||
|
[..] This section provides functions allowing to:
|
||||||
|
(+) Update FIFO configuration
|
||||||
|
|
||||||
|
@endverbatim
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
|
||||||
|
/**
|
||||||
|
* @brief Set Tx FIFO
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @param fifo The number of Tx fifo
|
||||||
|
* @param size Fifo size
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint32_t Tx_Offset;
|
||||||
|
|
||||||
|
/* TXn min size = 16 words. (n : Transmit FIFO index)
|
||||||
|
When a TxFIFO is not used, the Configuration should be as follows:
|
||||||
|
case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
|
||||||
|
--> Txm can use the space allocated for Txn.
|
||||||
|
case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
|
||||||
|
--> Txn should be configured with the minimum space of 16 words
|
||||||
|
The FIFO is used optimally when used TxFIFOs are allocated in the top
|
||||||
|
of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
|
||||||
|
When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
|
||||||
|
|
||||||
|
Tx_Offset = hpcd->Instance->GRXFSIZ;
|
||||||
|
|
||||||
|
if (fifo == 0U)
|
||||||
|
{
|
||||||
|
hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
|
||||||
|
for (i = 0U; i < (fifo - 1U); i++)
|
||||||
|
{
|
||||||
|
Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Multiply Tx_Size by 2 to get higher performance */
|
||||||
|
hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set Rx FIFO
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @param size Size of Rx fifo
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
|
||||||
|
{
|
||||||
|
hpcd->Instance->GRXFSIZ = size;
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Activate LPM feature.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd)
|
||||||
|
{
|
||||||
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
|
|
||||||
|
hpcd->lpm_active = 1U;
|
||||||
|
hpcd->LPM_State = LPM_L0;
|
||||||
|
USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM;
|
||||||
|
USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deactivate LPM feature.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd)
|
||||||
|
{
|
||||||
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
|
|
||||||
|
hpcd->lpm_active = 0U;
|
||||||
|
USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
|
||||||
|
USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle BatteryCharging Process.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd)
|
||||||
|
{
|
||||||
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
|
uint32_t tickstart = HAL_GetTick();
|
||||||
|
|
||||||
|
/* Enable DCD : Data Contact Detect */
|
||||||
|
USBx->GCCFG |= USB_OTG_GCCFG_DCDEN;
|
||||||
|
|
||||||
|
/* Wait for Min DCD Timeout */
|
||||||
|
HAL_Delay(300U);
|
||||||
|
|
||||||
|
/* Check Detect flag */
|
||||||
|
if ((USBx->GCCFG & USB_OTG_GCCFG_DCDET) == USB_OTG_GCCFG_DCDET)
|
||||||
|
{
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
hpcd->BCDCallback(hpcd, PCD_BCD_CONTACT_DETECTION);
|
||||||
|
#else
|
||||||
|
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CONTACT_DETECTION);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Primary detection: checks if connected to Standard Downstream Port
|
||||||
|
(without charging capability) */
|
||||||
|
USBx->GCCFG &= ~USB_OTG_GCCFG_DCDEN;
|
||||||
|
HAL_Delay(50U);
|
||||||
|
USBx->GCCFG |= USB_OTG_GCCFG_PDEN;
|
||||||
|
HAL_Delay(50U);
|
||||||
|
|
||||||
|
if ((USBx->GCCFG & USB_OTG_GCCFG_PDET) == 0U)
|
||||||
|
{
|
||||||
|
/* Case of Standard Downstream Port */
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
hpcd->BCDCallback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
|
||||||
|
#else
|
||||||
|
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* start secondary detection to check connection to Charging Downstream
|
||||||
|
Port or Dedicated Charging Port */
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_PDEN);
|
||||||
|
HAL_Delay(50U);
|
||||||
|
USBx->GCCFG |= USB_OTG_GCCFG_SDEN;
|
||||||
|
HAL_Delay(50U);
|
||||||
|
|
||||||
|
if ((USBx->GCCFG & USB_OTG_GCCFG_SDET) == USB_OTG_GCCFG_SDET)
|
||||||
|
{
|
||||||
|
/* case Dedicated Charging Port */
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
hpcd->BCDCallback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
|
||||||
|
#else
|
||||||
|
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* case Charging Downstream Port */
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
hpcd->BCDCallback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
|
||||||
|
#else
|
||||||
|
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Battery Charging capability discovery finished */
|
||||||
|
(void)HAL_PCDEx_DeActivateBCD(hpcd);
|
||||||
|
|
||||||
|
/* Check for the Timeout, else start USB Device */
|
||||||
|
if ((HAL_GetTick() - tickstart) > 1000U)
|
||||||
|
{
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
hpcd->BCDCallback(hpcd, PCD_BCD_ERROR);
|
||||||
|
#else
|
||||||
|
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_ERROR);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
hpcd->BCDCallback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
|
||||||
|
#else
|
||||||
|
HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Activate BatteryCharging feature.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd)
|
||||||
|
{
|
||||||
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
|
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_PDEN);
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_SDEN);
|
||||||
|
|
||||||
|
/* Power Down USB transceiver */
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
|
||||||
|
|
||||||
|
/* Enable Battery charging */
|
||||||
|
USBx->GCCFG |= USB_OTG_GCCFG_BCDEN;
|
||||||
|
|
||||||
|
hpcd->battery_charging_active = 1U;
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deactivate BatteryCharging feature.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd)
|
||||||
|
{
|
||||||
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
|
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_SDEN);
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_PDEN);
|
||||||
|
|
||||||
|
/* Disable Battery charging */
|
||||||
|
USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN);
|
||||||
|
|
||||||
|
hpcd->battery_charging_active = 0U;
|
||||||
|
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send LPM message to user layer callback.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @param msg LPM message
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
__weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
|
||||||
|
{
|
||||||
|
/* Prevent unused argument(s) compilation warning */
|
||||||
|
UNUSED(hpcd);
|
||||||
|
UNUSED(msg);
|
||||||
|
|
||||||
|
/* NOTE : This function should not be modified, when the callback is needed,
|
||||||
|
the HAL_PCDEx_LPM_Callback could be implemented in the user file
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send BatteryCharging message to user layer callback.
|
||||||
|
* @param hpcd PCD handle
|
||||||
|
* @param msg LPM message
|
||||||
|
* @retval HAL status
|
||||||
|
*/
|
||||||
|
__weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
|
||||||
|
{
|
||||||
|
/* Prevent unused argument(s) compilation warning */
|
||||||
|
UNUSED(hpcd);
|
||||||
|
UNUSED(msg);
|
||||||
|
|
||||||
|
/* NOTE : This function should not be modified, when the callback is needed,
|
||||||
|
the HAL_PCDEx_BCD_Callback could be implemented in the user file
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
|
||||||
|
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,226 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file stm32h7xx_hal_spi_ex.c
|
|
||||||
* @author MCD Application Team
|
|
||||||
* @brief Extended SPI HAL module driver.
|
|
||||||
* This file provides firmware functions to manage the following
|
|
||||||
* SPI peripheral extended functionalities :
|
|
||||||
* + IO operation functions
|
|
||||||
* + Peripheral Control functions
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2017 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "stm32h7xx_hal.h"
|
|
||||||
|
|
||||||
/** @addtogroup STM32H7xx_HAL_Driver
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup SPIEx SPIEx
|
|
||||||
* @brief SPI Extended HAL module driver
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
#ifdef HAL_SPI_MODULE_ENABLED
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
|
||||||
/* Private macros ------------------------------------------------------------*/
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
/* Exported functions --------------------------------------------------------*/
|
|
||||||
|
|
||||||
/** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
|
|
||||||
* @brief Data transfers functions
|
|
||||||
*
|
|
||||||
@verbatim
|
|
||||||
==============================================================================
|
|
||||||
##### IO operation functions #####
|
|
||||||
===============================================================================
|
|
||||||
[..]
|
|
||||||
This subsection provides a set of extended functions to manage the SPI
|
|
||||||
data transfers.
|
|
||||||
|
|
||||||
(#) SPIEx function:
|
|
||||||
(++) HAL_SPIEx_FlushRxFifo()
|
|
||||||
(++) HAL_SPIEx_EnableLockConfiguration()
|
|
||||||
(++) HAL_SPIEx_ConfigureUnderrun()
|
|
||||||
|
|
||||||
@endverbatim
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Flush the RX fifo.
|
|
||||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
|
||||||
* the configuration information for the specified SPI module.
|
|
||||||
* @retval HAL status
|
|
||||||
*/
|
|
||||||
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi)
|
|
||||||
{
|
|
||||||
uint8_t count = 0;
|
|
||||||
uint32_t itflag = hspi->Instance->SR;
|
|
||||||
__IO uint32_t tmpreg;
|
|
||||||
|
|
||||||
while (((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_RX_FIFO_0PACKET) || ((itflag & SPI_FLAG_RXWNE) != 0UL))
|
|
||||||
{
|
|
||||||
count += (uint8_t)4UL;
|
|
||||||
tmpreg = hspi->Instance->RXDR;
|
|
||||||
UNUSED(tmpreg); /* To avoid GCC warning */
|
|
||||||
|
|
||||||
if (IS_SPI_HIGHEND_INSTANCE(hspi->Instance))
|
|
||||||
{
|
|
||||||
if (count > SPI_HIGHEND_FIFO_SIZE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (count > SPI_LOWEND_FIFO_SIZE)
|
|
||||||
{
|
|
||||||
return HAL_TIMEOUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return HAL_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Enable the Lock for the AF configuration of associated IOs
|
|
||||||
* and write protect the Content of Configuration register 2
|
|
||||||
* when SPI is enabled
|
|
||||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
|
||||||
* the configuration information for SPI module.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
HAL_StatusTypeDef HAL_SPIEx_EnableLockConfiguration(SPI_HandleTypeDef *hspi)
|
|
||||||
{
|
|
||||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
|
||||||
|
|
||||||
/* Process Locked */
|
|
||||||
__HAL_LOCK(hspi);
|
|
||||||
|
|
||||||
if (hspi->State != HAL_SPI_STATE_READY)
|
|
||||||
{
|
|
||||||
errorcode = HAL_BUSY;
|
|
||||||
hspi->State = HAL_SPI_STATE_READY;
|
|
||||||
/* Process Unlocked */
|
|
||||||
__HAL_UNLOCK(hspi);
|
|
||||||
return errorcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if the SPI is disabled to edit IOLOCK bit */
|
|
||||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
|
||||||
{
|
|
||||||
SET_BIT(hspi->Instance->CR1, SPI_CR1_IOLOCK);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable SPI peripheral */
|
|
||||||
__HAL_SPI_DISABLE(hspi);
|
|
||||||
|
|
||||||
SET_BIT(hspi->Instance->CR1, SPI_CR1_IOLOCK);
|
|
||||||
|
|
||||||
/* Enable SPI peripheral */
|
|
||||||
__HAL_SPI_ENABLE(hspi);
|
|
||||||
}
|
|
||||||
|
|
||||||
hspi->State = HAL_SPI_STATE_READY;
|
|
||||||
/* Process Unlocked */
|
|
||||||
__HAL_UNLOCK(hspi);
|
|
||||||
return errorcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configure the UNDERRUN condition and behavior of slave transmitter.
|
|
||||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
|
||||||
* the configuration information for SPI module.
|
|
||||||
* @param UnderrunDetection : Detection of underrun condition at slave transmitter
|
|
||||||
* This parameter can be a value of @ref SPI_Underrun_Detection.
|
|
||||||
* @param UnderrunBehaviour : Behavior of slave transmitter at underrun condition
|
|
||||||
* This parameter can be a value of @ref SPI_Underrun_Behaviour.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
HAL_StatusTypeDef HAL_SPIEx_ConfigureUnderrun(SPI_HandleTypeDef *hspi, uint32_t UnderrunDetection,
|
|
||||||
uint32_t UnderrunBehaviour)
|
|
||||||
{
|
|
||||||
HAL_StatusTypeDef errorcode = HAL_OK;
|
|
||||||
|
|
||||||
/* Process Locked */
|
|
||||||
__HAL_LOCK(hspi);
|
|
||||||
|
|
||||||
/* Check State and Insure that Underrun configuration is managed only by Salve */
|
|
||||||
if ((hspi->State != HAL_SPI_STATE_READY) || (hspi->Init.Mode != SPI_MODE_SLAVE))
|
|
||||||
{
|
|
||||||
errorcode = HAL_BUSY;
|
|
||||||
hspi->State = HAL_SPI_STATE_READY;
|
|
||||||
/* Process Unlocked */
|
|
||||||
__HAL_UNLOCK(hspi);
|
|
||||||
return errorcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check the parameters */
|
|
||||||
assert_param(IS_SPI_UNDERRUN_DETECTION(UnderrunDetection));
|
|
||||||
assert_param(IS_SPI_UNDERRUN_BEHAVIOUR(UnderrunBehaviour));
|
|
||||||
|
|
||||||
/* Check if the SPI is disabled to edit CFG1 register */
|
|
||||||
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
|
|
||||||
{
|
|
||||||
/* Configure Underrun fields */
|
|
||||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRDET, UnderrunDetection);
|
|
||||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRCFG, UnderrunBehaviour);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Disable SPI peripheral */
|
|
||||||
__HAL_SPI_DISABLE(hspi);
|
|
||||||
|
|
||||||
/* Configure Underrun fields */
|
|
||||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRDET, UnderrunDetection);
|
|
||||||
MODIFY_REG(hspi->Instance->CFG1, SPI_CFG1_UDRCFG, UnderrunBehaviour);
|
|
||||||
|
|
||||||
/* Enable SPI peripheral */
|
|
||||||
__HAL_SPI_ENABLE(hspi);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
hspi->State = HAL_SPI_STATE_READY;
|
|
||||||
/* Process Unlocked */
|
|
||||||
__HAL_UNLOCK(hspi);
|
|
||||||
return errorcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -72,7 +72,7 @@
|
|||||||
/* #define HAL_SD_MODULE_ENABLED */
|
/* #define HAL_SD_MODULE_ENABLED */
|
||||||
/* #define HAL_MMC_MODULE_ENABLED */
|
/* #define HAL_MMC_MODULE_ENABLED */
|
||||||
/* #define HAL_SPDIFRX_MODULE_ENABLED */
|
/* #define HAL_SPDIFRX_MODULE_ENABLED */
|
||||||
#define HAL_SPI_MODULE_ENABLED
|
/* #define HAL_SPI_MODULE_ENABLED */
|
||||||
/* #define HAL_SWPMI_MODULE_ENABLED */
|
/* #define HAL_SWPMI_MODULE_ENABLED */
|
||||||
/* #define HAL_TIM_MODULE_ENABLED */
|
/* #define HAL_TIM_MODULE_ENABLED */
|
||||||
#define HAL_UART_MODULE_ENABLED
|
#define HAL_UART_MODULE_ENABLED
|
||||||
@ -80,7 +80,7 @@
|
|||||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||||
/* #define HAL_PCD_MODULE_ENABLED */
|
#define HAL_PCD_MODULE_ENABLED
|
||||||
/* #define HAL_HCD_MODULE_ENABLED */
|
/* #define HAL_HCD_MODULE_ENABLED */
|
||||||
/* #define HAL_DFSDM_MODULE_ENABLED */
|
/* #define HAL_DFSDM_MODULE_ENABLED */
|
||||||
/* #define HAL_DSI_MODULE_ENABLED */
|
/* #define HAL_DSI_MODULE_ENABLED */
|
||||||
|
|||||||
@ -55,6 +55,7 @@ void SVC_Handler(void);
|
|||||||
void DebugMon_Handler(void);
|
void DebugMon_Handler(void);
|
||||||
void PendSV_Handler(void);
|
void PendSV_Handler(void);
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
|
void OTG_FS_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|||||||
102
board/CubeMX_Config/Inc/usb_device.h
Normal file
102
board/CubeMX_Config/Inc/usb_device.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usb_device.h
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usb_device.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USB_DEVICE__H__
|
||||||
|
#define __USB_DEVICE__H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup USBD_OTG_DRIVER
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEVICE USBD_DEVICE
|
||||||
|
* @brief Device file for Usb otg low level driver.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert your variables declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END VARIABLES */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype
|
||||||
|
* @brief Declaration of public functions for Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** USB Device initialization function. */
|
||||||
|
void MX_USB_DEVICE_Init(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert functions declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN FD */
|
||||||
|
|
||||||
|
/* USER CODE END FD */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USB_DEVICE__H__ */
|
||||||
132
board/CubeMX_Config/Inc/usbd_cdc_if.h
Normal file
132
board/CubeMX_Config/Inc/usbd_cdc_if.h
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_cdc_if.h
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usbd_cdc_if.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef __USBD_CDC_IF_H__
|
||||||
|
#define __USBD_CDC_IF_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @brief For Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF USBD_CDC_IF
|
||||||
|
* @brief Usb VCP device module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines
|
||||||
|
* @brief Defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Define size for the receive and transmit buffer over CDC */
|
||||||
|
#define APP_RX_DATA_SIZE 2048
|
||||||
|
#define APP_TX_DATA_SIZE 2048
|
||||||
|
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types
|
||||||
|
* @brief Types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros
|
||||||
|
* @brief Aliases.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** CDC Interface callback. */
|
||||||
|
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype
|
||||||
|
* @brief Public functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CDC_IF_H__ */
|
||||||
|
|
||||||
173
board/CubeMX_Config/Inc/usbd_conf.h
Normal file
173
board/CubeMX_Config/Inc/usbd_conf.h
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_conf.h
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usbd_conf.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_CONF__H__
|
||||||
|
#define __USBD_CONF__H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "main.h"
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup USBD_OTG_DRIVER
|
||||||
|
* @brief Driver for Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF USBD_CONF
|
||||||
|
* @brief Configuration file for Usb otg low level driver.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines
|
||||||
|
* @brief Defines for configuration of the Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_MAX_STR_DESC_SIZ 512U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_DEBUG_LEVEL 0U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_LPM_ENABLED 1U
|
||||||
|
/*---------- -----------*/
|
||||||
|
#define USBD_SELF_POWERED 1U
|
||||||
|
|
||||||
|
/****************************************/
|
||||||
|
/* #define for FS and HS identification */
|
||||||
|
#define DEVICE_FS 0
|
||||||
|
#define DEVICE_HS 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros
|
||||||
|
* @brief Aliases.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Memory management macros make sure to use static memory allocation */
|
||||||
|
/** Alias for memory allocation. */
|
||||||
|
|
||||||
|
#define USBD_malloc (void *)USBD_static_malloc
|
||||||
|
|
||||||
|
/** Alias for memory release. */
|
||||||
|
#define USBD_free USBD_static_free
|
||||||
|
|
||||||
|
/** Alias for memory set. */
|
||||||
|
#define USBD_memset memset
|
||||||
|
|
||||||
|
/** Alias for memory copy. */
|
||||||
|
#define USBD_memcpy memcpy
|
||||||
|
|
||||||
|
/** Alias for delay. */
|
||||||
|
#define USBD_Delay HAL_Delay
|
||||||
|
|
||||||
|
/* DEBUG macros */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 0)
|
||||||
|
#define USBD_UsrLog(...) printf(__VA_ARGS__);\
|
||||||
|
printf("\n");
|
||||||
|
#else
|
||||||
|
#define USBD_UsrLog(...)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 0U) */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 1)
|
||||||
|
|
||||||
|
#define USBD_ErrLog(...) printf("ERROR: ");\
|
||||||
|
printf(__VA_ARGS__);\
|
||||||
|
printf("\n");
|
||||||
|
#else
|
||||||
|
#define USBD_ErrLog(...)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 1U) */
|
||||||
|
|
||||||
|
#if (USBD_DEBUG_LEVEL > 2)
|
||||||
|
#define USBD_DbgLog(...) printf("DEBUG : ");\
|
||||||
|
printf(__VA_ARGS__);\
|
||||||
|
printf("\n");
|
||||||
|
#else
|
||||||
|
#define USBD_DbgLog(...)
|
||||||
|
#endif /* (USBD_DEBUG_LEVEL > 2U) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types
|
||||||
|
* @brief Types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype
|
||||||
|
* @brief Declaration of public functions for Usb device.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Exported functions -------------------------------------------------------*/
|
||||||
|
void *USBD_static_malloc(uint32_t size);
|
||||||
|
void USBD_static_free(void *p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CONF__H__ */
|
||||||
|
|
||||||
143
board/CubeMX_Config/Inc/usbd_desc.h
Normal file
143
board/CubeMX_Config/Inc/usbd_desc.h
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_desc.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Header for usbd_conf.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_DESC__C__
|
||||||
|
#define __USBD_DESC__C__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC USBD_DESC
|
||||||
|
* @brief Usb device descriptors module.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants
|
||||||
|
* @brief Constants.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define DEVICE_ID1 (UID_BASE)
|
||||||
|
#define DEVICE_ID2 (UID_BASE + 0x4)
|
||||||
|
#define DEVICE_ID3 (UID_BASE + 0x8)
|
||||||
|
|
||||||
|
#define USB_SIZ_STRING_SERIAL 0x1A
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_CONSTANTS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_CONSTANTS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines
|
||||||
|
* @brief Defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions
|
||||||
|
* @brief Types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros
|
||||||
|
* @brief Aliases.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Descriptor for the Usb device. */
|
||||||
|
extern USBD_DescriptorsTypeDef FS_Desc;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype
|
||||||
|
* @brief Public functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_DESC__C__ */
|
||||||
|
|
||||||
@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief header file for the usbd_cdc.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USB_CDC_H
|
||||||
|
#define __USB_CDC_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup usbd_cdc
|
||||||
|
* @brief This file is the Header file for usbd_cdc.c
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup usbd_cdc_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#ifndef CDC_IN_EP
|
||||||
|
#define CDC_IN_EP 0x81U /* EP1 for data IN */
|
||||||
|
#endif /* CDC_IN_EP */
|
||||||
|
#ifndef CDC_OUT_EP
|
||||||
|
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
|
||||||
|
#endif /* CDC_OUT_EP */
|
||||||
|
#ifndef CDC_CMD_EP
|
||||||
|
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||||
|
#endif /* CDC_CMD_EP */
|
||||||
|
|
||||||
|
#ifndef CDC_HS_BINTERVAL
|
||||||
|
#define CDC_HS_BINTERVAL 0x10U
|
||||||
|
#endif /* CDC_HS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef CDC_FS_BINTERVAL
|
||||||
|
#define CDC_FS_BINTERVAL 0x10U
|
||||||
|
#endif /* CDC_FS_BINTERVAL */
|
||||||
|
|
||||||
|
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||||
|
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||||
|
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
|
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||||
|
|
||||||
|
#define USB_CDC_CONFIG_DESC_SIZ 67U
|
||||||
|
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||||
|
#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||||
|
|
||||||
|
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
|
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
|
|
||||||
|
#define CDC_REQ_MAX_DATA_SIZE 0x7U
|
||||||
|
/*---------------------------------------------------------------------*/
|
||||||
|
/* CDC definitions */
|
||||||
|
/*---------------------------------------------------------------------*/
|
||||||
|
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||||
|
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||||
|
#define CDC_SET_COMM_FEATURE 0x02U
|
||||||
|
#define CDC_GET_COMM_FEATURE 0x03U
|
||||||
|
#define CDC_CLEAR_COMM_FEATURE 0x04U
|
||||||
|
#define CDC_SET_LINE_CODING 0x20U
|
||||||
|
#define CDC_GET_LINE_CODING 0x21U
|
||||||
|
#define CDC_SET_CONTROL_LINE_STATE 0x22U
|
||||||
|
#define CDC_SEND_BREAK 0x23U
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t bitrate;
|
||||||
|
uint8_t format;
|
||||||
|
uint8_t paritytype;
|
||||||
|
uint8_t datatype;
|
||||||
|
} USBD_CDC_LineCodingTypeDef;
|
||||||
|
|
||||||
|
typedef struct _USBD_CDC_Itf
|
||||||
|
{
|
||||||
|
int8_t (* Init)(void);
|
||||||
|
int8_t (* DeInit)(void);
|
||||||
|
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||||
|
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||||
|
int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum);
|
||||||
|
} USBD_CDC_ItfTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */
|
||||||
|
uint8_t CmdOpCode;
|
||||||
|
uint8_t CmdLength;
|
||||||
|
uint8_t *RxBuffer;
|
||||||
|
uint8_t *TxBuffer;
|
||||||
|
uint32_t RxLength;
|
||||||
|
uint32_t TxLength;
|
||||||
|
|
||||||
|
__IO uint32_t TxState;
|
||||||
|
__IO uint32_t RxState;
|
||||||
|
} USBD_CDC_HandleTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern USBD_ClassTypeDef USBD_CDC;
|
||||||
|
#define USBD_CDC_CLASS &USBD_CDC
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_CDC_ItfTypeDef *fops);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length, uint8_t ClassId);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId);
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||||
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USB_CDC_H */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@ -0,0 +1,893 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief This file provides the high layer firmware functions to manage the
|
||||||
|
* following functionalities of the USB CDC Class:
|
||||||
|
* - Initialization and Configuration of high and low layer
|
||||||
|
* - Enumeration as CDC Device (and enumeration for each implemented memory interface)
|
||||||
|
* - OUT/IN data transfer
|
||||||
|
* - Command IN transfer (class requests management)
|
||||||
|
* - Error management
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @verbatim
|
||||||
|
*
|
||||||
|
* ===================================================================
|
||||||
|
* CDC Class Driver Description
|
||||||
|
* ===================================================================
|
||||||
|
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
|
||||||
|
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
|
||||||
|
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
|
||||||
|
* This driver implements the following aspects of the specification:
|
||||||
|
* - Device descriptor management
|
||||||
|
* - Configuration descriptor management
|
||||||
|
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||||
|
* - Requests management (as described in section 6.2 in specification)
|
||||||
|
* - Abstract Control Model compliant
|
||||||
|
* - Union Functional collection (using 1 IN endpoint for control)
|
||||||
|
* - Data interface class
|
||||||
|
*
|
||||||
|
* These aspects may be enriched or modified for a specific user application.
|
||||||
|
*
|
||||||
|
* This driver doesn't implement the following aspects of the specification
|
||||||
|
* (but it is possible to manage these features with some modifications on this driver):
|
||||||
|
* - Any class-specific aspect relative to communication classes should be managed by user application.
|
||||||
|
* - All communication classes other than PSTN are not managed
|
||||||
|
*
|
||||||
|
* @endverbatim
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* BSPDependencies
|
||||||
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
|
EndBSPDependencies */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
#include "usbd_ctlreq.h"
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC
|
||||||
|
* @brief usbd core module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
/* USB Standard Device Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
USB_LEN_DEV_QUALIFIER_DESC,
|
||||||
|
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x40,
|
||||||
|
0x01,
|
||||||
|
0x00,
|
||||||
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* CDC interface class callbacks structure */
|
||||||
|
USBD_ClassTypeDef USBD_CDC =
|
||||||
|
{
|
||||||
|
USBD_CDC_Init,
|
||||||
|
USBD_CDC_DeInit,
|
||||||
|
USBD_CDC_Setup,
|
||||||
|
NULL, /* EP0_TxSent */
|
||||||
|
USBD_CDC_EP0_RxReady,
|
||||||
|
USBD_CDC_DataIn,
|
||||||
|
USBD_CDC_DataOut,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
|
USBD_CDC_GetHSCfgDesc,
|
||||||
|
USBD_CDC_GetFSCfgDesc,
|
||||||
|
USBD_CDC_GetOtherSpeedCfgDesc,
|
||||||
|
USBD_CDC_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
/* USB CDC device Configuration Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
|
{
|
||||||
|
/* Configuration Descriptor */
|
||||||
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
|
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength */
|
||||||
|
0x00,
|
||||||
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
|
0x00, /* iConfiguration: Index of string descriptor
|
||||||
|
describing the configuration */
|
||||||
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif /* USBD_SELF_POWERED */
|
||||||
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Interface Descriptor */
|
||||||
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||||
|
/* Interface descriptor type */
|
||||||
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
|
0x01, /* bNumEndpoints: One endpoint used */
|
||||||
|
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||||
|
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||||
|
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||||
|
0x00, /* iInterface */
|
||||||
|
|
||||||
|
/* Header Functional Descriptor */
|
||||||
|
0x05, /* bLength: Endpoint Descriptor size */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||||
|
0x10, /* bcdCDC: spec release number */
|
||||||
|
0x01,
|
||||||
|
|
||||||
|
/* Call Management Functional Descriptor */
|
||||||
|
0x05, /* bFunctionLength */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||||
|
0x00, /* bmCapabilities: D0+D1 */
|
||||||
|
0x01, /* bDataInterface */
|
||||||
|
|
||||||
|
/* ACM Functional Descriptor */
|
||||||
|
0x04, /* bFunctionLength */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||||
|
0x02, /* bmCapabilities */
|
||||||
|
|
||||||
|
/* Union Functional Descriptor */
|
||||||
|
0x05, /* bFunctionLength */
|
||||||
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
|
0x06, /* bDescriptorSubtype: Union func desc */
|
||||||
|
0x00, /* bMasterInterface: Communication class interface */
|
||||||
|
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||||
|
|
||||||
|
/* Endpoint 2 Descriptor */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
|
CDC_CMD_EP, /* bEndpointAddress */
|
||||||
|
0x03, /* bmAttributes: Interrupt */
|
||||||
|
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
||||||
|
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||||
|
CDC_FS_BINTERVAL, /* bInterval */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Data class interface descriptor */
|
||||||
|
0x09, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||||
|
0x01, /* bInterfaceNumber: Number of Interface */
|
||||||
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
|
0x02, /* bNumEndpoints: Two endpoints used */
|
||||||
|
0x0A, /* bInterfaceClass: CDC */
|
||||||
|
0x00, /* bInterfaceSubClass */
|
||||||
|
0x00, /* bInterfaceProtocol */
|
||||||
|
0x00, /* iInterface */
|
||||||
|
|
||||||
|
/* Endpoint OUT Descriptor */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
|
CDC_OUT_EP, /* bEndpointAddress */
|
||||||
|
0x02, /* bmAttributes: Bulk */
|
||||||
|
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
||||||
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
|
0x00, /* bInterval */
|
||||||
|
|
||||||
|
/* Endpoint IN Descriptor */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
|
CDC_IN_EP, /* bEndpointAddress */
|
||||||
|
0x02, /* bmAttributes: Bulk */
|
||||||
|
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
||||||
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
|
0x00 /* bInterval */
|
||||||
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static uint8_t CDCInEpAdd = CDC_IN_EP;
|
||||||
|
static uint8_t CDCOutEpAdd = CDC_OUT_EP;
|
||||||
|
static uint8_t CDCCmdEpAdd = CDC_CMD_EP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_Private_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_Init
|
||||||
|
* Initialize the CDC interface
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param cfgidx: Configuration index
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
|
|
||||||
|
hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)USBD_memset(hcdc, 0, sizeof(USBD_CDC_HandleTypeDef));
|
||||||
|
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hcdc;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
/* Open EP IN */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Open EP OUT */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Set bInterval for CDC CMD Endpoint */
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = CDC_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Open EP IN */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Open EP OUT */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Set bInterval for CMD Endpoint */
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open Command IN EP */
|
||||||
|
(void)USBD_LL_OpenEP(pdev, CDCCmdEpAdd, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
hcdc->RxBuffer = NULL;
|
||||||
|
|
||||||
|
/* Init physical Interface components */
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
|
/* Init Xfer states */
|
||||||
|
hcdc->TxState = 0U;
|
||||||
|
hcdc->RxState = 0U;
|
||||||
|
|
||||||
|
if (hcdc->RxBuffer == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_Init
|
||||||
|
* DeInitialize the CDC layer
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param cfgidx: Configuration index
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this CDC class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
/* Close EP IN */
|
||||||
|
(void)USBD_LL_CloseEP(pdev, CDCInEpAdd);
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
|
/* Close EP OUT */
|
||||||
|
(void)USBD_LL_CloseEP(pdev, CDCOutEpAdd);
|
||||||
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
|
/* Close Command IN EP */
|
||||||
|
(void)USBD_LL_CloseEP(pdev, CDCCmdEpAdd);
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
|
/* DeInit physical Interface components */
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
|
pdev->pClassData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_Setup
|
||||||
|
* Handle the CDC specific requests
|
||||||
|
* @param pdev: instance
|
||||||
|
* @param req: usb requests
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_SetupReqTypedef *req)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
uint16_t len;
|
||||||
|
uint8_t ifalt = 0U;
|
||||||
|
uint16_t status_info = 0U;
|
||||||
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
|
{
|
||||||
|
case USB_REQ_TYPE_CLASS:
|
||||||
|
if (req->wLength != 0U)
|
||||||
|
{
|
||||||
|
if ((req->bmRequest & 0x80U) != 0U)
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
|
(uint8_t *)hcdc->data,
|
||||||
|
req->wLength);
|
||||||
|
|
||||||
|
len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength);
|
||||||
|
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hcdc->CmdOpCode = req->bRequest;
|
||||||
|
hcdc->CmdLength = (uint8_t)MIN(req->wLength, USB_MAX_EP0_SIZE);
|
||||||
|
|
||||||
|
(void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, hcdc->CmdLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
|
(uint8_t *)req, 0U);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_TYPE_STANDARD:
|
||||||
|
switch (req->bRequest)
|
||||||
|
{
|
||||||
|
case USB_REQ_GET_STATUS:
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_GET_INTERFACE:
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
(void)USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_SET_INTERFACE:
|
||||||
|
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_DataIn
|
||||||
|
* Data sent on non-control IN endpoint
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param epnum: endpoint number
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
||||||
|
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
||||||
|
{
|
||||||
|
/* Update the packet total length */
|
||||||
|
pdev->ep_in[epnum & 0xFU].total_length = 0U;
|
||||||
|
|
||||||
|
/* Send ZLP */
|
||||||
|
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hcdc->TxState = 0U;
|
||||||
|
|
||||||
|
if (((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt != NULL)
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_DataOut
|
||||||
|
* Data received on non-control Out endpoint
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param epnum: endpoint number
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the received data length */
|
||||||
|
hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||||
|
|
||||||
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
|
NAKed till the end of the application Xfer */
|
||||||
|
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_EP0_RxReady
|
||||||
|
* Handle EP0 Rx Ready event
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pdev->pUserData[pdev->classId] != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||||
|
{
|
||||||
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(hcdc->CmdOpCode,
|
||||||
|
(uint8_t *)hcdc->data,
|
||||||
|
(uint16_t)hcdc->CmdLength);
|
||||||
|
hcdc->CmdOpCode = 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetFSCfgDesc
|
||||||
|
* Return configuration descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
||||||
|
{
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetHSCfgDesc
|
||||||
|
* Return configuration descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
||||||
|
{
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetOtherSpeedCfgDesc
|
||||||
|
* Return configuration descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
|
{
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_GetDeviceQualifierDescriptor
|
||||||
|
* return Device Qualifier descriptor
|
||||||
|
* @param length : pointer data length
|
||||||
|
* @retval pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||||
|
{
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_DeviceQualifierDesc);
|
||||||
|
|
||||||
|
return USBD_CDC_DeviceQualifierDesc;
|
||||||
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_RegisterInterface
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param fops: CD Interface callback
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_CDC_ItfTypeDef *fops)
|
||||||
|
{
|
||||||
|
if (fops == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_SetTxBuffer
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param pbuff: Tx Buffer
|
||||||
|
* @param length: length of data to be sent
|
||||||
|
* @param ClassId: The Class ID
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuff, uint32_t length, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuff, uint32_t length)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc->TxBuffer = pbuff;
|
||||||
|
hcdc->TxLength = length;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_SetRxBuffer
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param pbuff: Rx Buffer
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc->RxBuffer = pbuff;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_TransmitPacket
|
||||||
|
* Transmit packet on IN endpoint
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param ClassId: The Class ID
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
USBD_StatusTypeDef ret = USBD_BUSY;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcdc->TxState == 0U)
|
||||||
|
{
|
||||||
|
/* Tx Transfer in progress */
|
||||||
|
hcdc->TxState = 1U;
|
||||||
|
|
||||||
|
/* Update the packet total length */
|
||||||
|
pdev->ep_in[CDCInEpAdd & 0xFU].total_length = hcdc->TxLength;
|
||||||
|
|
||||||
|
/* Transmit next packet */
|
||||||
|
(void)USBD_LL_Transmit(pdev, CDCInEpAdd, hcdc->TxBuffer, hcdc->TxLength);
|
||||||
|
|
||||||
|
ret = USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CDC_ReceivePacket
|
||||||
|
* prepare OUT Endpoint for reception
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Prepare Out endpoint to receive next packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_core.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for usbd_core.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_CORE_H
|
||||||
|
#define __USBD_CORE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
#include "usbd_ctlreq.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE
|
||||||
|
* @brief This file is the Header file for usbd_core.c file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#ifndef USBD_DEBUG_LEVEL
|
||||||
|
#define USBD_DEBUG_LEVEL 0U
|
||||||
|
#endif /* USBD_DEBUG_LEVEL */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define USBD_SOF USBD_LL_SOF
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CORE_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
||||||
|
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback);
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass,
|
||||||
|
USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index);
|
||||||
|
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
/* USBD Low Level Driver */
|
||||||
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t ep_type, uint16_t ep_mps);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t *pbuf, uint32_t size);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
|
uint8_t *pbuf, uint32_t size);
|
||||||
|
|
||||||
|
#ifdef USBD_HS_TESTMODE_ENABLE
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode);
|
||||||
|
#endif /* USBD_HS_TESTMODE_ENABLE */
|
||||||
|
|
||||||
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
|
||||||
|
void USBD_LL_Delay(uint32_t Delay);
|
||||||
|
|
||||||
|
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr);
|
||||||
|
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_CORE_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_req.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for the usbd_req.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USB_REQUEST_H
|
||||||
|
#define __USB_REQUEST_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ
|
||||||
|
* @brief header file for the usbd_req.c file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_REQ_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
|
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||||
|
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USB_REQUEST_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,523 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_def.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief General defines for the usb device library
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_DEF_H
|
||||||
|
#define __USBD_DEF_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_DEF
|
||||||
|
* @brief general defines for the usb device library file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USB_DEF_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL 0U
|
||||||
|
#endif /* NULL */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_NUM_INTERFACES
|
||||||
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
|
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_NUM_CONFIGURATION
|
||||||
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
|
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
#ifndef USBD_MAX_SUPPORTED_CLASS
|
||||||
|
#define USBD_MAX_SUPPORTED_CLASS 4U
|
||||||
|
#endif /* USBD_MAX_SUPPORTED_CLASS */
|
||||||
|
#else
|
||||||
|
#ifndef USBD_MAX_SUPPORTED_CLASS
|
||||||
|
#define USBD_MAX_SUPPORTED_CLASS 1U
|
||||||
|
#endif /* USBD_MAX_SUPPORTED_CLASS */
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_CLASS_ENDPOINTS
|
||||||
|
#define USBD_MAX_CLASS_ENDPOINTS 5U
|
||||||
|
#endif /* USBD_MAX_CLASS_ENDPOINTS */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_CLASS_INTERFACES
|
||||||
|
#define USBD_MAX_CLASS_INTERFACES 5U
|
||||||
|
#endif /* USBD_MAX_CLASS_INTERFACES */
|
||||||
|
|
||||||
|
#ifndef USBD_LPM_ENABLED
|
||||||
|
#define USBD_LPM_ENABLED 0U
|
||||||
|
#endif /* USBD_LPM_ENABLED */
|
||||||
|
|
||||||
|
#ifndef USBD_SELF_POWERED
|
||||||
|
#define USBD_SELF_POWERED 1U
|
||||||
|
#endif /*USBD_SELF_POWERED */
|
||||||
|
|
||||||
|
#ifndef USBD_MAX_POWER
|
||||||
|
#define USBD_MAX_POWER 0x32U /* 100 mA */
|
||||||
|
#endif /* USBD_MAX_POWER */
|
||||||
|
|
||||||
|
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||||
|
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||||
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#ifndef USBD_CLASS_USER_STRING_DESC
|
||||||
|
#define USBD_CLASS_USER_STRING_DESC 0U
|
||||||
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
|
||||||
|
#define USB_LEN_DEV_DESC 0x12U
|
||||||
|
#define USB_LEN_CFG_DESC 0x09U
|
||||||
|
#define USB_LEN_IF_DESC 0x09U
|
||||||
|
#define USB_LEN_EP_DESC 0x07U
|
||||||
|
#define USB_LEN_OTG_DESC 0x03U
|
||||||
|
#define USB_LEN_LANGID_STR_DESC 0x04U
|
||||||
|
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
|
||||||
|
|
||||||
|
#define USBD_IDX_LANGID_STR 0x00U
|
||||||
|
#define USBD_IDX_MFC_STR 0x01U
|
||||||
|
#define USBD_IDX_PRODUCT_STR 0x02U
|
||||||
|
#define USBD_IDX_SERIAL_STR 0x03U
|
||||||
|
#define USBD_IDX_CONFIG_STR 0x04U
|
||||||
|
#define USBD_IDX_INTERFACE_STR 0x05U
|
||||||
|
|
||||||
|
#define USB_REQ_TYPE_STANDARD 0x00U
|
||||||
|
#define USB_REQ_TYPE_CLASS 0x20U
|
||||||
|
#define USB_REQ_TYPE_VENDOR 0x40U
|
||||||
|
#define USB_REQ_TYPE_MASK 0x60U
|
||||||
|
|
||||||
|
#define USB_REQ_RECIPIENT_DEVICE 0x00U
|
||||||
|
#define USB_REQ_RECIPIENT_INTERFACE 0x01U
|
||||||
|
#define USB_REQ_RECIPIENT_ENDPOINT 0x02U
|
||||||
|
#define USB_REQ_RECIPIENT_MASK 0x03U
|
||||||
|
|
||||||
|
#define USB_REQ_GET_STATUS 0x00U
|
||||||
|
#define USB_REQ_CLEAR_FEATURE 0x01U
|
||||||
|
#define USB_REQ_SET_FEATURE 0x03U
|
||||||
|
#define USB_REQ_SET_ADDRESS 0x05U
|
||||||
|
#define USB_REQ_GET_DESCRIPTOR 0x06U
|
||||||
|
#define USB_REQ_SET_DESCRIPTOR 0x07U
|
||||||
|
#define USB_REQ_GET_CONFIGURATION 0x08U
|
||||||
|
#define USB_REQ_SET_CONFIGURATION 0x09U
|
||||||
|
#define USB_REQ_GET_INTERFACE 0x0AU
|
||||||
|
#define USB_REQ_SET_INTERFACE 0x0BU
|
||||||
|
#define USB_REQ_SYNCH_FRAME 0x0CU
|
||||||
|
|
||||||
|
#define USB_DESC_TYPE_DEVICE 0x01U
|
||||||
|
#define USB_DESC_TYPE_CONFIGURATION 0x02U
|
||||||
|
#define USB_DESC_TYPE_STRING 0x03U
|
||||||
|
#define USB_DESC_TYPE_INTERFACE 0x04U
|
||||||
|
#define USB_DESC_TYPE_ENDPOINT 0x05U
|
||||||
|
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
|
||||||
|
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
|
||||||
|
#define USB_DESC_TYPE_IAD 0x0BU
|
||||||
|
#define USB_DESC_TYPE_BOS 0x0FU
|
||||||
|
|
||||||
|
#define USB_CONFIG_REMOTE_WAKEUP 0x02U
|
||||||
|
#define USB_CONFIG_SELF_POWERED 0x01U
|
||||||
|
|
||||||
|
#define USB_FEATURE_EP_HALT 0x00U
|
||||||
|
#define USB_FEATURE_REMOTE_WAKEUP 0x01U
|
||||||
|
#define USB_FEATURE_TEST_MODE 0x02U
|
||||||
|
|
||||||
|
#define USB_DEVICE_CAPABITY_TYPE 0x10U
|
||||||
|
|
||||||
|
#define USB_CONF_DESC_SIZE 0x09U
|
||||||
|
#define USB_IF_DESC_SIZE 0x09U
|
||||||
|
#define USB_EP_DESC_SIZE 0x07U
|
||||||
|
#define USB_IAD_DESC_SIZE 0x08U
|
||||||
|
|
||||||
|
#define USB_HS_MAX_PACKET_SIZE 512U
|
||||||
|
#define USB_FS_MAX_PACKET_SIZE 64U
|
||||||
|
#define USB_MAX_EP0_SIZE 64U
|
||||||
|
|
||||||
|
/* Device Status */
|
||||||
|
#define USBD_STATE_DEFAULT 0x01U
|
||||||
|
#define USBD_STATE_ADDRESSED 0x02U
|
||||||
|
#define USBD_STATE_CONFIGURED 0x03U
|
||||||
|
#define USBD_STATE_SUSPENDED 0x04U
|
||||||
|
|
||||||
|
|
||||||
|
/* EP0 State */
|
||||||
|
#define USBD_EP0_IDLE 0x00U
|
||||||
|
#define USBD_EP0_SETUP 0x01U
|
||||||
|
#define USBD_EP0_DATA_IN 0x02U
|
||||||
|
#define USBD_EP0_DATA_OUT 0x03U
|
||||||
|
#define USBD_EP0_STATUS_IN 0x04U
|
||||||
|
#define USBD_EP0_STATUS_OUT 0x05U
|
||||||
|
#define USBD_EP0_STALL 0x06U
|
||||||
|
|
||||||
|
#define USBD_EP_TYPE_CTRL 0x00U
|
||||||
|
#define USBD_EP_TYPE_ISOC 0x01U
|
||||||
|
#define USBD_EP_TYPE_BULK 0x02U
|
||||||
|
#define USBD_EP_TYPE_INTR 0x03U
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
#define USBD_EP_IN 0x80U
|
||||||
|
#define USBD_EP_OUT 0x00U
|
||||||
|
#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U
|
||||||
|
#define USBD_DESC_SUBTYPE_ACM 0x0FU
|
||||||
|
#define USBD_DESC_ECM_BCD_LOW 0x00U
|
||||||
|
#define USBD_DESC_ECM_BCD_HIGH 0x10U
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct usb_setup_req
|
||||||
|
{
|
||||||
|
uint8_t bmRequest;
|
||||||
|
uint8_t bRequest;
|
||||||
|
uint16_t wValue;
|
||||||
|
uint16_t wIndex;
|
||||||
|
uint16_t wLength;
|
||||||
|
} USBD_SetupReqTypedef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t wTotalLength;
|
||||||
|
uint8_t bNumInterfaces;
|
||||||
|
uint8_t bConfigurationValue;
|
||||||
|
uint8_t iConfiguration;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint8_t bMaxPower;
|
||||||
|
} __PACKED USBD_ConfigDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t wTotalLength;
|
||||||
|
uint8_t bNumDeviceCaps;
|
||||||
|
} USBD_BosDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bEndpointAddress;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint16_t wMaxPacketSize;
|
||||||
|
uint8_t bInterval;
|
||||||
|
} __PACKED USBD_EpDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubType;
|
||||||
|
} USBD_DescHeaderTypeDef;
|
||||||
|
|
||||||
|
struct _USBD_HandleTypeDef;
|
||||||
|
|
||||||
|
typedef struct _Device_cb
|
||||||
|
{
|
||||||
|
uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
/* Control Endpoints*/
|
||||||
|
uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
|
||||||
|
/* Class Specific Endpoints*/
|
||||||
|
uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
|
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
||||||
|
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
||||||
|
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
||||||
|
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||||
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
|
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
|
} USBD_ClassTypeDef;
|
||||||
|
|
||||||
|
/* Following USB Device Speed */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
USBD_SPEED_HIGH = 0U,
|
||||||
|
USBD_SPEED_FULL = 1U,
|
||||||
|
USBD_SPEED_LOW = 2U,
|
||||||
|
} USBD_SpeedTypeDef;
|
||||||
|
|
||||||
|
/* Following USB Device status */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
USBD_OK = 0U,
|
||||||
|
USBD_BUSY,
|
||||||
|
USBD_EMEM,
|
||||||
|
USBD_FAIL,
|
||||||
|
} USBD_StatusTypeDef;
|
||||||
|
|
||||||
|
/* USB Device descriptors structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
|
uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||||
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
|
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
} USBD_DescriptorsTypeDef;
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t total_length;
|
||||||
|
uint32_t rem_length;
|
||||||
|
uint32_t maxpacket;
|
||||||
|
uint16_t is_used;
|
||||||
|
uint16_t bInterval;
|
||||||
|
} USBD_EndpointTypeDef;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CLASS_TYPE_NONE = 0,
|
||||||
|
CLASS_TYPE_HID = 1,
|
||||||
|
CLASS_TYPE_CDC = 2,
|
||||||
|
CLASS_TYPE_MSC = 3,
|
||||||
|
CLASS_TYPE_DFU = 4,
|
||||||
|
CLASS_TYPE_CHID = 5,
|
||||||
|
CLASS_TYPE_AUDIO = 6,
|
||||||
|
CLASS_TYPE_ECM = 7,
|
||||||
|
CLASS_TYPE_RNDIS = 8,
|
||||||
|
CLASS_TYPE_MTP = 9,
|
||||||
|
CLASS_TYPE_VIDEO = 10,
|
||||||
|
CLASS_TYPE_PRINTER = 11,
|
||||||
|
CLASS_TYPE_CCID = 12,
|
||||||
|
} USBD_CompositeClassTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t add;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t size;
|
||||||
|
uint8_t is_used;
|
||||||
|
} USBD_EPTypeDef;
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
USBD_CompositeClassTypeDef ClassType;
|
||||||
|
uint32_t ClassId;
|
||||||
|
uint32_t Active;
|
||||||
|
uint32_t NumEps;
|
||||||
|
USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS];
|
||||||
|
uint8_t *EpAdd;
|
||||||
|
uint32_t NumIf;
|
||||||
|
uint8_t Ifs[USBD_MAX_CLASS_INTERFACES];
|
||||||
|
uint32_t CurrPcktSze;
|
||||||
|
} USBD_CompositeElementTypeDef;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
/* USB Device handle structure */
|
||||||
|
typedef struct _USBD_HandleTypeDef
|
||||||
|
{
|
||||||
|
uint8_t id;
|
||||||
|
uint32_t dev_config;
|
||||||
|
uint32_t dev_default_config;
|
||||||
|
uint32_t dev_config_status;
|
||||||
|
USBD_SpeedTypeDef dev_speed;
|
||||||
|
USBD_EndpointTypeDef ep_in[16];
|
||||||
|
USBD_EndpointTypeDef ep_out[16];
|
||||||
|
__IO uint32_t ep0_state;
|
||||||
|
uint32_t ep0_data_len;
|
||||||
|
__IO uint8_t dev_state;
|
||||||
|
__IO uint8_t dev_old_state;
|
||||||
|
uint8_t dev_address;
|
||||||
|
uint8_t dev_connection_status;
|
||||||
|
uint8_t dev_test_mode;
|
||||||
|
uint32_t dev_remote_wakeup;
|
||||||
|
uint8_t ConfIdx;
|
||||||
|
|
||||||
|
USBD_SetupReqTypedef request;
|
||||||
|
USBD_DescriptorsTypeDef *pDesc;
|
||||||
|
USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pClassData;
|
||||||
|
void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pUserData[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pData;
|
||||||
|
void *pBosDesc;
|
||||||
|
void *pConfDesc;
|
||||||
|
uint32_t classId;
|
||||||
|
uint32_t NumClasses;
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
void (* DevStateCallback)(uint8_t dev_state, uint8_t cfgidx); /*!< User Notification callback */
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
} USBD_HandleTypeDef;
|
||||||
|
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
typedef void (*USBD_DevStateCallbackTypeDef)(uint8_t dev_state, uint8_t cfgidx); /*!< pointer to User callback function */
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
|
||||||
|
/* USB Device endpoint direction */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
OUT = 0x00,
|
||||||
|
IN = 0x80,
|
||||||
|
} USBD_EPDirectionTypeDef;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NETWORK_CONNECTION = 0x00,
|
||||||
|
RESPONSE_AVAILABLE = 0x01,
|
||||||
|
CONNECTION_SPEED_CHANGE = 0x2A
|
||||||
|
} USBD_CDC_NotifCodeTypeDef;
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
||||||
|
{
|
||||||
|
uint16_t _SwapVal;
|
||||||
|
uint16_t _Byte1;
|
||||||
|
uint16_t _Byte2;
|
||||||
|
uint8_t *_pbuff = addr;
|
||||||
|
|
||||||
|
_Byte1 = *(uint8_t *)_pbuff;
|
||||||
|
_pbuff++;
|
||||||
|
_Byte2 = *(uint8_t *)_pbuff;
|
||||||
|
|
||||||
|
_SwapVal = (_Byte2 << 8) | _Byte1;
|
||||||
|
|
||||||
|
return _SwapVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef LOBYTE
|
||||||
|
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||||
|
#endif /* LOBYTE */
|
||||||
|
|
||||||
|
#ifndef HIBYTE
|
||||||
|
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||||
|
#endif /* HIBYTE */
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif /* MIN */
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif /* MAX */
|
||||||
|
|
||||||
|
#if defined ( __GNUC__ )
|
||||||
|
#ifndef __weak
|
||||||
|
#define __weak __attribute__((weak))
|
||||||
|
#endif /* __weak */
|
||||||
|
#ifndef __packed
|
||||||
|
#define __packed __attribute__((__packed__))
|
||||||
|
#endif /* __packed */
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
|
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||||
|
with the DMA during the transaction process should be 4-bytes aligned */
|
||||||
|
|
||||||
|
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
|
||||||
|
#ifndef __ALIGN_END
|
||||||
|
#define __ALIGN_END __attribute__ ((aligned (4U)))
|
||||||
|
#endif /* __ALIGN_END */
|
||||||
|
#ifndef __ALIGN_BEGIN
|
||||||
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
|
#else
|
||||||
|
#ifndef __ALIGN_END
|
||||||
|
#define __ALIGN_END
|
||||||
|
#endif /* __ALIGN_END */
|
||||||
|
#ifndef __ALIGN_BEGIN
|
||||||
|
#if defined (__CC_ARM) /* ARM Compiler */
|
||||||
|
#define __ALIGN_BEGIN __align(4U)
|
||||||
|
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||||
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __CC_ARM */
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DEF_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_DEF_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_ioreq.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for the usbd_ioreq.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_IOREQ_H
|
||||||
|
#define __USBD_IOREQ_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_def.h"
|
||||||
|
#include "usbd_core.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ
|
||||||
|
* @brief header file for the usbd_ioreq.c file
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Types
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len);
|
||||||
|
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
|
||||||
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_IOREQ_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,224 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_ioreq.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief This file provides the IO requests APIs for control endpoints.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ
|
||||||
|
* @brief control I/O requests module
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_TypesDefinitions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Variables
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @defgroup USBD_IOREQ_Private_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlSendData
|
||||||
|
* send data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be sent
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||||
|
pdev->ep_in[0].total_length = len;
|
||||||
|
|
||||||
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
|
pdev->ep_in[0].rem_length = 0U;
|
||||||
|
#else
|
||||||
|
pdev->ep_in[0].rem_length = len;
|
||||||
|
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlContinueSendData
|
||||||
|
* continue sending data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be sent
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
/* Start the next transfer */
|
||||||
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlPrepareRx
|
||||||
|
* receive data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be received
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||||
|
pdev->ep_out[0].total_length = len;
|
||||||
|
|
||||||
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
|
pdev->ep_out[0].rem_length = 0U;
|
||||||
|
#else
|
||||||
|
pdev->ep_out[0].rem_length = len;
|
||||||
|
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlContinueRx
|
||||||
|
* continue receive data on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param buff: pointer to data buffer
|
||||||
|
* @param len: length of data to be received
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuf, uint32_t len)
|
||||||
|
{
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlSendStatus
|
||||||
|
* send zero lzngth packet on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_CtlReceiveStatus
|
||||||
|
* receive zero lzngth packet on the ctl pipe
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
/* Set EP0 State */
|
||||||
|
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||||
|
|
||||||
|
/* Start the transfer */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_GetRxCount
|
||||||
|
* returns the received data length
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param ep_addr: endpoint address
|
||||||
|
* @retval Rx Data blength
|
||||||
|
*/
|
||||||
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
This software component is provided to you as part of a software package and
|
||||||
|
applicable license terms are in the Package_license file. If you received this
|
||||||
|
software component outside of a package or without applicable license terms,
|
||||||
|
the terms of the SLA0044 license shall apply and are fully reproduced below:
|
||||||
|
|
||||||
|
SLA0044 Rev5/February 2018
|
||||||
|
|
||||||
|
Software license agreement
|
||||||
|
|
||||||
|
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT
|
||||||
|
|
||||||
|
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
||||||
|
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
|
||||||
|
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
|
||||||
|
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
|
||||||
|
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
|
||||||
|
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.
|
||||||
|
|
||||||
|
Under STMicroelectronics’ intellectual property rights, the redistribution,
|
||||||
|
reproduction and use in source and binary forms of the software or any part
|
||||||
|
thereof, with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
1. Redistribution of source code (modified or not) must retain any copyright
|
||||||
|
notice, this list of conditions and the disclaimer set forth below as items 10
|
||||||
|
and 11.
|
||||||
|
|
||||||
|
2. Redistributions in binary form, except as embedded into microcontroller or
|
||||||
|
microprocessor device manufactured by or for STMicroelectronics or a software
|
||||||
|
update for such device, must reproduce any copyright notice provided with the
|
||||||
|
binary code, this list of conditions, and the disclaimer set forth below as
|
||||||
|
items 10 and 11, in documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
3. Neither the name of STMicroelectronics nor the names of other contributors to
|
||||||
|
this software may be used to endorse or promote products derived from this
|
||||||
|
software or part thereof without specific written permission.
|
||||||
|
|
||||||
|
4. This software or any part thereof, including modifications and/or derivative
|
||||||
|
works of this software, must be used and execute solely and exclusively on or in
|
||||||
|
combination with a microcontroller or microprocessor device manufactured by or
|
||||||
|
for STMicroelectronics.
|
||||||
|
|
||||||
|
5. No use, reproduction or redistribution of this software partially or totally
|
||||||
|
may be done in any manner that would subject this software to any Open Source
|
||||||
|
Terms. “Open Source Terms” shall mean any open source license which requires as
|
||||||
|
part of distribution of software that the source code of such software is
|
||||||
|
distributed therewith or otherwise made available, or open source license that
|
||||||
|
substantially complies with the Open Source definition specified at
|
||||||
|
www.opensource.org and any other comparable open source license such as for
|
||||||
|
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
|
||||||
|
Software License, BSD license or MIT license.
|
||||||
|
|
||||||
|
6. STMicroelectronics has no obligation to provide any maintenance, support or
|
||||||
|
updates for the software.
|
||||||
|
|
||||||
|
7. The software is and will remain the exclusive property of STMicroelectronics
|
||||||
|
and its licensors. The recipient will not take any action that jeopardizes
|
||||||
|
STMicroelectronics and its licensors' proprietary rights or acquire any rights
|
||||||
|
in the software, except the limited rights specified hereunder.
|
||||||
|
|
||||||
|
8. The recipient shall comply with all applicable laws and regulations affecting
|
||||||
|
the use of the software or any part thereof including any applicable export
|
||||||
|
control law or regulation.
|
||||||
|
|
||||||
|
9. Redistribution and use of this software or any part thereof other than as
|
||||||
|
permitted under this license is void and will automatically terminate your
|
||||||
|
rights under this license.
|
||||||
|
|
||||||
|
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
|
||||||
|
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
|
||||||
|
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
|
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
|
||||||
|
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
|
||||||
|
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
|
||||||
|
|
||||||
@ -18,6 +18,7 @@
|
|||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "usb_device.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
@ -43,8 +44,6 @@
|
|||||||
|
|
||||||
QSPI_HandleTypeDef hqspi;
|
QSPI_HandleTypeDef hqspi;
|
||||||
|
|
||||||
SPI_HandleTypeDef hspi5;
|
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
UART_HandleTypeDef huart1;
|
||||||
UART_HandleTypeDef huart2;
|
UART_HandleTypeDef huart2;
|
||||||
UART_HandleTypeDef huart3;
|
UART_HandleTypeDef huart3;
|
||||||
@ -58,10 +57,9 @@ void SystemClock_Config(void);
|
|||||||
static void MPU_Config(void);
|
static void MPU_Config(void);
|
||||||
static void MX_GPIO_Init(void);
|
static void MX_GPIO_Init(void);
|
||||||
static void MX_USART1_UART_Init(void);
|
static void MX_USART1_UART_Init(void);
|
||||||
static void MX_QUADSPI_Init(void);
|
|
||||||
static void MX_SPI5_Init(void);
|
|
||||||
static void MX_USART2_UART_Init(void);
|
static void MX_USART2_UART_Init(void);
|
||||||
static void MX_USART3_UART_Init(void);
|
static void MX_USART3_UART_Init(void);
|
||||||
|
static void MX_QUADSPI_Init(void);
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
/* USER CODE END PFP */
|
||||||
@ -104,10 +102,10 @@ int main(void)
|
|||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_USART1_UART_Init();
|
MX_USART1_UART_Init();
|
||||||
MX_QUADSPI_Init();
|
|
||||||
MX_SPI5_Init();
|
|
||||||
MX_USART2_UART_Init();
|
MX_USART2_UART_Init();
|
||||||
MX_USART3_UART_Init();
|
MX_USART3_UART_Init();
|
||||||
|
MX_USB_DEVICE_Init();
|
||||||
|
MX_QUADSPI_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
@ -145,17 +143,16 @@ void SystemClock_Config(void)
|
|||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
RCC_OscInitStruct.PLL.PLLM = 5;
|
||||||
RCC_OscInitStruct.PLL.PLLN = 60;
|
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||||
RCC_OscInitStruct.PLL.PLLP = 2;
|
RCC_OscInitStruct.PLL.PLLP = 2;
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
RCC_OscInitStruct.PLL.PLLQ = 20;
|
||||||
RCC_OscInitStruct.PLL.PLLR = 2;
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
||||||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
||||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
@ -217,54 +214,6 @@ static void MX_QUADSPI_Init(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI5 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void MX_SPI5_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 1 */
|
|
||||||
/* SPI5 parameter configuration*/
|
|
||||||
hspi5.Instance = SPI5;
|
|
||||||
hspi5.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi5.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
|
|
||||||
hspi5.Init.DataSize = SPI_DATASIZE_4BIT;
|
|
||||||
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
||||||
hspi5.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
|
||||||
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi5.Init.CRCPolynomial = 0x0;
|
|
||||||
hspi5.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
|
||||||
hspi5.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
|
|
||||||
hspi5.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
|
|
||||||
hspi5.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
|
||||||
hspi5.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
|
||||||
hspi5.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
|
|
||||||
hspi5.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
|
|
||||||
hspi5.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
|
|
||||||
hspi5.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
|
|
||||||
hspi5.Init.IOSwap = SPI_IO_SWAP_DISABLE;
|
|
||||||
if (HAL_SPI_Init(&hspi5) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI5_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USART1 Initialization Function
|
* @brief USART1 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
@ -427,9 +376,7 @@ static void MX_GPIO_Init(void)
|
|||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOK_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin : PE9 */
|
/*Configure GPIO pin : PE9 */
|
||||||
|
|||||||
@ -108,7 +108,6 @@ void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
|
|||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
/**QUADSPI GPIO Configuration
|
/**QUADSPI GPIO Configuration
|
||||||
PG6 ------> QUADSPI_BK1_NCS
|
PG6 ------> QUADSPI_BK1_NCS
|
||||||
PF6 ------> QUADSPI_BK1_IO3
|
|
||||||
PF7 ------> QUADSPI_BK1_IO2
|
PF7 ------> QUADSPI_BK1_IO2
|
||||||
PF8 ------> QUADSPI_BK1_IO0
|
PF8 ------> QUADSPI_BK1_IO0
|
||||||
PF10 ------> QUADSPI_CLK
|
PF10 ------> QUADSPI_CLK
|
||||||
@ -121,7 +120,7 @@ void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
|
|||||||
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
||||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_10;
|
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_10;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
@ -161,7 +160,6 @@ void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
|
|||||||
|
|
||||||
/**QUADSPI GPIO Configuration
|
/**QUADSPI GPIO Configuration
|
||||||
PG6 ------> QUADSPI_BK1_NCS
|
PG6 ------> QUADSPI_BK1_NCS
|
||||||
PF6 ------> QUADSPI_BK1_IO3
|
|
||||||
PF7 ------> QUADSPI_BK1_IO2
|
PF7 ------> QUADSPI_BK1_IO2
|
||||||
PF8 ------> QUADSPI_BK1_IO0
|
PF8 ------> QUADSPI_BK1_IO0
|
||||||
PF10 ------> QUADSPI_CLK
|
PF10 ------> QUADSPI_CLK
|
||||||
@ -169,8 +167,7 @@ void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
|
|||||||
*/
|
*/
|
||||||
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_6);
|
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_6);
|
||||||
|
|
||||||
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_10
|
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_10|GPIO_PIN_9);
|
||||||
|GPIO_PIN_9);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN QUADSPI_MspDeInit 1 */
|
/* USER CODE BEGIN QUADSPI_MspDeInit 1 */
|
||||||
|
|
||||||
@ -179,93 +176,6 @@ void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI MSP Initialization
|
|
||||||
* This function configures the hardware resources used in this example
|
|
||||||
* @param hspi: SPI handle pointer
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
||||||
if(hspi->Instance==SPI5)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN SPI5_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_MspInit 0 */
|
|
||||||
|
|
||||||
/** Initializes the peripherals clock
|
|
||||||
*/
|
|
||||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI5;
|
|
||||||
PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_D2PCLK1;
|
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Peripheral clock enable */
|
|
||||||
__HAL_RCC_SPI5_CLK_ENABLE();
|
|
||||||
|
|
||||||
__HAL_RCC_GPIOK_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
|
||||||
/**SPI5 GPIO Configuration
|
|
||||||
PK0 ------> SPI5_SCK
|
|
||||||
PJ10 ------> SPI5_MOSI
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
|
|
||||||
HAL_GPIO_Init(GPIOK, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
|
|
||||||
HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_MspInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_MspInit 1 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SPI MSP De-Initialization
|
|
||||||
* This function freeze the hardware resources used in this example
|
|
||||||
* @param hspi: SPI handle pointer
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
|
||||||
{
|
|
||||||
if(hspi->Instance==SPI5)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN SPI5_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_MspDeInit 0 */
|
|
||||||
/* Peripheral clock disable */
|
|
||||||
__HAL_RCC_SPI5_CLK_DISABLE();
|
|
||||||
|
|
||||||
/**SPI5 GPIO Configuration
|
|
||||||
PK0 ------> SPI5_SCK
|
|
||||||
PJ10 ------> SPI5_MOSI
|
|
||||||
*/
|
|
||||||
HAL_GPIO_DeInit(GPIOK, GPIO_PIN_0);
|
|
||||||
|
|
||||||
HAL_GPIO_DeInit(GPIOJ, GPIO_PIN_10);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI5_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UART MSP Initialization
|
* @brief UART MSP Initialization
|
||||||
* This function configures the hardware resources used in this example
|
* This function configures the hardware resources used in this example
|
||||||
@ -448,4 +358,81 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
|||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
LL Driver Callbacks (PCD -> USB Device Library)
|
||||||
|
*******************************************************************************/
|
||||||
|
/* MSP Init */
|
||||||
|
|
||||||
|
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 0 */
|
||||||
|
|
||||||
|
/** Initializes the peripherals clock
|
||||||
|
*/
|
||||||
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||||
|
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
|
||||||
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Enable USB Voltage detector
|
||||||
|
*/
|
||||||
|
HAL_PWREx_EnableUSBVoltageDetector();
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA12 ------> USB_OTG_FS_DP
|
||||||
|
PA11 ------> USB_OTG_FS_DM
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* Peripheral clock enable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* Peripheral interrupt init */
|
||||||
|
HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
|
||||||
|
{
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
|
||||||
|
/* Peripheral clock disable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
|
||||||
|
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA12 ------> USB_OTG_FS_DP
|
||||||
|
PA11 ------> USB_OTG_FS_DM
|
||||||
|
*/
|
||||||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11);
|
||||||
|
|
||||||
|
/* Peripheral interrupt Deinit*/
|
||||||
|
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|||||||
@ -55,7 +55,7 @@
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/* External variables --------------------------------------------------------*/
|
/* External variables --------------------------------------------------------*/
|
||||||
|
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
|
|
||||||
/* USER CODE END EV */
|
/* USER CODE END EV */
|
||||||
@ -198,6 +198,20 @@ void SysTick_Handler(void)
|
|||||||
/* please refer to the startup file (startup_stm32h7xx.s). */
|
/* please refer to the startup file (startup_stm32h7xx.s). */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles USB On The Go FS global interrupt.
|
||||||
|
*/
|
||||||
|
void OTG_FS_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN OTG_FS_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END OTG_FS_IRQn 0 */
|
||||||
|
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
|
||||||
|
/* USER CODE BEGIN OTG_FS_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END OTG_FS_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|||||||
101
board/CubeMX_Config/Src/usb_device.c
Normal file
101
board/CubeMX_Config/Src/usb_device.c
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usb_device.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : This file implements the USB Device
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "usb_device.h"
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_desc.h"
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
#include "usbd_cdc_if.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* USB Device Core handle declaration. */
|
||||||
|
USBD_HandleTypeDef hUsbDeviceFS;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert your variables declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -- Insert your external function declaration here --
|
||||||
|
*/
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init USB device Library, add supported class and start the library
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void MX_USB_DEVICE_Init(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
|
||||||
|
|
||||||
|
/* USER CODE END USB_DEVICE_Init_PreTreatment */
|
||||||
|
|
||||||
|
/* Init Device Library, add supported class and start the library. */
|
||||||
|
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
|
||||||
|
HAL_PWREx_EnableUSBVoltageDetector();
|
||||||
|
|
||||||
|
/* USER CODE END USB_DEVICE_Init_PostTreatment */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
328
board/CubeMX_Config/Src/usbd_cdc_if.c
Normal file
328
board/CubeMX_Config/Src/usbd_cdc_if.c
Normal file
@ -0,0 +1,328 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_cdc_if.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : Usb device for Virtual Com Port.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_cdc_if.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @brief Usb device library.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup USBD_CDC_IF
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions
|
||||||
|
* @brief Private types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines
|
||||||
|
* @brief Private defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||||
|
/* USER CODE END PRIVATE_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros
|
||||||
|
* @brief Private macros.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables
|
||||||
|
* @brief Private variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/* Create buffer for reception and transmission */
|
||||||
|
/* It's up to user to redefine and/or remove those define */
|
||||||
|
/** Received data over USB are stored in this buffer */
|
||||||
|
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
|
||||||
|
|
||||||
|
/** Data to send over USB CDC are stored in this buffer */
|
||||||
|
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
|
||||||
|
* @brief Public variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_VARIABLES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes
|
||||||
|
* @brief Private functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int8_t CDC_Init_FS(void);
|
||||||
|
static int8_t CDC_DeInit_FS(void);
|
||||||
|
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||||
|
static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len);
|
||||||
|
static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
|
||||||
|
{
|
||||||
|
CDC_Init_FS,
|
||||||
|
CDC_DeInit_FS,
|
||||||
|
CDC_Control_FS,
|
||||||
|
CDC_Receive_FS,
|
||||||
|
CDC_TransmitCplt_FS
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* @brief Initializes the CDC media low layer over the FS USB IP
|
||||||
|
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_Init_FS(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
/* Set Application Buffers */
|
||||||
|
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
|
||||||
|
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DeInitializes the CDC media low layer
|
||||||
|
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_DeInit_FS(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Manage the CDC class requests
|
||||||
|
* @param cmd: Command code
|
||||||
|
* @param pbuf: Buffer containing command data (request parameters)
|
||||||
|
* @param length: Number of data to be sent (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 5 */
|
||||||
|
switch(cmd)
|
||||||
|
{
|
||||||
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_COMM_FEATURE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_COMM_FEATURE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_CLEAR_COMM_FEATURE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
/* Line Coding Structure */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Offset | Field | Size | Value | Description */
|
||||||
|
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
|
||||||
|
/* 4 | bCharFormat | 1 | Number | Stop bits */
|
||||||
|
/* 0 - 1 Stop bit */
|
||||||
|
/* 1 - 1.5 Stop bits */
|
||||||
|
/* 2 - 2 Stop bits */
|
||||||
|
/* 5 | bParityType | 1 | Number | Parity */
|
||||||
|
/* 0 - None */
|
||||||
|
/* 1 - Odd */
|
||||||
|
/* 2 - Even */
|
||||||
|
/* 3 - Mark */
|
||||||
|
/* 4 - Space */
|
||||||
|
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
|
||||||
|
/*******************************************************************************/
|
||||||
|
case CDC_SET_LINE_CODING:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_GET_LINE_CODING:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SET_CONTROL_LINE_STATE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CDC_SEND_BREAK:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 5 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data received over USB OUT endpoint are sent over CDC interface
|
||||||
|
* through this function.
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* This function will issue a NAK packet on any OUT packet received on
|
||||||
|
* USB endpoint until exiting this function. If you exit this function
|
||||||
|
* before transfer is complete on CDC interface (ie. using DMA controller)
|
||||||
|
* it will result in receiving more data while previous ones are still
|
||||||
|
* not sent.
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be received
|
||||||
|
* @param Len: Number of data received (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
|
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
|
||||||
|
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
|
||||||
|
return (USBD_OK);
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CDC_Transmit_FS
|
||||||
|
* Data to send over USB IN endpoint are sent over CDC interface
|
||||||
|
* through this function.
|
||||||
|
* @note
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be sent
|
||||||
|
* @param Len: Number of data to be sent (in bytes)
|
||||||
|
* @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
|
||||||
|
*/
|
||||||
|
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
|
||||||
|
{
|
||||||
|
uint8_t result = USBD_OK;
|
||||||
|
/* USER CODE BEGIN 7 */
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
|
||||||
|
if (hcdc->TxState != 0){
|
||||||
|
return USBD_BUSY;
|
||||||
|
}
|
||||||
|
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
|
||||||
|
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
||||||
|
/* USER CODE END 7 */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CDC_TransmitCplt_FS
|
||||||
|
* Data transmitted callback
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* This function is IN transfer complete callback used to inform user that
|
||||||
|
* the submitted Data is successfully sent over USB.
|
||||||
|
*
|
||||||
|
* @param Buf: Buffer of data to be received
|
||||||
|
* @param Len: Number of data received (in bytes)
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||||
|
{
|
||||||
|
uint8_t result = USBD_OK;
|
||||||
|
/* USER CODE BEGIN 13 */
|
||||||
|
UNUSED(Buf);
|
||||||
|
UNUSED(Len);
|
||||||
|
UNUSED(epnum);
|
||||||
|
/* USER CODE END 13 */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
693
board/CubeMX_Config/Src/usbd_conf.c
Normal file
693
board/CubeMX_Config/Src/usbd_conf.c
Normal file
@ -0,0 +1,693 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_conf.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : This file implements the board support package for the USB device library
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32h7xx.h"
|
||||||
|
#include "stm32h7xx_hal.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||||
|
void Error_Handler(void);
|
||||||
|
|
||||||
|
/* External functions --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status);
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
LL Driver Callbacks (PCD -> USB Device Library)
|
||||||
|
*******************************************************************************/
|
||||||
|
/* MSP Init */
|
||||||
|
|
||||||
|
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 0 */
|
||||||
|
|
||||||
|
/** Initializes the peripherals clock
|
||||||
|
*/
|
||||||
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||||
|
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
|
||||||
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Enable USB Voltage detector
|
||||||
|
*/
|
||||||
|
HAL_PWREx_EnableUSBVoltageDetector();
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA12 ------> USB_OTG_FS_DP
|
||||||
|
PA11 ------> USB_OTG_FS_DM
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* Peripheral clock enable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* Peripheral interrupt init */
|
||||||
|
HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
|
||||||
|
{
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
|
||||||
|
/* Peripheral clock disable */
|
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
|
||||||
|
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA12 ------> USB_OTG_FS_DP
|
||||||
|
PA11 ------> USB_OTG_FS_DM
|
||||||
|
*/
|
||||||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11);
|
||||||
|
|
||||||
|
/* Peripheral interrupt Deinit*/
|
||||||
|
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Setup stage callback
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data Out stage callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data In stage callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SOF callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
|
||||||
|
|
||||||
|
if ( hpcd->Init.speed == PCD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
speed = USBD_SPEED_HIGH;
|
||||||
|
}
|
||||||
|
else if ( hpcd->Init.speed == PCD_SPEED_FULL)
|
||||||
|
{
|
||||||
|
speed = USBD_SPEED_FULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* Set Speed. */
|
||||||
|
USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed);
|
||||||
|
|
||||||
|
/* Reset Device. */
|
||||||
|
USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Suspend callback.
|
||||||
|
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
/* Inform USB library that core enters in suspend Mode. */
|
||||||
|
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
__HAL_PCD_GATE_PHYCLOCK(hpcd);
|
||||||
|
/* Enter in STOP mode. */
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
if (hpcd->Init.low_power_enable)
|
||||||
|
{
|
||||||
|
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
|
||||||
|
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
|
||||||
|
}
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resume callback.
|
||||||
|
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ISOOUTIncomplete callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ISOINIncomplete callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @param epnum: Endpoint number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Connect callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disconnect callback.
|
||||||
|
* @param hpcd: PCD handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#else
|
||||||
|
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
{
|
||||||
|
USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
LL Driver Interface (USB Device Library --> PCD)
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
/* Init USB Ip. */
|
||||||
|
if (pdev->id == DEVICE_FS) {
|
||||||
|
/* Link the driver to the stack. */
|
||||||
|
hpcd_USB_OTG_FS.pData = pdev;
|
||||||
|
pdev->pData = &hpcd_USB_OTG_FS;
|
||||||
|
|
||||||
|
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
|
||||||
|
hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
|
||||||
|
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
|
||||||
|
hpcd_USB_OTG_FS.Init.dma_enable = ENABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||||
|
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
|
||||||
|
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
|
||||||
|
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler( );
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
||||||
|
/* Register USB PCD CallBacks */
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback);
|
||||||
|
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
|
||||||
|
|
||||||
|
HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback);
|
||||||
|
HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback);
|
||||||
|
HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback);
|
||||||
|
HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback);
|
||||||
|
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
||||||
|
/* USER CODE BEGIN TxRx_Configuration */
|
||||||
|
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
|
||||||
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
|
||||||
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);
|
||||||
|
/* USER CODE END TxRx_Configuration */
|
||||||
|
}
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief De-Initializes the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_DeInit(pdev->pData);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_Start(pdev->pData);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stops the low level portion of the device driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_Stop(pdev->pData);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Opens an endpoint of the low level driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @param ep_type: Endpoint type
|
||||||
|
* @param ep_mps: Endpoint max packet size
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Closes an endpoint of the low level driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flushes an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns Stall condition.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval Stall (1: Yes, 0: No)
|
||||||
|
*/
|
||||||
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
|
||||||
|
|
||||||
|
if((ep_addr & 0x80) == 0x80)
|
||||||
|
{
|
||||||
|
return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Assigns a USB address to the device.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param dev_addr: Device address
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transmits data over an endpoint.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @param pbuf: Pointer to data to be sent
|
||||||
|
* @param size: Data size
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prepares an endpoint for reception.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @param pbuf: Pointer to data to be received
|
||||||
|
* @param size: Data size
|
||||||
|
* @retval USBD status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef hal_status = HAL_OK;
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
|
||||||
|
|
||||||
|
usb_status = USBD_Get_USB_Status(hal_status);
|
||||||
|
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the last transferred packet size.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param ep_addr: Endpoint number
|
||||||
|
* @retval Received Data Size
|
||||||
|
*/
|
||||||
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
|
{
|
||||||
|
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USBD_HS_TESTMODE_ENABLE
|
||||||
|
/**
|
||||||
|
* @brief Set High speed Test mode.
|
||||||
|
* @param pdev: Device handle
|
||||||
|
* @param testmode: test mode
|
||||||
|
* @retval USBD Status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode)
|
||||||
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(testmode);
|
||||||
|
|
||||||
|
return USBD_OK;
|
||||||
|
}
|
||||||
|
#endif /* USBD_HS_TESTMODE_ENABLE */
|
||||||
|
/**
|
||||||
|
* @brief Static single allocation.
|
||||||
|
* @param size: Size of allocated memory
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void *USBD_static_malloc(uint32_t size)
|
||||||
|
{
|
||||||
|
UNUSED(size);
|
||||||
|
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Dummy memory free
|
||||||
|
* @param p: Pointer to allocated memory address
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void USBD_static_free(void *p)
|
||||||
|
{
|
||||||
|
UNUSED(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Delays routine for the USB device library.
|
||||||
|
* @param Delay: Delay in ms
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void USBD_LL_Delay(uint32_t Delay)
|
||||||
|
{
|
||||||
|
HAL_Delay(Delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the USB status depending on the HAL status:
|
||||||
|
* @param hal_status: HAL status
|
||||||
|
* @retval USB status
|
||||||
|
*/
|
||||||
|
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status)
|
||||||
|
{
|
||||||
|
USBD_StatusTypeDef usb_status = USBD_OK;
|
||||||
|
|
||||||
|
switch (hal_status)
|
||||||
|
{
|
||||||
|
case HAL_OK :
|
||||||
|
usb_status = USBD_OK;
|
||||||
|
break;
|
||||||
|
case HAL_ERROR :
|
||||||
|
usb_status = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
case HAL_BUSY :
|
||||||
|
usb_status = USBD_BUSY;
|
||||||
|
break;
|
||||||
|
case HAL_TIMEOUT :
|
||||||
|
usb_status = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
usb_status = USBD_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return usb_status;
|
||||||
|
}
|
||||||
418
board/CubeMX_Config/Src/usbd_desc.c
Normal file
418
board/CubeMX_Config/Src/usbd_desc.c
Normal file
@ -0,0 +1,418 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : usbd_desc.c
|
||||||
|
* @version : v1.0_Cube
|
||||||
|
* @brief : This file implements the USB device descriptors.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_desc.h"
|
||||||
|
#include "usbd_conf.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN INCLUDE */
|
||||||
|
|
||||||
|
/* USER CODE END INCLUDE */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup USBD_DESC
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
|
||||||
|
* @brief Private types.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_TYPES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
|
||||||
|
* @brief Private defines.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define USBD_VID 1155
|
||||||
|
#define USBD_LANGID_STRING 1033
|
||||||
|
#define USBD_MANUFACTURER_STRING "STMicroelectronics"
|
||||||
|
#define USBD_PID_FS 22336
|
||||||
|
#define USBD_PRODUCT_STRING_FS "STM32 Virtual ComPort"
|
||||||
|
#define USBD_CONFIGURATION_STRING_FS "CDC Config"
|
||||||
|
#define USBD_INTERFACE_STRING_FS "CDC Interface"
|
||||||
|
|
||||||
|
#define USB_SIZ_BOS_DESC 0x0C
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_DEFINES */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
|
||||||
|
* @brief Private macros.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/* USER CODE END PRIVATE_MACRO */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
|
||||||
|
* @brief Private functions declaration.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void Get_SerialNum(void);
|
||||||
|
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
|
||||||
|
* @brief Private functions declaration for FS.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
|
||||||
|
* @brief Private variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
USBD_DescriptorsTypeDef FS_Desc =
|
||||||
|
{
|
||||||
|
USBD_FS_DeviceDescriptor
|
||||||
|
, USBD_FS_LangIDStrDescriptor
|
||||||
|
, USBD_FS_ManufacturerStrDescriptor
|
||||||
|
, USBD_FS_ProductStrDescriptor
|
||||||
|
, USBD_FS_SerialStrDescriptor
|
||||||
|
, USBD_FS_ConfigStrDescriptor
|
||||||
|
, USBD_FS_InterfaceStrDescriptor
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
/** USB standard device descriptor. */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x12, /*bLength */
|
||||||
|
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
|
||||||
|
0x00, /*bcdUSB */
|
||||||
|
0x02,
|
||||||
|
0x02, /*bDeviceClass*/
|
||||||
|
0x02, /*bDeviceSubClass*/
|
||||||
|
0x00, /*bDeviceProtocol*/
|
||||||
|
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||||
|
LOBYTE(USBD_VID), /*idVendor*/
|
||||||
|
HIBYTE(USBD_VID), /*idVendor*/
|
||||||
|
LOBYTE(USBD_PID_FS), /*idProduct*/
|
||||||
|
HIBYTE(USBD_PID_FS), /*idProduct*/
|
||||||
|
0x00, /*bcdDevice rel. 2.00*/
|
||||||
|
0x02,
|
||||||
|
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
|
||||||
|
USBD_IDX_PRODUCT_STR, /*Index of product string*/
|
||||||
|
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
|
||||||
|
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/* USB_DeviceDescriptor */
|
||||||
|
/** BOS descriptor. */
|
||||||
|
#if (USBD_LPM_ENABLED == 1)
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x5,
|
||||||
|
USB_DESC_TYPE_BOS,
|
||||||
|
0xC,
|
||||||
|
0x0,
|
||||||
|
0x1, /* 1 device capability*/
|
||||||
|
/* device capability*/
|
||||||
|
0x7,
|
||||||
|
USB_DEVICE_CAPABITY_TYPE,
|
||||||
|
0x2,
|
||||||
|
0x2, /* LPM capability bit set*/
|
||||||
|
0x0,
|
||||||
|
0x0,
|
||||||
|
0x0
|
||||||
|
};
|
||||||
|
#endif /* (USBD_LPM_ENABLED == 1) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
|
||||||
|
* @brief Private variables.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
|
||||||
|
/** USB lang identifier descriptor. */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||||
|
{
|
||||||
|
USB_LEN_LANGID_STR_DESC,
|
||||||
|
USB_DESC_TYPE_STRING,
|
||||||
|
LOBYTE(USBD_LANGID_STRING),
|
||||||
|
HIBYTE(USBD_LANGID_STRING)
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /* IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif /* defined ( __ICCARM__ ) */
|
||||||
|
/* Internal string descriptor. */
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif
|
||||||
|
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
|
||||||
|
USB_SIZ_STRING_SERIAL,
|
||||||
|
USB_DESC_TYPE_STRING,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
|
||||||
|
* @brief Private functions.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the device descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
*length = sizeof(USBD_FS_DeviceDesc);
|
||||||
|
return USBD_FS_DeviceDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the LangID string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
*length = sizeof(USBD_LangIDDesc);
|
||||||
|
return USBD_LangIDDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the product string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if(speed == 0)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the manufacturer string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the serial number string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
*length = USB_SIZ_STRING_SERIAL;
|
||||||
|
|
||||||
|
/* Update the serial number string descriptor with the data from the unique
|
||||||
|
* ID */
|
||||||
|
Get_SerialNum();
|
||||||
|
/* USER CODE BEGIN USBD_FS_SerialStrDescriptor */
|
||||||
|
|
||||||
|
/* USER CODE END USBD_FS_SerialStrDescriptor */
|
||||||
|
return (uint8_t *) USBD_StringSerial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the configuration string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if(speed == USBD_SPEED_HIGH)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the interface string descriptor
|
||||||
|
* @param speed : Current device speed
|
||||||
|
* @param length : Pointer to data length variable
|
||||||
|
* @retval Pointer to descriptor buffer
|
||||||
|
*/
|
||||||
|
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
|
{
|
||||||
|
if(speed == 0)
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||||
|
}
|
||||||
|
return USBD_StrDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create the serial number string descriptor
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void Get_SerialNum(void)
|
||||||
|
{
|
||||||
|
uint32_t deviceserial0;
|
||||||
|
uint32_t deviceserial1;
|
||||||
|
uint32_t deviceserial2;
|
||||||
|
|
||||||
|
deviceserial0 = *(uint32_t *) DEVICE_ID1;
|
||||||
|
deviceserial1 = *(uint32_t *) DEVICE_ID2;
|
||||||
|
deviceserial2 = *(uint32_t *) DEVICE_ID3;
|
||||||
|
|
||||||
|
deviceserial0 += deviceserial2;
|
||||||
|
|
||||||
|
if (deviceserial0 != 0)
|
||||||
|
{
|
||||||
|
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);
|
||||||
|
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert Hex 32Bits value into char
|
||||||
|
* @param value: value to convert
|
||||||
|
* @param pbuf: pointer to the buffer
|
||||||
|
* @param len: buffer length
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t idx = 0;
|
||||||
|
|
||||||
|
for (idx = 0; idx < len; idx++)
|
||||||
|
{
|
||||||
|
if (((value >> 28)) < 0xA)
|
||||||
|
{
|
||||||
|
pbuf[2 * idx] = (value >> 28) + '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = value << 4;
|
||||||
|
|
||||||
|
pbuf[2 * idx + 1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
@ -14,6 +14,8 @@ set(MX_Include_Dirs
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Inc
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Inc
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Inc
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Inc
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Inc
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Device/ST/STM32H7xx/Include
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Device/ST/STM32H7xx/Include
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Include
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Include
|
||||||
)
|
)
|
||||||
@ -21,6 +23,10 @@ set(MX_Include_Dirs
|
|||||||
# STM32CubeMX generated application sources
|
# STM32CubeMX generated application sources
|
||||||
set(MX_Application_Src
|
set(MX_Application_Src
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/main.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/main.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/usb_device.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/usbd_conf.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/usbd_desc.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/usbd_cdc_if.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/stm32h7xx_it.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/stm32h7xx_it.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/stm32h7xx_hal_msp.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/stm32h7xx_hal_msp.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/sysmem.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/sysmem.c
|
||||||
@ -31,7 +37,9 @@ set(MX_Application_Src
|
|||||||
# STM32 HAL/LL Drivers
|
# STM32 HAL/LL Drivers
|
||||||
set(STM32_Drivers_Src
|
set(STM32_Drivers_Src
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/system_stm32h7xx.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Src/system_stm32h7xx.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pcd_ex.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_usb.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c
|
||||||
@ -43,14 +51,13 @@ set(STM32_Drivers_Src
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_delayblock.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_delayblock.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi_ex.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
|
||||||
@ -60,6 +67,12 @@ set(STM32_Drivers_Src
|
|||||||
# Drivers Midllewares
|
# Drivers Midllewares
|
||||||
|
|
||||||
|
|
||||||
|
set(USB_Device_Library_Src
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
|
||||||
|
)
|
||||||
|
|
||||||
# Link directories setup
|
# Link directories setup
|
||||||
set(MX_LINK_DIRS
|
set(MX_LINK_DIRS
|
||||||
@ -69,7 +82,7 @@ set(MX_LINK_DIRS
|
|||||||
set(MX_LINK_LIBS
|
set(MX_LINK_LIBS
|
||||||
STM32_Drivers
|
STM32_Drivers
|
||||||
${TOOLCHAIN_LINK_LIBRARIES}
|
${TOOLCHAIN_LINK_LIBRARIES}
|
||||||
|
USB_Device_Library
|
||||||
)
|
)
|
||||||
# Interface library for includes and symbols
|
# Interface library for includes and symbols
|
||||||
add_library(stm32cubemx INTERFACE)
|
add_library(stm32cubemx INTERFACE)
|
||||||
@ -82,6 +95,11 @@ target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
|
|||||||
target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)
|
target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)
|
||||||
|
|
||||||
|
|
||||||
|
# Create USB_Device_Library static library
|
||||||
|
add_library(USB_Device_Library OBJECT)
|
||||||
|
target_sources(USB_Device_Library PRIVATE ${USB_Device_Library_Src})
|
||||||
|
target_link_libraries(USB_Device_Library PUBLIC stm32cubemx)
|
||||||
|
|
||||||
# Add STM32CubeMX generated application sources to the project
|
# Add STM32CubeMX generated application sources to the project
|
||||||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
|
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,10 @@ menu "On-chip Peripheral Drivers"
|
|||||||
bool "Enable GPIO"
|
bool "Enable GPIO"
|
||||||
select RT_USING_PIN
|
select RT_USING_PIN
|
||||||
default y
|
default y
|
||||||
|
config BSP_USING_USBD
|
||||||
|
bool "Enable USB Device"
|
||||||
|
select RT_USING_USB_DEVICE
|
||||||
|
default y
|
||||||
|
|
||||||
# menuconfig BSP_USING_UART
|
# menuconfig BSP_USING_UART
|
||||||
# bool "Enable UART"
|
# bool "Enable UART"
|
||||||
|
|||||||
@ -8,9 +8,11 @@ cwd = GetCurrentDir()
|
|||||||
# add the general drivers.
|
# add the general drivers.
|
||||||
src = Glob('board.c')
|
src = Glob('board.c')
|
||||||
src += Glob('CubeMX_Config/Src/stm32h7xx_hal_msp.c')
|
src += Glob('CubeMX_Config/Src/stm32h7xx_hal_msp.c')
|
||||||
src += Glob('ports/qspi_flash_init.c')
|
# src += Glob('ports/qspi_flash_init.c')
|
||||||
|
src += Glob('ports/usb/*.c')
|
||||||
path = [cwd]
|
path = [cwd]
|
||||||
path += [cwd + '/CubeMX_Config/Inc']
|
path += [cwd + '/CubeMX_Config/Inc']
|
||||||
|
path += [cwd + '/ports/usb']
|
||||||
|
|
||||||
# 这样需要包含 core_cm7.h
|
# 这样需要包含 core_cm7.h
|
||||||
ROOT = os.path.abspath(os.path.join(cwd, '..'))
|
ROOT = os.path.abspath(os.path.join(cwd, '..'))
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration ,因为boot 开启了QSPI的时钟,故这里也要开启。要和boot 保持一致,如何要和
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void)
|
void SystemClock_Config(void)
|
||||||
@ -32,17 +32,16 @@ void SystemClock_Config(void)
|
|||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
RCC_OscInitStruct.PLL.PLLM = 5;
|
||||||
RCC_OscInitStruct.PLL.PLLN = 60;
|
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||||
RCC_OscInitStruct.PLL.PLLP = 2;
|
RCC_OscInitStruct.PLL.PLLP = 2;
|
||||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
RCC_OscInitStruct.PLL.PLLQ = 20;
|
||||||
RCC_OscInitStruct.PLL.PLLR = 2;
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
||||||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
|
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
||||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
@ -126,9 +125,4 @@ static int ota_app_vtor_reconfig(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
INIT_BOARD_EXPORT(ota_app_vtor_reconfig);
|
INIT_BOARD_EXPORT(ota_app_vtor_reconfig);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INIT_BOARD_EXPORT(MPU_Config);
|
INIT_BOARD_EXPORT(MPU_Config);
|
||||||
@ -1,14 +1,16 @@
|
|||||||
/* STM32H750XBHx - RT-Thread linker script (GCC/ld)
|
/* STM32H750XBHx - RT-Thread linker script (GCC/ld)
|
||||||
* FLASH 128K @ 0x08000000 (代码/常量/表)
|
*
|
||||||
* DTCMRAM 128K @ 0x20000000 (data/bss, MSP stack top)
|
* XIP QSPI FLASH: 0x9000_0000 (8MB) -> .isr_vector/.text/.rodata/const tables
|
||||||
* AXI SRAM 512K @ 0x24000000 (heap recommended)
|
* DTCM RAM : 0x2000_0000 (128KB)-> .data/.bss (fast CPU access, NOT for DMA)
|
||||||
* D2 SRAM 288K @ 0x30000000 (no use)
|
* AXI SRAM : 0x2400_0000 (512KB)-> system heap recommended
|
||||||
* D3 SRAM 64K @ 0x38000000 (no use)
|
* D2 SRAM : 0x3000_0000 (288KB)-> USB DMA buffers (nocache/buffer) recommended
|
||||||
* ITCMRAM 64K @ 0x00000000 (no use)
|
* D3 SRAM : 0x3800_0000 (64KB)
|
||||||
|
* ITCM RAM : 0x0000_0000 (64KB)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ENTRY(Reset_Handler)
|
ENTRY(Reset_Handler)
|
||||||
|
|
||||||
|
/* Memory regions */
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
|
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
|
||||||
@ -22,11 +24,13 @@ MEMORY
|
|||||||
/* MSP stack top (startup uses this) */
|
/* MSP stack top (startup uses this) */
|
||||||
_estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM);
|
_estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM);
|
||||||
|
|
||||||
/* Only for link-check (does NOT define RT-Thread heap) */
|
/* Only for link-check / startup template compatibility
|
||||||
_Min_Stack_Size = 0x400;
|
* NOTE: RT-Thread thread stacks are NOT defined by this.
|
||||||
_Min_Heap_Size = 0x0;
|
*/
|
||||||
|
_Min_Stack_Size = 0x800;
|
||||||
|
_Min_Heap_Size = 0x400;
|
||||||
|
|
||||||
/* RT-Thread heap range in AXI SRAM (use these in board.h) */
|
/* RT-Thread heap range in AXI SRAM (use these in board.c/board.h) */
|
||||||
PROVIDE(__heap_start__ = ORIGIN(RAM));
|
PROVIDE(__heap_start__ = ORIGIN(RAM));
|
||||||
PROVIDE(__heap_end__ = ORIGIN(RAM) + LENGTH(RAM));
|
PROVIDE(__heap_end__ = ORIGIN(RAM) + LENGTH(RAM));
|
||||||
|
|
||||||
@ -141,15 +145,17 @@ SECTIONS
|
|||||||
{
|
{
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_sdata = .;
|
_sdata = .;
|
||||||
|
|
||||||
*(.data)
|
*(.data)
|
||||||
*(.data*)
|
*(.data*)
|
||||||
*(.RamFunc)
|
*(.RamFunc)
|
||||||
*(.RamFunc*)
|
*(.RamFunc*)
|
||||||
|
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_edata = .;
|
_edata = .;
|
||||||
} > DTCMRAM AT> FLASH
|
} > DTCMRAM AT> FLASH
|
||||||
|
|
||||||
/* used by startup to copy .data from FLASH to DTCM */
|
/* Used by startup to copy .data from FLASH to DTCM */
|
||||||
_sidata = LOADADDR(.data);
|
_sidata = LOADADDR(.data);
|
||||||
|
|
||||||
/* BSS -> DTCM */
|
/* BSS -> DTCM */
|
||||||
@ -169,6 +175,25 @@ SECTIONS
|
|||||||
PROVIDE(__bss_end = .);
|
PROVIDE(__bss_end = .);
|
||||||
} > DTCMRAM
|
} > DTCMRAM
|
||||||
|
|
||||||
|
/* ---------------- USB DMA buffers in D2 SRAM ----------------
|
||||||
|
* Put all USB DMA related buffers here:
|
||||||
|
* __attribute__((section(".usb_nocache"))) / ".noncacheable"
|
||||||
|
* Align to 32 bytes for safety (future D-Cache + cache-line ops)
|
||||||
|
*/
|
||||||
|
.usb_nocache (NOLOAD) :
|
||||||
|
{
|
||||||
|
. = ALIGN(32);
|
||||||
|
__usb_nocache_start__ = .;
|
||||||
|
|
||||||
|
*(.usb_nocache)
|
||||||
|
*(.usb_nocache*)
|
||||||
|
*(.noncacheable)
|
||||||
|
*(.noncacheable*)
|
||||||
|
|
||||||
|
. = ALIGN(32);
|
||||||
|
__usb_nocache_end__ = .;
|
||||||
|
} > RAM_D2
|
||||||
|
|
||||||
/* End symbols (end of DTCM used sections) */
|
/* End symbols (end of DTCM used sections) */
|
||||||
PROVIDE(end = .);
|
PROVIDE(end = .);
|
||||||
PROVIDE(_end = .);
|
PROVIDE(_end = .);
|
||||||
@ -181,3 +206,7 @@ SECTIONS
|
|||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
} > DTCMRAM
|
} > DTCMRAM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Optional: sanity checks */
|
||||||
|
ASSERT(_ebss <= (ORIGIN(DTCMRAM) + LENGTH(DTCMRAM)), "DTCMRAM overflow: .data/.bss too large");
|
||||||
|
ASSERT(__usb_nocache_end__ <= (ORIGIN(RAM_D2) + LENGTH(RAM_D2)), "D2 overflow: USB nocache section too large");
|
||||||
|
|||||||
408
board/ports/usb/usb_cdc_char_device.c
Normal file
408
board/ports/usb/usb_cdc_char_device.c
Normal file
@ -0,0 +1,408 @@
|
|||||||
|
#include "usb_cdc_char_device.h"
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <rtdevice.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_cdc_acm.h"
|
||||||
|
|
||||||
|
#if !defined(RT_USING_DEVICE_OPS)
|
||||||
|
#error "RT_USING_DEVICE_OPS must be enabled"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CONFIG_USBDEV_ADVANCE_DESC)
|
||||||
|
#error "Please enable CONFIG_USBDEV_ADVANCE_DESC"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* -------------------- FS fixed config -------------------- */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
CDC_IN_EP = 0x81,
|
||||||
|
CDC_OUT_EP = 0x02,
|
||||||
|
CDC_INT_EP = 0x83,
|
||||||
|
|
||||||
|
CDC_VID = 0xFFFF,
|
||||||
|
CDC_PID = 0xFFFF,
|
||||||
|
|
||||||
|
CDC_MAX_POWER_MA = 100,
|
||||||
|
CDC_MAX_MPS = 64, /* FS */
|
||||||
|
|
||||||
|
CDC_RX_DMA_SIZE = 2048, /* OUT DMA buffer */
|
||||||
|
CDC_TX_DMA_SIZE = 2048, /* IN DMA buffer */
|
||||||
|
CDC_RX_RING_SIZE = 8192, /* software RX ringbuffer */
|
||||||
|
|
||||||
|
CDC_CONFIG_SIZE = (9 + CDC_ACM_DESCRIPTOR_LEN),
|
||||||
|
|
||||||
|
/* 保险丝:防止上层误传超大 size(比如把负数当无符号) */
|
||||||
|
CDC_WRITE_SIZE_GUARD = 64 * 1024, /* 64KB */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* -------------------- DMA buffers in nocache RAM -------------------- */
|
||||||
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX static uint8_t g_rx_dma[CDC_RX_DMA_SIZE];
|
||||||
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX static uint8_t g_tx_dma[CDC_TX_DMA_SIZE];
|
||||||
|
|
||||||
|
/* -------------------- descriptors (advance-desc callbacks) -------------------- */
|
||||||
|
static const uint8_t g_device_desc[] = {
|
||||||
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01,
|
||||||
|
CDC_VID, CDC_PID,
|
||||||
|
0x0100, 0x01)
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t g_config_desc[] = {
|
||||||
|
USB_CONFIG_DESCRIPTOR_INIT(CDC_CONFIG_SIZE, 0x02, 0x01,
|
||||||
|
USB_CONFIG_BUS_POWERED, CDC_MAX_POWER_MA),
|
||||||
|
CDC_ACM_DESCRIPTOR_INIT(0x00,
|
||||||
|
CDC_INT_EP,
|
||||||
|
CDC_OUT_EP,
|
||||||
|
CDC_IN_EP,
|
||||||
|
CDC_MAX_MPS,
|
||||||
|
0x02)
|
||||||
|
};
|
||||||
|
|
||||||
|
/* qualifier:FS 下不是必须,但留着不影响 */
|
||||||
|
static const uint8_t g_device_qual_desc[] = {
|
||||||
|
0x0a, USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||||
|
0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00,
|
||||||
|
0x40,
|
||||||
|
0x00, 0x00,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char g_langid_bytes[] = { 0x09, 0x04 };
|
||||||
|
static const char *g_string_desc[] = {
|
||||||
|
g_langid_bytes,
|
||||||
|
"CherryUSB",
|
||||||
|
"RTT CDC ACM FS",
|
||||||
|
"000000000001",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t *device_descriptor_cb(uint8_t speed) { (void)speed; return g_device_desc; }
|
||||||
|
static const uint8_t *config_descriptor_cb(uint8_t speed) { (void)speed; return g_config_desc; }
|
||||||
|
static const uint8_t *device_qual_descriptor_cb(uint8_t speed) { (void)speed; return g_device_qual_desc; }
|
||||||
|
static const char *string_descriptor_cb(uint8_t speed, uint8_t index)
|
||||||
|
{
|
||||||
|
(void)speed;
|
||||||
|
if (index > 3) return RT_NULL;
|
||||||
|
return g_string_desc[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct usb_descriptor g_cdc_desc = {
|
||||||
|
.device_descriptor_callback = device_descriptor_cb,
|
||||||
|
.config_descriptor_callback = config_descriptor_cb,
|
||||||
|
.device_quality_descriptor_callback = device_qual_descriptor_cb,
|
||||||
|
.string_descriptor_callback = string_descriptor_cb
|
||||||
|
};
|
||||||
|
|
||||||
|
/* -------------------- driver object -------------------- */
|
||||||
|
struct cdc_char_dev
|
||||||
|
{
|
||||||
|
struct rt_device dev; /* must be first */
|
||||||
|
|
||||||
|
uint8_t busid;
|
||||||
|
uintptr_t reg_base;
|
||||||
|
|
||||||
|
volatile rt_uint8_t dtr_enable;
|
||||||
|
volatile rt_uint8_t connected;
|
||||||
|
volatile rt_uint8_t configured;
|
||||||
|
|
||||||
|
struct rt_ringbuffer *rx_rb;
|
||||||
|
|
||||||
|
rt_sem_t tx_sem;
|
||||||
|
rt_mutex_t tx_lock;
|
||||||
|
|
||||||
|
uint32_t tx_timeout_ms;
|
||||||
|
uint8_t require_dtr_tx;
|
||||||
|
|
||||||
|
struct usbd_interface intf0;
|
||||||
|
struct usbd_interface intf1;
|
||||||
|
struct usbd_endpoint out_ep;
|
||||||
|
struct usbd_endpoint in_ep;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct cdc_char_dev g_cdc;
|
||||||
|
|
||||||
|
/* -------------------- forward declarations -------------------- */
|
||||||
|
static void usbd_event_handler(uint8_t busid, uint8_t event);
|
||||||
|
static void cdc_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||||
|
static void cdc_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||||
|
|
||||||
|
/* -------------------- RT device ops -------------------- */
|
||||||
|
static rt_err_t cdc_init(rt_device_t dev) { (void)dev; return RT_EOK; }
|
||||||
|
static rt_err_t cdc_open(rt_device_t dev, rt_uint16_t oflag) { (void)dev; (void)oflag; return RT_EOK; }
|
||||||
|
static rt_err_t cdc_close(rt_device_t dev) { (void)dev; return RT_EOK; }
|
||||||
|
|
||||||
|
static rt_ssize_t cdc_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
||||||
|
{
|
||||||
|
(void)pos;
|
||||||
|
if (!dev || !buffer) return -RT_EINVAL;
|
||||||
|
if (size == 0) return 0;
|
||||||
|
|
||||||
|
struct cdc_char_dev *c = (struct cdc_char_dev *)dev;
|
||||||
|
|
||||||
|
/* 未枚举配置完成,不允许读(避免上层误用) */
|
||||||
|
if (!c->configured) return -RT_EIO;
|
||||||
|
|
||||||
|
if (!c->rx_rb) return -RT_ERROR;
|
||||||
|
|
||||||
|
rt_base_t level = rt_hw_interrupt_disable();
|
||||||
|
rt_size_t got = rt_ringbuffer_get(c->rx_rb, (rt_uint8_t *)buffer, size);
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
|
return (rt_ssize_t)got; /* ringbuffer 空则返回 0 */
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_ssize_t cdc_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
||||||
|
{
|
||||||
|
(void)pos;
|
||||||
|
if (!dev || !buffer) return -RT_EINVAL;
|
||||||
|
if (size == 0) return 0;
|
||||||
|
|
||||||
|
/* 保险丝:防止上层把负数当 size 传下来 */
|
||||||
|
if (size > CDC_WRITE_SIZE_GUARD) return -RT_EINVAL;
|
||||||
|
|
||||||
|
struct cdc_char_dev *c = (struct cdc_char_dev *)dev;
|
||||||
|
|
||||||
|
/* 未配置/断开,不允许写 */
|
||||||
|
if (!c->configured) return -RT_EIO;
|
||||||
|
if (c->require_dtr_tx && !c->dtr_enable) return -RT_EIO;
|
||||||
|
|
||||||
|
if (!c->tx_sem || !c->tx_lock) return -RT_ERROR;
|
||||||
|
|
||||||
|
rt_mutex_take(c->tx_lock, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
|
rt_size_t sent_total = 0;
|
||||||
|
const rt_uint8_t *p = (const rt_uint8_t *)buffer;
|
||||||
|
|
||||||
|
while (sent_total < size)
|
||||||
|
{
|
||||||
|
/* 如果中途断开/重置,立刻失败 */
|
||||||
|
if (!c->configured)
|
||||||
|
{
|
||||||
|
rt_mutex_release(c->tx_lock);
|
||||||
|
return (sent_total > 0) ? (rt_ssize_t)sent_total : -RT_EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_size_t chunk = size - sent_total;
|
||||||
|
if (chunk > CDC_TX_DMA_SIZE) chunk = CDC_TX_DMA_SIZE;
|
||||||
|
|
||||||
|
memcpy(g_tx_dma, p + sent_total, chunk);
|
||||||
|
|
||||||
|
/* 清掉旧 token */
|
||||||
|
while (rt_sem_trytake(c->tx_sem) == RT_EOK) {}
|
||||||
|
|
||||||
|
usbd_ep_start_write(c->busid, CDC_IN_EP, g_tx_dma, (uint32_t)chunk);
|
||||||
|
|
||||||
|
rt_tick_t to = rt_tick_from_millisecond(c->tx_timeout_ms);
|
||||||
|
if (rt_sem_take(c->tx_sem, to) != RT_EOK)
|
||||||
|
{
|
||||||
|
rt_mutex_release(c->tx_lock);
|
||||||
|
return (sent_total > 0) ? (rt_ssize_t)sent_total : -RT_ETIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 被唤醒后再次确认仍处于 configured(避免断开时“假完成”) */
|
||||||
|
if (!c->configured)
|
||||||
|
{
|
||||||
|
rt_mutex_release(c->tx_lock);
|
||||||
|
return (sent_total > 0) ? (rt_ssize_t)sent_total : -RT_EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
sent_total += chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_mutex_release(c->tx_lock);
|
||||||
|
return (rt_ssize_t)sent_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_err_t cdc_control(rt_device_t dev, int cmd, void *args)
|
||||||
|
{
|
||||||
|
if (!dev) return -RT_EINVAL;
|
||||||
|
struct cdc_char_dev *c = (struct cdc_char_dev *)dev;
|
||||||
|
|
||||||
|
switch (cmd)
|
||||||
|
{
|
||||||
|
case CDC_CTRL_SET_TX_TIMEOUT_MS:
|
||||||
|
if (args) c->tx_timeout_ms = *(uint32_t *)args;
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
case CDC_CTRL_GET_TX_TIMEOUT_MS:
|
||||||
|
if (args) *(uint32_t *)args = c->tx_timeout_ms;
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
case CDC_CTRL_GET_DTR:
|
||||||
|
if (args) *(uint8_t *)args = c->dtr_enable;
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
case CDC_CTRL_SET_REQUIRE_DTR_TX:
|
||||||
|
if (args) c->require_dtr_tx = (*(uint8_t *)args) ? 1 : 0;
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
case CDC_CTRL_GET_CONFIGURED: /* ✅ 新增:查询是否已枚举配置 */
|
||||||
|
if (args) *(uint8_t *)args = c->configured;
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return -RT_ENOSYS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ops table */
|
||||||
|
static const struct rt_device_ops cdc_ops =
|
||||||
|
{
|
||||||
|
.init = cdc_init,
|
||||||
|
.open = cdc_open,
|
||||||
|
.close = cdc_close,
|
||||||
|
.read = cdc_read,
|
||||||
|
.write = cdc_write,
|
||||||
|
.control = cdc_control,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* -------------------- CherryUSB callbacks -------------------- */
|
||||||
|
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||||
|
{
|
||||||
|
(void)busid;
|
||||||
|
|
||||||
|
switch (event)
|
||||||
|
{
|
||||||
|
case USBD_EVENT_RESET:
|
||||||
|
g_cdc.configured = 0;
|
||||||
|
g_cdc.connected = 0;
|
||||||
|
|
||||||
|
/* 可选:唤醒等待线程,让它能尽快感知状态变化 */
|
||||||
|
if (g_cdc.dev.rx_indicate)
|
||||||
|
g_cdc.dev.rx_indicate((rt_device_t)&g_cdc.dev, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USBD_EVENT_CONNECTED:
|
||||||
|
g_cdc.connected = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USBD_EVENT_DISCONNECTED:
|
||||||
|
g_cdc.configured = 0;
|
||||||
|
g_cdc.connected = 0;
|
||||||
|
|
||||||
|
/* 可选:唤醒等待线程 */
|
||||||
|
if (g_cdc.dev.rx_indicate)
|
||||||
|
g_cdc.dev.rx_indicate((rt_device_t)&g_cdc.dev, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USBD_EVENT_CONFIGURED:
|
||||||
|
g_cdc.connected = 1;
|
||||||
|
g_cdc.configured = 1;
|
||||||
|
|
||||||
|
/* 重新启动 OUT 读(防止 reset 后没读) */
|
||||||
|
usbd_ep_start_read(g_cdc.busid, CDC_OUT_EP, g_rx_dma, CDC_RX_DMA_SIZE);
|
||||||
|
|
||||||
|
/* 可选:唤醒等待线程,让“先启动线程再插线”也能快速进入工作状态 */
|
||||||
|
if (g_cdc.dev.rx_indicate)
|
||||||
|
g_cdc.dev.rx_indicate((rt_device_t)&g_cdc.dev, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cdc_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
|
{
|
||||||
|
(void)busid;
|
||||||
|
(void)ep;
|
||||||
|
|
||||||
|
/* 未配置时忽略数据,并继续挂下一次读 */
|
||||||
|
if (!g_cdc.configured)
|
||||||
|
{
|
||||||
|
usbd_ep_start_read(g_cdc.busid, CDC_OUT_EP, g_rx_dma, CDC_RX_DMA_SIZE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbytes > 0 && nbytes <= CDC_RX_DMA_SIZE && g_cdc.rx_rb)
|
||||||
|
{
|
||||||
|
(void)rt_ringbuffer_put(g_cdc.rx_rb, g_rx_dma, (rt_size_t)nbytes);
|
||||||
|
|
||||||
|
if (g_cdc.dev.rx_indicate)
|
||||||
|
g_cdc.dev.rx_indicate((rt_device_t)&g_cdc.dev, (rt_size_t)nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
usbd_ep_start_read(g_cdc.busid, CDC_OUT_EP, g_rx_dma, CDC_RX_DMA_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cdc_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
|
{
|
||||||
|
(void)busid;
|
||||||
|
|
||||||
|
/* ZLP:长度是 MPS 整倍数时补 0 包 */
|
||||||
|
if ((nbytes % usbd_get_ep_mps(g_cdc.busid, ep)) == 0 && nbytes)
|
||||||
|
{
|
||||||
|
usbd_ep_start_write(g_cdc.busid, CDC_IN_EP, RT_NULL, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cdc.tx_sem) rt_sem_release(g_cdc.tx_sem);
|
||||||
|
|
||||||
|
if (g_cdc.dev.tx_complete)
|
||||||
|
g_cdc.dev.tx_complete((rt_device_t)&g_cdc.dev, RT_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DTR hook */
|
||||||
|
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||||
|
{
|
||||||
|
(void)busid;
|
||||||
|
(void)intf;
|
||||||
|
g_cdc.dtr_enable = dtr ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* endpoints */
|
||||||
|
static struct usbd_endpoint g_out_ep = { .ep_addr = CDC_OUT_EP, .ep_cb = cdc_bulk_out };
|
||||||
|
static struct usbd_endpoint g_in_ep = { .ep_addr = CDC_IN_EP, .ep_cb = cdc_bulk_in };
|
||||||
|
|
||||||
|
/* -------------------- public init -------------------- */
|
||||||
|
int rt_hw_usbd_cdc_char_init(const char *dev_name, uint8_t busid, uintptr_t reg_base)
|
||||||
|
{
|
||||||
|
if (!dev_name) return -RT_EINVAL;
|
||||||
|
|
||||||
|
memset(&g_cdc, 0, sizeof(g_cdc));
|
||||||
|
g_cdc.busid = busid;
|
||||||
|
g_cdc.reg_base = reg_base;
|
||||||
|
|
||||||
|
g_cdc.tx_timeout_ms = 2000;
|
||||||
|
g_cdc.require_dtr_tx = 0;
|
||||||
|
g_cdc.connected = 0;
|
||||||
|
g_cdc.configured = 0;
|
||||||
|
|
||||||
|
g_cdc.rx_rb = rt_ringbuffer_create(CDC_RX_RING_SIZE);
|
||||||
|
if (!g_cdc.rx_rb) return -RT_ENOMEM;
|
||||||
|
|
||||||
|
g_cdc.tx_sem = rt_sem_create("cdc_tx", 0, RT_IPC_FLAG_FIFO);
|
||||||
|
if (!g_cdc.tx_sem) return -RT_ENOMEM;
|
||||||
|
|
||||||
|
g_cdc.tx_lock = rt_mutex_create("cdc_txL", RT_IPC_FLAG_FIFO);
|
||||||
|
if (!g_cdc.tx_lock) return -RT_ENOMEM;
|
||||||
|
|
||||||
|
/* register char device */
|
||||||
|
g_cdc.dev.type = RT_Device_Class_Char;
|
||||||
|
g_cdc.dev.rx_indicate = RT_NULL;
|
||||||
|
g_cdc.dev.tx_complete = RT_NULL;
|
||||||
|
g_cdc.dev.ops = &cdc_ops;
|
||||||
|
g_cdc.dev.user_data = RT_NULL;
|
||||||
|
|
||||||
|
rt_err_t r = rt_device_register((rt_device_t)&g_cdc.dev, dev_name, RT_DEVICE_FLAG_RDWR);
|
||||||
|
if (r != RT_EOK) return r;
|
||||||
|
|
||||||
|
/* init CherryUSB CDC */
|
||||||
|
usbd_desc_register(g_cdc.busid, &g_cdc_desc);
|
||||||
|
|
||||||
|
usbd_add_interface(g_cdc.busid, usbd_cdc_acm_init_intf(g_cdc.busid, &g_cdc.intf0));
|
||||||
|
usbd_add_interface(g_cdc.busid, usbd_cdc_acm_init_intf(g_cdc.busid, &g_cdc.intf1));
|
||||||
|
|
||||||
|
g_cdc.out_ep = g_out_ep;
|
||||||
|
g_cdc.in_ep = g_in_ep;
|
||||||
|
usbd_add_endpoint(g_cdc.busid, &g_cdc.out_ep);
|
||||||
|
usbd_add_endpoint(g_cdc.busid, &g_cdc.in_ep);
|
||||||
|
|
||||||
|
usbd_initialize(g_cdc.busid, g_cdc.reg_base, usbd_event_handler);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
20
board/ports/usb/usb_cdc_char_device.h
Normal file
20
board/ports/usb/usb_cdc_char_device.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CDC_CTRL_SET_TX_TIMEOUT_MS 0x10 /* arg: uint32_t* */
|
||||||
|
#define CDC_CTRL_GET_TX_TIMEOUT_MS 0x11 /* arg: uint32_t* */
|
||||||
|
#define CDC_CTRL_GET_DTR 0x12 /* arg: uint8_t* */
|
||||||
|
#define CDC_CTRL_SET_REQUIRE_DTR_TX 0x13 /* arg: uint8_t* (0/1) */
|
||||||
|
#define CDC_CTRL_GET_CONFIGURED 0x14 /* arg: uint8_t* (0/1) */
|
||||||
|
|
||||||
|
int rt_hw_usbd_cdc_char_init(const char *dev_name, uint8_t busid, uintptr_t reg_base);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
154
board/ports/usb/usb_cdc_init.c
Normal file
154
board/ports/usb/usb_cdc_init.c
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2025/12/31.
|
||||||
|
//
|
||||||
|
#include "usb_cdc_char_device.h"
|
||||||
|
#include <board.h>
|
||||||
|
|
||||||
|
// 例如在 board init / main 里
|
||||||
|
int usb_init(void)
|
||||||
|
{
|
||||||
|
return rt_hw_usbd_cdc_char_init("cdc0", 0, USB_OTG_FS_PERIPH_BASE);
|
||||||
|
}
|
||||||
|
// INIT_APP_EXPORT(usb_init);
|
||||||
|
|
||||||
|
|
||||||
|
#include "usb_cdc_char_device.h" /* 为了 CDC_CTRL_GET_CONFIGURED */
|
||||||
|
|
||||||
|
/* 线程参数 */
|
||||||
|
#define CDC_ECHO_THREAD_NAME "cdc_echo"
|
||||||
|
#define CDC_ECHO_THREAD_STACK 4096
|
||||||
|
#define CDC_ECHO_THREAD_PRIO 20
|
||||||
|
#define CDC_ECHO_THREAD_TICK 10
|
||||||
|
|
||||||
|
/* 等待策略 */
|
||||||
|
#define CDC_WAIT_SEM_TIMEOUT_MS 500 /* 不要 FOREVER,支持先启动后插线/断开重连 */
|
||||||
|
#define CDC_NOT_CFG_DELAY_MS 50
|
||||||
|
|
||||||
|
/* RX 等待信号量 */
|
||||||
|
static rt_sem_t s_cdc_rx_sem = RT_NULL;
|
||||||
|
/* 保存设备句柄 */
|
||||||
|
static rt_device_t s_cdc_dev = RT_NULL;
|
||||||
|
|
||||||
|
/* RX 回调:有数据到来时被驱动调用(或驱动事件里用 size=0 唤醒) */
|
||||||
|
static rt_err_t cdc_rx_ind(rt_device_t dev, rt_size_t size)
|
||||||
|
{
|
||||||
|
(void)dev;
|
||||||
|
(void)size;
|
||||||
|
|
||||||
|
if (s_cdc_rx_sem)
|
||||||
|
{
|
||||||
|
rt_sem_release(s_cdc_rx_sem);
|
||||||
|
}
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cdc_is_configured(rt_device_t dev)
|
||||||
|
{
|
||||||
|
uint8_t cfg = 0;
|
||||||
|
if (rt_device_control(dev, CDC_CTRL_GET_CONFIGURED, &cfg) == RT_EOK)
|
||||||
|
{
|
||||||
|
return cfg ? 1 : 0;
|
||||||
|
}
|
||||||
|
/* control 不支持时,保守认为未配置 */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* echo 线程:等待 -> 读 -> 立刻写回(支持断开重连) */
|
||||||
|
static void cdc_echo_thread(void *parameter)
|
||||||
|
{
|
||||||
|
(void)parameter;
|
||||||
|
|
||||||
|
s_cdc_dev = rt_device_find("cdc0");
|
||||||
|
if (!s_cdc_dev)
|
||||||
|
{
|
||||||
|
rt_kprintf("cdc_echo: cdc0 not found\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rt_device_open(s_cdc_dev, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
|
||||||
|
{
|
||||||
|
rt_kprintf("cdc_echo: open cdc0 failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_cdc_rx_sem = rt_sem_create("cdc_rx", 0, RT_IPC_FLAG_FIFO);
|
||||||
|
if (!s_cdc_rx_sem)
|
||||||
|
{
|
||||||
|
rt_kprintf("cdc_echo: sem create failed\n");
|
||||||
|
rt_device_close(s_cdc_dev);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_device_set_rx_indicate(s_cdc_dev, cdc_rx_ind);
|
||||||
|
|
||||||
|
rt_kprintf("cdc_echo: started, supports plug/unplug\n");
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* 关键:不要 FOREVER,避免未插线/断开时永远卡住 */
|
||||||
|
rt_sem_take(s_cdc_rx_sem, rt_tick_from_millisecond(CDC_WAIT_SEM_TIMEOUT_MS));
|
||||||
|
|
||||||
|
/* 没枚举好/断开:不读不写,稍等继续 */
|
||||||
|
if (!cdc_is_configured(s_cdc_dev))
|
||||||
|
{
|
||||||
|
rt_thread_mdelay(CDC_NOT_CFG_DELAY_MS);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 把 ringbuffer 里当前所有数据读光并回写 */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
rt_ssize_t rn = rt_device_read(s_cdc_dev, 0, buf, sizeof(buf));
|
||||||
|
if (rn > 0)
|
||||||
|
{
|
||||||
|
rt_ssize_t wn = rt_device_write(s_cdc_dev, 0, buf, (rt_size_t)rn);
|
||||||
|
if (wn < 0)
|
||||||
|
{
|
||||||
|
/* 典型:断开/未配置 => -RT_EIO */
|
||||||
|
rt_kprintf("cdc_echo: write err=%d\n", (int)wn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (rn == 0)
|
||||||
|
{
|
||||||
|
/* 暂时没数据 */
|
||||||
|
rt_kprintf("cdc_echo: read err=%d\n", (int)rn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* rn < 0:典型 -RT_EIO(断开/未配置) */
|
||||||
|
rt_kprintf("cdc_echo: read err=%d\n", (int)rn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 创建并启动线程 */
|
||||||
|
int cdc_echo_start(void)
|
||||||
|
{
|
||||||
|
if (rt_thread_find(CDC_ECHO_THREAD_NAME))
|
||||||
|
{
|
||||||
|
rt_kprintf("cdc_echo: thread already running\n");
|
||||||
|
return -RT_EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_thread_t tid = rt_thread_create(CDC_ECHO_THREAD_NAME,
|
||||||
|
cdc_echo_thread,
|
||||||
|
RT_NULL,
|
||||||
|
CDC_ECHO_THREAD_STACK,
|
||||||
|
CDC_ECHO_THREAD_PRIO,
|
||||||
|
CDC_ECHO_THREAD_TICK);
|
||||||
|
if (!tid)
|
||||||
|
{
|
||||||
|
rt_kprintf("cdc_echo: create thread failed\n");
|
||||||
|
return -RT_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_thread_startup(tid);
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
MSH_CMD_EXPORT(cdc_echo_start, start usb cdc echo thread);
|
||||||
320
board/ports/usb/usb_config.h
Normal file
320
board/ports/usb/usb_config.h
Normal file
@ -0,0 +1,320 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef CHERRYUSB_CONFIG_H
|
||||||
|
#define CHERRYUSB_CONFIG_H
|
||||||
|
|
||||||
|
/* ================ USB common Configuration ================ */
|
||||||
|
|
||||||
|
#ifdef __RTTHREAD__
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
#define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define CONFIG_USB_PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USB_DBG_LEVEL
|
||||||
|
#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Enable print with color */
|
||||||
|
#define CONFIG_USB_PRINTF_COLOR_ENABLE
|
||||||
|
|
||||||
|
// #define CONFIG_USB_DCACHE_ENABLE
|
||||||
|
|
||||||
|
/* data align size when use dma or use dcache */
|
||||||
|
#ifdef CONFIG_USB_DCACHE_ENABLE
|
||||||
|
#define CONFIG_USB_ALIGN_SIZE 32 // 32 or 64
|
||||||
|
#else
|
||||||
|
#define CONFIG_USB_ALIGN_SIZE 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* attribute data into no cache ram */
|
||||||
|
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable")))
|
||||||
|
|
||||||
|
/* use usb_memcpy default for high performance but cost more flash memory.
|
||||||
|
* And, arm libc has a bug that memcpy() may cause data misalignment when the size is not a multiple of 4.
|
||||||
|
*/
|
||||||
|
// #define CONFIG_USB_MEMCPY_DISABLE
|
||||||
|
|
||||||
|
/* ================= USB Device Stack Configuration ================ */
|
||||||
|
|
||||||
|
/* Ep0 in and out transfer buffer */
|
||||||
|
#ifndef CONFIG_USBDEV_REQUEST_BUFFER_LEN
|
||||||
|
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 512
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Send ep0 in data from user buffer instead of copying into ep0 reqdata
|
||||||
|
* Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE
|
||||||
|
*/
|
||||||
|
// #define CONFIG_USBDEV_EP0_INDATA_NO_COPY
|
||||||
|
|
||||||
|
/* Check if the input descriptor is correct */
|
||||||
|
// #define CONFIG_USBDEV_DESC_CHECK
|
||||||
|
|
||||||
|
/* Enable test mode */
|
||||||
|
// #define CONFIG_USBDEV_TEST_MODE
|
||||||
|
|
||||||
|
/* enable advance desc register api */
|
||||||
|
#define CONFIG_USBDEV_ADVANCE_DESC
|
||||||
|
|
||||||
|
/* move ep0 setup handler from isr to thread */
|
||||||
|
// #define CONFIG_USBDEV_EP0_THREAD
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_EP0_PRIO
|
||||||
|
#define CONFIG_USBDEV_EP0_PRIO 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_EP0_STACKSIZE
|
||||||
|
#define CONFIG_USBDEV_EP0_STACKSIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_MAX_LUN
|
||||||
|
#define CONFIG_USBDEV_MSC_MAX_LUN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE
|
||||||
|
#define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
|
||||||
|
#define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
|
||||||
|
#define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_VERSION_STRING
|
||||||
|
#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* move msc read & write from isr to while(1), you should call usbd_msc_polling in while(1) */
|
||||||
|
// #define CONFIG_USBDEV_MSC_POLLING
|
||||||
|
|
||||||
|
/* move msc read & write from isr to thread */
|
||||||
|
// #define CONFIG_USBDEV_MSC_THREAD
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_PRIO
|
||||||
|
#define CONFIG_USBDEV_MSC_PRIO 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MSC_STACKSIZE
|
||||||
|
#define CONFIG_USBDEV_MSC_STACKSIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MTP_MAX_BUFSIZE
|
||||||
|
#define CONFIG_USBDEV_MTP_MAX_BUFSIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MTP_MAX_OBJECTS
|
||||||
|
#define CONFIG_USBDEV_MTP_MAX_OBJECTS 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MTP_MAX_PATHNAME
|
||||||
|
#define CONFIG_USBDEV_MTP_MAX_PATHNAME 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CONFIG_USBDEV_MTP_THREAD
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MTP_PRIO
|
||||||
|
#define CONFIG_USBDEV_MTP_PRIO 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MTP_STACKSIZE
|
||||||
|
#define CONFIG_USBDEV_MTP_STACKSIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
|
||||||
|
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* rndis transfer buffer size, must be a multiple of (1536 + 44)*/
|
||||||
|
#ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
|
||||||
|
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1580
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
|
||||||
|
#define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
|
||||||
|
#define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CONFIG_USBDEV_RNDIS_USING_LWIP
|
||||||
|
#define CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||||
|
|
||||||
|
/* ================ USB HOST Stack Configuration ================== */
|
||||||
|
|
||||||
|
#define CONFIG_USBHOST_MAX_RHPORTS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_EXTHUBS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_EHPORTS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_INTERFACES 8
|
||||||
|
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 2
|
||||||
|
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
|
||||||
|
|
||||||
|
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_HID_CLASS 4
|
||||||
|
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
|
||||||
|
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
|
||||||
|
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
|
||||||
|
|
||||||
|
#define CONFIG_USBHOST_DEV_NAMELEN 16
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBHOST_PSC_PRIO
|
||||||
|
#define CONFIG_USBHOST_PSC_PRIO 0
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_USBHOST_PSC_STACKSIZE
|
||||||
|
#define CONFIG_USBHOST_PSC_STACKSIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#define CONFIG_USBHOST_GET_STRING_DESC
|
||||||
|
|
||||||
|
// #define CONFIG_USBHOST_MSOS_ENABLE
|
||||||
|
#ifndef CONFIG_USBHOST_MSOS_VENDOR_CODE
|
||||||
|
#define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Ep0 max transfer buffer */
|
||||||
|
#ifndef CONFIG_USBHOST_REQUEST_BUFFER_LEN
|
||||||
|
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
|
||||||
|
#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBHOST_MSC_TIMEOUT
|
||||||
|
#define CONFIG_USBHOST_MSC_TIMEOUT 5000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
|
||||||
|
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
|
||||||
|
*/
|
||||||
|
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE
|
||||||
|
#define CONFIG_USBHOST_RNDIS_ETH_MAX_RX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
|
||||||
|
#ifndef CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE
|
||||||
|
#define CONFIG_USBHOST_RNDIS_ETH_MAX_TX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
|
||||||
|
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
|
||||||
|
*/
|
||||||
|
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE
|
||||||
|
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_RX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
|
||||||
|
#ifndef CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE
|
||||||
|
#define CONFIG_USBHOST_CDC_NCM_ETH_MAX_TX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
|
||||||
|
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
|
||||||
|
*/
|
||||||
|
#ifndef CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE
|
||||||
|
#define CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
|
||||||
|
#ifndef CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE
|
||||||
|
#define CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This parameter affects usb performance, and depends on (TCP_WND)tcp eceive windows size,
|
||||||
|
* you can change to 2K ~ 16K and must be larger than TCP RX windows size in order to avoid being overflow.
|
||||||
|
*/
|
||||||
|
#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE
|
||||||
|
#define CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
/* Because lwip do not support multi pbuf at a time, so increasing this variable has no performance improvement */
|
||||||
|
#ifndef CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE
|
||||||
|
#define CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE (2048)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CONFIG_USBHOST_BLUETOOTH_HCI_H4
|
||||||
|
// #define CONFIG_USBHOST_BLUETOOTH_HCI_LOG
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBHOST_BLUETOOTH_TX_SIZE
|
||||||
|
#define CONFIG_USBHOST_BLUETOOTH_TX_SIZE 2048
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_USBHOST_BLUETOOTH_RX_SIZE
|
||||||
|
#define CONFIG_USBHOST_BLUETOOTH_RX_SIZE 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ================ USB Device Port Configuration ================*/
|
||||||
|
|
||||||
|
#ifndef CONFIG_USBDEV_MAX_BUS
|
||||||
|
#define CONFIG_USBDEV_MAX_BUS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// #define CONFIG_USBDEV_SOF_ENABLE
|
||||||
|
|
||||||
|
/* ---------------- FSDEV Configuration ---------------- */
|
||||||
|
//#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 // maybe 1 or 2, many chips may have a difference
|
||||||
|
|
||||||
|
/* ---------------- DWC2 Configuration ---------------- */
|
||||||
|
/* enable dwc2 buffer dma mode for device
|
||||||
|
* in xxx32 chips, only pb14/pb15 can support dma mode, pa11/pa12 is not supported(only a few supports, but we ignore them)
|
||||||
|
*/
|
||||||
|
// #define CONFIG_USB_DWC2_DMA_ENABLE
|
||||||
|
|
||||||
|
/* ---------------- MUSB Configuration ---------------- */
|
||||||
|
#define CONFIG_USB_MUSB_EP_NUM 8
|
||||||
|
// #define CONFIG_USB_MUSB_SUNXI
|
||||||
|
|
||||||
|
/* ================ USB Host Port Configuration ==================*/
|
||||||
|
#ifndef CONFIG_USBHOST_MAX_BUS
|
||||||
|
#define CONFIG_USBHOST_MAX_BUS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---------------- EHCI Configuration ---------------- */
|
||||||
|
|
||||||
|
#define CONFIG_USB_EHCI_HCCR_OFFSET (0x0)
|
||||||
|
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024
|
||||||
|
#define CONFIG_USB_EHCI_QH_NUM 10
|
||||||
|
#define CONFIG_USB_EHCI_QTD_NUM (CONFIG_USB_EHCI_QH_NUM * 3)
|
||||||
|
#define CONFIG_USB_EHCI_ITD_NUM 4
|
||||||
|
// #define CONFIG_USB_EHCI_HCOR_RESERVED_DISABLE
|
||||||
|
// #define CONFIG_USB_EHCI_CONFIGFLAG
|
||||||
|
// #define CONFIG_USB_EHCI_ISO
|
||||||
|
// #define CONFIG_USB_EHCI_WITH_OHCI
|
||||||
|
// #define CONFIG_USB_EHCI_DESC_DCACHE_ENABLE
|
||||||
|
|
||||||
|
/* ---------------- OHCI Configuration ---------------- */
|
||||||
|
#define CONFIG_USB_OHCI_HCOR_OFFSET (0x0)
|
||||||
|
#define CONFIG_USB_OHCI_ED_NUM 10
|
||||||
|
#define CONFIG_USB_OHCI_TD_NUM 3
|
||||||
|
// #define CONFIG_USB_OHCI_DESC_DCACHE_ENABLE
|
||||||
|
|
||||||
|
/* ---------------- XHCI Configuration ---------------- */
|
||||||
|
#define CONFIG_USB_XHCI_HCCR_OFFSET (0x0)
|
||||||
|
|
||||||
|
/* ---------------- DWC2 Configuration ---------------- */
|
||||||
|
// nothing to define
|
||||||
|
|
||||||
|
/* ---------------- MUSB Configuration ---------------- */
|
||||||
|
#define CONFIG_USB_MUSB_PIPE_NUM 8
|
||||||
|
// #define CONFIG_USB_MUSB_SUNXI
|
||||||
|
|
||||||
|
/* When your chip hardware supports high-speed and wants to initialize it in high-speed mode,
|
||||||
|
* the relevant IP will configure the internal or external high-speed PHY according to CONFIG_USB_HS.
|
||||||
|
*
|
||||||
|
* in xxx32 chips, only pb14/pb15 can support hs mode, pa11/pa12 is not supported(only a few supports, but we ignore them).
|
||||||
|
*/
|
||||||
|
// #define CONFIG_USB_HS
|
||||||
|
|
||||||
|
#ifndef usb_phyaddr2ramaddr
|
||||||
|
#define usb_phyaddr2ramaddr(addr) (addr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef usb_ramaddr2phyaddr
|
||||||
|
#define usb_ramaddr2phyaddr(addr) (addr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -41,6 +41,9 @@ menu "Third Packages Drivers"
|
|||||||
config ERPC_TRANSPORTS_TCP
|
config ERPC_TRANSPORTS_TCP
|
||||||
bool "TCP transports"
|
bool "TCP transports"
|
||||||
default n
|
default n
|
||||||
|
config ERPC_TRANSPORTS_USB_CDC
|
||||||
|
bool "USB CDC transports"
|
||||||
|
default n
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
5
packages/erpc-1.14.0/SConscript
vendored
5
packages/erpc-1.14.0/SConscript
vendored
@ -35,6 +35,7 @@ src = Split("""
|
|||||||
|
|
||||||
if GetDepend(['ERPC_USING_RTT']):
|
if GetDepend(['ERPC_USING_RTT']):
|
||||||
src += Glob('erpc_c/port/erpc_threading_pthreads.cpp')
|
src += Glob('erpc_c/port/erpc_threading_pthreads.cpp')
|
||||||
|
src += Glob('erpc_c/port/erpc_port_rtt.cpp')
|
||||||
# src += Glob('erpc_c/port/erpc_port_threadx.cpp')
|
# src += Glob('erpc_c/port/erpc_port_threadx.cpp')
|
||||||
|
|
||||||
if GetDepend(['ERPC_TRANSPORTS_SPI','ERPC_MODE_CLIENT']):
|
if GetDepend(['ERPC_TRANSPORTS_SPI','ERPC_MODE_CLIENT']):
|
||||||
@ -52,6 +53,10 @@ if GetDepend(['ERPC_TRANSPORTS_UART']):
|
|||||||
src += Glob('erpc_c/setup/erpc_setup_serial.cpp')
|
src += Glob('erpc_c/setup/erpc_setup_serial.cpp')
|
||||||
src += Glob('erpc_c/transports/erpc_serial_transport.cpp')
|
src += Glob('erpc_c/transports/erpc_serial_transport.cpp')
|
||||||
|
|
||||||
|
if GetDepend(['ERPC_TRANSPORTS_USB_CDC']):
|
||||||
|
src += Glob('erpc_c/setup/erpc_setup_usb_cdc.cpp')
|
||||||
|
src += Glob('erpc_c/transports/erpc_usb_cdc_transport.cpp')
|
||||||
|
|
||||||
if GetDepend(['ERPC_TRANSPORTS_TCP']):
|
if GetDepend(['ERPC_TRANSPORTS_TCP']):
|
||||||
src += Glob('erpc_c/setup/erpc_setup_tcp.cpp')
|
src += Glob('erpc_c/setup/erpc_setup_tcp.cpp')
|
||||||
src += Glob('erpc_c/transports/erpc_tcp_transport.cpp')
|
src += Glob('erpc_c/transports/erpc_tcp_transport.cpp')
|
||||||
|
|||||||
15
packages/erpc-1.14.0/erpc_c/port/erpc_port_rtt.cpp
vendored
Normal file
15
packages/erpc-1.14.0/erpc_c/port/erpc_port_rtt.cpp
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "erpc_port.h"
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
extern "C" void *erpc_malloc(std::size_t size)
|
||||||
|
{
|
||||||
|
return rt_malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void erpc_free(void *ptr)
|
||||||
|
{
|
||||||
|
if (ptr) rt_free(ptr);
|
||||||
|
}
|
||||||
|
// 其他的实现在 rt-thread/components/libc/cplusplus/cxx_crt.cpp 中
|
||||||
@ -1,182 +1,250 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2020-2021 NXP
|
* RT-Thread UsbCdcTransport for eRPC
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "erpc_usb_cdc_transport.hpp"
|
#include "erpc_usb_cdc_transport.hpp"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "stm32h750xx.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <rtdevice.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 你的 CDC 驱动控制命令:用于查询是否已枚举配置 */
|
||||||
|
extern "C" {
|
||||||
|
#include "usb_cdc_char_device.h" // 这里应包含 CDC_CTRL_GET_CONFIGURED
|
||||||
|
}
|
||||||
|
|
||||||
using namespace erpc;
|
using namespace erpc;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
/* 仅支持单实例最简单;如需多实例,用 dev->user_data 存 this 即可 */
|
||||||
// Variables
|
static UsbCdcTransport *s_usbcdc_instance = RT_NULL;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static volatile bool s_isTransferReceiveCompleted = false;
|
UsbCdcTransport::UsbCdcTransport(serial_handle_t serialHandle,
|
||||||
static volatile bool s_isTransferSendCompleted = false;
|
serial_manager_config_t *serialConfig,
|
||||||
static UsbCdcTransport *s_usbcdc_instance = NULL;
|
serial_port_usb_cdc_config_t *usbCdcConfig,
|
||||||
|
uint8_t *usbRingBuffer,
|
||||||
SDK_ALIGN(static uint8_t s_serialWriteHandleBuffer[SERIAL_MANAGER_WRITE_HANDLE_SIZE], 4);
|
uint32_t usbRingBufferLength)
|
||||||
static serial_write_handle_t s_serialWriteHandle = &s_serialWriteHandleBuffer[0]; /*!< serial manager write handle */
|
: m_rxSem(RT_NULL),
|
||||||
|
m_txSem(RT_NULL),
|
||||||
SDK_ALIGN(static uint8_t s_serialReadHandleBuffer[SERIAL_MANAGER_READ_HANDLE_SIZE], 4);
|
m_devName("cdc0"),
|
||||||
static serial_read_handle_t s_serialReadHandle = &s_serialReadHandleBuffer[0]; /*!< serial manager read handle */
|
m_rxWaitMs(1000),
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
m_txWaitMs(1000),
|
||||||
// Code
|
m_dev(RT_NULL),
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static void ERPC_SerialManagerTxCallback(const void *callbackParam, const serial_manager_callback_message_t *message,
|
|
||||||
serial_manager_status_t status)
|
|
||||||
{
|
|
||||||
UsbCdcTransport *transport = s_usbcdc_instance;
|
|
||||||
if ((NULL != callbackParam) && (NULL != message))
|
|
||||||
{
|
|
||||||
if (kStatus_SerialManager_Success == status)
|
|
||||||
{
|
|
||||||
transport->tx_cb();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Handle other status if needed */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ERPC_SerialManagerRxCallback(const void *callbackParam, const serial_manager_callback_message_t *message,
|
|
||||||
serial_manager_status_t status)
|
|
||||||
{
|
|
||||||
UsbCdcTransport *transport = s_usbcdc_instance;
|
|
||||||
if ((NULL != callbackParam) && (NULL != message))
|
|
||||||
{
|
|
||||||
if (kStatus_SerialManager_Success == status)
|
|
||||||
{
|
|
||||||
transport->rx_cb();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Handle other status if needed */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UsbCdcTransport::tx_cb(void)
|
|
||||||
{
|
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
|
||||||
m_txSemaphore.putFromISR();
|
|
||||||
#else
|
|
||||||
s_isTransferSendCompleted = true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void UsbCdcTransport::rx_cb(void)
|
|
||||||
{
|
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
|
||||||
m_rxSemaphore.putFromISR();
|
|
||||||
#else
|
|
||||||
s_isTransferReceiveCompleted = true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
UsbCdcTransport::UsbCdcTransport(serial_handle_t serialHandle, serial_manager_config_t *serialConfig,
|
|
||||||
serial_port_usb_cdc_config_t *usbCdcConfig, uint8_t *usbRingBuffer,
|
|
||||||
uint32_t usbRingBufferLength) :
|
|
||||||
m_serialHandle(serialHandle),
|
m_serialHandle(serialHandle),
|
||||||
m_serialConfig(serialConfig), m_usbCdcConfig(usbCdcConfig), m_usbRingBuffer(usbRingBuffer),
|
m_serialConfig(serialConfig),
|
||||||
|
m_usbCdcConfig(usbCdcConfig),
|
||||||
|
m_usbRingBuffer(usbRingBuffer),
|
||||||
m_usbRingBufferLength(usbRingBufferLength)
|
m_usbRingBufferLength(usbRingBufferLength)
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
|
||||||
,
|
|
||||||
m_rxSemaphore(), m_txSemaphore()
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
s_usbcdc_instance = this;
|
s_usbcdc_instance = this;
|
||||||
|
rt_hw_usbd_cdc_char_init("cdc0", 0, USB_OTG_FS_PERIPH_BASE);
|
||||||
|
|
||||||
|
if (m_usbCdcConfig && m_usbCdcConfig->dev_name)
|
||||||
|
m_devName = m_usbCdcConfig->dev_name;
|
||||||
|
|
||||||
|
if (m_usbCdcConfig)
|
||||||
|
{
|
||||||
|
if (m_usbCdcConfig->rx_wait_ms != 0) m_rxWaitMs = m_usbCdcConfig->rx_wait_ms;
|
||||||
|
if (m_usbCdcConfig->tx_wait_ms != 0) m_txWaitMs = m_usbCdcConfig->tx_wait_ms;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCdcTransport::~UsbCdcTransport(void)
|
UsbCdcTransport::~UsbCdcTransport(void)
|
||||||
{
|
{
|
||||||
/* Cleanup */
|
if (m_dev)
|
||||||
SerialManager_CloseWriteHandle(s_serialWriteHandle);
|
{
|
||||||
SerialManager_CloseReadHandle(s_serialReadHandle);
|
/* 取消回调(可选) */
|
||||||
SerialManager_Deinit(m_serialHandle);
|
rt_device_set_rx_indicate(m_dev, RT_NULL);
|
||||||
|
rt_device_set_tx_complete(m_dev, RT_NULL);
|
||||||
|
rt_device_close(m_dev);
|
||||||
|
m_dev = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_rxSem) { rt_sem_delete(m_rxSem); m_rxSem = RT_NULL; }
|
||||||
|
if (m_txSem) { rt_sem_delete(m_txSem); m_txSem = RT_NULL; }
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_err_t UsbCdcTransport::rx_indicate_stub(rt_device_t dev, rt_size_t size)
|
||||||
|
{
|
||||||
|
(void)dev;
|
||||||
|
(void)size;
|
||||||
|
if (s_usbcdc_instance) s_usbcdc_instance->rx_cb();
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_err_t UsbCdcTransport::tx_complete_stub(rt_device_t dev, void *buffer)
|
||||||
|
{
|
||||||
|
(void)dev;
|
||||||
|
(void)buffer;
|
||||||
|
if (s_usbcdc_instance) s_usbcdc_instance->tx_cb();
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UsbCdcTransport::rx_cb(void)
|
||||||
|
{
|
||||||
|
if (m_rxSem) rt_sem_release(m_rxSem);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UsbCdcTransport::tx_cb(void)
|
||||||
|
{
|
||||||
|
if (m_txSem) rt_sem_release(m_txSem);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UsbCdcTransport::is_configured(void)
|
||||||
|
{
|
||||||
|
if (!m_dev) return false;
|
||||||
|
|
||||||
|
rt_uint8_t cfg = 0;
|
||||||
|
rt_err_t r = rt_device_control(m_dev, CDC_CTRL_GET_CONFIGURED, &cfg);
|
||||||
|
if (r != RT_EOK) return false;
|
||||||
|
return (cfg != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UsbCdcTransport::wait_configured(rt_int32_t wait_ms)
|
||||||
|
{
|
||||||
|
if (is_configured()) return true;
|
||||||
|
|
||||||
|
if (wait_ms <= 0)
|
||||||
|
{
|
||||||
|
/* 永久等:用轮询 + sleep(避免忙等) */
|
||||||
|
while (!is_configured())
|
||||||
|
rt_thread_mdelay(10);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_tick_t deadline = rt_tick_get() + rt_tick_from_millisecond((rt_uint32_t)wait_ms);
|
||||||
|
while (!is_configured())
|
||||||
|
{
|
||||||
|
if ((rt_int32_t)(rt_tick_get() - deadline) >= 0)
|
||||||
|
return false;
|
||||||
|
rt_thread_mdelay(10);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
erpc_status_t UsbCdcTransport::init(void)
|
erpc_status_t UsbCdcTransport::init(void)
|
||||||
{
|
{
|
||||||
erpc_status_t status = kErpcStatus_InitFailed;
|
/* 打开设备 */
|
||||||
|
m_dev = rt_device_find(m_devName);
|
||||||
|
if (!m_dev)
|
||||||
|
return kErpcStatus_InitFailed;
|
||||||
|
|
||||||
/* Init Serial Manager for USB CDC */
|
if (rt_device_open(m_dev, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
|
||||||
m_serialConfig->type = kSerialPort_UsbCdc;
|
return kErpcStatus_InitFailed;
|
||||||
m_serialConfig->ringBuffer = m_usbRingBuffer;
|
|
||||||
m_serialConfig->ringBufferSize = m_usbRingBufferLength;
|
|
||||||
m_serialConfig->portConfig = m_usbCdcConfig;
|
|
||||||
|
|
||||||
if (kStatus_SerialManager_Success == SerialManager_Init(m_serialHandle, m_serialConfig))
|
/* 建信号量 */
|
||||||
{
|
if (!m_rxSem) m_rxSem = rt_sem_create("erpc_rx", 0, RT_IPC_FLAG_FIFO);
|
||||||
if (kStatus_SerialManager_Success == SerialManager_OpenWriteHandle(m_serialHandle, s_serialWriteHandle))
|
if (!m_txSem) m_txSem = rt_sem_create("erpc_tx", 0, RT_IPC_FLAG_FIFO);
|
||||||
{
|
if (!m_rxSem || !m_txSem)
|
||||||
if (kStatus_SerialManager_Success == SerialManager_OpenReadHandle(m_serialHandle, s_serialReadHandle))
|
return kErpcStatus_InitFailed;
|
||||||
{
|
|
||||||
if (kStatus_SerialManager_Success == SerialManager_InstallTxCallback(s_serialWriteHandle,
|
/* 注册回调:RX 数据到来唤醒 Receive */
|
||||||
ERPC_SerialManagerTxCallback,
|
rt_device_set_rx_indicate(m_dev, rx_indicate_stub);
|
||||||
s_serialWriteHandle))
|
rt_device_set_tx_complete(m_dev, tx_complete_stub);
|
||||||
{
|
|
||||||
if (kStatus_SerialManager_Success == SerialManager_InstallRxCallback(s_serialReadHandle,
|
return kErpcStatus_Success;
|
||||||
ERPC_SerialManagerRxCallback,
|
|
||||||
s_serialReadHandle))
|
|
||||||
{
|
|
||||||
status = kErpcStatus_Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* eRPC framed transport 会多次调用 underlyingReceive() 来收 header/payload。
|
||||||
|
* 所以:这里必须严格“收满 size 字节”才返回 Success。
|
||||||
|
*/
|
||||||
erpc_status_t UsbCdcTransport::underlyingReceive(uint8_t *data, uint32_t size)
|
erpc_status_t UsbCdcTransport::underlyingReceive(uint8_t *data, uint32_t size)
|
||||||
{
|
{
|
||||||
erpc_status_t status = kErpcStatus_ReceiveFailed;
|
if (!data || size == 0)
|
||||||
|
return kErpcStatus_Success;
|
||||||
|
|
||||||
s_isTransferReceiveCompleted = false;
|
/* 先等枚举,支持“先启动后插线” */
|
||||||
|
if (!wait_configured(m_rxWaitMs))
|
||||||
|
return kErpcStatus_ReceiveFailed;
|
||||||
|
|
||||||
if (kStatus_SerialManager_Success == SerialManager_ReadNonBlocking(s_serialReadHandle, data, size))
|
uint32_t got_total = 0;
|
||||||
|
|
||||||
|
while (got_total < size)
|
||||||
{
|
{
|
||||||
/* wait until the receiving is finished */
|
/* 断开/重置:立刻失败,避免死等 */
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
if (!is_configured())
|
||||||
(void)m_rxSemaphore.get();
|
return kErpcStatus_ConnectionClosed;
|
||||||
#else
|
|
||||||
while (!s_isTransferReceiveCompleted)
|
/* 先尽可能读一次(非阻塞:没数据返回 0) */
|
||||||
|
rt_ssize_t rn = rt_device_read(m_dev, 0, data + got_total, (rt_size_t)(size - got_total));
|
||||||
|
if (rn > 0)
|
||||||
{
|
{
|
||||||
|
got_total += (uint32_t)rn;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
else if (rn < 0)
|
||||||
status = kErpcStatus_Success;
|
{
|
||||||
|
/* 负值是错误码,不能当长度用 */
|
||||||
|
return kErpcStatus_ReceiveFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
/* rn==0:没数据 -> 等 rx 信号量 */
|
||||||
|
if (m_rxWaitMs <= 0)
|
||||||
|
{
|
||||||
|
(void)rt_sem_take(m_rxSem, RT_WAITING_FOREVER);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_tick_t to = rt_tick_from_millisecond((rt_uint32_t)m_rxWaitMs);
|
||||||
|
if (rt_sem_take(m_rxSem, to) != RT_EOK)
|
||||||
|
{
|
||||||
|
/* 超时:再确认是否断开;否则认为 receive failed */
|
||||||
|
if (!is_configured())
|
||||||
|
return kErpcStatus_ConnectionClosed;
|
||||||
|
return kErpcStatus_ReceiveFailed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < size; ++i)
|
||||||
|
// {
|
||||||
|
// rt_kprintf("%0x ", data[i]);
|
||||||
|
// }
|
||||||
|
// rt_kprintf("\r\n ");
|
||||||
|
|
||||||
|
return kErpcStatus_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 发送:你的 cdc0 驱动 write() 已经“阻塞等待发送完成”(tx_sem),
|
||||||
|
* 所以这里直接循环 write 即可,确保发满 size。
|
||||||
|
*/
|
||||||
erpc_status_t UsbCdcTransport::underlyingSend(const uint8_t *data, uint32_t size)
|
erpc_status_t UsbCdcTransport::underlyingSend(const uint8_t *data, uint32_t size)
|
||||||
{
|
{
|
||||||
erpc_status_t status = kErpcStatus_SendFailed;
|
if (!data || size == 0)
|
||||||
|
return kErpcStatus_Success;
|
||||||
|
|
||||||
s_isTransferSendCompleted = false;
|
/* 先等枚举,避免“未配置仍写”导致上层各种异常 */
|
||||||
|
if (!wait_configured(m_txWaitMs))
|
||||||
|
return kErpcStatus_SendFailed;
|
||||||
|
|
||||||
if (kStatus_SerialManager_Success == SerialManager_WriteNonBlocking(s_serialWriteHandle, data, size))
|
uint32_t sent_total = 0;
|
||||||
|
while (sent_total < size)
|
||||||
{
|
{
|
||||||
/* wait until the sending is finished */
|
if (!is_configured())
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
return kErpcStatus_ConnectionClosed;
|
||||||
(void)m_txSemaphore.get();
|
|
||||||
#else
|
rt_ssize_t wn = rt_device_write(m_dev, 0, data + sent_total, (rt_size_t)(size - sent_total));
|
||||||
while (!s_isTransferSendCompleted)
|
if (wn > 0)
|
||||||
{
|
{
|
||||||
|
sent_total += (uint32_t)wn;
|
||||||
|
}
|
||||||
|
else if (wn == 0)
|
||||||
|
{
|
||||||
|
/* 理论不该 0,给个让步:稍等再试 */
|
||||||
|
rt_thread_mdelay(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* 负值错误码 */
|
||||||
|
return kErpcStatus_SendFailed;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
status = kErpcStatus_Success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return kErpcStatus_Success;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,128 +1,94 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2020 NXP
|
* RT-Thread UsbCdcTransport for eRPC
|
||||||
* All rights reserved.
|
|
||||||
*
|
*
|
||||||
*
|
* Uses RT-Thread rt_device ("cdc0") character device as backend.
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* No NXP SerialManager.
|
||||||
|
* Still keeps the class name UsbCdcTransport and init/rx_cb/tx_cb APIs.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_
|
#ifndef _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_
|
||||||
#define _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_
|
#define _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_
|
||||||
|
|
||||||
#include "erpc_config_internal.h"
|
#include "erpc_config_internal.h"
|
||||||
#include <cstdio>
|
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
|
||||||
#include "erpc_threading.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "erpc_framed_transport.hpp"
|
#include "erpc_framed_transport.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "fsl_component_serial_manager.h"
|
#include <rtthread.h>
|
||||||
|
#include <rtdevice.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
#ifdef __cplusplus
|
||||||
* @addtogroup USB_CDC_transport
|
|
||||||
* @{
|
|
||||||
* @file
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
/* 复用原 NXP 类型名:保持 transport_setup_usb_cdc.cpp 签名不变 */
|
||||||
// Classes
|
typedef struct serial_port_usb_cdc_config
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
{
|
||||||
|
const char *dev_name; /* e.g. "cdc0" */
|
||||||
|
rt_int32_t rx_wait_ms; /* receive 等待超时(ms),<=0 表示永久等待 */
|
||||||
|
rt_int32_t tx_wait_ms; /* send 等待超时(ms),<=0 表示永久等待(通常不用,写已阻塞) */
|
||||||
|
} serial_port_usb_cdc_config_t;
|
||||||
|
|
||||||
|
/* 保持签名兼容,但 RT-Thread 适配不使用这些参数 */
|
||||||
|
typedef void *serial_handle_t;
|
||||||
|
typedef struct serial_manager_config serial_manager_config_t;
|
||||||
|
|
||||||
namespace erpc {
|
namespace erpc {
|
||||||
/*!
|
|
||||||
* @brief Very basic transport to send/receive messages via virtual USB CDC port.
|
|
||||||
*
|
|
||||||
* @ingroup USB_CDC_transport
|
|
||||||
*/
|
|
||||||
class UsbCdcTransport : public FramedTransport
|
class UsbCdcTransport : public FramedTransport
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*!
|
UsbCdcTransport(serial_handle_t serialHandle,
|
||||||
* @brief Constructor.
|
serial_manager_config_t *serialConfig,
|
||||||
*
|
serial_port_usb_cdc_config_t *usbCdcConfig,
|
||||||
* @param[in] serialHandle Pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE allocated by the
|
uint8_t *usbRingBuffer,
|
||||||
* caller, see serial manager header file.
|
uint32_t usbRingBufferLength);
|
||||||
* @param[in] serialConfig Pointer to user-defined configuration structure allocated by the caller, see serial
|
|
||||||
* manager header file.
|
|
||||||
* @param[in] usbCdcConfig Pointer to serial port usb config structure allocated by the caller, see serial manager
|
|
||||||
* header file.
|
|
||||||
* @param[in] usbRingBuffer Pointer to point serial manager ring buffer allocated by the caller, see serial manager
|
|
||||||
* header file.
|
|
||||||
* @param[in] usbRingBufferLength Serial manager ring buffer size.
|
|
||||||
*/
|
|
||||||
UsbCdcTransport(serial_handle_t serialHandle, serial_manager_config_t *serialConfig,
|
|
||||||
serial_port_usb_cdc_config_t *usbCdcConfig, uint8_t *usbRingBuffer, uint32_t usbRingBufferLength);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Destructor.
|
|
||||||
*/
|
|
||||||
virtual ~UsbCdcTransport(void);
|
virtual ~UsbCdcTransport(void);
|
||||||
|
|
||||||
/*!
|
/* 打开 cdc0,注册 rx_indicate/tx_complete,创建信号量 */
|
||||||
* @brief Initialize USB CDC peripheral configuration structure with values specified in UsbCdcTransport
|
|
||||||
* constructor.
|
|
||||||
*
|
|
||||||
* @retval kErpcStatus_InitFailed When USB CDC init function failed.
|
|
||||||
* @retval kErpcStatus_Success When USB CDC init function was executed successfully.
|
|
||||||
*/
|
|
||||||
virtual erpc_status_t init(void);
|
virtual erpc_status_t init(void);
|
||||||
|
|
||||||
/*!
|
/* 被 rx_indicate/tx_complete 调用,用信号量唤醒 */
|
||||||
* @brief Function called from Serial Manager Rx Callback to unblock the receive function
|
|
||||||
*
|
|
||||||
* Unblocks the receive function.
|
|
||||||
*/
|
|
||||||
void rx_cb(void);
|
void rx_cb(void);
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Function called from Serial Manager Tx Callback to unblock the send function
|
|
||||||
*
|
|
||||||
* Unblocks the send function.
|
|
||||||
*/
|
|
||||||
void tx_cb(void);
|
void tx_cb(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if !ERPC_THREADS_IS(NONE)
|
/* ✅ 不用 erpc::Semaphore,直接用 RT-Thread 信号量 */
|
||||||
Semaphore m_rxSemaphore; /*!< Semaphore used by RTOS to block task until the receiving is not complete */
|
rt_sem_t m_rxSem;
|
||||||
Semaphore m_txSemaphore; /*!< Semaphore used by RTOS to block task until the sending is not complete */
|
rt_sem_t m_txSem;
|
||||||
#endif
|
|
||||||
private:
|
private:
|
||||||
|
using FramedTransport::underlyingReceive;
|
||||||
|
using FramedTransport::underlyingSend;
|
||||||
|
|
||||||
|
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
|
||||||
|
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static rt_err_t rx_indicate_stub(rt_device_t dev, rt_size_t size);
|
||||||
|
static rt_err_t tx_complete_stub(rt_device_t dev, void *buffer);
|
||||||
|
|
||||||
|
bool is_configured(void);
|
||||||
|
|
||||||
|
/* 等待 configured,避免“先启动再插线” */
|
||||||
|
bool wait_configured(rt_int32_t wait_ms);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char *m_devName;
|
||||||
|
rt_int32_t m_rxWaitMs;
|
||||||
|
rt_int32_t m_txWaitMs;
|
||||||
|
|
||||||
|
rt_device_t m_dev;
|
||||||
|
|
||||||
|
/* keep original members for signature compatibility */
|
||||||
serial_handle_t m_serialHandle;
|
serial_handle_t m_serialHandle;
|
||||||
serial_manager_config_t *m_serialConfig;
|
serial_manager_config_t *m_serialConfig;
|
||||||
serial_port_usb_cdc_config_t *m_usbCdcConfig;
|
serial_port_usb_cdc_config_t *m_usbCdcConfig;
|
||||||
uint8_t *m_usbRingBuffer;
|
uint8_t *m_usbRingBuffer;
|
||||||
uint32_t m_usbRingBufferLength;
|
uint32_t m_usbRingBufferLength;
|
||||||
|
|
||||||
using FramedTransport::underlyingReceive;
|
|
||||||
using FramedTransport::underlyingSend;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Receive data from USB CDC peripheral.
|
|
||||||
*
|
|
||||||
* @param[inout] data Preallocated buffer for receiving data.
|
|
||||||
* @param[in] size Size of data to read.
|
|
||||||
*
|
|
||||||
* @retval kErpcStatus_ReceiveFailed USB CDC failed to receive data.
|
|
||||||
* @retval kErpcStatus_Success Successfully received all data.
|
|
||||||
*/
|
|
||||||
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Write data to USB CDC peripheral.
|
|
||||||
*
|
|
||||||
* @param[in] data Buffer to send.
|
|
||||||
* @param[in] size Size of data to send.
|
|
||||||
*
|
|
||||||
* @retval kErpcStatus_Success Always returns success status.
|
|
||||||
*/
|
|
||||||
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace erpc
|
} // namespace erpc
|
||||||
|
|
||||||
/*! @} */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif /* _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_ */
|
#endif /* _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_ */
|
||||||
|
|||||||
Binary file not shown.
@ -15,7 +15,7 @@ extern "C" {
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "usb_config.h"
|
#include "../../../../../../board/ports/usb/usb_config.h"
|
||||||
#include "usb_util.h"
|
#include "usb_util.h"
|
||||||
#include "usb_errno.h"
|
#include "usb_errno.h"
|
||||||
#include "usb_def.h"
|
#include "usb_def.h"
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "usb_config.h"
|
#include "../../../../../../board/ports/usb/usb_config.h"
|
||||||
#include "usb_util.h"
|
#include "usb_util.h"
|
||||||
#include "usb_errno.h"
|
#include "usb_errno.h"
|
||||||
#include "usb_def.h"
|
#include "usb_def.h"
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
#include "rtthread.h"
|
#include "rtthread.h"
|
||||||
#include "usb_config.h"
|
#include "../../../../../../../board/ports/usb/usb_config.h"
|
||||||
|
|
||||||
#if defined(PKG_CHERRYUSB_HOST) || defined(RT_CHERRYUSB_HOST)
|
#if defined(PKG_CHERRYUSB_HOST) || defined(RT_CHERRYUSB_HOST)
|
||||||
|
|
||||||
|
|||||||
15
rtconfig.h
15
rtconfig.h
@ -99,6 +99,7 @@
|
|||||||
#define RT_USING_HEAP
|
#define RT_USING_HEAP
|
||||||
/* end of Memory Management */
|
/* end of Memory Management */
|
||||||
#define RT_USING_DEVICE
|
#define RT_USING_DEVICE
|
||||||
|
#define RT_USING_DEVICE_OPS
|
||||||
#define RT_USING_CONSOLE
|
#define RT_USING_CONSOLE
|
||||||
#define RT_CONSOLEBUF_SIZE 128
|
#define RT_CONSOLEBUF_SIZE 128
|
||||||
#define RT_CONSOLE_DEVICE_NAME "uart1"
|
#define RT_CONSOLE_DEVICE_NAME "uart1"
|
||||||
@ -142,10 +143,18 @@
|
|||||||
#define RT_USING_SERIAL
|
#define RT_USING_SERIAL
|
||||||
#define RT_USING_SERIAL_V1
|
#define RT_USING_SERIAL_V1
|
||||||
#define RT_SERIAL_USING_DMA
|
#define RT_SERIAL_USING_DMA
|
||||||
#define RT_SERIAL_RB_BUFSZ 1024
|
#define RT_SERIAL_RB_BUFSZ 64
|
||||||
#define RT_USING_SPI
|
#define RT_USING_SPI
|
||||||
#define RT_USING_PIN
|
#define RT_USING_PIN
|
||||||
#define RT_USING_KTIME
|
#define RT_USING_KTIME
|
||||||
|
#define RT_USING_CHERRYUSB
|
||||||
|
#define RT_CHERRYUSB_DEVICE
|
||||||
|
#define RT_CHERRYUSB_DEVICE_SPEED_FS
|
||||||
|
#define RT_CHERRYUSB_DEVICE_DWC2_ST
|
||||||
|
#define RT_CHERRYUSB_DEVICE_CDC_ACM
|
||||||
|
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 1024
|
||||||
|
#define CONFIG_USBDEV_MSC_MAX_BUFSIZE 1024
|
||||||
|
#define RT_CHERRYUSB_DEVICE_TEMPLATE_NONE
|
||||||
/* end of Device Drivers */
|
/* end of Device Drivers */
|
||||||
|
|
||||||
/* C/C++ and POSIX layer */
|
/* C/C++ and POSIX layer */
|
||||||
@ -176,6 +185,7 @@
|
|||||||
/* end of Interprocess Communication (IPC) */
|
/* end of Interprocess Communication (IPC) */
|
||||||
/* end of POSIX (Portable Operating System Interface) layer */
|
/* end of POSIX (Portable Operating System Interface) layer */
|
||||||
#define RT_USING_CPLUSPLUS
|
#define RT_USING_CPLUSPLUS
|
||||||
|
#define RT_USING_CPP_EXCEPTIONS
|
||||||
/* end of C/C++ and POSIX layer */
|
/* end of C/C++ and POSIX layer */
|
||||||
|
|
||||||
/* Network */
|
/* Network */
|
||||||
@ -444,9 +454,8 @@
|
|||||||
#define ERPC_USING_RTT
|
#define ERPC_USING_RTT
|
||||||
#define ERPC_MODE
|
#define ERPC_MODE
|
||||||
#define ERPC_MODE_SERVER
|
#define ERPC_MODE_SERVER
|
||||||
#define ERPC_MODE_CLIENT
|
|
||||||
#define ERPC_TRANSPORTS
|
#define ERPC_TRANSPORTS
|
||||||
#define ERPC_TRANSPORTS_UART
|
#define ERPC_TRANSPORTS_USB_CDC
|
||||||
/* end of Third Packages Drivers */
|
/* end of Third Packages Drivers */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user