refactor: USB HAL conversion + USB lib update (#4207)
Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com> Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
co-authored by
raphaelcoeffic
Richard Li
parent
a68ad817d7
commit
c9334ebda3
@@ -7,54 +7,114 @@ option(LUA_ALLOCATOR_TRACER "Trace Lua memory (de)allocations to debug port (als
|
||||
option(USB_SERIAL "Enable USB serial (CDC)" OFF)
|
||||
|
||||
set(ARCH ARM)
|
||||
set(STM32USB_DIR ${THIRDPARTY_DIR}/STM32_USB-Host-Device_Lib_V2.2.0/Libraries)
|
||||
add_definitions(-DSTM32 -DLUA_INPUTS -DVARIO)
|
||||
|
||||
set(LINKER_DIR ${RADIO_SRC_DIR}/boards/generic_stm32/linker)
|
||||
add_link_options(-L${LINKER_DIR} -L${LINKER_DIR}/${TARGET_LINKER_DIR})
|
||||
|
||||
include_directories(${RADIO_SRC_DIR}/targets/common/arm/stm32)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_OTG_Driver/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Core/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/hid/inc)
|
||||
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/cdc/inc)
|
||||
set(STM32_DRIVER_DIR targets/common/arm/stm32)
|
||||
include_directories(${STM32_DRIVER_DIR})
|
||||
|
||||
set(STM32USB_SRC
|
||||
STM32_USB_OTG_Driver/src/usb_core.c
|
||||
STM32_USB_OTG_Driver/src/usb_dcd.c
|
||||
STM32_USB_OTG_Driver/src/usb_dcd_int.c
|
||||
STM32_USB_Device_Library/Core/src/usbd_core.c
|
||||
STM32_USB_Device_Library/Core/src/usbd_ioreq.c
|
||||
STM32_USB_Device_Library/Core/src/usbd_req.c
|
||||
if(NOT NATIVE_BUILD)
|
||||
|
||||
# STM32 USB Device library
|
||||
set(STM32USB_DIR ${THIRDPARTY_DIR}/STM32_USB_Device_Library)
|
||||
|
||||
add_library(stm32usb OBJECT EXCLUDE_FROM_ALL
|
||||
${STM32USB_DIR}/Core/Src/usbd_core.c
|
||||
${STM32USB_DIR}/Core/Src/usbd_ctlreq.c
|
||||
${STM32USB_DIR}/Core/Src/usbd_ioreq.c
|
||||
${STM32USB_DIR}/Class/CDC/Src/usbd_cdc.c
|
||||
${STM32USB_DIR}/Class/MSC/Src/usbd_msc_data.c
|
||||
${STM32USB_DIR}/Class/MSC/Src/usbd_msc_scsi.c
|
||||
${STM32USB_DIR}/Class/MSC/Src/usbd_msc_bot.c
|
||||
${STM32USB_DIR}/Class/MSC/Src/usbd_msc.c
|
||||
)
|
||||
|
||||
target_include_directories(stm32usb PRIVATE
|
||||
${STM32USB_DIR}/Core/Inc
|
||||
${STM32USB_DIR}/Class/CDC/Inc
|
||||
${STM32USB_DIR}/Class/HID/Inc
|
||||
${STM32USB_DIR}/Class/MSC/Inc)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32usb>)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32usb>)
|
||||
|
||||
# Bootloader USB devices
|
||||
add_library(stm32usb_device_bl OBJECT EXCLUDE_FROM_ALL
|
||||
${STM32_DRIVER_DIR}/usbd_conf.c
|
||||
${STM32_DRIVER_DIR}/usbd_desc.c
|
||||
${STM32_DRIVER_DIR}/usb_driver.cpp
|
||||
${STM32_DRIVER_DIR}/usbd_storage_msd.cpp
|
||||
)
|
||||
|
||||
target_compile_options(stm32usb_device_bl PRIVATE -DBOOT)
|
||||
target_include_directories(stm32usb_device_bl PRIVATE
|
||||
${STM32USB_DIR}/Core/Inc
|
||||
${STM32USB_DIR}/Class/CDC/Inc
|
||||
${STM32USB_DIR}/Class/HID/Inc
|
||||
${STM32USB_DIR}/Class/MSC/Inc)
|
||||
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32usb_device_bl>)
|
||||
|
||||
# Firmware USB devices
|
||||
add_library(stm32usb_device_fw OBJECT EXCLUDE_FROM_ALL
|
||||
${STM32_DRIVER_DIR}/usbd_conf.c
|
||||
${STM32_DRIVER_DIR}/usbd_desc.c
|
||||
${STM32_DRIVER_DIR}/usb_driver.cpp
|
||||
${STM32_DRIVER_DIR}/usbd_storage_msd.cpp
|
||||
${STM32_DRIVER_DIR}/usbd_cdc.cpp
|
||||
${STM32_DRIVER_DIR}/usbd_hid_joystick.c
|
||||
)
|
||||
|
||||
if(DEBUG OR CLI OR USB_SERIAL)
|
||||
target_compile_options(stm32usb_device_fw PRIVATE -DUSB_SERIAL)
|
||||
endif()
|
||||
|
||||
target_include_directories(stm32usb_device_fw PRIVATE
|
||||
${STM32USB_DIR}/Core/Inc
|
||||
${STM32USB_DIR}/Class/CDC/Inc
|
||||
${STM32USB_DIR}/Class/HID/Inc
|
||||
${STM32USB_DIR}/Class/MSC/Inc)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32usb_device_fw>)
|
||||
|
||||
# HAL/LL based driver library
|
||||
add_library(stm32_drivers OBJECT EXCLUDE_FROM_ALL
|
||||
${STM32_DRIVER_DIR}/stm32_hal.cpp
|
||||
${STM32_DRIVER_DIR}/timers_driver.cpp
|
||||
${STM32_DRIVER_DIR}/sdcard_spi.cpp
|
||||
${STM32_DRIVER_DIR}/diskio_spi.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_exti_driver.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_serial_driver.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_usart_driver.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_gpio_driver.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_i2c_driver.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_timer.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_dma.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_spi.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_adc.cpp
|
||||
)
|
||||
|
||||
if(NOT PCB STREQUAL PL18)
|
||||
target_sources(stm32_drivers PUBLIC
|
||||
${STM32_DRIVER_DIR}/diskio_sdio.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32_drivers>)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32_drivers>)
|
||||
endif()
|
||||
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/rtc_driver.cpp
|
||||
../common/arm/stm32/timers_driver.cpp
|
||||
../common/arm/stm32/delays_driver.cpp
|
||||
../common/arm/stm32/trainer_driver.cpp
|
||||
../common/arm/stm32/usb_bsp.c
|
||||
../common/arm/stm32/usbd_desc.c
|
||||
../common/arm/stm32/usbd_usr.cpp
|
||||
../common/arm/stm32/usb_driver.cpp
|
||||
../common/arm/stm32/flash_driver.cpp
|
||||
../common/arm/stm32/usbd_storage_msd.cpp
|
||||
../common/arm/stm32/usbd_hid_joystick.c
|
||||
../common/arm/stm32/stm32_hal.cpp
|
||||
../common/arm/stm32/stm32_i2c_driver.cpp
|
||||
../common/arm/stm32/stm32_serial_driver.cpp
|
||||
../common/arm/stm32/stm32_softserial_driver.cpp
|
||||
../common/arm/stm32/stm32_pulse_driver.cpp
|
||||
../common/arm/stm32/stm32_usart_driver.cpp
|
||||
../common/arm/stm32/module_timer_driver.cpp
|
||||
../common/arm/stm32/stm32_switch_driver.cpp
|
||||
../common/arm/stm32/stm32_adc.cpp
|
||||
../common/arm/stm32/stm32_spi.cpp
|
||||
../common/arm/stm32/stm32_timer.cpp
|
||||
../common/arm/stm32/stm32_dma.cpp
|
||||
../common/arm/stm32/stm32_gpio_driver.cpp
|
||||
../common/arm/stm32/stm32_exti_driver.cpp
|
||||
../common/arm/stm32/mixer_scheduler_driver.cpp
|
||||
../common/arm/stm32/pwr_driver.cpp
|
||||
../common/arm/stm32/watchdog_driver.cpp
|
||||
@@ -89,33 +149,15 @@ if(FLYSKY_GIMBAL)
|
||||
endif()
|
||||
|
||||
if(DEBUG OR CLI OR USB_SERIAL)
|
||||
set(STM32USB_SRC ${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_cdc.cpp
|
||||
)
|
||||
add_definitions(-DUSB_SERIAL)
|
||||
message("-- Adding support for USB serial")
|
||||
endif()
|
||||
|
||||
set(STM32USB_SRC ${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
|
||||
)
|
||||
|
||||
if(GVARS)
|
||||
set(GUI_SRC ${GUI_SRC} ${GVAR_SCREEN})
|
||||
endif()
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} syscalls.c)
|
||||
|
||||
|
||||
foreach(FILE ${STM32USB_SRC})
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} ${STM32USB_DIR}/${FILE})
|
||||
endforeach()
|
||||
|
||||
set(TARGET_SRC ${TARGET_SRC} ../common/arm/stm32/cpu_id.cpp)
|
||||
set(SRC ${SRC} io/bootloader_flash.cpp)
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "cpu_id.h"
|
||||
|
||||
#if !defined(SIMU) && !defined(BACKUP)
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
@@ -37,7 +36,6 @@
|
||||
#include "stm32f4xx_spi.h"
|
||||
#include "stm32f4xx_pwr.h"
|
||||
#include "stm32f4xx_dma.h"
|
||||
#include "stm32f4xx_flash.h"
|
||||
#include "stm32f4xx_dbgmcu.h"
|
||||
#include "misc.h"
|
||||
#else
|
||||
@@ -50,15 +48,13 @@
|
||||
#include "stm32f2xx_spi.h"
|
||||
#include "stm32f2xx_pwr.h"
|
||||
#include "stm32f2xx_dma.h"
|
||||
#include "stm32f2xx_flash.h"
|
||||
#include "stm32f2xx_dbgmcu.h"
|
||||
#include "misc.h"
|
||||
#include "dwt.h" // the old ST library that we use does not define DWT register for STM32F2xx
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include "usb_driver.h"
|
||||
//#include "usb_driver.h"
|
||||
|
||||
#if defined(SIMU)
|
||||
#include "../simu/simpgmspace.h"
|
||||
|
||||
@@ -11,36 +11,14 @@ set(BOOTLOADER_SRC
|
||||
../../../../../strhelpers.cpp
|
||||
../../../../../stamp.cpp
|
||||
../../../../../syscalls.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_OTG_Driver/src/usb_core.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_OTG_Driver/src/usb_dcd.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_OTG_Driver/src/usb_dcd_int.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Core/src/usbd_core.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Core/src/usbd_ioreq.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Core/src/usbd_req.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
|
||||
../../../../../${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
|
||||
../../../../../targets/${TARGET_DIR}/${LCD_DRIVER}
|
||||
../../../../../targets/${TARGET_DIR}/backlight_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/board.cpp
|
||||
../../../../../targets/${TARGET_DIR}/bootloader/boot_menu.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hal_keys.inc
|
||||
../pwr_driver.cpp
|
||||
../usbd_usr.cpp
|
||||
../usbd_storage_msd.cpp
|
||||
../delays_driver.cpp
|
||||
../timers_driver.cpp
|
||||
../usbd_desc.c
|
||||
../usb_bsp.c
|
||||
../usb_driver.cpp
|
||||
../flash_driver.cpp
|
||||
../stm32_exti_driver.cpp
|
||||
../stm32_serial_driver.cpp
|
||||
../stm32_usart_driver.cpp
|
||||
../stm32_gpio_driver.cpp
|
||||
../stm32_timer.cpp
|
||||
../stm32_dma.cpp
|
||||
../watchdog_driver.cpp
|
||||
../abnormal_reboot.cpp
|
||||
init.c
|
||||
@@ -81,18 +59,13 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14 OR PCB STREQUAL PL
|
||||
../../../../../targets/common/arm/stm32/rtc_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/diskio_spi_flash.cpp
|
||||
../../../../../targets/common/arm/stm32/spi_flash.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_spi.cpp
|
||||
../../../../../drivers/frftl.cpp
|
||||
../../../../../crc.cpp
|
||||
../../../../../targets/${TARGET_DIR}/sdram_driver.c
|
||||
../../../../../targets/${TARGET_DIR}/haptic_driver.cpp
|
||||
)
|
||||
|
||||
if(NOT PCB STREQUAL PL18)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
|
||||
../../../../../targets/common/arm/stm32/diskio_sdio.cpp
|
||||
)
|
||||
else()
|
||||
if(PCB STREQUAL PL18)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC}
|
||||
../../../../../targets/pl18/key_driver.cpp
|
||||
)
|
||||
@@ -123,9 +96,6 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14 OR PCB STREQUAL PL
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../serial.cpp
|
||||
../../../../../boards/generic_stm32/aux_ports.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_serial_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_usart_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_dma.cpp
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
@@ -133,10 +103,6 @@ else()
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../gui/common/stdlcd/fonts.cpp
|
||||
../../../../../gui/common/stdlcd/utf8.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_gpio_driver.cpp
|
||||
../../../../../targets/common/arm/stm32/stm32_spi.cpp
|
||||
../../../../../targets/common/arm/stm32/sdcard_spi.cpp
|
||||
../../../../../targets/common/arm/stm32/diskio_spi.cpp
|
||||
../../../../../crc.cpp
|
||||
)
|
||||
remove_definitions(-DDEBUG)
|
||||
@@ -151,6 +117,14 @@ remove_definitions(-DUSE_WATCHDOG)
|
||||
|
||||
add_definitions(-DBOOT)
|
||||
|
||||
if(NOT NO_LTO)
|
||||
message("-- Use LTO to compile bootloader")
|
||||
target_compile_options(stm32cube_ll PRIVATE -flto)
|
||||
target_compile_options(stm32usb PRIVATE -flto)
|
||||
target_compile_options(stm32usb_device_bl PRIVATE -flto)
|
||||
target_compile_options(stm32usb_device_fw PRIVATE -flto)
|
||||
target_compile_options(stm32_drivers PRIVATE -flto)
|
||||
endif()
|
||||
add_executable(bootloader EXCLUDE_FROM_ALL ${BOOTLOADER_SRC})
|
||||
add_dependencies(bootloader ${BITMAPS_TARGET})
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
#include "bluetooth_driver.h"
|
||||
@@ -29,9 +30,7 @@
|
||||
#include "board.h"
|
||||
#include "boot.h"
|
||||
#include "bin_files.h"
|
||||
#include "dataconstants.h"
|
||||
#include "lcd.h"
|
||||
// #include "keys.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "timers_driver.h"
|
||||
@@ -100,11 +99,9 @@ FlashCheckRes valid;
|
||||
MemoryType memoryType;
|
||||
uint32_t unlocked = 0;
|
||||
|
||||
volatile uint32_t timer10MsCount;
|
||||
|
||||
void per5ms() {} // make linker happy
|
||||
void per10ms()
|
||||
{
|
||||
timer10MsCount++;
|
||||
tenms |= 1u; // 10 mS has passed
|
||||
g_tmr10ms++;
|
||||
|
||||
@@ -122,12 +119,6 @@ void per10ms()
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" uint32_t HAL_GetTick(void)
|
||||
{
|
||||
return timer10MsCount * 10;
|
||||
}
|
||||
|
||||
|
||||
uint32_t isValidBufferStart(const uint8_t * buffer)
|
||||
{
|
||||
#if !defined(SIMU)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "diskio_sdio.h"
|
||||
|
||||
#include "stm32_dma.h"
|
||||
@@ -28,6 +29,8 @@
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#if !defined(SD_SPI)
|
||||
|
||||
// #include "delays_driver.h"
|
||||
#include "debug.h"
|
||||
|
||||
@@ -429,3 +432,5 @@ extern "C" void SD_SDIO_DMA_IRQHANDLER(void)
|
||||
DEBUG_INTERRUPT(INT_SDIO_DMA);
|
||||
HAL_DMA_IRQHandler(&sdioTxDma);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#if defined(SD_SPI)
|
||||
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
|
||||
@@ -145,3 +147,5 @@ const diskio_driver_t sdcard_spi_driver = {
|
||||
.write = sdcard_spi_write,
|
||||
.ioctl = sdcard_spi_ioctl,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,6 +23,7 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_exti.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_adc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_spi.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_ll_usb.c
|
||||
# HAL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_pwr.c
|
||||
@@ -30,6 +31,8 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_rcc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_rtc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_i2c.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_pcd.c
|
||||
${STM32CUBE_DIR}/Src/stm32f2xx_hal_pcd_ex.c
|
||||
)
|
||||
|
||||
target_compile_options(stm32cube_ll PRIVATE -DUSE_FULL_LL_DRIVER)
|
||||
|
||||
@@ -32,6 +32,7 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_sdmmc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_adc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_spi.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_usb.c
|
||||
# HAL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pwr.c
|
||||
@@ -43,6 +44,8 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_i2c_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_sd.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pcd.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pcd_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_cortex.c
|
||||
|
||||
${STM32_COLORLCD_DRIVERS}
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
#include "board.h"
|
||||
#include "hal/watchdog_driver.h"
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx_flash.h"
|
||||
#elif defined(STM32F2)
|
||||
#include "stm32f2xx_flash.h"
|
||||
#endif
|
||||
|
||||
void waitFlashIdle()
|
||||
{
|
||||
do {
|
||||
|
||||
@@ -26,6 +26,12 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(STM32F4)
|
||||
|
||||
// Workaround to prevent the other CMSIS header to be included
|
||||
// and fix some missing items in the old one
|
||||
#include "thirdparty/CMSIS/Include/cmsis_compiler.h"
|
||||
#define __CORE_CM4_H_GENERIC
|
||||
|
||||
#include "CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#elif defined(STM32F2)
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if defined(STM32F4)
|
||||
#include "CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
@@ -29,4 +31,6 @@ extern "C" {
|
||||
#include "CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#include "stm32f2xx_hal.h"
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,10 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define USE_FULL_LL_DRIVER
|
||||
|
||||
// Hack to prevent "Legacy/stm32_hal_legacy.h" from being included
|
||||
#define STM32_HAL_LEGACY
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma2d.h"
|
||||
@@ -41,6 +45,7 @@ extern "C" {
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_spi.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_iwdg.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h"
|
||||
#elif defined(STM32F2)
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_bus.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_gpio.h"
|
||||
@@ -53,6 +58,7 @@ extern "C" {
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_adc.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_spi.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_iwdg.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_usb.h"
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
// #define HAL_SMARTCARD_MODULE_ENABLED
|
||||
// #define HAL_WWDG_MODULE_ENABLED
|
||||
// #define HAL_CORTEX_MODULE_ENABLED
|
||||
// #define HAL_PCD_MODULE_ENABLED
|
||||
#define HAL_PCD_MODULE_ENABLED
|
||||
// #define HAL_HCD_MODULE_ENABLED
|
||||
// #define HAL_MMC_MODULE_ENABLED
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
// #define HAL_SMARTCARD_MODULE_ENABLED
|
||||
// #define HAL_WWDG_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
// #define HAL_PCD_MODULE_ENABLED
|
||||
#define HAL_PCD_MODULE_ENABLED
|
||||
// #define HAL_HCD_MODULE_ENABLED
|
||||
// #define HAL_FMPI2C_MODULE_ENABLED
|
||||
// #define HAL_FMPSMBUS_MODULE_ENABLED
|
||||
|
||||
@@ -76,11 +76,6 @@ void watchdogSuspend(uint32_t timeout)
|
||||
watchdogTimeout = timeout;
|
||||
}
|
||||
|
||||
#define __weak __attribute__((weak))
|
||||
|
||||
__weak void per10ms() {}
|
||||
__weak void per5ms() {}
|
||||
|
||||
static inline void _interrupt_1ms()
|
||||
{
|
||||
static uint8_t pre_scale = 0;
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usb_bsp.h"
|
||||
#include "board.h"
|
||||
#include "usbd_conf.h"
|
||||
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_Init
|
||||
* Initilizes BSP configurations
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_AHB1PeriphClockCmd(USB_RCC_AHB1Periph_GPIO, ENABLE);
|
||||
|
||||
/* Configure DM and DP Pins */
|
||||
GPIO_InitStructure.GPIO_Pin = USB_GPIO_PIN_DM | USB_GPIO_PIN_DP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(USB_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(USB_GPIO, USB_GPIO_PinSource_DM, USB_GPIO_AF);
|
||||
GPIO_PinAFConfig(USB_GPIO, USB_GPIO_PinSource_DP, USB_GPIO_AF);
|
||||
|
||||
#if defined(USB_GPIO_PIN_VBUS)
|
||||
/* Configure VBUS Pin */
|
||||
GPIO_InitStructure.GPIO_Pin = USB_GPIO_PIN_VBUS;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
||||
GPIO_Init(USB_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
|
||||
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
|
||||
}
|
||||
|
||||
void USB_OTG_BSP_Deinit(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_EnableInterrupt
|
||||
* Enable USB Global interrupt
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
// FreeRTOS syscall prio is 5
|
||||
NVIC_SetPriority(OTG_FS_IRQn, 11); // Lower priority interrupt
|
||||
NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_DisableInterrupt
|
||||
* Disable USB Global interrupt
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_DisableInterrupt(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_uDelay
|
||||
* This function provides delay time in micro sec
|
||||
* @param usec : Value of delay required in micro sec
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_uDelay (const uint32_t usec)
|
||||
{
|
||||
delay_us(usec);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_mDelay
|
||||
* This function provides delay time in milli sec
|
||||
* @param msec : Value of delay required in milli sec
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_mDelay (const uint32_t msec)
|
||||
{
|
||||
delay_ms(msec);
|
||||
}
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -23,11 +23,7 @@
|
||||
#ifndef _USB_CONF_H_
|
||||
#define _USB_CONF_H_
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx.h"
|
||||
#else
|
||||
#include "stm32f2xx.h"
|
||||
#endif
|
||||
#include "stm32_cmsis.h"
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
@@ -132,41 +128,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************** C Compilers dependant keywords ****************************/
|
||||
/* 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 */
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined (__GNUC__) /* GNU Compiler */
|
||||
#define __ALIGN_END __attribute__ ((aligned (4)))
|
||||
#define __ALIGN_BEGIN
|
||||
#else
|
||||
#define __ALIGN_END
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __ALIGN_BEGIN __align(4)
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __ALIGN_BEGIN
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __ALIGN_BEGIN __align(4)
|
||||
#endif /* __CC_ARM */
|
||||
#endif /* __GNUC__ */
|
||||
#else
|
||||
#define __ALIGN_BEGIN
|
||||
#define __ALIGN_END
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
/* __packed keyword used to decrease the data type alignment to 1-byte */
|
||||
#if !defined(__packed)
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined ( __GNUC__ ) /* GNU Compiler */
|
||||
#define __packed __attribute__ ((__packed__))
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __packed __unaligned
|
||||
#endif /* __CC_ARM */
|
||||
#endif
|
||||
|
||||
#endif // _USB_CONF_H_
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -19,25 +19,25 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "usb_driver.h"
|
||||
|
||||
#if defined(USBJ_EX)
|
||||
#include "usb_joystick.h"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "usb_conf.h"
|
||||
#include "usb_dcd_int.h"
|
||||
#include "usb_bsp.h"
|
||||
#include "usbd_conf.h"
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_msc_core.h"
|
||||
#include "usbd_msc.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_usr.h"
|
||||
#include "usbd_hid_core.h"
|
||||
#include "usbd_cdc_core.h"
|
||||
#include "usbd_hid.h"
|
||||
#include "usbd_cdc.h"
|
||||
}
|
||||
|
||||
#include "board.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "debug.h"
|
||||
|
||||
static bool usbDriverStarted = false;
|
||||
@@ -47,6 +47,8 @@ static usbMode selectedUsbMode = USB_MASS_STORAGE_MODE;
|
||||
static usbMode selectedUsbMode = USB_UNSELECTED_MODE;
|
||||
#endif
|
||||
|
||||
USBD_HandleTypeDef hUsbDeviceFS;
|
||||
|
||||
int getSelectedUsbMode()
|
||||
{
|
||||
return selectedUsbMode;
|
||||
@@ -63,7 +65,7 @@ int usbPlugged()
|
||||
static uint8_t debouncedState = 0;
|
||||
static uint8_t lastState = 0;
|
||||
|
||||
uint8_t state = GPIO_ReadInputDataBit(USB_GPIO, USB_GPIO_PIN_VBUS);
|
||||
uint8_t state = LL_GPIO_IsInputPinSet(USB_GPIO, USB_GPIO_PIN_VBUS);
|
||||
|
||||
if (state == lastState)
|
||||
debouncedState = state;
|
||||
@@ -74,25 +76,49 @@ int usbPlugged()
|
||||
}
|
||||
#endif
|
||||
|
||||
USB_OTG_CORE_HANDLE USB_OTG_dev;
|
||||
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
|
||||
extern "C" void OTG_FS_IRQHandler()
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_OTG_FS);
|
||||
USBD_OTG_ISR_Handler(&USB_OTG_dev);
|
||||
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
|
||||
}
|
||||
|
||||
void usbInit()
|
||||
{
|
||||
// Initialize hardware
|
||||
USB_OTG_BSP_Init(&USB_OTG_dev);
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||
LL_GPIO_StructInit(&GPIO_InitStruct);
|
||||
|
||||
#if defined(USB_GPIO_PIN_VBUS)
|
||||
GPIO_InitStruct.Pin = USB_GPIO_PIN_VBUS;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(USB_GPIO, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
GPIO_InitStruct.Pin = USB_GPIO_PIN_DM | USB_GPIO_PIN_DP;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_10; // USB
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
usbDriverStarted = false;
|
||||
}
|
||||
|
||||
extern void usbInitLUNs();
|
||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||
extern "C" USBD_StorageTypeDef USBD_Storage_Interface_fops_FS;
|
||||
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
|
||||
|
||||
void usbStart()
|
||||
{
|
||||
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
|
||||
switch (getSelectedUsbMode()) {
|
||||
#if !defined(BOOT)
|
||||
case USB_JOYSTICK_MODE:
|
||||
@@ -100,42 +126,40 @@ void usbStart()
|
||||
#if defined(USBJ_EX)
|
||||
setupUSBJoystick();
|
||||
#endif
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
//USBD_Init(&hUsbDeviceFS, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
//MX_USB_DEVICE_Init();
|
||||
USBD_RegisterClass(&hUsbDeviceFS, &USBD_HID);
|
||||
break;
|
||||
#endif
|
||||
#if defined(USB_SERIAL)
|
||||
case USB_SERIAL_MODE:
|
||||
// initialize USB as CDC device (virtual serial port)
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
|
||||
//USBD_Init(&hUsbDeviceFS, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
|
||||
//MX_USB_DEVICE_Init();
|
||||
USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC);
|
||||
USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
default:
|
||||
case USB_MASS_STORAGE_MODE:
|
||||
// initialize USB as MSC device
|
||||
usbInitLUNs();
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
|
||||
//MX_USB_DEVICE_Init();
|
||||
USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC);
|
||||
USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS);
|
||||
//USBD_Init(&hUsbDeviceFS, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
|
||||
break;
|
||||
}
|
||||
USBD_Start(&hUsbDeviceFS);
|
||||
usbDriverStarted = true;
|
||||
}
|
||||
|
||||
void usbStop()
|
||||
{
|
||||
usbDriverStarted = false;
|
||||
USBD_DeInit(&USB_OTG_dev);
|
||||
USBD_DeInit(&hUsbDeviceFS);
|
||||
}
|
||||
|
||||
#if defined(USBJ_EX)
|
||||
void usbJoystickRestart()
|
||||
{
|
||||
if (getSelectedUsbMode() != USB_JOYSTICK_MODE) return;
|
||||
|
||||
USBD_DeInit(&USB_OTG_dev);
|
||||
DCD_DevDisconnect(&USB_OTG_dev);
|
||||
DCD_DevConnect(&USB_OTG_dev);
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool usbStarted()
|
||||
{
|
||||
@@ -143,7 +167,28 @@ bool usbStarted()
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
#include "globals.h"
|
||||
|
||||
#if defined(USBJ_EX)
|
||||
extern "C" void delay_ms(uint32_t count);
|
||||
void usbJoystickRestart()
|
||||
{
|
||||
if (!usbDriverStarted || getSelectedUsbMode() != USB_JOYSTICK_MODE) return;
|
||||
|
||||
USBD_DeInit(&hUsbDeviceFS);
|
||||
delay_ms(100);
|
||||
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
|
||||
USBD_RegisterClass(&hUsbDeviceFS, &USBD_HID);
|
||||
USBD_Start(&hUsbDeviceFS);
|
||||
}
|
||||
#else
|
||||
// TODO: fix after HAL conversion is complete
|
||||
#warning channelOutputs should come from "globals.h"
|
||||
|
||||
#define MAX_OUTPUT_CHANNELS 32
|
||||
extern int16_t channelOutputs[MAX_OUTPUT_CHANNELS];
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Prepare and send new USB data packet
|
||||
@@ -155,45 +200,39 @@ bool usbStarted()
|
||||
void usbJoystickUpdate()
|
||||
{
|
||||
#if !defined(USBJ_EX)
|
||||
static uint8_t HID_Buffer[HID_IN_PACKET];
|
||||
static uint8_t HID_Buffer[0/*HID_IN_PACKET*/];
|
||||
|
||||
// test to se if TX buffer is free
|
||||
if (USBD_HID_SendReport(&USB_OTG_dev, 0, 0) == USBD_OK) {
|
||||
//buttons
|
||||
HID_Buffer[0] = 0;
|
||||
HID_Buffer[1] = 0;
|
||||
HID_Buffer[2] = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ( channelOutputs[i+8] > 0 ) {
|
||||
HID_Buffer[0] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+16] > 0 ) {
|
||||
HID_Buffer[1] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+24] > 0 ) {
|
||||
HID_Buffer[2] |= (1 << i);
|
||||
}
|
||||
}
|
||||
//buttons
|
||||
HID_Buffer[0] = 0;
|
||||
HID_Buffer[1] = 0;
|
||||
HID_Buffer[2] = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ( channelOutputs[i+8] > 0 ) {
|
||||
HID_Buffer[0] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+16] > 0 ) {
|
||||
HID_Buffer[1] |= (1 << i);
|
||||
}
|
||||
if ( channelOutputs[i+24] > 0 ) {
|
||||
HID_Buffer[2] |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
//analog values
|
||||
//uint8_t * p = HID_Buffer + 1;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
//analog values
|
||||
//uint8_t * p = HID_Buffer + 1;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
|
||||
int16_t value = channelOutputs[i] + 1024;
|
||||
if ( value > 2047 ) value = 2047;
|
||||
else if ( value < 0 ) value = 0;
|
||||
HID_Buffer[i*2 +3] = static_cast<uint8_t>(value & 0xFF);
|
||||
HID_Buffer[i*2 +4] = static_cast<uint8_t>((value >> 8) & 0x07);
|
||||
int16_t value = channelOutputs[i] + 1024;
|
||||
if ( value > 2047 ) value = 2047;
|
||||
else if ( value < 0 ) value = 0;
|
||||
HID_Buffer[i*2 +3] = static_cast<uint8_t>(value & 0xFF);
|
||||
HID_Buffer[i*2 +4] = static_cast<uint8_t>((value >> 8) & 0x07);
|
||||
|
||||
}
|
||||
USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, HID_IN_PACKET);
|
||||
}
|
||||
}
|
||||
USBD_HID_SendReport(&hUsbDeviceFS, HID_Buffer, HID_IN_PACKET);
|
||||
#else
|
||||
// test to se if TX buffer is free
|
||||
if (USBD_HID_SendReport(&USB_OTG_dev, 0, 0) == USBD_OK) {
|
||||
usbReport_t ret = usbReport();
|
||||
USBD_HID_SendReport(&USB_OTG_dev, ret.ptr, ret.size);
|
||||
}
|
||||
usbReport_t ret = usbReport();
|
||||
USBD_HID_SendReport(&hUsbDeviceFS, ret.ptr, ret.size);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/serial_port.h"
|
||||
#include "definitions.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// USB driver
|
||||
enum usbMode {
|
||||
USB_UNSELECTED_MODE,
|
||||
USB_JOYSTICK_MODE,
|
||||
USB_MASS_STORAGE_MODE,
|
||||
USB_SERIAL_MODE,
|
||||
#if defined(USB_SERIAL)
|
||||
USB_MAX_MODE=USB_SERIAL_MODE
|
||||
#else
|
||||
USB_MAX_MODE=USB_MASS_STORAGE_MODE
|
||||
#endif
|
||||
};
|
||||
|
||||
// Control line state bits
|
||||
#define CTRL_LINE_STATE_DTR (1 << 0)
|
||||
#define CTRL_LINE_STATE_RTS (1 << 1)
|
||||
|
||||
int usbPlugged();
|
||||
void usbInit();
|
||||
void usbStart();
|
||||
void usbStop();
|
||||
#if defined(USBJ_EX)
|
||||
void usbJoystickRestart();
|
||||
#endif
|
||||
bool usbStarted();
|
||||
|
||||
EXTERN_C(int getSelectedUsbMode());
|
||||
void setSelectedUsbMode(int mode);
|
||||
|
||||
EXTERN_C(uint32_t usbSerialFreeSpace());
|
||||
|
||||
extern const etx_serial_port_t UsbSerialPort;
|
||||
@@ -19,19 +19,11 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#pragma data_alignment = 4
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
// include STM32 headers and generic board defs
|
||||
#include "board_common.h"
|
||||
#include "usb_driver.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_conf.h"
|
||||
#include "usbd_cdc_core.h"
|
||||
#include "usbd_cdc.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
@@ -51,29 +43,64 @@ typedef struct __attribute__ ((packed))
|
||||
|
||||
static LINE_CODING g_lc;
|
||||
|
||||
/* These are external variables imported from CDC core to be used for IN
|
||||
transfer management. */
|
||||
extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer.
|
||||
These data will be sent over USB IN endpoint
|
||||
in the CDC core functions. */
|
||||
extern volatile uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to
|
||||
start address when writing received data
|
||||
in the buffer APP_Rx_Buffer. */
|
||||
extern volatile uint32_t APP_Rx_ptr_out;
|
||||
#if defined(USE_USB_HS)
|
||||
uint8_t UserRxBufferFS[CDC_DATA_HS_OUT_PACKET_SIZE];
|
||||
#else
|
||||
uint8_t UserRxBufferFS[CDC_DATA_FS_OUT_PACKET_SIZE];
|
||||
#endif
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint16_t VCP_Init (void);
|
||||
static uint16_t VCP_DeInit (void);
|
||||
static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
|
||||
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len);
|
||||
/** Data to send over USB CDC are stored in this buffer */
|
||||
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
|
||||
volatile uint32_t APP_Tx_ptr_in = 0;
|
||||
volatile uint32_t APP_Tx_ptr_out = 0;
|
||||
|
||||
extern "C" const CDC_IF_Prop_TypeDef VCP_fops =
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VCP_IF_Exported_Variables USBD_VCP_IF_Exported_Variables
|
||||
* @brief Public variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VCP_IF_Private_FunctionPrototypes USBD_VCP_IF_Private_FunctionPrototypes
|
||||
* @brief Private functions declaration.
|
||||
* @{
|
||||
*/
|
||||
|
||||
static int8_t VCP_Init_FS(void);
|
||||
static int8_t VCP_DeInit_FS(void);
|
||||
static int8_t VCP_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||
static int8_t VCP_Receive_FS(uint8_t* pbuf, uint32_t *Len);
|
||||
static int8_t VCP_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||
static int8_t VCP_StartOfFrame_FS();
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
|
||||
{
|
||||
VCP_Init,
|
||||
VCP_DeInit,
|
||||
VCP_Ctrl,
|
||||
0,
|
||||
VCP_DataRx
|
||||
VCP_Init_FS,
|
||||
VCP_DeInit_FS,
|
||||
VCP_Control_FS,
|
||||
VCP_Receive_FS,
|
||||
VCP_TransmitCplt_FS,
|
||||
VCP_StartOfFrame_FS,
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
@@ -90,33 +117,31 @@ bool cdcConnected = false;
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief VCP_Init
|
||||
* Initializes the Media on the STM32
|
||||
* @param None
|
||||
* @retval Result of the opeartion (USBD_OK in all cases)
|
||||
* @brief Initializes the CDC media low layer over the FS USB IP
|
||||
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static uint16_t VCP_Init(void)
|
||||
static int8_t VCP_Init_FS(void)
|
||||
{
|
||||
cdcConnected = true;
|
||||
// receiveDataCb = nullptr;
|
||||
// baudRateCb = nullptr;
|
||||
|
||||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
|
||||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VCP_DeInit
|
||||
* DeInitializes the Media on the STM32
|
||||
* @param None
|
||||
* @retval Result of the opeartion (USBD_OK in all cases)
|
||||
* @brief DeInitializes the CDC media low layer
|
||||
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static uint16_t VCP_DeInit(void)
|
||||
static int8_t VCP_DeInit_FS(void)
|
||||
{
|
||||
/* USER CODE BEGIN 4 */
|
||||
cdcConnected = false;
|
||||
receiveDataCb = nullptr;
|
||||
baudRateCb = nullptr;
|
||||
|
||||
return USBD_OK;
|
||||
APP_Tx_ptr_in = 0;
|
||||
APP_Tx_ptr_out = 0;
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 4 */
|
||||
}
|
||||
|
||||
void ust_cpy(LINE_CODING* plc2, const LINE_CODING* plc1)
|
||||
@@ -128,43 +153,43 @@ void ust_cpy(LINE_CODING* plc2, const LINE_CODING* plc1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VCP_Ctrl
|
||||
* Manage the CDC class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the opeartion (USBD_OK in all cases)
|
||||
* @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 uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
static int8_t VCP_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
{
|
||||
LINE_CODING* plc = (LINE_CODING*)Buf;
|
||||
LINE_CODING* plc = (LINE_CODING*)pbuf;
|
||||
|
||||
/* USER CODE BEGIN 5 */
|
||||
assert_param(Len>=sizeof(LINE_CODING));
|
||||
|
||||
switch (Cmd)
|
||||
|
||||
switch(cmd)
|
||||
{
|
||||
case SEND_ENCAPSULATED_COMMAND:
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case GET_ENCAPSULATED_RESPONSE:
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case SET_COMM_FEATURE:
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case GET_COMM_FEATURE:
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case CLEAR_COMM_FEATURE:
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case SET_LINE_CODING:
|
||||
if (plc && (Len == sizeof (*plc))) {
|
||||
case CDC_SET_LINE_CODING:
|
||||
if (plc && (length == sizeof (*plc))) {
|
||||
// If a callback is provided, tell the upper driver of changes in baud rate
|
||||
auto _cb = baudRateCb;
|
||||
// auto _ctx = baudRateCbCtx;
|
||||
@@ -176,13 +201,13 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_LINE_CODING:
|
||||
if (plc && (Len == sizeof (*plc))) {
|
||||
case CDC_GET_LINE_CODING:
|
||||
if (plc && (length == sizeof (*plc))) {
|
||||
ust_cpy(plc, &g_lc);
|
||||
}
|
||||
break;
|
||||
|
||||
case SET_CONTROL_LINE_STATE:
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
// If a callback is provided, tell the upper driver of changes in DTR/RTS state
|
||||
// if (plc && (Len == sizeof (uint16_t))) {
|
||||
// if (ctrlLineStateCb) {
|
||||
@@ -191,7 +216,7 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
// }
|
||||
break;
|
||||
|
||||
case SEND_BREAK:
|
||||
case CDC_SEND_BREAK:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
@@ -199,21 +224,88 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VCP_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 VCP_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;
|
||||
}
|
||||
|
||||
static int8_t VCP_StartOfFrame_FS()
|
||||
{
|
||||
uint8_t result = USBD_OK;
|
||||
static uint8_t FrameCount = 0; // modified by OpenTX
|
||||
|
||||
if (FrameCount++ >= CDC_IN_FRAME_INTERVAL) // modified by OpenTX
|
||||
{
|
||||
/* Reset the frame counter */
|
||||
FrameCount = 0;
|
||||
|
||||
/* Check the data to be sent through IN pipe */
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
|
||||
|
||||
if (hcdc->TxState != 0)
|
||||
return USBD_OK;
|
||||
|
||||
if (APP_Tx_ptr_out == APP_TX_DATA_SIZE)
|
||||
APP_Tx_ptr_out = 0;
|
||||
|
||||
if(APP_Tx_ptr_out == APP_Tx_ptr_in)
|
||||
return USBD_OK;
|
||||
|
||||
size_t length = 0;
|
||||
|
||||
if(APP_Tx_ptr_out > APP_Tx_ptr_in) /* rollback */
|
||||
{
|
||||
length = APP_TX_DATA_SIZE - APP_Tx_ptr_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = APP_Tx_ptr_in - APP_Tx_ptr_out;
|
||||
}
|
||||
|
||||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &UserTxBufferFS[APP_Tx_ptr_out], length);
|
||||
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
||||
if(result == USBD_OK)
|
||||
APP_Tx_ptr_out += length;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// return the bytes free in the circular buffer
|
||||
uint32_t usbSerialFreeSpace()
|
||||
{
|
||||
// functionally equivalent to:
|
||||
//
|
||||
// (APP_Rx_ptr_out > APP_Rx_ptr_in ? APP_Rx_ptr_out - APP_Rx_ptr_in :
|
||||
// APP_RX_DATA_SIZE - APP_Rx_ptr_in + APP_Rx_ptr_in)
|
||||
// (APP_Tx_ptr_out > APP_Tx_ptr_in ? APP_Tx_ptr_out - APP_Tx_ptr_in :
|
||||
// APP_TX_DATA_SIZE - APP_Tx_ptr_in + APP_Tx_ptr_in)
|
||||
//
|
||||
// but without the impact of the condition check.
|
||||
|
||||
return ((APP_Rx_ptr_out - APP_Rx_ptr_in) +
|
||||
(-((int)(APP_Rx_ptr_out <= APP_Rx_ptr_in)) & APP_RX_DATA_SIZE)) -
|
||||
return ((APP_Tx_ptr_out - APP_Tx_ptr_in) +
|
||||
(-((int)(APP_Tx_ptr_out <= APP_Tx_ptr_in)) & APP_TX_DATA_SIZE)) -
|
||||
1;
|
||||
}
|
||||
|
||||
@@ -230,7 +322,7 @@ void usbSerialPutc(void*, uint8_t c)
|
||||
if (!cdcConnected) return;
|
||||
|
||||
/*
|
||||
APP_Rx_Buffer and associated variables must be modified
|
||||
k and associated variables must be modified
|
||||
atomically, because they are used from the interrupt
|
||||
*/
|
||||
|
||||
@@ -240,38 +332,45 @@ void usbSerialPutc(void*, uint8_t c)
|
||||
uint32_t prim = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
|
||||
APP_Rx_Buffer[APP_Rx_ptr_in] = c;
|
||||
APP_Rx_ptr_in = (APP_Rx_ptr_in + 1) % APP_RX_DATA_SIZE;
|
||||
UserTxBufferFS[APP_Tx_ptr_in] = c;
|
||||
APP_Tx_ptr_in = (APP_Tx_ptr_in + 1) % APP_TX_DATA_SIZE;
|
||||
|
||||
if (!prim) __enable_irq();
|
||||
/* USER CODE BEGIN 7 */
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
|
||||
while (hcdc->TxState != 0);
|
||||
/* USER CODE END 7 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VCP_DataRx
|
||||
* Data received over USB OUT endpoint is available here
|
||||
* @brief Data received over USB OUT endpoint are sent over CDC interface
|
||||
* through this function.
|
||||
*
|
||||
* @note
|
||||
* This function will block any OUT packet reception 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.
|
||||
* 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.
|
||||
*
|
||||
* @note
|
||||
* This function is executed inside the USBD_OTG_ISR_Handler() interrupt handler!
|
||||
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
|
||||
static int8_t VCP_Receive_FS(uint8_t* Buf, uint32_t *Len)
|
||||
{
|
||||
auto _rxCb = receiveDataCb;
|
||||
// auto _ctx = receiveDataCbCtx;
|
||||
|
||||
if (_rxCb) _rxCb(/*_ctx,*/ Buf, Len);
|
||||
if (_rxCb) _rxCb(/*_ctx,*/ Buf, *Len);
|
||||
|
||||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
|
||||
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
uint32_t usbSerialBaudRate(void*)
|
||||
{
|
||||
return g_lc.bitrate;
|
||||
|
||||
@@ -0,0 +1,670 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : Target/usbd_conf.c
|
||||
* @version : v1.0_Cube
|
||||
* @brief : This file implements the board support package for the USB device library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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 "stm32_cmsis.h"
|
||||
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "usbd_def.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
#include "usbd_msc.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 --------------------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
|
||||
/* 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)
|
||||
{
|
||||
if(pcdHandle->Instance==USB_OTG_FS)
|
||||
{
|
||||
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
|
||||
|
||||
/* USER CODE END USB_OTG_FS_MspInit 0 */
|
||||
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
|
||||
/* Peripheral interrupt init */
|
||||
NVIC_SetPriority(OTG_FS_IRQn, 11); // Lower priority interrupt
|
||||
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
|
||||
*/
|
||||
// LLL_GPIO_DeInit(GPIOA, USB_GPIO_PIN_DM | USB_GPIO_PIN_DP);
|
||||
|
||||
/* Peripheral interrupt Deinit*/
|
||||
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 = 4;
|
||||
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
|
||||
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
|
||||
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE;
|
||||
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
|
||||
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
|
||||
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
|
||||
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 */
|
||||
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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
static uint32_t mem[(sizeof(USBD_MSC_BOT_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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
@@ -1,76 +1,191 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_conf.h
|
||||
* @version : v1.0_Cube
|
||||
* @brief : Header for usbd_conf.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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_
|
||||
#ifndef __USBD_CONF__H__
|
||||
#define __USBD_CONF__H__
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <inttypes.h>
|
||||
|
||||
#define USBD_CFG_MAX_NUM 1
|
||||
#define USBD_ITF_MAX_NUM 1
|
||||
#define USB_MAX_STR_DESC_SIZ 64
|
||||
|
||||
#define USBD_SELF_POWERED
|
||||
|
||||
/* Class Layer Parameter */
|
||||
|
||||
#define MSC_IN_EP 0x81
|
||||
#define MSC_OUT_EP 0x01
|
||||
#define MSC_MAX_PACKET 64
|
||||
|
||||
// Save some RAM on smaller STM32 processors. Slightly lowers USB mass storage speed
|
||||
#if defined(STM32F2) && !defined(BOOT)
|
||||
#define MSC_MEDIA_PACKET 512
|
||||
#else
|
||||
#define MSC_MEDIA_PACKET 4096
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HID_IN_EP 0x81
|
||||
#define HID_OUT_EP 0x01
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "stm32_cmsis.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
#include "usbd_msc_conf.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.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F2)
|
||||
#define CDC_IN_FRAME_INTERVAL 4 /* Number of frames between IN transfers */
|
||||
#define APP_TX_DATA_SIZE 512 /* Total size of IN buffer: APP_TX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
|
||||
#else
|
||||
#define CDC_IN_FRAME_INTERVAL 15 /* Number of frames between IN transfers */
|
||||
#define APP_TX_DATA_SIZE 2048 /* Total size of IN buffer: APP_TX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
|
||||
#endif
|
||||
|
||||
/*---------- -----------*/
|
||||
#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 0U
|
||||
/*---------- -----------*/
|
||||
#define USBD_SELF_POWERED 1U
|
||||
/*---------- -----------*/
|
||||
#define MSC_MEDIA_PACKET MASS_STORAGE_BUFFER_SIZE
|
||||
|
||||
#if !defined(USBJ_EX)
|
||||
#define HID_IN_PACKET 19
|
||||
#endif
|
||||
#define HID_OUT_PACKET 9
|
||||
|
||||
#define CDC_IN_EP 0x81 /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x01 /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
|
||||
/****************************************/
|
||||
/* #define for FS and HS identification */
|
||||
#define DEVICE_FS 0
|
||||
#define DEVICE_HS 1
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
#define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined(STM32F2)
|
||||
#define CDC_IN_FRAME_INTERVAL 4 /* Number of frames between IN transfers */
|
||||
#define APP_RX_DATA_SIZE 512 /* Total size of IN buffer: APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
|
||||
/** @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 CDC_IN_FRAME_INTERVAL 15 /* Number of frames between IN transfers */
|
||||
#define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer: APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
|
||||
#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);
|
||||
void ErrorHandler(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#define APP_FOPS VCP_fops
|
||||
|
||||
#endif // _USBD_CONF_H_
|
||||
#endif /* __USBD_CONF__H__ */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -1,56 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : App/usbd_desc.c
|
||||
* @version : v1.0_Cube
|
||||
* @brief : This file implements the USB device descriptors.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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_desc.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "board.h"
|
||||
#include "usbd_conf.h"
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_req.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_conf.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
#include "hal/usb_driver.h"
|
||||
#include "usb_descriptor.h"
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
#include "usb_driver.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC
|
||||
* @brief USBD descriptors module
|
||||
/** @addtogroup USBD_DESC
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_TypesDefinitions
|
||||
/** @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
|
||||
/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
|
||||
* @brief Private defines.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@@ -84,53 +93,193 @@
|
||||
#define USBD_CDC_CONFIGURATION_FS_STRING "VSP Config"
|
||||
#define USBD_CDC_INTERFACE_FS_STRING "VSP Interface"
|
||||
|
||||
const USBD_DEVICE USR_desc =
|
||||
{
|
||||
USBD_USR_DeviceDescriptor,
|
||||
USBD_USR_LangIDStrDescriptor,
|
||||
USBD_USR_ManufacturerStrDescriptor,
|
||||
USBD_USR_ProductStrDescriptor,
|
||||
USBD_USR_SerialStrDescriptor,
|
||||
USBD_USR_ConfigStrDescriptor,
|
||||
USBD_USR_InterfaceStrDescriptor,
|
||||
};
|
||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||
|
||||
/* USER CODE END PRIVATE_DEFINES */
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_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,
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_STRING_LANGID,
|
||||
USB_DESC_TYPE_STRING,
|
||||
LOBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ; // modified by OpenTX
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*
|
||||
* @brief USBD_USR_DeviceDescriptor
|
||||
* return the device descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
/** @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);
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#endif /* (USBD_LPM_ENABLED == 1) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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 (USBD_LPM_ENABLED == 1)
|
||||
, USBD_FS_USR_BOSDescriptor
|
||||
#endif /* (USBD_LPM_ENABLED == 1) */
|
||||
};
|
||||
#if 0
|
||||
#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*/
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
0x01, /*bcdUSB */ /* changed to USB version 2.01
|
||||
in order to support LPM L1 suspend
|
||||
resume test of USBCV3.0*/
|
||||
#else
|
||||
0x00, /*bcdUSB */
|
||||
#endif /* (USBD_LPM_ENABLED == 1) */
|
||||
0x02,
|
||||
0x00, /*bDeviceClass*/
|
||||
0x00, /*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*/
|
||||
};
|
||||
#endif
|
||||
/* 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);
|
||||
|
||||
int vid, pid;
|
||||
|
||||
switch (getSelectedUsbMode()) {
|
||||
@@ -155,16 +304,16 @@ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
}
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_DEVICE_DESC, /*bLength */
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
|
||||
USB_LEN_DEV_DESC, /*bLength */
|
||||
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
|
||||
0x00, /*bcdUSB */
|
||||
0x02,
|
||||
0x00, /*bDeviceClass*/
|
||||
0x00, /*bDeviceSubClass*/
|
||||
0x00, /*bDeviceProtocol*/
|
||||
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||
LOBYTE(vid), /*idVendor*/
|
||||
HIBYTE(vid), /*idVendor*/
|
||||
LOBYTE(pid), /*idVendor*/
|
||||
@@ -174,7 +323,7 @@ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
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_CFG_MAX_NUM /*bNumConfigurations*/
|
||||
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
*length = sizeof(USBD_DeviceDesc);
|
||||
@@ -183,28 +332,26 @@ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_LangIDStrDescriptor
|
||||
* 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_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
* @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)
|
||||
{
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
UNUSED(speed);
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
memcpy(USBD_StrDesc, USBD_LangIDDesc, *length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ProductStrDescriptor
|
||||
* 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_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
* @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)
|
||||
{
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
@@ -217,44 +364,42 @@ uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
USBD_GetString ((uint8_t*)USBD_MSC_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ManufacturerStrDescriptor
|
||||
* 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_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
* @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)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
UNUSED(speed);
|
||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_SerialStrDescriptor
|
||||
* 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_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
* @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)
|
||||
{
|
||||
|
||||
USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ConfigStrDescriptor
|
||||
* 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_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
* @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)
|
||||
{
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
@@ -270,15 +415,13 @@ uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_InterfaceStrDescriptor
|
||||
* 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_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
* @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)
|
||||
{
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
@@ -294,4 +437,81 @@ uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
/**
|
||||
* @brief Return the BOS descriptor
|
||||
* @param speed : Current device speed
|
||||
* @param length : Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
*length = sizeof(USBD_FS_BOSDesc);
|
||||
return (uint8_t*)USBD_FS_BOSDesc;
|
||||
}
|
||||
#endif /* (USBD_LPM_ENABLED == 1) */
|
||||
|
||||
/**
|
||||
* @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;
|
||||
// }
|
||||
//}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,115 +1,144 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_desc.c
|
||||
* @version : v1.0_Cube
|
||||
* @brief : Header for usbd_conf.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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__
|
||||
|
||||
#ifndef _USBD_DESC_H_
|
||||
#define _USBD_DESC_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_core.h"
|
||||
#include "usbd_def.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DESC
|
||||
* @brief general defines for the usb device library file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DESC_Exported_Defines
|
||||
/** @defgroup USBD_DESC USBD_DESC
|
||||
* @brief Usb device descriptors module.
|
||||
* @{
|
||||
*/
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
||||
#define USB_SIZ_DEVICE_DESC 18
|
||||
#define USB_SIZ_STRING_LANGID 4
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_TypesDefinitions
|
||||
/** @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_Macros
|
||||
/** @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_Variables
|
||||
/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions
|
||||
* @brief Types.
|
||||
* @{
|
||||
*/
|
||||
extern const uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC];
|
||||
extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ];
|
||||
extern const uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC];
|
||||
extern const uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC];
|
||||
extern const uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID];
|
||||
extern const USBD_DEVICE USR_desc;
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||
|
||||
/* USER CODE END EXPORTED_TYPES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_FunctionsPrototype
|
||||
/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros
|
||||
* @brief Aliases.
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||
|
||||
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_ManufacturerStrDescriptor ( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_ProductStrDescriptor ( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
|
||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
||||
uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length);
|
||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif // _USBD_DESC_H_
|
||||
/* 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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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__ */
|
||||
|
||||
|
||||
@@ -19,79 +19,66 @@
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_hid_core.h"
|
||||
#include "usbd_req.h"
|
||||
#include "usbd_hid.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
#if defined(USBJ_EX)
|
||||
#include "usb_joystick.h"
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID
|
||||
/** @defgroup USBD_HID
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_HID_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_HID_Init (void *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_HID_DeInit (void *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_HID_Setup (void *pdev,
|
||||
USB_SETUP_REQ *req);
|
||||
|
||||
static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
|
||||
|
||||
static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
#if !defined(USBJ_EX)
|
||||
/*
|
||||
This USB HID endpoint report description defines a device with:
|
||||
@@ -149,121 +136,133 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END =
|
||||
|
||||
/** @defgroup USBD_HID_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
const USBD_Class_cb_TypeDef USBD_HID_cb =
|
||||
USBD_ClassTypeDef USBD_HID =
|
||||
{
|
||||
USBD_HID_Init,
|
||||
USBD_HID_DeInit,
|
||||
USBD_HID_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_HID_DataIn, /*DataIn*/
|
||||
NULL, /*DataOut*/
|
||||
NULL, /*SOF */
|
||||
NULL, /* EP0_TxSent */
|
||||
NULL, /* EP0_RxReady */
|
||||
USBD_HID_DataIn, /* DataIn */
|
||||
NULL, /* DataOut */
|
||||
NULL, /* SOF */
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_HID_GetCfgDesc,
|
||||
#ifdef USB_OTG_HS_CORE
|
||||
USBD_HID_GetCfgDesc, /* use same config as per FS */
|
||||
#endif
|
||||
NULL,
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
#else
|
||||
USBD_HID_GetHSCfgDesc,
|
||||
USBD_HID_GetFSCfgDesc,
|
||||
USBD_HID_GetOtherSpeedCfgDesc,
|
||||
USBD_HID_GetDeviceQualifierDesc,
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
};
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
__ALIGN_BEGIN static uint32_t USBD_HID_AltSet __ALIGN_END = 0;
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
__ALIGN_BEGIN static uint32_t USBD_HID_Protocol __ALIGN_END = 0;
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
__ALIGN_BEGIN static uint32_t USBD_HID_IdleState __ALIGN_END = 0;
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
/* USB HID device Configuration Descriptor */
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/* USB HID device FS Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
||||
USB_HID_CONFIG_DESC_SIZ,
|
||||
/* wTotalLength: Bytes returned */
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||
0x00,
|
||||
0x01, /*bNumInterfaces: 1 interface*/
|
||||
0x01, /*bConfigurationValue: Configuration value*/
|
||||
0x00, /*iConfiguration: Index of string descriptor describing
|
||||
the configuration*/
|
||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor
|
||||
describing the configuration */
|
||||
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||
|
||||
/************** Descriptor of Joystick Mouse interface ****************/
|
||||
/* 09 */
|
||||
0x09, /*bLength: Interface Descriptor size*/
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
|
||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
||||
0x00, /*bAlternateSetting: Alternate setting*/
|
||||
0x01, /*bNumEndpoints*/
|
||||
0x03, /*bInterfaceClass: HID*/
|
||||
0x00 /*0x01*/, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
||||
0x00 /*0x02*/, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
||||
0, /*iInterface: Index of string descriptor*/
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints */
|
||||
0x03, /* bInterfaceClass: HID */
|
||||
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||
/* 18 */
|
||||
0x09, /*bLength: HID Descriptor size*/
|
||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
||||
0x11, /*bcdHID: HID Class Spec release number*/
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /*bCountryCode: Hardware target country*/
|
||||
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
|
||||
0x22, /*bDescriptorType*/
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
#if !defined(USBJ_EX)
|
||||
sizeof(HID_JOYSTICK_ReportDesc),/*wItemLength: Total length of Report descriptor*/
|
||||
sizeof(HID_JOYSTICK_ReportDesc), /*wItemLength: Total length of Report descriptor*/
|
||||
#else
|
||||
0,/*wItemLength: Total length of Report descriptor*/
|
||||
0, /*wItemLength: Total length of Report descriptor*/
|
||||
#endif
|
||||
0x00,
|
||||
/******************** Descriptor of Mouse endpoint ********************/
|
||||
/* 27 */
|
||||
0x07, /*bLength: Endpoint Descriptor size*/
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
|
||||
|
||||
HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/
|
||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
||||
HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
#if !defined(USBJ_EX)
|
||||
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
|
||||
HID_EPIN_SIZE, /*wMaxPacketSize: 4 Byte max */
|
||||
#else
|
||||
0,/*HID_IN_PACKET,*/ /*wMaxPacketSize*/
|
||||
0, /*HID_IN_PACKET,*/ /*wMaxPacketSize*/
|
||||
#endif
|
||||
0x00,
|
||||
0x01, /*bInterval: Polling Interval (1 ms)*/
|
||||
0x01, /*bInterval: Polling Interval (1 ms)*/
|
||||
/* 34 */
|
||||
} ;
|
||||
};
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* USB HID device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* 18 */
|
||||
0x09, /* bLength: HID Descriptor size */
|
||||
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
||||
0x11, /* bcdHID: HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||
0x00,
|
||||
};
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_HID_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 */
|
||||
|
||||
static uint8_t ReportSent;
|
||||
static uint8_t HIDInEpAdd = HID_EPIN_ADDR;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_HID_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_Init
|
||||
@@ -272,49 +271,80 @@ static uint8_t ReportSent;
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Init (void *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
#if defined(USBJ_EX)
|
||||
uint8_t hid_in_pkt_size = usbReportSize();
|
||||
#else
|
||||
uint8_t hid_in_pkt_size = HID_EPIN_SIZE;
|
||||
#endif
|
||||
|
||||
USBD_HID_HandleTypeDef *hhid;
|
||||
|
||||
hhid = (USBD_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
pdev->pClassDataCmsit[pdev->classId] = (void *)hhid;
|
||||
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pdev->ep_in[HIDInEpAdd & 0xFU].bInterval = 1;
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
pdev->ep_in[HIDInEpAdd & 0xFU].bInterval = 1;
|
||||
}
|
||||
|
||||
/* Open EP IN */
|
||||
DCD_EP_Open(pdev,
|
||||
HID_IN_EP,
|
||||
#if !defined(USBJ_EX)
|
||||
HID_IN_PACKET,
|
||||
#else
|
||||
hid_in_pkt_size /*HID_IN_PACKET*/,
|
||||
#endif
|
||||
USB_OTG_EP_INT);
|
||||
|
||||
/* Open EP OUT */
|
||||
DCD_EP_Open(pdev,
|
||||
HID_OUT_EP,
|
||||
HID_OUT_PACKET,
|
||||
USB_OTG_EP_INT);
|
||||
(void)USBD_LL_OpenEP(pdev, HIDInEpAdd, USBD_EP_TYPE_INTR, hid_in_pkt_size);
|
||||
pdev->ep_in[HIDInEpAdd & 0xFU].is_used = 1U;
|
||||
|
||||
ReportSent = 1;
|
||||
return USBD_OK;
|
||||
hhid->state = HID_IDLE;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_Init
|
||||
* @brief USBD_HID_DeInit
|
||||
* DeInitialize the HID layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DeInit (void *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* Close HID EPs */
|
||||
DCD_EP_Close (pdev , HID_IN_EP);
|
||||
DCD_EP_Close (pdev , HID_OUT_EP);
|
||||
|
||||
ReportSent = 1;
|
||||
return USBD_OK;
|
||||
(void)USBD_LL_CloseEP(pdev, HIDInEpAdd);
|
||||
pdev->ep_in[HIDInEpAdd & 0xFU].is_used = 0U;
|
||||
pdev->ep_in[HIDInEpAdd & 0xFU].bInterval = 0U;
|
||||
|
||||
/* Free allocated memory */
|
||||
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||
{
|
||||
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,164 +354,316 @@ static uint8_t USBD_HID_DeInit (void *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Setup (void *pdev,
|
||||
USB_SETUP_REQ *req)
|
||||
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
const uint8_t *pbuf = NULL;
|
||||
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t len;
|
||||
uint8_t *pbuf;
|
||||
uint16_t status_info = 0U;
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
|
||||
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
USBD_HID_Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&USBD_HID_Protocol,
|
||||
1);
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_IDLE:
|
||||
USBD_HID_IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&USBD_HID_IdleState,
|
||||
1);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
return USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( req->wValue >> 8 == HID_REPORT_DESC)
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
#if !defined(USBJ_EX)
|
||||
len = MIN(sizeof(HID_JOYSTICK_ReportDesc) , req->wLength);
|
||||
pbuf = HID_JOYSTICK_ReportDesc; // wiiccReportDescriptor; //
|
||||
#else
|
||||
struct usbReport_t ret = usbReportDesc();
|
||||
len = MIN(ret.size, req->wLength);
|
||||
pbuf = ret.ptr;
|
||||
#endif
|
||||
}
|
||||
else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
pbuf = USBD_HID_Desc;
|
||||
#else
|
||||
pbuf = USBD_HID_CfgDesc + 0x12;
|
||||
#endif
|
||||
len = MIN(USB_HID_DESC_SIZ , req->wLength);
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
pbuf,
|
||||
len);
|
||||
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&USBD_HID_AltSet,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
USBD_HID_AltSet = (uint8_t)(req->wValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
hhid->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_IDLE:
|
||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_IDLE:
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
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_DESCRIPTOR:
|
||||
if ((req->wValue >> 8) == HID_REPORT_DESC)
|
||||
{
|
||||
#if !defined(USBJ_EX)
|
||||
len = MIN(sizeof(HID_JOYSTICK_ReportDesc) , req->wLength);
|
||||
pbuf = (uint8_t*)HID_JOYSTICK_ReportDesc; // wiiccReportDescriptor; //
|
||||
#else
|
||||
struct usbReport_t ret = usbReportDesc();
|
||||
len = MIN(ret.size, req->wLength);
|
||||
pbuf = ret.ptr;
|
||||
#endif
|
||||
}
|
||||
else if ((req->wValue >> 8) == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_HID_Desc;
|
||||
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
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_HID_SendReport
|
||||
* Send HID Report if TX buffer is free and USB device is configured.
|
||||
* Send HID Report
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to report, if this parameter is NULL then function just test if new buffer can be sent
|
||||
* @param buff: pointer to report
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_HID_SendReport(USB_OTG_CORE_HANDLE *pdev, uint8_t * report, uint16_t len)
|
||||
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
if (pdev->dev.device_status == USB_OTG_CONFIGURED) {
|
||||
if (ReportSent) {
|
||||
if (report) {
|
||||
ReportSent = 0;
|
||||
DCD_EP_Tx (pdev, HID_IN_EP, report, len);
|
||||
}
|
||||
return USBD_OK;
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (hhid->state == HID_IDLE)
|
||||
{
|
||||
hhid->state = HID_BUSY;
|
||||
(void)USBD_LL_Transmit(pdev, HIDInEpAdd, report, len);
|
||||
} else {
|
||||
return (uint8_t)USBD_BUSY;
|
||||
}
|
||||
}
|
||||
return USBD_FAIL;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @brief USBD_HID_GetPollingInterval
|
||||
* return polling interval from endpoint descriptor
|
||||
* @param pdev: device instance
|
||||
* @retval polling interval
|
||||
*/
|
||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint32_t polling_interval;
|
||||
#if 0
|
||||
/* HIGH-speed endpoints */
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Sets the data transfer polling interval for high speed transfers.
|
||||
Values between 1..16 are allowed. Values correspond to interval
|
||||
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
||||
polling_interval = (((1U << (HID_HS_BINTERVAL - 1U))) / 8U);
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
/* Sets the data transfer polling interval for low and full
|
||||
speed transfers */
|
||||
polling_interval = HID_FS_BINTERVAL;
|
||||
}
|
||||
#else
|
||||
polling_interval = 1;
|
||||
#endif
|
||||
return ((uint32_t)(polling_interval));
|
||||
}
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/**
|
||||
* @brief USBD_HID_GetCfgFSDesc
|
||||
* return FS configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_HID_CfgDesc, HID_EPIN_ADDR);
|
||||
|
||||
if (pEpDesc != NULL)
|
||||
{
|
||||
pEpDesc->bInterval = 1;
|
||||
}
|
||||
|
||||
#if defined(USBJ_EX)
|
||||
struct usbReport_t ret = usbReportDesc();
|
||||
USBD_HID_CfgDesc[25] = ret.size;
|
||||
USBD_HID_CfgDesc[31] = usbReportSize();
|
||||
#endif
|
||||
|
||||
*length = sizeof (USBD_HID_CfgDesc);
|
||||
*length = (uint16_t)sizeof(USBD_HID_CfgDesc);
|
||||
return USBD_HID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_GetCfgHSDesc
|
||||
* return HS configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_HID_CfgDesc, HID_EPIN_ADDR);
|
||||
|
||||
if (pEpDesc != NULL)
|
||||
{
|
||||
pEpDesc->bInterval = 1;
|
||||
}
|
||||
|
||||
#if defined(USBJ_EX)
|
||||
struct usbReport_t ret = usbReportDesc();
|
||||
USBD_HID_CfgDesc[25] = ret.size;
|
||||
USBD_HID_CfgDesc[31] = usbReportSize();
|
||||
#endif
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_HID_CfgDesc);
|
||||
return USBD_HID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_GetOtherSpeedCfgDesc
|
||||
* return other speed configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_HID_CfgDesc, HID_EPIN_ADDR);
|
||||
|
||||
if (pEpDesc != NULL)
|
||||
{
|
||||
pEpDesc->bInterval = 1;
|
||||
}
|
||||
#if defined(USBJ_EX)
|
||||
struct usbReport_t ret = usbReportDesc();
|
||||
USBD_HID_CfgDesc[25] = ret.size;
|
||||
USBD_HID_CfgDesc[31] = usbReportSize();
|
||||
#endif
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_HID_CfgDesc);
|
||||
return USBD_HID_CfgDesc;
|
||||
}
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
|
||||
This function is called when buffer has been sent over the USB.
|
||||
The TX buffer is now empty and can be filled with new data.
|
||||
*/
|
||||
static uint8_t USBD_HID_DataIn (void *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
ReportSent = 1;
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
UNUSED(epnum);
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
be caused by a new transfer before the end of the previous transfer */
|
||||
DCD_EP_Flush(pdev, HID_IN_EP);
|
||||
return USBD_OK;
|
||||
((USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = HID_IDLE;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_HID_DeviceQualifierDesc);
|
||||
|
||||
return USBD_HID_DeviceQualifierDesc;
|
||||
}
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define MASS_STORAGE_BUFFER_SIZE 512U
|
||||
@@ -21,13 +21,20 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usbd_def.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#include "hal/fatfs_diskio.h"
|
||||
#include "hal/storage.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "fw_version.h"
|
||||
#include "board.h"
|
||||
#include "hal.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "usbd_storage_msd.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -44,11 +51,9 @@
|
||||
#define WATCHDOG_SUSPEND(...)
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
#if !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usbd_msc_mem.h"
|
||||
#include "usb_conf.h"
|
||||
|
||||
enum MassstorageLuns {
|
||||
@@ -59,14 +64,21 @@ enum MassstorageLuns {
|
||||
STORAGE_LUN_NBR
|
||||
};
|
||||
|
||||
/* USB Mass storage Standard Inquiry Data */
|
||||
const unsigned char STORAGE_Inquirydata[] = {
|
||||
|
||||
// TODO: remove hack
|
||||
#define USB_NAME "RM TX16S"
|
||||
#define USB_MANUFACTURER 'R', 'M', '_', 'T', 'X', ' ', ' ', ' ' /* 8 bytes */
|
||||
#define USB_PRODUCT 'R', 'M', ' ', 'T', 'X', '1', '6', 'S' /* 8 Bytes */
|
||||
|
||||
|
||||
/** USB Mass storage Standard Inquiry Data. */
|
||||
const uint8_t STORAGE_Inquirydata_FS[] = {/* 36 */
|
||||
/* LUN 0 */
|
||||
0x00,
|
||||
0x80,
|
||||
0x02,
|
||||
0x02,
|
||||
(USBD_STD_INQUIRY_LENGTH - 5),
|
||||
(STANDARD_INQUIRY_DATA_LEN - 5),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -100,59 +112,45 @@ const unsigned char STORAGE_Inquirydata[] = {
|
||||
|
||||
int8_t STORAGE_Init (uint8_t lun);
|
||||
|
||||
int8_t STORAGE_GetCapacity (uint8_t lun,
|
||||
uint32_t *block_num,
|
||||
uint32_t *block_size);
|
||||
static int8_t STORAGE_Init_FS(uint8_t lun);
|
||||
static int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
||||
|
||||
int8_t STORAGE_IsReady (uint8_t lun);
|
||||
static int8_t STORAGE_IsReady_FS(uint8_t lun);
|
||||
|
||||
int8_t STORAGE_IsWriteProtected (uint8_t lun);
|
||||
static int8_t STORAGE_IsWriteProtected_FS(uint8_t lun);
|
||||
static int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||
static int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||
static int8_t STORAGE_GetMaxLun_FS(void);
|
||||
|
||||
int8_t STORAGE_Read (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
int8_t STORAGE_Write (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
|
||||
int8_t STORAGE_GetMaxLun (void);
|
||||
|
||||
const USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops =
|
||||
USBD_StorageTypeDef USBD_Storage_Interface_fops_FS =
|
||||
{
|
||||
STORAGE_Init,
|
||||
STORAGE_GetCapacity,
|
||||
STORAGE_IsReady,
|
||||
STORAGE_IsWriteProtected,
|
||||
STORAGE_Read,
|
||||
STORAGE_Write,
|
||||
STORAGE_GetMaxLun,
|
||||
(int8_t *)STORAGE_Inquirydata,
|
||||
STORAGE_Init_FS,
|
||||
STORAGE_GetCapacity_FS,
|
||||
STORAGE_IsReady_FS,
|
||||
STORAGE_IsWriteProtected_FS,
|
||||
STORAGE_Read_FS,
|
||||
STORAGE_Write_FS,
|
||||
STORAGE_GetMaxLun_FS,
|
||||
(int8_t *)STORAGE_Inquirydata_FS
|
||||
};
|
||||
|
||||
const USBD_STORAGE_cb_TypeDef * const USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops;
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
int8_t STORAGE_Init (uint8_t lun)
|
||||
int8_t STORAGE_Init_FS(uint8_t lun)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
NVIC_SetPriority(SDIO_IRQn, 0);
|
||||
NVIC_EnableIRQ(SDIO_IRQn);
|
||||
|
||||
/* TODO if no SD ... if( SD_Init() != 0)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
*/
|
||||
return (0);
|
||||
return (USBD_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +160,7 @@ int8_t STORAGE_Init (uint8_t lun)
|
||||
* @param block_size : size of a physical block
|
||||
* @retval Status
|
||||
*/
|
||||
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||
{
|
||||
#if defined(FWDRIVE)
|
||||
if (lun == STORAGE_EEPROM_LUN) {
|
||||
@@ -177,7 +175,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
|
||||
#endif
|
||||
|
||||
if (!SD_CARD_PRESENT())
|
||||
return -1;
|
||||
return USBD_FAIL;
|
||||
|
||||
*block_size = BLOCK_SIZE;
|
||||
|
||||
@@ -186,12 +184,12 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
|
||||
auto drv = storageGetDefaultDriver();
|
||||
if (drv->ioctl(0, GET_SECTOR_COUNT, §or_count) != RES_OK) {
|
||||
sector_count = 0;
|
||||
return -1;
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
*block_num = sector_count;
|
||||
return 0;
|
||||
return (USBD_OK);
|
||||
}
|
||||
|
||||
uint8_t lunReady[STORAGE_LUN_NBR];
|
||||
@@ -209,14 +207,14 @@ void usbInitLUNs()
|
||||
* @param lun : logical unit number
|
||||
* @retval Status
|
||||
*/
|
||||
int8_t STORAGE_IsReady (uint8_t lun)
|
||||
int8_t STORAGE_IsReady_FS(uint8_t lun)
|
||||
{
|
||||
#if defined(FWDRIVE) && defined(EEPROM)
|
||||
if (lun == STORAGE_EEPROM_LUN) {
|
||||
return (lunReady[STORAGE_EEPROM_LUN] != 0) ? 0 : -1;
|
||||
}
|
||||
#endif
|
||||
return (lunReady[STORAGE_SDCARD_LUN] != 0 && storageIsPresent()) ? 0 : -1;
|
||||
return (lunReady[STORAGE_SDCARD_LUN] != 0 && storageIsPresent()) ? USBD_OK : USBD_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,9 +222,9 @@ int8_t STORAGE_IsReady (uint8_t lun)
|
||||
* @param lun : logical unit number
|
||||
* @retval Status
|
||||
*/
|
||||
int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
||||
int8_t STORAGE_IsWriteProtected_FS(uint8_t lun)
|
||||
{
|
||||
return 0;
|
||||
return (USBD_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +236,7 @@ int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
||||
* @retval Status
|
||||
*/
|
||||
|
||||
int8_t STORAGE_Read (uint8_t lun,
|
||||
int8_t STORAGE_Read_FS (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len)
|
||||
@@ -252,7 +250,7 @@ int8_t STORAGE_Read (uint8_t lun,
|
||||
#endif
|
||||
|
||||
auto drv = storageGetDefaultDriver();
|
||||
return (drv->read(0, buf, blk_addr, blk_len) == RES_OK) ? 0 : -1;
|
||||
return (drv->read(0, buf, blk_addr, blk_len) == RES_OK) ? USBD_OK : USBD_FAIL;
|
||||
}
|
||||
/**
|
||||
* @brief Write data to the medium
|
||||
@@ -262,11 +260,7 @@ int8_t STORAGE_Read (uint8_t lun,
|
||||
* @param blk_len : nmber of blocks to be read
|
||||
* @retval Status
|
||||
*/
|
||||
|
||||
int8_t STORAGE_Write (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len)
|
||||
int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
|
||||
{
|
||||
WATCHDOG_SUSPEND(100/*1s*/);
|
||||
|
||||
@@ -277,7 +271,7 @@ int8_t STORAGE_Write (uint8_t lun,
|
||||
#endif
|
||||
|
||||
auto drv = storageGetDefaultDriver();
|
||||
return (drv->write(0, buf, blk_addr, blk_len) == RES_OK) ? 0 : -1;
|
||||
return (drv->write(0, buf, blk_addr, blk_len) == RES_OK) ? USBD_OK : USBD_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,9 +280,9 @@ int8_t STORAGE_Write (uint8_t lun,
|
||||
* @retval number of logical unit
|
||||
*/
|
||||
|
||||
int8_t STORAGE_GetMaxLun (void)
|
||||
int8_t STORAGE_GetMaxLun_FS(void)
|
||||
{
|
||||
return STORAGE_LUN_NBR - 1;
|
||||
return (STORAGE_LUN_NBR - 1);
|
||||
}
|
||||
|
||||
#if defined(FWDRIVE)
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usbd_storage_if.h
|
||||
* @version : v1.0_Cube
|
||||
* @brief : Header for usbd_storage_if.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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_STORAGE_IF_H__
|
||||
#define __USBD_STORAGE_IF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @brief For Usb device.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_STORAGE USBD_STORAGE
|
||||
* @brief Header file for the usb_storage_if.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_STORAGE_Exported_Defines USBD_STORAGE_Exported_Defines
|
||||
* @brief Defines.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||
|
||||
/* USER CODE END EXPORTED_DEFINES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_STORAGE_Exported_Types USBD_STORAGE_Exported_Types
|
||||
* @brief Types.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||
|
||||
/* USER CODE END EXPORTED_TYPES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_STORAGE_Exported_Macros USBD_STORAGE_Exported_Macros
|
||||
* @brief Aliases.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||
|
||||
/* USER CODE END EXPORTED_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_STORAGE_Exported_Variables USBD_STORAGE_Exported_Variables
|
||||
* @brief Public variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** STORAGE Interface callback. */
|
||||
extern USBD_StorageTypeDef USBD_Storage_Interface_fops_FS;
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_STORAGE_Exported_FunctionsPrototype USBD_STORAGE_Exported_FunctionsPrototype
|
||||
* @brief Public functions declaration.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||
|
||||
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_STORAGE_IF_H__ */
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
extern "C" {
|
||||
#include "usbd_usr.h"
|
||||
|
||||
/* Points to the DEVICE_PROP structure of current device */
|
||||
/* The purpose of this register is to speed up the execution */
|
||||
|
||||
|
||||
const USBD_Usr_cb_TypeDef USR_cb =
|
||||
{
|
||||
USBD_USR_Init,
|
||||
USBD_USR_DeviceReset,
|
||||
USBD_USR_DeviceConfigured,
|
||||
USBD_USR_DeviceSuspended,
|
||||
USBD_USR_DeviceResumed,
|
||||
|
||||
USBD_USR_DeviceConnected,
|
||||
USBD_USR_DeviceDisconnected,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Whatever the user application needs to do when USB is initialised
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Displays the message on LCD on device reset event
|
||||
* @param speed : device speed
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_DeviceReset (uint8_t speed)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Displays the message on LCD on device config event
|
||||
* @param None
|
||||
* @retval Staus
|
||||
*/
|
||||
void USBD_USR_DeviceConfigured (void)
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Displays the message on LCD on device suspend event
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_DeviceSuspended(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Displays the message on LCD on device resume event
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_DeviceResumed(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_DeviceConnected
|
||||
* Displays the message on LCD on device connection Event
|
||||
* @param None
|
||||
* @retval Staus
|
||||
*/
|
||||
void USBD_USR_DeviceConnected (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_DeviceDisonnected
|
||||
* Displays the message on LCD on device disconnection Event
|
||||
* @param None
|
||||
* @retval Staus
|
||||
*/
|
||||
void USBD_USR_DeviceDisconnected (void)
|
||||
{
|
||||
#if !defined(BOOT) && defined(EEPROM)
|
||||
// TODO is it really needed if we didn't write the EEPROM?
|
||||
// if (getSelectedUsbMode() == USB_MASS_STORAGE_MODE)
|
||||
// NVIC_SystemReset();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user