diff --git a/.mxproject b/.mxproject deleted file mode 100644 index eb88349..0000000 --- a/.mxproject +++ /dev/null @@ -1,65 +0,0 @@ -[PreviousLibFiles] -LibFiles=Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pcd.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pcd_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_usb.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_bus.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_system.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_utils.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ramfunc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dmamux.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal.h;Drivers\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_def.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_sdmmc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_sd.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_uart.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_usart.h;Middlewares\Third_Party\FreeRTOS\Source\include\croutine.h;Middlewares\Third_Party\FreeRTOS\Source\include\deprecated_definitions.h;Middlewares\Third_Party\FreeRTOS\Source\include\event_groups.h;Middlewares\Third_Party\FreeRTOS\Source\include\FreeRTOS.h;Middlewares\Third_Party\FreeRTOS\Source\include\list.h;Middlewares\Third_Party\FreeRTOS\Source\include\message_buffer.h;Middlewares\Third_Party\FreeRTOS\Source\include\mpu_prototypes.h;Middlewares\Third_Party\FreeRTOS\Source\include\mpu_wrappers.h;Middlewares\Third_Party\FreeRTOS\Source\include\portable.h;Middlewares\Third_Party\FreeRTOS\Source\include\projdefs.h;Middlewares\Third_Party\FreeRTOS\Source\include\queue.h;Middlewares\Third_Party\FreeRTOS\Source\include\semphr.h;Middlewares\Third_Party\FreeRTOS\Source\include\stack_macros.h;Middlewares\Third_Party\FreeRTOS\Source\include\StackMacros.h;Middlewares\Third_Party\FreeRTOS\Source\include\stream_buffer.h;Middlewares\Third_Party\FreeRTOS\Source\include\task.h;Middlewares\Third_Party\FreeRTOS\Source\include\timers.h;Middlewares\Third_Party\FreeRTOS\Source\include\atomic.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os2.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\freertos_mpool.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\freertos_os2.h;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\portmacro.h;Middlewares\Third_Party\FatFs\src\diskio.h;Middlewares\Third_Party\FatFs\src\ff.h;Middlewares\Third_Party\FatFs\src\ff_gen_drv.h;Middlewares\Third_Party\FatFs\src\integer.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_core.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_ctlreq.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_def.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_ioreq.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc_bot.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc_data.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc_scsi.h;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pcd.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pcd_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_usb.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_sdmmc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_sd.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c;Middlewares\Third_Party\FreeRTOS\Source\croutine.c;Middlewares\Third_Party\FreeRTOS\Source\event_groups.c;Middlewares\Third_Party\FreeRTOS\Source\list.c;Middlewares\Third_Party\FreeRTOS\Source\queue.c;Middlewares\Third_Party\FreeRTOS\Source\stream_buffer.c;Middlewares\Third_Party\FreeRTOS\Source\tasks.c;Middlewares\Third_Party\FreeRTOS\Source\timers.c;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os2.c;Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\port.c;Middlewares\Third_Party\FatFs\src\diskio.c;Middlewares\Third_Party\FatFs\src\ff.c;Middlewares\Third_Party\FatFs\src\ff_gen_drv.c;Middlewares\Third_Party\FatFs\src\option\syscall.c;Middlewares\Third_Party\FatFs\src\option\cc936.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_core.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ctlreq.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ioreq.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_bot.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_data.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_scsi.c;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pcd.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pcd_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_usb.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_bus.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_system.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_utils.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ramfunc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dmamux.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal.h;Drivers\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_def.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_sdmmc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_sd.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_uart.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_usart.h;Middlewares\Third_Party\FreeRTOS\Source\include\croutine.h;Middlewares\Third_Party\FreeRTOS\Source\include\deprecated_definitions.h;Middlewares\Third_Party\FreeRTOS\Source\include\event_groups.h;Middlewares\Third_Party\FreeRTOS\Source\include\FreeRTOS.h;Middlewares\Third_Party\FreeRTOS\Source\include\list.h;Middlewares\Third_Party\FreeRTOS\Source\include\message_buffer.h;Middlewares\Third_Party\FreeRTOS\Source\include\mpu_prototypes.h;Middlewares\Third_Party\FreeRTOS\Source\include\mpu_wrappers.h;Middlewares\Third_Party\FreeRTOS\Source\include\portable.h;Middlewares\Third_Party\FreeRTOS\Source\include\projdefs.h;Middlewares\Third_Party\FreeRTOS\Source\include\queue.h;Middlewares\Third_Party\FreeRTOS\Source\include\semphr.h;Middlewares\Third_Party\FreeRTOS\Source\include\stack_macros.h;Middlewares\Third_Party\FreeRTOS\Source\include\StackMacros.h;Middlewares\Third_Party\FreeRTOS\Source\include\stream_buffer.h;Middlewares\Third_Party\FreeRTOS\Source\include\task.h;Middlewares\Third_Party\FreeRTOS\Source\include\timers.h;Middlewares\Third_Party\FreeRTOS\Source\include\atomic.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os2.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\freertos_mpool.h;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\freertos_os2.h;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\portmacro.h;Middlewares\Third_Party\FatFs\src\diskio.h;Middlewares\Third_Party\FatFs\src\ff.h;Middlewares\Third_Party\FatFs\src\ff_gen_drv.h;Middlewares\Third_Party\FatFs\src\integer.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_core.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_ctlreq.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_def.h;Middlewares\ST\STM32_USB_Device_Library\Core\Inc\usbd_ioreq.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc_bot.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc_data.h;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc\usbd_msc_scsi.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f407xx.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f4xx.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\system_stm32f4xx.h;Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; - -[PreviousUsedMakefileFiles] -SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\freertos.c;Core\Src\dma.c;FATFS\Target\bsp_driver_sd.c;FATFS\Target\sd_diskio.c;FATFS\App\fatfs.c;FATFS\Target\fatfs_platform.c;Core\Src\i2c.c;Core\Src\sdio.c;Core\Src\tim.c;Core\Src\usart.c;USB_DEVICE\App\usb_device.c;USB_DEVICE\Target\usbd_conf.c;USB_DEVICE\App\usbd_desc.c;USB_DEVICE\App\usbd_storage_if.c;Core\Src\stm32f4xx_it.c;Core\Src\stm32f4xx_hal_msp.c;Core\Src\stm32f4xx_hal_timebase_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pcd.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pcd_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_usb.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_sdmmc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_sd.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c;Middlewares\Third_Party\FreeRTOS\Source\croutine.c;Middlewares\Third_Party\FreeRTOS\Source\event_groups.c;Middlewares\Third_Party\FreeRTOS\Source\list.c;Middlewares\Third_Party\FreeRTOS\Source\queue.c;Middlewares\Third_Party\FreeRTOS\Source\stream_buffer.c;Middlewares\Third_Party\FreeRTOS\Source\tasks.c;Middlewares\Third_Party\FreeRTOS\Source\timers.c;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os2.c;Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\port.c;Middlewares\Third_Party\FatFs\src\diskio.c;Middlewares\Third_Party\FatFs\src\ff.c;Middlewares\Third_Party\FatFs\src\ff_gen_drv.c;Middlewares\Third_Party\FatFs\src\option\syscall.c;Middlewares\Third_Party\FatFs\src\option\cc936.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_core.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ctlreq.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ioreq.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_bot.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_data.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_scsi.c;Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c;Core\Src\system_stm32f4xx.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pcd.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pcd_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_usb.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_sdmmc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_sd.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c;Middlewares\Third_Party\FreeRTOS\Source\croutine.c;Middlewares\Third_Party\FreeRTOS\Source\event_groups.c;Middlewares\Third_Party\FreeRTOS\Source\list.c;Middlewares\Third_Party\FreeRTOS\Source\queue.c;Middlewares\Third_Party\FreeRTOS\Source\stream_buffer.c;Middlewares\Third_Party\FreeRTOS\Source\tasks.c;Middlewares\Third_Party\FreeRTOS\Source\timers.c;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os2.c;Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\port.c;Middlewares\Third_Party\FatFs\src\diskio.c;Middlewares\Third_Party\FatFs\src\ff.c;Middlewares\Third_Party\FatFs\src\ff_gen_drv.c;Middlewares\Third_Party\FatFs\src\option\syscall.c;Middlewares\Third_Party\FatFs\src\option\cc936.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_core.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ctlreq.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ioreq.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_bot.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_data.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_scsi.c;Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c;Core\Src\system_stm32f4xx.c;;;Middlewares\Third_Party\FatFs\src\diskio.c;Middlewares\Third_Party\FatFs\src\ff.c;Middlewares\Third_Party\FatFs\src\ff_gen_drv.c;Middlewares\Third_Party\FatFs\src\option\syscall.c;Middlewares\Third_Party\FatFs\src\option\cc936.c;Middlewares\Third_Party\FreeRTOS\Source\croutine.c;Middlewares\Third_Party\FreeRTOS\Source\event_groups.c;Middlewares\Third_Party\FreeRTOS\Source\list.c;Middlewares\Third_Party\FreeRTOS\Source\queue.c;Middlewares\Third_Party\FreeRTOS\Source\stream_buffer.c;Middlewares\Third_Party\FreeRTOS\Source\tasks.c;Middlewares\Third_Party\FreeRTOS\Source\timers.c;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2\cmsis_os2.c;Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\heap_4.c;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F\port.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_core.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ctlreq.c;Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_ioreq.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_bot.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_data.c;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Src\usbd_msc_scsi.c; -HeaderPath=Drivers\STM32F4xx_HAL_Driver\Inc;Drivers\STM32F4xx_HAL_Driver\Inc\Legacy;Middlewares\Third_Party\FreeRTOS\Source\include;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS_V2;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F;Middlewares\Third_Party\FatFs\src;Middlewares\ST\STM32_USB_Device_Library\Core\Inc;Middlewares\ST\STM32_USB_Device_Library\Class\MSC\Inc;Drivers\CMSIS\Device\ST\STM32F4xx\Include;Drivers\CMSIS\Include;Core\Inc;FATFS\Target;FATFS\App;USB_DEVICE\App;USB_DEVICE\Target; -CDefines=USE_HAL_DRIVER;STM32F407xx;USE_HAL_DRIVER;USE_HAL_DRIVER; - -[PreviousGenFiles] -AdvancedFolderStructure=true -HeaderFileListSize=19 -HeaderFiles#0=..\Core\Inc\gpio.h -HeaderFiles#1=..\Core\Inc\FreeRTOSConfig.h -HeaderFiles#2=..\Core\Inc\dma.h -HeaderFiles#3=..\FATFS\Target\ffconf.h -HeaderFiles#4=..\FATFS\Target\bsp_driver_sd.h -HeaderFiles#5=..\FATFS\Target\sd_diskio.h -HeaderFiles#6=..\FATFS\App\fatfs.h -HeaderFiles#7=..\FATFS\Target\fatfs_platform.h -HeaderFiles#8=..\Core\Inc\i2c.h -HeaderFiles#9=..\Core\Inc\sdio.h -HeaderFiles#10=..\Core\Inc\tim.h -HeaderFiles#11=..\Core\Inc\usart.h -HeaderFiles#12=..\USB_DEVICE\App\usb_device.h -HeaderFiles#13=..\USB_DEVICE\Target\usbd_conf.h -HeaderFiles#14=..\USB_DEVICE\App\usbd_desc.h -HeaderFiles#15=..\USB_DEVICE\App\usbd_storage_if.h -HeaderFiles#16=..\Core\Inc\stm32f4xx_it.h -HeaderFiles#17=..\Core\Inc\stm32f4xx_hal_conf.h -HeaderFiles#18=..\Core\Inc\main.h -HeaderFolderListSize=5 -HeaderPath#0=..\Core\Inc -HeaderPath#1=..\FATFS\Target -HeaderPath#2=..\FATFS\App -HeaderPath#3=..\USB_DEVICE\App -HeaderPath#4=..\USB_DEVICE\Target -HeaderFiles=; -SourceFileListSize=19 -SourceFiles#0=..\Core\Src\gpio.c -SourceFiles#1=..\Core\Src\freertos.c -SourceFiles#2=..\Core\Src\dma.c -SourceFiles#3=..\FATFS\Target\bsp_driver_sd.c -SourceFiles#4=..\FATFS\Target\sd_diskio.c -SourceFiles#5=..\FATFS\App\fatfs.c -SourceFiles#6=..\FATFS\Target\fatfs_platform.c -SourceFiles#7=..\Core\Src\i2c.c -SourceFiles#8=..\Core\Src\sdio.c -SourceFiles#9=..\Core\Src\tim.c -SourceFiles#10=..\Core\Src\usart.c -SourceFiles#11=..\USB_DEVICE\App\usb_device.c -SourceFiles#12=..\USB_DEVICE\Target\usbd_conf.c -SourceFiles#13=..\USB_DEVICE\App\usbd_desc.c -SourceFiles#14=..\USB_DEVICE\App\usbd_storage_if.c -SourceFiles#15=..\Core\Src\stm32f4xx_it.c -SourceFiles#16=..\Core\Src\stm32f4xx_hal_msp.c -SourceFiles#17=..\Core\Src\stm32f4xx_hal_timebase_tim.c -SourceFiles#18=..\Core\Src\main.c -SourceFolderListSize=5 -SourcePath#0=..\Core\Src -SourcePath#1=..\FATFS\Target -SourcePath#2=..\FATFS\App -SourcePath#3=..\USB_DEVICE\App -SourcePath#4=..\USB_DEVICE\Target -SourceFiles=; - diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 650aef1..1e6bdea 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,7 +6,7 @@ "${workspaceFolder}/**", "${workspaceFolder}/Code/base/Inc", "${workspaceFolder}/Code/device/Inc", - "${workspaceFolder}/Code/libraries/Inc", + // "${workspaceFolder}/Code/libraries/Inc", "${workspaceFolder}/Code/port/**", "${workspaceFolder}/Core/Inc", "${workspaceFolder}/Drivers/**", diff --git a/.vscode/launch.json b/.vscode/launch.json index 79921c7..e96f0fc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,8 +25,8 @@ "args": [], "stopAtEntry": false, "externalConsole": true, - "cwd": "d:/Mycode/stm32Code/H2S_407ZET6", - "program": "d:/Mycode/stm32Code/H2S_407ZET6/build/Debug/outDebug", + "cwd": "d:/Mycode/stm32Code/H2S", + "program": "d:/Mycode/stm32Code/H2S/build/Debug/outDebug", "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ diff --git a/.vscode/settings.json b/.vscode/settings.json index c3736ae..be52a9c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -61,7 +61,11 @@ "lv_textarea.h": "c", "typeinfo": "c", "usbd_cdc_if.h": "c", - "port.h": "c" + "port.h": "c", + "eeprom.h": "c", + "ds1302.h": "c", + "i2c_ads1115.h": "c", + "ph.h": "c" }, "C_Cpp_Runner.msvcBatchPath": "", "C_Cpp_Runner.cCompilerPath": "gcc", diff --git a/Code/base/Inc/base.h b/Code/base/Inc/base.h index 91a4a8a..9eb3b8f 100644 --- a/Code/base/Inc/base.h +++ b/Code/base/Inc/base.h @@ -15,12 +15,15 @@ #include "stm32f4xx.h" #include "tim.h" +#include "myrtos.h" + #include "led.h" #include "ds1302.h" -// #include "eeprom.h" +#include "eeprom.h" #include "i2c_ads1115.h" -#include "usbd_storage_if.h" +#include "pH.h" +// #include "usbd_storage_if.h" // #include "sensor.h" // #include "ILI93xx.h" // #include "touch.h" diff --git a/Code/base/Inc/i2c_ads1115.h b/Code/base/Inc/i2c_ads1115.h index 7aff0b6..3340907 100644 --- a/Code/base/Inc/i2c_ads1115.h +++ b/Code/base/Inc/i2c_ads1115.h @@ -1,22 +1,205 @@ //i2c_ads1115.h #ifndef __IIC_ADS1115_H #define __IIC_ADS1115_H - +#include "FreeRTOS.h" +#include "task.h" +#include "main.h" +#include "cmsis_os.h" #include "i2c.h" #define ADS1115_WRITE_ADDRESS 0x90 #define ADS1115_READ_ADDRESS 0x91 //以下两个预处理作为配置寄存器预处理要更改其配在这里更改 //也可以添加新的预处理对不同通道的采集或者选取不同的采样速率等 -#define CONFIG_REG_H ADS1115_REG_CONFIG_OS_START|\ - ADS1115_REG_CONFIG_MUX_SINGLE_0|\ - ADS1115_REG_CONFIG_PGA_4|\ - ADS1115_REG_CONFIG_MODE_SINGLE -#define CONFIG_REG_L ADS1115_REG_CONFIG_DR_128|\ - ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL|\ - ADS1115_REG_CONFIG_COMP_POL_LOW|\ - ADS1115_REG_CONFIG_COMP_LAT_NONLATCH|\ - ADS1115_REG_CONFIG_COMP_QUE_DIS + +/*事件开始 set, 事件完成 clear */ +typedef enum +{ + ADS1115_Event_READY, + ADS1115_Event_INIT, + ADS1115_Event_SET_REGISTER, + ADS1115_Event_SET_POINT_ADDR, + ADS1115_Event_RCV_DATA, +} ADS1115_Event_TypeDef; + +typedef enum { + ADS1115_WORK_STATE_WAITING, + ADS1115_WORK_STATE_READY, + ADS1115_WORK_STATE_INIT, + ADS1115_WORK_STATE_INIT_SUCCESS, + ADS1115_WORK_STATE_SET_REGISTER, + ADS1115_WORK_STATE_SET_REGISTER_SUCCESS, + ADS1115_WORK_STATE_SET_POINT_ADDR, + ADS1115_WORK_STATE_SET_POINT_ADDR_SUCCESS, + ADS1115_WORK_STATE_RCV_DATA, + ADS1115_WORK_STATE_RCV_DATA_SUCCESS, + ADS1115_WORK_STATE_DATA_OK, + ADS1115_WORK_STATE_ERROR, + ADS1115_WORK_STATE_TIMEOUT, + ADS1115_WORK_STATE_STOP +}ADS1115_WORK_STATE_TypeDef; + +typedef enum { + ADS1115_OUTPUT_UNIT_v, + ADS1115_OUTPUT_UNIT_mv +}ADS1115_OUTPUT_UNIT_TypeDef; + + +//地址指针寄存器 +typedef enum +{ + ADS1115_REG_POINTER_CONVERT = 0x00, // 转换寄存器 + ADS1115_REG_POINTER_CONFIG = 0x01 , // 配置寄存器 16bit + ADS1115_REG_POINTER_LOWTHRESH = 0x02 , + ADS1115_REG_POINTER_HITHRESH = 0x03 +} ADS1115_REG_POINTER_TypeDef; + + +// 单次转换开始 +typedef enum +{ + ADS1115_REG_CONFIG_OS_START = (0x1U << 7),//设备单词转换开启 高字节的最高位 + ADS1115_REG_CONFIG_OS_NULL = (0x0U << 7) +} ADS1115_REG_CONFIG_OS_TypeDef; + + +//输入引脚选择和输入方式选择 +typedef enum +{ + ADS1115_REG_CONFIG_MUX_Diff_01 = (0x0U << 4), // 差分输入0引脚和1引脚 + ADS1115_REG_CONFIG_MUX_Diff_03 = (0x1U << 4), // 差分输入0引脚和3引脚 + ADS1115_REG_CONFIG_MUX_Diff_13 = (0x2U << 4), // 差分输入1引脚和3引脚 + ADS1115_REG_CONFIG_MUX_Diff_23 = (0x3U << 4), // 差分输入2引脚和3引脚 + ADS1115_REG_CONFIG_MUX_SINGLE_0= (0x4U << 4), //单端输入 0 + ADS1115_REG_CONFIG_MUX_SINGLE_1= (0x5U << 4), //单端输入 1 + ADS1115_REG_CONFIG_MUX_SINGLE_2= (0x6U << 4), //单端输入 2 + ADS1115_REG_CONFIG_MUX_SINGLE_3= (0x7U << 4) //单端输入 3 +} ADS1115_REG_CONFIG_MUX_Diff_TypeDef; + + + +//量程选择 +typedef enum +{ + ADS1115_REG_CONFIG_PGA_6 = (0x0U << 1), // +/- 6.1144 + ADS1115_REG_CONFIG_PGA_4 =(0x1U << 1), // +/- 4.096 + ADS1115_REG_CONFIG_PGA_2 = (0x2U << 1), // +/- 2.048 + ADS1115_REG_CONFIG_PGA_1 = (0x3U << 1) , // +/- 1.024 + ADS1115_REG_CONFIG_PGA_05 = (0x4U << 1) , // +/- 0.512 + ADS1115_REG_CONFIG_PGA_02 =(0x5U << 1) , // +/- 0.256 +} ADS1115_REG_CONFIG_PGA_TypeDef; + + +//运行方式 +typedef enum +{ + ADS1115_REG_CONFIG_MODE_SINGLE = (0x1U << 0) , // 单次 + ADS1115_REG_CONFIG_MODE_CONTIN = (0x0U << 0) //连续转换 +} ADS1115_REG_CONFIG_MODE_TypeDef; + + +//转换速率 +typedef enum +{ + ADS1115_REG_CONFIG_DR_8 = (0x0U << 5), + ADS1115_REG_CONFIG_DR_16= (0x1U << 5), + ADS1115_REG_CONFIG_DR_32 = (0x2U << 5), + ADS1115_REG_CONFIG_DR_64 = (0x3U << 5), + ADS1115_REG_CONFIG_DR_128 = (0x4U << 5), + ADS1115_REG_CONFIG_DR_250 = (0x5U << 5), + ADS1115_REG_CONFIG_DR_475 = (0x6U << 5), + ADS1115_REG_CONFIG_DR_860 = (0x7U << 5) +} ADS1115_REG_CONFIG_DR_TypeDef; + + + +//比较器模式 +typedef enum +{ + ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL = (0x0U << 4),//默认 + ADS1115_REG_CONFIG_COMP_MODE_WINDOW = (0x1U << 4) +} ADS1115_REG_CONFIG_COMP_MODE_TypeDef; + + +typedef enum +{ + ADS1115_REG_CONFIG_COMP_POL_LOW = (0x0U << 3),//默认 + ADS1115_REG_CONFIG_COMP_POL_HIG = (0x1U << 3) +} ADS1115_REG_CONFIG_COMP_POL_TypeDef; + + + +typedef enum +{ + ADS1115_REG_CONFIG_COMP_LAT_NONLATCH = (0x0U << 2), + ADS1115_REG_CONFIG_COMP_LAT_LATCH = (0x1U << 2) +} ADS1115_REG_CONFIG_COMP_LAT_TypeDef; + + +typedef enum +{ + ADS1115_REG_CONFIG_COMP_QUE_ONE = (0x0U << 0), + ADS1115_REG_CONFIG_COMP_QUE_TWO = (0x1U << 0), + ADS1115_REG_CONFIG_COMP_QUE_THR = (0x2U << 0), + ADS1115_REG_CONFIG_COMP_QUE_DIS = (0x3U << 0) +} ADS1115_REG_CONFIG_COMP_QUE_TypeDef; + + +typedef struct{ + int (*init)(void); + void (*port)(void); + int (*test)(void); + void (*start)(void); + void (*stop)(void); + I2C_HandleTypeDef *hi2c; + + uint8_t config_os; + uint8_t config_mux; + uint8_t config_PGA; + uint8_t config_MODE; + uint8_t config_DR; + uint8_t config_COMP_MODE; + uint8_t config_COMP_POL; + uint8_t config_COMP_LAT; + uint8_t config_COMP_QUE; + uint8_t point_ADDR; // 要读取的数据指针地址 + volatile uint8_t config_H; + volatile uint8_t config_L; + uint8_t reg_data[3]; + ADS1115_OUTPUT_UNIT_TypeDef unit; + + uint32_t time_ticks; + volatile uint8_t event_flags; + volatile ADS1115_WORK_STATE_TypeDef state; + uint8_t result[2]; +}ADS1115_TypeDef; + +extern ADS1115_TypeDef my_ads1115; + +int ads1115_init(); +void ads1115_port(); +int ads1115_test(); +void ads1115_start(); +void ads1115_stop(); +int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux); +void ads1115_set_event_flags(ADS1115_Event_TypeDef evt); +void ads1115_set_state(ADS1115_WORK_STATE_TypeDef state); +// void ads1115_config_register(I2C_HandleTypeDef *ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); +int16_t ads1115_read_data( ); +double ads1115_get_voltage_val( ); +double ADS1115_Get_Voltage_From_U16( uint16_t voltage); +uint16_t ADS1115_Get_Coeff_BY_128( ); +#endif + + +/** + * @brief 使用说明 + * init 初始化 + * 读数据, ads1115_setup 设置寄存器通道。 指向转换寄存器, 然后读取 + * 设置的是 多路复用 + * + * @details + */ /***************/ @@ -40,7 +223,7 @@ CRL[7:0] (R/W) * | | 0 : 正在转换 * | | 1 : 未执行转换 * ----------------------------------------------------------------------------------- - * 14:12 | MUX [2:0] | 输入复用多路配置 + * 14:12 | MUX [2:0] | 输入复用多路配置 -- 如果多路的话需要每次分开测量 * | | 000 : AINP = AIN0 and AINN = AIN1 (default) * | | 001 : AINP = AIN0 and AINN = AIN3 * | | 010 : AINP = AIN1 and AINN = AIN3 @@ -62,7 +245,7 @@ CRL[7:0] (R/W) * ----------------------------------------------------------------------------------- * 8 | MODE | 工作模式 * | | 0 : 连续转换 - * | | 1 : 单词转换 + * | | 1 : 单次转换 * ----------------------------------------------------------------------------------- * 7:5 | DR [2:0] | 采样频率 * | | 000 : 8 SPS @@ -93,91 +276,3 @@ CRL[7:0] (R/W) * | | 11 : 禁用比较器并将ALERT/RDY设置为高阻抗 (default) * ----------------------------------------------------------------------------------- */ - - - -//地址指针寄存器 - -#define ADS1015_REG_POINTER_CONVERT (0x00) -#define ADS1015_REG_POINTER_CONFIG (0x01) -#define ADS1015_REG_POINTER_LOWTHRESH (0x02) -#define ADS1015_REG_POINTER_HITHRESH (0x03) -// 单次转换开始 -#define ADS1115_REG_CONFIG_OS_START (0x1U << 7)//设备单次转换开启 高字节的最高位 -#define ADS1115_REG_CONFIG_OS_NULL (0x0U << 7) -//输入引脚选择和输入方式选择 -#define ADS1115_REG_CONFIG_MUX_Diff_01 (0x0U << 4) // 差分输入0引脚和1引脚 -#define ADS1115_REG_CONFIG_MUX_Diff_03 (0x1U << 4) // 差分输入0引脚和3引脚 -#define ADS1115_REG_CONFIG_MUX_Diff_13 (0x2U << 4) // 差分输入1引脚和3引脚 -#define ADS1115_REG_CONFIG_MUX_Diff_23 (0x3U << 4) // 差分输入2引脚和3引脚 -#define ADS1115_REG_CONFIG_MUX_SINGLE_0 (0x4U << 4) //单端输入 0 -#define ADS1115_REG_CONFIG_MUX_SINGLE_1 (0x5U << 4) //单端输入 1 -#define ADS1115_REG_CONFIG_MUX_SINGLE_2 (0x6U << 4) //单端输入 2 -#define ADS1115_REG_CONFIG_MUX_SINGLE_3 (0x7U << 4) //单端输入 3 - -//量程选择 -#define ADS1115_REG_CONFIG_PGA_6 (0x0U << 1) // +/- 6.1144 -#define ADS1115_REG_CONFIG_PGA_4 (0x1U << 1) // +/- 4.096 -#define ADS1115_REG_CONFIG_PGA_2 (0x2U << 1) // +/- 2.048 -#define ADS1115_REG_CONFIG_PGA_1 (0x3U << 1) // +/- 1.024 -#define ADS1115_REG_CONFIG_PGA_05 (0x4U << 1) // +/- 0.512 -#define ADS1115_REG_CONFIG_PGA_02 (0x5U << 1) // +/- 0.256 - -//运行方式 - -#define ADS1115_REG_CONFIG_MODE_SINGLE (0x1U << 0) // 单次 -#define ADS1115_REG_CONFIG_MODE_CONTIN (0x0U << 0) //连续转换 - -//转换速率 - -#define ADS1115_REG_CONFIG_DR_8 (0x0U << 5) -#define ADS1115_REG_CONFIG_DR_16 (0x1U << 5) -#define ADS1115_REG_CONFIG_DR_32 (0x2U << 5) -#define ADS1115_REG_CONFIG_DR_64 (0x3U << 5) -#define ADS1115_REG_CONFIG_DR_128 (0x4U << 5) -#define ADS1115_REG_CONFIG_DR_250 (0x5U << 5) -#define ADS1115_REG_CONFIG_DR_475 (0x6U << 5) -#define ADS1115_REG_CONFIG_DR_860 (0x7U << 5) - -//比较器模式 -#define ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL (0x0U << 4)//默认 -#define ADS1115_REG_CONFIG_COMP_MODE_WINDOW (0x1U << 4) - - -#define ADS1115_REG_CONFIG_COMP_POL_LOW (0x0U << 3)//默认 -#define ADS1115_REG_CONFIG_COMP_POL_HIG (0x1U << 3) - - -#define ADS1115_REG_CONFIG_COMP_LAT_NONLATCH (0x0U << 2) -#define ADS1115_REG_CONFIG_COMP_LAT_LATCH (0x1U << 2) - - -#define ADS1115_REG_CONFIG_COMP_QUE_ONE (0x0U << 0) -#define ADS1115_REG_CONFIG_COMP_QUE_TWO (0x1U << 0) -#define ADS1115_REG_CONFIG_COMP_QUE_THR (0x2U << 0) -#define ADS1115_REG_CONFIG_COMP_QUE_DIS (0x3U << 0) - -int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle); -void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); -int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle); -double ads1115_get_voltage_val(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); -#endif - -/* -步骤一:write to config register(写配置寄存器) -1:发送从机地址0x90(写) -2:发送0x01 (指向配置寄存器) -3:配置config register -发送字节:0x84(高八位) -发送字节:0x83(低八位) - -步骤二:write to pointer register(转向转换寄存器) -1:发送从机地址0x90(写) -2:发送0x00(指向转换寄存器) - -步骤三:read conversion register(读取转换寄存器的数据) -1:发送从机地址0x91(读) -2:接收转换寄存器的高八位 -3:接收转换寄存器的低八位 - -*/ \ No newline at end of file diff --git a/Code/base/Inc/led.h b/Code/base/Inc/led.h index 7bf3c19..55c6e47 100644 --- a/Code/base/Inc/led.h +++ b/Code/base/Inc/led.h @@ -2,9 +2,19 @@ #define __LED_H #include "stdint.h" +#include "FreeRTOS.h" +#include "task.h" #include "main.h" +#include "cmsis_os.h" + #define LED_MAX_NUM 4 +typedef enum { + LED_SEQ_0, + LED_SEQ_1, + // LED_COLOR_GREEN, +}MY_LED_COLOR_SEQ; + // 回调需要这个参数,控制时开关还是闪烁,闪烁快慢 enum led_state{ LED_STATE_ON, @@ -24,12 +34,51 @@ struct led uint16_t level_on; }; +typedef struct +{ + int (*init)(); + int (*port)(uint16_t delay_ms); + uint8_t led_num; + uint16_t delay_base_ms; + // struct led *led[LED_MAX_NUM]; + // void * led; +}My_LED_TypeDef; +extern My_LED_TypeDef my_led; + +int Led_Init( ); + + +int Led_Port( uint16_t delay_ms ); + +int led_setup(uint8_t seq, GPIO_TypeDef *gpio,uint16_t pin,enum led_state state,uint16_t level_on); + // 依据GPIO 信息注册 -int led_register(struct led *led, GPIO_TypeDef *gpio, uint16_t pin, enum led_state state, uint16_t level_on ); +// int led_register(struct led *led, GPIO_TypeDef *gpio, uint16_t pin, enum led_state state, uint16_t level_on ); // 初始化状态 -int led_set_state(struct led *led,enum led_state state); +int led_set_state(uint8_t seq,enum led_state state); +// int led_set_state(struct led *led,enum led_state state); // 执行 -- 由状态决定 void led_callback(void); #endif + + +/** + * @usage: + * .h 中定义 + + typedef enum { + LED_SEQ_0, + LED_SEQ_1, + // LED_COLOR_GREEN, + }MY_LED_COLOR_SEQ; + + int Led_Init() 函数中注册以上的 LED + + 调用, init port 初始化 + + led_set_state 设置状态 + + + */ \ No newline at end of file diff --git a/Code/base/Inc/pH.h b/Code/base/Inc/pH.h new file mode 100644 index 0000000..5167d1c --- /dev/null +++ b/Code/base/Inc/pH.h @@ -0,0 +1,158 @@ +#ifndef __PH_H +#define __PH_H + +#ifdef __cplusplus + extern "C" { +#endif + + + +#include "FreeRTOS.h" +#include "task.h" +#include "main.h" +#include "cmsis_os.h" +#include "usart.h" + + +#include "elog.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#include +#include "uart_helper.h" +#include "uart_interface.h" +// #include "config.h" + +#define PH_Rcv_Buf_Size 9 +#define PH_Command_Number 1 + +typedef enum +{ + PH_Status_Waiting , + PH_Status_Ready , + PH_Status_Sending , + PH_Status_Send_Cplt , + PH_Status_RCV_OK , + PH_Status_DATA_OK , + PH_Status_Timeout , + PH_Status_Error , +} PH_Status_TypeDef; + +typedef struct +{ + UartHelper_TypeDef *uarthelper; + // UART_HandleTypeDef *huart; + uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/ + uint8_t *send_buf; + uint16_t size_send; + uint8_t *rcv_buf; + uint16_t size_rcv; + + + uint8_t mode_232_485; /* 0: common, 1: 485 */ + uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/ + uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/ + uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */ + uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/ + + uint64_t timebase; + uint16_t timeout_ms; + volatile uint8_t send_flag; /* 发送标志位 */ + Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/ + Uart_Status_TypeDef status; /* 发送状态 1:正在发送 busy,0:发送ok,*/ + + uint8_t command_seq ; /* 命令序号 */ + uint8_t mode; /* 0 : normal , 1 : get wavelength , 2 : get sn */ + + uint8_t vipersn_buf[15]; + uint8_t PH_Wavelength_Buf[2][ PH_Rcv_Buf_Size ]; + uint8_t PH_Data_Buf[2][ PH_Rcv_Buf_Size ]; + + uint8_t rcv_ok; /* 接收数据完整可以处理 */ + uint8_t data_begin_flag; /* 接收数据完整可以处理 */ + uint8_t data_ok; /* 接收数据完整可以处理 */ + + volatile PH_Status_TypeDef state; + + // int (*Init)(void); //初始化触摸屏控制器 + // // uint8_t (*Setup)( ); //扫描触摸屏.0,屏幕扫描;1,物理坐标; + // uint8_t (*Port)( ); //扫描触摸屏.0,屏幕扫描;1,物理坐标; + + +}PH_TypeDef; + +extern PH_TypeDef *ph ; + +int PH_Init( ); +int PH_Test( ); +void PH_Start( ); +void PH_Stop( ); + +void PH_Set_Uarthelper( PH_TypeDef *ph, UartHelper_TypeDef * uarthelper ); +void PH_Set_Interface( PH_TypeDef *ph, UartInterface_TypeDef * interface ); +void PH_Set_Huart( PH_TypeDef *ph, UART_HandleTypeDef * huart ); +void PH_Set_Interface_Type( PH_TypeDef *ph, Uart_Interface_Type_Typedef interface_type ); +void PH_Set_Trans_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_type ); +void PH_Set_Rcv_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef rcv_type ); +void PH_Set_Idle_Enable( PH_TypeDef *ph, Uart_IDLE_Enable_TypeDef idle_enable_disable ); +void PH_Set_TransMode( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_mode ); +void PH_Set_RsMode_232_485( PH_TypeDef *ph, Uart_RS_Mode_TypeDef rs_232_485 ); +void PH_Set_Timeout( PH_TypeDef *ph, uint16_t timeout_ms ); +void PH_Set_Sendbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size ); +void PH_Set_Rcvbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size ); + +int PH_Send( PH_TypeDef *ph, uint8_t * buf, uint16_t size); + + +void PH_Begin_Rcv(PH_TypeDef *ph, uint8_t * buf, uint16_t size); + +extern void PH_Rcv_Cplt_Callback( PH_TypeDef *ph ); +extern void PH_Send_Cplt_Callback( PH_TypeDef *ph ); + +int PH_Get_Data_OK(PH_TypeDef *ph ); +void PH_Set_Send_Flag( PH_TypeDef *ph ); + +// extern void PH_Setup( ); +extern void PH_Port( ); +// extern void PH_SN( ); +// extern void PH_Wavelength( ); +void PH_Task( ); + +/* 再封装演示 */ +typedef struct +{ + uint8_t (*init)( ); + uint8_t (*port)(void); + int (*test)(void); + void (*start)(void); + int (*stop)(void); + //扫描触摸屏.0,屏幕扫描;1,物理坐标; + GPIO_TypeDef *sel_gpio; + GPIO_TypeDef *dplx_gpio; + GPIO_TypeDef *de_gpio; + uint16_t sel_pin; + uint16_t dplx_pin; + uint16_t de_pin; + + Uart_Interface_Type_Typedef interface_type; /* 0: common, 1: 485 ,2:3160*/ + Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/ + Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/ + Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/ + Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲*/ + + uint16_t ph_val; + uint16_t temp_val; + PH_TypeDef *ph; /*不是常量 不能直接初始化*/ + + +}My_PH_TypeDef; +extern My_PH_TypeDef my_pH ; + + + +#ifdef __cplusplus + } +#endif +#endif diff --git a/Code/base/Src/base.c b/Code/base/Src/base.c index f75ae48..c4516c1 100644 --- a/Code/base/Src/base.c +++ b/Code/base/Src/base.c @@ -11,7 +11,7 @@ int _write(int fd, char *ch, int len) return len; } -extern struct led led_0; +// extern struct led led_0; // extern struct led led_1; extern struct ds1302 ds1302; @@ -23,26 +23,23 @@ extern volatile uint16_t cc ; extern volatile uint16_t dd ; // extern osTimerId_t myTimer01Handle; -// uint8_t send_buf[8] = {0x01,0x03,0x00,0x00,0x00,0x04,0x44,0x09}; -// uint8_t rcv_buf[14] = {0}; -// uint8_t rcv_buf_2[13] = {0}; - -double voltage = 0.0; -double H2S_concentration = 0.0; -float pH_value = 0.0; -float temperature = 0.0; -float H2S = 0.0; -uint8_t pH_send_buf[8] = {0x01,0x03,0x00,0x00,0x00,0x02,0xC4,0x0B}; -uint8_t pH_rcv_buf[9] = {0}; -uint8_t measuring_flag = 0; -uint8_t pH_measuring_flag = 0; -uint8_t pH_send_flag = 0; -uint8_t pH_rcv_flag = 0; -uint8_t pH_measure_ok = 8; -uint8_t voltage_measure_ok = 0; -uint64_t timebase; + +// H2s 相关参数 +double a0 = 3.149951E+00; +double a1 = -1.768957E-01; +double a2 = 3.656828E-03; +double a3 = -1.176627E-05; + +double a20 = 7.939553E-03; +double Ug = 7.0E+00; + +double h2s; +double phval; +double tempval; + uint8_t measure_step = 0; -float result[3] ; /* H2S T pH */ +uint64_t timebase; +float result[3] ; /* H2S T pH */ void MY_INIT( ) { @@ -53,173 +50,195 @@ void MY_INIT( ) uart4_power_enable(); uart6_power_enable(); - HAL_TIM_Base_Start_IT(&htim2); - __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_UPDATE); // 使能定时器更新中断 + // HAL_TIM_Base_Start_IT(&htim2); + // __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_UPDATE); // 使能定时器更新中断 } - void measureTimer_Callback(void *argument) { log_i("measure timer begin .... " ); - led_set_state( &led_0, LED_STATE_FLICKER_QUICK ); - voltage = 0.0; - H2S = 0.0; - memset(pH_rcv_buf, 0, 9 ); - memset(result, 0, 12 ); - timebase = osKernelGetTickCount(); - measuring_flag = 1; - pH_send_flag = 0; - pH_rcv_flag = 0; - pH_measuring_flag = 0; - pH_measure_ok = 0; - voltage_measure_ok = 0; - measure_step = 0; -} + // led_set_state( LED_SEQ_0, LED_STATE_FLICKER_QUICK ); + // 打开测量 + if (measure_step == 0 ) + { + led_set_state( LED_SEQ_0, LED_STATE_FLICKER_QUICK ); + measure_step = 1; + timebase = osKernelGetTickCount(); + }else{ + log_w(" still measuring .... measurestep -> %d",measure_step); + } +} - void pHTask(void *argument) +/* 判断测量是否完成,完成进行完成操作 */ +void measureTask( void *argument ) { for (;;) { - - // log_i(" ph... pH_measure_ok %d", pH_measure_ok); - if ( pH_measure_ok ==0 && pH_send_flag == 0) + if ( measure_step == 0 ) + { + osDelay(20); + } + // 开始采集 + if ( measure_step == 1 ) { - log_i(" send stage ... "); - HAL_UART_Receive_DMA(&huart3, pH_rcv_buf, 9 ); timebase = osKernelGetTickCount(); - max3160_485_send_mode(); - pH_send_flag = 1; - HAL_UART_Transmit_DMA(&huart3, pH_send_buf, 8 ); + my_ads1115.start(); // ADS1115 + my_pH.start(); // pH + measure_step++; + // log_i( " ph->state = %d, my_ads1115.state = %d ",ph->state, my_ads1115.state ); + osDelay(2); } - if ( pH_measure_ok ==0 && pH_send_flag == 1 && pH_rcv_flag == 0 ) + + // 等待数据采集完成 + if ( measure_step==2 ) { - uint64_t time_ticks = osKernelGetTickCount() ; - // log_i( " time_ticks :%d " , time_ticks); - if ( (time_ticks - timebase ) >400) + // log_i( " step == 2 -> %d %d " ,ph->state , my_ads1115.state); + if ( ph->state == PH_Status_DATA_OK && my_ads1115.state==ADS1115_WORK_STATE_DATA_OK) { - log_i( " pH timeout ..... " ); - measureTimer_Callback(NULL); + measure_step++ ; + continue; } + osDelay(20); } - if ( pH_measure_ok ==0 && pH_rcv_flag == 1 ) + + // 采集完成,停止,处理数据 + if ( measure_step==3 ) { - log_i( " pH ok ..... " ); - pH_measure_ok = 1; + my_ads1115.stop(); + my_pH.stop(); + measure_step++ ; + continue; } - if ( pH_measure_ok ==1 ) - { - ; + + // 数据处理 + if ( measure_step==4 ) + { + // log_i( "4444 ph->state = %d, my_ads1115.state = %d ",ph->state, my_ads1115.state ); + double temp_h2s_mv = 0.0; + uint16_t voltage; + uint16_t coeff; + + coeff = ADS1115_Get_Coeff_BY_128(); // 获得放大系数 * 128 + // log_i( " coeff %d, ",coeff ); + + phval = (my_ads1115.result[0]*256 + my_ads1115.result[1] )/100.0; + tempval = (my_ads1115.result[0]*256 + my_ads1115.result[1] )/10.0; + + voltage = my_ads1115.result[0]*256 + my_ads1115.result[1] ; // 电压整数 + temp_h2s_mv = (double)voltage * coeff / 128.0 /1000.0; // 电压毫伏 + h2s = ( temp_h2s_mv - Ug) * a20 *( a3*tempval*tempval*tempval+ a2*tempval*tempval + a1*tempval + a0 ); // 温度校正 + + result[0] = h2s; + result[1] = tempval; + result[2] = phval; + + measure_step++ ; + continue; + } + // // send to screen + if ( measure_step==5 ) + { + HAL_UART_Transmit_DMA(&huart1, (uint8_t *)result, 12); + measure_step++ ; + continue; + } + // 等发送完成 + if ( measure_step==6 ) + { + osDelay(2); } - osDelay(200); + // 改写 modbus数据 + if ( measure_step==7 ) + { + log_i( " measure_step == 7 ... " ); + measure_step++ ; + continue; + } + + // // 数据完成 等待 + if ( measure_step==8 ) + { + log_i( " measure_step == 8 ... " ); + measure_step = 0; + } + osDelay(2); } } -void voltageTask(void *argument) +static void Default_Task_Init() { - for (;;) - { - if (voltage_measure_ok ==0) - { - voltage = ads1115_get_voltage_val(hi2c1 ,0x01, CONFIG_REG_H, CONFIG_REG_L); - log_w( " voltage :%.6f " , voltage); - voltage_measure_ok = 1; - } - osDelay(20); - } -} + // measuring_flag = 0; + my_led.init(); + if ( 0 == my_led.port(200) ) { + log_i("Led Port init Ok .... "); + }else { + log_e("Led Port init Failure .... "); + }; + led_set_state( LED_SEQ_0, LED_STATE_FLICKER_SLOW ); -void measureTask(void *argument) -{ - for (;;) - { - /* convert */ - if ( measure_step==0 && pH_measure_ok == 1 && voltage_measure_ok == 1 ) - { - /** TODO ...*/ - result[1] = (pH_rcv_buf[5]*256 + pH_rcv_buf[6])/10.0; /* Temp /10.0*/ - result[2] = (pH_rcv_buf[3]*256 + pH_rcv_buf[4])/100.0; /* pH /10.0*/ - // log_i( " temperature :%.6f pH : %.6f " , temperature ,pH_value); - get_h2s_2(&H2S_concentration , voltage, result[1]); - result[0] = H2S_concentration; - led_set_state(&led_0, LED_STATE_FLICKER_SLOW); - // log_i( "H2S : %.6f " ,H2S); - measure_step++; - } + my_eeprom.init(); + if ( 0 == Eeprom_Test( ) ) { + log_i("Eeeprom Test Ok .... "); + } else { + log_e("Eeeprom Test Failure .... "); + }; - /* 写modbus数据 */ - if ( measure_step==1 ) - { - /* 写modbus 临界区 */ - log_i( "-------> H2S: %.6f TEMP: %.6f pH: %.6f ", result[0] , result[1], result[2]); - // 数据全反过来 40db851f41a80000402771f2 -》 f2712740......// - - Modbus_Set_HoldingBuff( (uint8_t *)result, 12, 0); - - measure_step++; - /*pH 686 : 40db851f 41a80000 402771f2 */ - } - /* 输出数据 uart1 */ - if ( measure_step==2 ) + + if ( 0 == ds1302_port() ) { - log_i( "send to screen... " ); - int ret= HAL_UART_Transmit_IT(&huart1, (uint8_t *)result, 12); - if( ret==HAL_OK) - log_i( "send ok.. " ); + log_i("ds1302 init Ok .... "); + }else { + log_e("ds1302 init Failure .... "); + }; - measure_step++; - } - if ( measure_step==3 ) + /* ads1115 */ + if ( 0 == my_ads1115.init() ) { - osDelay(2); - } - osDelay(20); + log_i( "ads1115 init Ok .... " ); + }else + { + log_e( "ads1115 init Failure .... " ); } -} + osDelay(10); + + my_ads1115.port(); + osDelay(10); + // pH init port -static void Default_Task_Init() -{ - measuring_flag = 0; - if (0==Led_Port()){ - log_i("Led Port int Ok .... "); - } - led_set_state(&led_0, LED_STATE_FLICKER_SLOW); - - if (0==ds1302_port()) + if ( 0!= my_pH.init() ) { - log_i("ds1302 init Ok .... "); - } - if ( 0== ads1115_test(hi2c1)) - { - log_i("ads1115 init Ok .... "); - } + log_e( "pH init Failure .... " ); + + }else{ + log_i( "pH init ok .... " ); + }; + + my_pH.port(); - // my_ads1115.init(); // // SD_Test(); // // Test_Port(); - Modbus_Port( ); RTOS_Port( ); + + Modbus_Port( ); extern osTimerId_t measureTimerHandle; osTimerStart( measureTimerHandle, 3000); - // MX_USB_DEVICE_Init(); - } - void StartDefaultTask(void *argument) { Init_Logger(); - log_i("System is initiating.... "); + log_i( "System is initiating.... " ); Default_Task_Init(); @@ -229,8 +248,7 @@ void StartDefaultTask(void *argument) { // log_i("looo... "); // CDC_Transmit_HS(send_buf, 8); - osDelay(1000 ); - + osDelay( 1000 ); // log_i(" aa bb cc dd : %d %d %d %d ",aa, bb,cc, dd); } } @@ -239,12 +257,12 @@ void USART1_IRQHandler(void) { if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TC) != RESET) { - log_i(" uart1 tc..... "); + // log_i(" uart1 tc..... "); // osSemaphoreRelease(elog_dma_lockHandle); + measure_step++; huart1.gState = HAL_UART_STATE_READY; __HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_TC); } - HAL_UART_IRQHandler(&huart1); } @@ -254,44 +272,41 @@ void USART2_IRQHandler(void) { // HAL_UART_Transmit(&huart3, (uint8_t*)"tddddd", 6,0xFF); // extern osSemaphoreId_t elog_dma_lockHandle; - osSemaphoreRelease(elog_dma_lockHandle); + osSemaphoreRelease( elog_dma_lockHandle ); huart2.gState = HAL_UART_STATE_READY; - __HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_TC); + __HAL_UART_CLEAR_FLAG(&huart2, UART_FLAG_TC); } - HAL_UART_IRQHandler(&huart2); } -void USART3_IRQHandler(void) -{ - - // if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TC) != RESET) - // { - // max3160_485_receive_mode(); - // // huart3.gState = HAL_UART_STATE_READY; - // __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_TC); - // } - - - // if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE) != RESET) - // { - // log_i("....huart3 IDLE...."); - // __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_IDLE); - // } +// void USART3_IRQHandler(void) +// { - HAL_UART_IRQHandler(&huart3); -} +// if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TC) != RESET) +// { +// log_i(" uart3 tc..... "); +// max3160_485_receive_mode(); +// // huart3.gState = HAL_UART_STATE_READY; +// __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_TC); +// } + +// if (__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE) != RESET) +// { +// log_i("....huart3 IDLE...."); +// __HAL_UART_CLEAR_IDLEFLAG(&huart3); +// } +// HAL_UART_IRQHandler(&huart3); +// } void UART4_IRQHandler(void) { -// if (__HAL_UART_GET_FLAG(&huart4, UART_IT_TXE) ==SET ) +// if (__HAL_UART_GET_FLAG(&huart4, UART_IT_TXE) ==SET ) // { // log_i("....huart4 tc callback...."); // // HAL_GPIO_WritePin(DE485_GPIO_Port, DE485_Pin, SET); // // HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET); // __HAL_UART_CLEAR_FLAG(&huart4, UART_IT_TXE); // } - HAL_UART_IRQHandler(&huart4); } @@ -305,46 +320,42 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == huart2.Instance) { - log_i("....huart2 rx callback...."); + // log_i("....huart2 rx callback...."); __HAL_UART_CLEAR_FLAG(&huart2, UART_FLAG_RXNE); } - if (huart->Instance == huart3.Instance) - { - // measure_step++; - pH_rcv_flag = 1; - // log_i("....huart3 rx callback.... " ); - // log_i( "rcvbuf : %d %d %d %d %d %d", rcv_buf_2[0], rcv_buf_2[1], rcv_buf_2[2],rcv_buf_2[3], rcv_buf_2[4], rcv_buf_2[5]); - __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_RXNE); - } - - + // if (huart->Instance == huart3.Instance) + // { + // // measure_step++; + // pH_rcv_flag = 1; + // log_i("....huart3 rx callback.... " ); + // // log_i( "rcvbuf : %d %d %d %d %d %d", rcv_buf_2[0], rcv_buf_2[1], rcv_buf_2[2],rcv_buf_2[3], rcv_buf_2[4], rcv_buf_2[5]); + // __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_RXNE); + // } } void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) { - if (huart->Instance == huart3.Instance) - { - /* 拷贝数据 到菜单 */ - log_i("huart3 log dma idle...."); - __HAL_UART_CLEAR_IDLEFLAG(&huart3); -// __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_IDLE); - } +// if (huart->Instance == huart3.Instance) +// { +// /* 拷贝数据 到菜单 */ +// log_i("huart3 Ex idle...."); +// __HAL_UART_CLEAR_IDLEFLAG(&huart3); +// // __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_IDLE); +// } } void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { - if (huart->Instance == huart3.Instance) - { - max3160_485_receive_mode(); - // huart3.gState = HAL_UART_STATE_READY; - __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_TC); - } - - +// if (huart->Instance == huart3.Instance) +// { +// max3160_485_receive_mode(); +// // huart3.gState = HAL_UART_STATE_READY; +// __HAL_UART_CLEAR_FLAG(&huart3, UART_FLAG_TC); +// } // if (huart->Instance == huart6.Instance) // { @@ -377,27 +388,27 @@ void Soft_Reboot() void SD_Test() { - BSP_SD_Init(); - // printf_sdcard_info( ); - if (Init_FatFas_Mount()) - { - log_i("SD mount failure .. "); - } - else - { - log_i(" SD mount success.. "); - } - // extern SD_HandleTypeDef hsd; + // BSP_SD_Init(); + // // printf_sdcard_info( ); + // if (Init_FatFas_Mount()) + // { + // log_i("SD mount failure .. "); + // } + // else + // { + // log_i(" SD mount success.. "); + // } + // // extern SD_HandleTypeDef hsd; - if ( open_file( "0:aa.txt") == 0) - { - write_file( (char*)"data\r\n", 6 ); - // close_file(); - } - else - { - log_e(" open file failure .. "); - } + // if ( open_file( "0:aa.txt") == 0) + // { + // write_file( (char*)"data\r\n", 6 ); + // // close_file(); + // } + // else + // { + // log_e(" open file failure .. "); + // } } /* @@ -560,4 +571,84 @@ void SD_Test() // osDelay(20); // } -// } \ No newline at end of file +// } + + +// void pHTask(void *argument) +// { +// for (;;) +// { +// // log_i(" ph... pH_measure_ok %d", pH_measure_ok); +// if ( pH_measure_ok ==0 && pH_send_flag == 0) +// { +// log_i(" pH send ... "); +// HAL_UART_Receive_DMA( &huart3, pH_rcv_buf, 9 ); +// timebase = osKernelGetTickCount(); +// max3160_485_send_mode(); +// pH_send_flag = 1; +// HAL_UART_Transmit_DMA( &huart3, pH_send_buf, 8 ); +// } +// if ( pH_measure_ok ==0 && pH_send_flag == 1 && pH_rcv_flag == 0 ) +// { +// uint64_t time_ticks = osKernelGetTickCount() ; +// log_i( " time_ticks :%d %d" , time_ticks, timebase); +// if ( (time_ticks - timebase ) >400) +// { +// log_i( " pH timeout ..... " ); +// measureTimer_Callback(NULL); +// } +// } +// if ( pH_measure_ok ==0 && pH_rcv_flag == 1 ) +// { +// log_i( " pH ok ..... %d %d " ,pH_rcv_buf[5],pH_rcv_buf[6] ); +// pH_measure_ok = 1; +// } +// if ( pH_measure_ok ==1 ) +// { +// ; +// } +// osDelay(50); +// } +// } + +// void voltageTask(void *argument) +// { +// for ( ; ; ) +// { +// if (voltage_measure_ok ==0) +// { +// int16_t t = ads1115_read_data( hi2c1 ); +// log_i( "ads1115 ttt .... %d ", t ); +// // double vol = ads1115_get_voltage_val( hi2c1 , 0x01, CONFIG_REG_H, CONFIG_REG_L ); +// // ads1115_get_voltage_val( hi2c1 , 0x01, CONFIG_REG_H, CONFIG_REG_L ); +// // int vol = ads1115_get ( hi2c1 , 0x01, CONFIG_REG_H, CONFIG_REG_L ); +// // log_w( " voltage :%.6f " , voltage); +// voltage_measure_ok = 1; +// } +// osDelay(20); +// } +// } + + + // log_i( "ads1115 set **** .... " ); + // ads1115_set_state( ADS1115_WORK_STATE_SET_REGISTER ); + + // osDelay(10); + // res = my_ads1115.read( ); + // log_i( "ads1115 result .... %d " , my_ads1115.result ); + + + + // ads1115_config_register( hi2c1, 0x01, CONFIG_REG_H, CONFIG_REG_L ); + + // int16_t t = ads1115_read_data( hi2c1 ); + // log_i( "ads1115 ttt .... %d ", t ); + + // float vol; + + // vol = 100.0/1000; + + // log_i( " float ... " ); + // // log_i(" flaot %.6f" , vol); + // // log_i(" fl %.6f ", vol) ; + // log_i( " float end " ); diff --git a/Code/base/Src/device_port.c b/Code/base/Src/device_port.c index 37d4b8e..035ebec 100644 --- a/Code/base/Src/device_port.c +++ b/Code/base/Src/device_port.c @@ -33,7 +33,8 @@ void usart6_send_enable() void max3243_enable() { /* 使能 3243 工作, 系统默认低电平, 启动开启工作*/ - HAL_GPIO_WritePin(MAX3242_EN_GPIO_Port,MAX3242_EN_Pin, SET); + // HAL_GPIO_WritePin(MAX3242_EN_GPIO_Port,MAX3242_EN_Pin, SET); + HAL_GPIO_WritePin(UART_EN_GPIO_Port,UART_EN_Pin, SET); } diff --git a/Code/base/Src/i2c_ads1115.c b/Code/base/Src/i2c_ads1115.c index 01f4971..d060bec 100644 --- a/Code/base/Src/i2c_ads1115.c +++ b/Code/base/Src/i2c_ads1115.c @@ -1,107 +1,492 @@ -//i2c_ads1115.c +// i2c_ads1115.c #include "i2c_ads1115.h" -#include -#include "i2c.h" -#include "main.h" +#include "stdlib.h" +#include "stdio.h" #include "elog.h" /* -* ads1115_get_voltage_val( hi2c1, 0x00, CONFIG_REG_H, CONFIG_REG_L ) + 多路测量的话, 需要配置不同的 config_H config_L */ -extern I2C_HandleTypeDef hi2c1; -#define ADS1115_hi2c hi2c1 -int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle) +static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1; + +osThreadId_t ads1115TaskHandle; +const osThreadAttr_t ads1115Task_attributes = { + .name = "ads1115Task", + .stack_size = 256 * 4, + .priority = (osPriority_t) osPriorityNormal, +}; + +osEventFlagsId_t ads1115EventHandle; +const osEventFlagsAttr_t ads1115Event_attributes = { + .name = "ads1115Event", +}; + +// ads1115EventHandle = osEventFlagsNew (&ads1115Event_attributes); +// typedef enum +// { +// EV_READY, /*!< Startup finished. */ +// EV_FRAME_RECEIVED, /*!< Frame received. */ +// EV_EXECUTE, /*!< Execute function. */ +// EV_FRAME_SENT /*!< Frame sent. */ +// } eMBEventType; +// osEventFlagsSet(modbusEventHandle,eEvent); + // osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) +// recvedEvent = osEventFlagsWait (modbusEventHandle, +// EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | +// EV_FRAME_SENT, /* 接收任务感兴趣的事件 */ +// 0, +// portMAX_DELAY); /* 指定超时事件,无限等待 */ + +ADS1115_TypeDef my_ads1115 = + { + ads1115_init, + ads1115_port, + ads1115_test, + ads1115_start, + ads1115_stop, + NULL, + ADS1115_REG_CONFIG_OS_START, + ADS1115_REG_CONFIG_MUX_SINGLE_0, + ADS1115_REG_CONFIG_PGA_4, + ADS1115_REG_CONFIG_MODE_SINGLE, + ADS1115_REG_CONFIG_DR_128, + ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL, + ADS1115_REG_CONFIG_COMP_POL_LOW, + ADS1115_REG_CONFIG_COMP_LAT_NONLATCH, + ADS1115_REG_CONFIG_COMP_QUE_DIS, + 0, // point addr + 0, // config_H + 0, // config_L + { 0, 0, 0 }, // reg_data[3] + ADS1115_OUTPUT_UNIT_mv, // 默认输出毫伏 + 0, // event_flags + 0, // state + {0,0}, // result +}; + +void ads1115_task(void) { - ads1115_config_register(ads1115_I2cHandle, 0x00, CONFIG_REG_H, CONFIG_REG_L); - return 0; + uint8_t event_flags; + uint8_t reg_data[3] ={0}; + for (;;) + { + switch ( my_ads1115.state ) + { + case ADS1115_WORK_STATE_WAITING: + osDelay(20); + break; + + // Init + case ADS1115_WORK_STATE_INIT: + // log_i("ads1115 init .... %d ", osEventFlagsGet( ads1115EventHandle)); + + if ( osEventFlagsGet( ads1115EventHandle) == 0 ) + { + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_INIT ); + + my_ads1115.reg_data[0] = 0x01; // point addr 8bit 配置寄存器 + my_ads1115.reg_data[1] = my_ads1115.config_H; // config_reg 高位 + my_ads1115.time_ticks = osKernelGetTickCount( ); + if ( HAL_I2C_Master_Transmit_IT( pADS1115_I2C, ADS1115_WRITE_ADDRESS, my_ads1115.reg_data, 3 ) != HAL_OK) + { + // log_e( "ads1115 set register failure while reading!!!" ); + my_ads1115.state == ADS1115_WORK_STATE_ERROR ; + } + } + if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000) + { + my_ads1115.state == ADS1115_WORK_STATE_TIMEOUT ; + } + break; + case ADS1115_WORK_STATE_INIT_SUCCESS: + // log_i("ads1115 init success ... " ); + osEventFlagsClear( ads1115EventHandle, ADS1115_Event_INIT ); + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); + break; + + // SET REGISTER + case ADS1115_WORK_STATE_SET_REGISTER: + // log_i("ads1115 set register .... %d ", osEventFlagsGet( ads1115EventHandle)); + + if ( osEventFlagsGet( ads1115EventHandle) == 0 ) + { + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_REGISTER ); + + my_ads1115.reg_data[0] = 0x01; // point addr 8bit 配置寄存器 + my_ads1115.reg_data[1] = my_ads1115.config_H; // config_reg 高位 + my_ads1115.time_ticks = osKernelGetTickCount( ); + if ( HAL_I2C_Master_Transmit_IT( pADS1115_I2C, ADS1115_WRITE_ADDRESS, my_ads1115.reg_data, 3 ) != HAL_OK) + { + // log_e("ads1115 set register failure while reading!!!"); + my_ads1115.state = ADS1115_WORK_STATE_ERROR ; + } + } + if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000) + { + my_ads1115.state = ADS1115_WORK_STATE_TIMEOUT ; + } + break; + case ADS1115_WORK_STATE_SET_REGISTER_SUCCESS: + // log_e("ads1115 set register.....succ"); + osEventFlagsClear( ads1115EventHandle, ADS1115_Event_SET_REGISTER ); + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); + my_ads1115.state = ADS1115_WORK_STATE_SET_POINT_ADDR ; + break; + + // SET POINT ADDR + case ADS1115_WORK_STATE_SET_POINT_ADDR: + // log_i("ads1115 set point addr .... %d ", osEventFlagsGet( ads1115EventHandle)); + if ( osEventFlagsGet( ads1115EventHandle) == 0 ) + { + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ); + my_ads1115.time_ticks = osKernelGetTickCount( ); + if ( HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1 ) != HAL_OK ) + { + // log_e("ads1115 set register failure while reading!!!"); + my_ads1115.state = ADS1115_WORK_STATE_ERROR ; + } + } + if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000 ) + { + my_ads1115.state = ADS1115_WORK_STATE_TIMEOUT ; + } + break; + case ADS1115_WORK_STATE_SET_POINT_ADDR_SUCCESS: + // log_e("ads1115 set point addr.....succ"); + osEventFlagsClear( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ); + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); + my_ads1115.state = ADS1115_WORK_STATE_RCV_DATA ; + break; + + // RCV DATA + case ADS1115_WORK_STATE_RCV_DATA: + // log_i("ads1115 rcv data .... %d ", osEventFlagsGet( ads1115EventHandle)); + if ( osEventFlagsGet( ads1115EventHandle) == 0 ) + { + // log_e("ads1115 set rcv data *** ....."); + my_ads1115.time_ticks = osKernelGetTickCount( ); + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_RCV_DATA ); + if ( HAL_I2C_Master_Receive_IT( pADS1115_I2C, ADS1115_READ_ADDRESS, my_ads1115.result , 2 ) != HAL_OK ) + { + // log_e("ads1115 set register failure while reading!!!"); + my_ads1115.state = ADS1115_WORK_STATE_ERROR ; + } + } + if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000 ) + { + my_ads1115.state = ADS1115_WORK_STATE_TIMEOUT ; + } + break; + case ADS1115_WORK_STATE_RCV_DATA_SUCCESS: + // log_w("ads1115 rcv data .....succ result : %d ", my_ads1115.result ); + osEventFlagsClear( ads1115EventHandle, ADS1115_Event_RCV_DATA ); + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); + my_ads1115.state = ADS1115_WORK_STATE_DATA_OK ; + + // log_i( "ad val : %d ", 256*my_ads1115.result[0] +my_ads1115.result[1] ); + break; + case ADS1115_WORK_STATE_DATA_OK: + osDelay(20); + break; + case ADS1115_WORK_STATE_ERROR: + log_e("ads1115 error!!!"); + break; + case ADS1115_WORK_STATE_TIMEOUT: + log_e("ads1115 timeout!!!"); + break; + case ADS1115_WORK_STATE_STOP: + break; + default: + break; + } + osDelay( 20 ); + + } +} + +void ads1115_port(void) +{ + ads1115TaskHandle = osThreadNew(ads1115_task, NULL, &ads1115Task_attributes); + ads1115EventHandle = osEventFlagsNew ( &ads1115Event_attributes ); } /** - * @brief - * @param [in] ads1115_I2cHandle - * @param [in] pointADD -- 0x01 写配置寄存器 - * @param [in] configH - * @param [in] configL - * - * @details + * @brief + * @param [in] ads1115_I2cHandle + * @param [in] pointADD -- 读的寄存器地址 + * @param [in] configH + * @param [in] configL + * + * @details */ -void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL) +int ads1115_init() { - uint8_t reg_data[3]={pointADD,configH,configL}; - while(HAL_I2C_Master_Transmit(&ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, reg_data, 3, 2000) != HAL_OK) - { - if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) - { - log_i("ads1115 Config Register error!!!\r\n"); - } - } + uint8_t reg_data[3]; + my_ads1115.hi2c= pADS1115_I2C; + my_ads1115.config_H = my_ads1115.config_os|my_ads1115.config_mux + |my_ads1115.config_PGA|my_ads1115.config_MODE; + my_ads1115.config_L = my_ads1115.config_DR|my_ads1115.config_COMP_MODE|my_ads1115.config_COMP_POL + |my_ads1115.config_COMP_LAT|my_ads1115.config_COMP_QUE ; + my_ads1115.reg_data[0] = 0x01; // point addr 8bit 配置寄存器 0x01 + my_ads1115.reg_data[1] = my_ads1115.config_H; // config_reg 高位 + my_ads1115.reg_data[2] = my_ads1115.config_L; // config_reg 低位 + + ads1115_set_state( ADS1115_WORK_STATE_INIT ); + // osEventFlagsSet ( ads1115EventHandle, ADS1115_Event_INIT ); + // if (HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, my_ads1115.reg_data, 3 ) != HAL_OK) + // { + // return -1; + // } + return 0; +} + +int ads1115_test() +{ + + return 0; } -int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle) +void ads1115_start( ) // set register开始测量 +{ + osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); + ads1115_set_state( ADS1115_WORK_STATE_SET_REGISTER ); +} +void ads1115_stop( ) // 结束测量 等待 +{ + ads1115_set_state( ADS1115_WORK_STATE_WAITING ); +} + +int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux) +{ + my_ads1115.config_mux &= mux; + my_ads1115.config_H =my_ads1115.config_os|my_ads1115.config_mux + |my_ads1115.config_PGA|my_ads1115.config_MODE; + my_ads1115.reg_data[1] = my_ads1115.config_H; + return 0; +} + +void ads1115_set_event_flags(ADS1115_Event_TypeDef evt) +{ + osEventFlagsSet ( ads1115EventHandle, evt ); +} + +void ads1115_set_state(ADS1115_WORK_STATE_TypeDef state) +{ + my_ads1115.state = state; +} + +int16_t ads1115_read_data( ) { int16_t data; - uint8_t rx_data[2]={0}; + uint8_t rx_data[2] = {0}; - while(HAL_I2C_Master_Transmit(&ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000) != HAL_OK) + // TODO 阻塞式, 改为 DMA 中断模式 + // 读寄存器 0x00 十六位 + while (HAL_I2C_Master_Transmit(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000) != HAL_OK) + // while ( HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1 ) != HAL_OK ) { - if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) + if (HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF) { - log_i("ads1115 convert Register error!!!\r\n"); + printf("ads1115 convert Register error!!!\r\n"); } } - - while(HAL_I2C_Master_Receive(&ads1115_I2cHandle, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK) + // 读两位 + // while (HAL_I2C_Master_Receive(pADS1115_I2C, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK) + while ( HAL_I2C_Master_Receive_IT(pADS1115_I2C, ADS1115_READ_ADDRESS, rx_data, 2 ) != HAL_OK ) { - if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) + if ( HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF ) { - log_i("ads1115 read data error!!!\r\n"); + printf("ads1115 read data error!!!\r\n"); } } - - data = rx_data[0]*256 + rx_data[1]; + data = rx_data[0] * 256 + rx_data[1]; return data; } -double ads1115_get_voltage_val( I2C_HandleTypeDef ads1115_I2cHandle, uint8_t pointADD, uint8_t configH, uint8_t configL) +double ads1115_get_voltage_val( ) { double val; int16_t ad_val; - double coeff_mv = 1000.0; /* 输出 毫伏*/ - double coeff_v = 1000000.0; /* 输出 伏*/ - - ads1115_config_register( ads1115_I2cHandle, pointADD, configH, configL ); - // HAL_Delay(10); - osDelay(10); + // TODO 去掉延时,使用寄存器的指示, setup 和读取数据分开执行 + // ads1115_setup( pADS1115_I2C, pointADD, configH, configL ); + // ads1115_setup( ADS1115_REG_CONFIG_MUX_SINGLE_0 ); + + HAL_Delay(10); + // ad_val = ads1115_read_data( pADS1115_I2C ); + ad_val = my_ads1115.result[0] * 256 + my_ads1115.result[1]; + if ( (ad_val == 0x7FFF) | (ad_val == 0X8000)) // 是否超量程了 + { + ad_val = 0; + // printf("over PGA\r\n"); + } + switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率 + { + case (0x00): + val = (double)ad_val * 187.5 / 1000.0; // + break; + case (0x01): + val = (double)ad_val * 125 / 1000.0; + break; + case (0x02): + val = (double)ad_val * 62.5 / 1000.0; + break; + case (0x03): + val = (double)ad_val * 31.25 / 1000.0; + break; + case (0x04): + val = (double)ad_val * 15.625 / 1000.0; + break; + case (0x05): + val = (double)ad_val * 7.8125 / 1000.0; + break; + } + return (my_ads1115.unit == ADS1115_OUTPUT_UNIT_mv)?val:(val/1000.0); +} - ad_val=ads1115_read_data( ads1115_I2cHandle ); - if( (ad_val==0x7FFF)|(ad_val==0X8000) )//是否超量程了 +uint16_t ADS1115_Get_Coeff_BY_128( ) +{ + uint16_t val; + + switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率 { - ad_val=0; - log_i("over PGA\r\n"); + case (0x00): + val = (int)( 187.5 * 128.0); // + break; + case (0x01): + val = (int)( 125.5 * 128.0); + break; + case (0x02): + val = (int)( 62.5 * 128.0); + break; + case (0x03): + val = (int)( 31.25 * 128.0); + break; + case (0x04): + val = (int)( 15.625 * 128.0); + break; + case (0x05): + val = (int)( 7.8125 * 128.0); + break; } - switch( ( 0x0E&configH )>>1 )//量程对应的分辨率 + return val; +} + +double ADS1115_Get_Voltage_From_U16( uint16_t voltage) +{ + double val; + if ( ( voltage == 0x7FFF) | (voltage == 0X8000)) // 是否超量程了 { - case(0x00): - val=(double)ad_val*187.5/coeff_mv;// + voltage = 0; + // printf("over PGA\r\n"); + } + switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率 + { + case (0x00): + val = (double)voltage * 187.5 / 1000.0; // break; - case(0x01): - val=(double)ad_val*125/coeff_mv; + case (0x01): + val = (double)voltage * 125 / 1000.0; break; - case(0x02): - val=(double)ad_val*62.5/coeff_mv; + case (0x02): + val = (double)voltage * 62.5 / 1000.0; break; - case(0x03): - val=(double)ad_val*31.25/coeff_mv; + case (0x03): + val = (double)voltage * 31.25 / 1000.0; break; - case(0x04): - val=(double)ad_val*15.625/coeff_mv; + case (0x04): + val = (double)voltage * 15.625 / 1000.0; break; - case(0x05): - val=(double)ad_val*7.8125/coeff_mv; + case (0x05): + val = (double)voltage * 7.8125 / 1000.0; break; } + return val; +} + +//主机模式发送回调函数 +void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) +{ + if (I2cHandle == pADS1115_I2C) + { + log_i("ads1115 send cplt..."); + if ( my_ads1115.state == ADS1115_WORK_STATE_INIT ) + { + my_ads1115.state = ADS1115_WORK_STATE_INIT_SUCCESS; + // osEventFlagsSet( ads1115EventHandle, ADS1115_Event_INIT_SUCCESS ); + // osEventFlagsClear( ads1115EventHandle, ADS1115_Event_INIT ); + } + if ( my_ads1115.state == ADS1115_WORK_STATE_SET_REGISTER ) + { + my_ads1115.state = ADS1115_WORK_STATE_SET_REGISTER_SUCCESS; + // osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_REGISTER_SUCCESS ); + } + if ( my_ads1115.state == ADS1115_WORK_STATE_SET_POINT_ADDR ) + { + my_ads1115.state = ADS1115_WORK_STATE_SET_POINT_ADDR_SUCCESS; + // osEventFlagsSet( ads1115EventHandle, ADS1115_Event_TRANS_SUCCESS ); + } + } +} +//主机模式接收回调函数 +void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) +{ + if (I2cHandle == pADS1115_I2C) + { + log_i("ads1115 rcv cplt..."); + if ( my_ads1115.state == ADS1115_WORK_STATE_RCV_DATA ) + { + my_ads1115.state = ADS1115_WORK_STATE_RCV_DATA_SUCCESS; + // osEventFlagsSet( ads1115EventHandle, ADS1115_Event_RCV_DATA_SUCCESS ); + } + } +} + + +// int ads1115_test() +// { + +// log_i( "ads1115_test -> " ); +// uint32_t flag; + +// flag = osEventFlagsWait ( ads1115EventHandle, +// ADS1115_Event_READY|ADS1115_Event_INIT|ADS1115_Event_SET_REGISTER|ADS1115_Event_SET_POINT_ADDR|ADS1115_Event_RCV_DATA, +// 0, +// 10); +// log_i( "flag -> %d ", flag ); + + +// log_i( " -> %d ", osEventFlagsGet( ads1115EventHandle) ); +// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ) ; +// log_i( " ready -> %d ", osEventFlagsGet( ads1115EventHandle) ); +// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_INIT ) ; +// log_i( " init -> %d ", osEventFlagsGet( ads1115EventHandle) ); + +// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_RCV_DATA ) ; +// log_i( " set register -> %d ", osEventFlagsGet( ads1115EventHandle) ); + +// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_REGISTER ) ; +// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ) ; +// log_i( " set register -> %d ", osEventFlagsGet( ads1115EventHandle) ); + + +// osEventFlagsClear( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ) ; +// log_i( " clear -> %d ", osEventFlagsGet( ads1115EventHandle) ); +// flag = osEventFlagsWait ( ads1115EventHandle, +// ADS1115_Event_READY|ADS1115_Event_INIT|ADS1115_Event_SET_REGISTER|ADS1115_Event_SET_POINT_ADDR|ADS1115_Event_RCV_DATA, +// 0, +// 10); +// log_i( "flag 2 -> %d ", flag ); + +// if (flag&ADS1115_Event_SET_POINT_ADDR == 0) +// { +// log_i("get ...... "); +// }else{ +// log_i(" not get ... "); + +// } -} \ No newline at end of file +// return 0; +// } diff --git a/Code/base/Src/led.c b/Code/base/Src/led.c index b3bcaf7..fa50675 100644 --- a/Code/base/Src/led.c +++ b/Code/base/Src/led.c @@ -1,74 +1,139 @@ #include "led.h" +// #include "platform.h" static struct led *led_table[LED_MAX_NUM]; -static uint32_t p_led_table=0; -/** - * @brief 注册LED灯 - * - * @param led struct led 结构指针 - * @param gpio LED所在的GPIO - * @param pin LED所在的引脚 - * @param state LED初始状态 - * @param level_on LED点亮时的电平 1:高 0:低 - * @return int 0:成功 非0:失败 - */ -int led_register(struct led *led,GPIO_TypeDef *gpio,uint16_t pin,enum led_state state,uint16_t level_on) +static uint32_t p_led_table = 0; +static uint32_t delay_time_ms = 1; + +osThreadId_t ledHandle; +const osThreadAttr_t led_attributes = { + .name = "led", + .stack_size = 256 * 4, + .priority = (osPriority_t)osPriorityBelowNormal, +}; + +My_LED_TypeDef my_led = { + Led_Init, + Led_Port, + 0, + 0, + // led_table, + +}; + +/* 修改 MY_LED_COLOR_SEQ ,以及在 Led_Init 添加LED*/ + +int Led_Init() { - if(p_led_table>=LED_MAX_NUM-1){ + + led_setup(LED_SEQ_0, LED0_GPIO_Port, LED0_Pin, LED_STATE_ON, RESET); + led_set_state(LED_SEQ_0, LED_STATE_FLICKER_MEDIUM); + + led_setup(LED_SEQ_1, LED1_GPIO_Port, LED1_Pin, LED_STATE_ON, RESET); + led_set_state(LED_SEQ_1, LED_STATE_FLICKER_MEDIUM); + + return 0; +} + +void Led_Task(void *argument) +{ + uint16_t *delay_ms = argument; + for (;;) + { + led_callback(); + osDelay(*delay_ms); + // osDelay(200); + } +} + +int Led_Port(uint16_t delay_ms) +{ + delay_time_ms = delay_ms; + ledHandle = osThreadNew(Led_Task, (void *)(&delay_time_ms), &led_attributes); + return 0; +} + +int led_setup(uint8_t seq, GPIO_TypeDef *gpio, uint16_t pin, enum led_state state, uint16_t level_on) +{ + if (seq >= LED_MAX_NUM - 1 || seq < 0) + { + return -1; + } + struct led *Handle = (struct led *)malloc(sizeof(struct led)); + if (Handle == NULL) + { return -1; } - led->gpio=gpio; - led->pin=pin; - led->state=state; - led->level_on=level_on; - led_table[p_led_table++]=led; + led_table[seq] = Handle; + led_table[seq]->gpio = gpio; + led_table[seq]->pin = pin; + led_table[seq]->state = state; + led_table[seq]->level_on = level_on; + p_led_table++; return 0; } -/** - * @brief 设置LED状态 - * - * @param led struct led 结构指针 - * @param state LED状态 - * @return int 0:成功 - */ -int led_set_state(struct led *led,enum led_state state) + +// int led_register(struct led *led, GPIO_TypeDef *gpio,uint16_t pin,enum led_state state,uint16_t level_on) +// { +// if(p_led_table>=LED_MAX_NUM-1){ +// return -1; +// } +// led->gpio=gpio; +// led->pin=pin; +// led->state=state; +// led->level_on=level_on; +// led_table[p_led_table++]=led; +// return 0; +// } + +int led_set_state(uint8_t seq, enum led_state state) { - led->state=state; + + if (led_table[seq] == NULL) + { + return -1; + } + led_table[seq]->state = state; return 0; } + /** * @brief led回调函数 每100ms调用一次 - * + * */ void led_callback(void) { int i; - static uint32_t tick_con=0; + static uint32_t tick_con = 0; tick_con++; - for(i=0;istate) { case LED_STATE_OFF: - HAL_GPIO_WritePin( led_table[i]->gpio,led_table[i]->pin,(~led_table[i]->level_on)&1 ); + HAL_GPIO_WritePin(led_table[i]->gpio, led_table[i]->pin, (~led_table[i]->level_on) & 1); // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,(~led_table[i]->level_on)&1); break; case LED_STATE_ON: - HAL_GPIO_WritePin( led_table[i]->gpio,led_table[i]->pin,led_table[i]->level_on&1 ); + HAL_GPIO_WritePin(led_table[i]->gpio, led_table[i]->pin, led_table[i]->level_on & 1); // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,led_table[i]->level_on&1); break; case LED_STATE_FLICKER_QUICK: - HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); + HAL_GPIO_TogglePin(led_table[i]->gpio, led_table[i]->pin); // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin)); break; case LED_STATE_FLICKER_MEDIUM: - if((tick_con&0x01)==0){ - HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); + + if ((tick_con & 0x01) == 0) + { + HAL_GPIO_TogglePin(led_table[i]->gpio, led_table[i]->pin); // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin)); } break; case LED_STATE_FLICKER_SLOW: - if((tick_con&0x03)==0){ - HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); + if ((tick_con & 0x03) == 0) + { + HAL_GPIO_TogglePin(led_table[i]->gpio, led_table[i]->pin); // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin)); } break; diff --git a/Code/base/Src/myrtos.c b/Code/base/Src/myrtos.c index 58f5918..af65cda 100644 --- a/Code/base/Src/myrtos.c +++ b/Code/base/Src/myrtos.c @@ -1,33 +1,33 @@ #include "myrtos.h" -osThreadId_t pHTaskHandle; -const osThreadAttr_t pHTask_attributes = { - .name = "pHTask", - .stack_size = 256 * 4, - .priority = (osPriority_t) osPriorityLow, -}; -__weak void pHTask(void *argument) -{ - for (;;) - { - osDelay(1); - } -} +// osThreadId_t pHTaskHandle; +// const osThreadAttr_t pHTask_attributes = { +// .name = "pHTask", +// .stack_size = 256 * 4, +// .priority = (osPriority_t) osPriorityLow, +// }; +// __weak void pHTask(void *argument) +// { +// for (;;) +// { +// osDelay(1); +// } +// } -osThreadId_t voltageTaskHandle; -const osThreadAttr_t voltageTask_attributes = { - .name = "voltageTask", - .stack_size = 256 * 4, - .priority = (osPriority_t) osPriorityLow, -}; -__weak void voltageTask(void *argument) -{ - for (;;) - { - osDelay(1); - } -} +// osThreadId_t voltageTaskHandle; +// const osThreadAttr_t voltageTask_attributes = { +// .name = "voltageTask", +// .stack_size = 256 * 4, +// .priority = (osPriority_t) osPriorityLow, +// }; +// __weak void voltageTask(void *argument) +// { +// for (;;) +// { +// osDelay(1); +// } +// } osThreadId_t measureTaskHandle; @@ -59,8 +59,8 @@ void RTOS_Port(void) measureTaskHandle = osThreadNew( measureTask, NULL, &measureTask_attributes ); measureTimerHandle = osTimerNew(measureTimer_Callback, osTimerPeriodic, NULL, &measureTimer_attributes); - pHTaskHandle = osThreadNew( pHTask, NULL, &pHTask_attributes ); - voltageTaskHandle = osThreadNew( voltageTask, NULL, &measureTask_attributes ); + // pHTaskHandle = osThreadNew( pHTask, NULL, &pHTask_attributes ); + // voltageTaskHandle = osThreadNew( voltageTask, NULL, &measureTask_attributes ); } diff --git a/Code/base/Src/pH.c b/Code/base/Src/pH.c new file mode 100644 index 0000000..12e59da --- /dev/null +++ b/Code/base/Src/pH.c @@ -0,0 +1,412 @@ +#include "pH.h" +#include "elog.h" +#include "FreeRTOS.h" +#include "cmsis_os.h" +#include "stm32f4xx.h" +#include "usart.h" +#include "main.h" + + +/****** Port ***************/ +#if 1 + +#define PH_Uart_IRQHandler USART3_IRQHandler +// #define PH_Uart_IRQHandler USART4_IRQHandler +UART_HandleTypeDef *pPHUart = &huart3; +PH_TypeDef *ph ; + +My_PH_TypeDef my_pH = +{ + PH_Init, + PH_Port, + PH_Test, + PH_Start, + PH_Stop, + SEL_232_485_GPIO_Port, + HDPLX_GPIO_Port, + DE485_GPIO_Port, + SEL_232_485_Pin, + HDPLX_Pin, + DE485_Pin, + Uart_Interface_Max3160, /* 接口类型 0: common, 1: 485 ,2:3160*/ + Uart_RSMODE_485, /* mode_232_485 0 commome 1:485*/ + Uart_Trans_DMA, /* trans_type0 :polling, 1: IT 2: DMA*/ + Uart_Trans_DMA, /* rcv_type 0 :polling, 1: IT 2: DMA*/ + Uart_IDLE_IT_ENABLE, /* idle_enable_disable 0 :不启用空闲 , 1: 启用空闲*/ + 0, //ph + 0, // temprature + NULL, /* pointer huart*/ +}; + +extern volatile uint8_t measure_flag ; + +uint8_t PH_SND_Buf[8] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B }; +uint8_t PH_RCV_Buf[PH_Rcv_Buf_Size*2] = { 0 }; + +osThreadId_t phHandle; +const osThreadAttr_t PH_attributes = { + .name = "ph", + .stack_size = 1024, + .priority = (osPriority_t) osPriorityBelowNormal, +}; + +void PH_Uart_IRQHandler(void) +{ + if (__HAL_UART_GET_FLAG( ph->uarthelper->huart, UART_FLAG_TC) != RESET) + { + // log_i("ph....huart3 TC callback ..."); + PH_Send_Cplt_Callback( ph ); + // ph->state = PH_Status_Send_Cplt; + ph->uarthelper->huart->gState = HAL_UART_STATE_READY; + __HAL_UART_CLEAR_FLAG( ph->uarthelper->huart, UART_FLAG_TC ); + } + + if (__HAL_UART_GET_FLAG( ph->uarthelper->huart, UART_FLAG_IDLE ) != RESET) + { + uint16_t count = __HAL_DMA_GET_COUNTER( ph->uarthelper->huart->hdmarx ); + log_i("....huart3 IDLE.... %d site3 == 4 %02X ", count, PH_RCV_Buf[2] ); + uint16_t data_length = 2*PH_Rcv_Buf_Size - count; + if (count == PH_Rcv_Buf_Size) + { + // HAL_UART_DMAStop( ph->uarthelper->huart ); + ph->state = PH_Status_RCV_OK; + } + if (count < PH_Rcv_Buf_Size) + { + // HAL_UART_DMAStop( ph->uarthelper->huart ); + ph->state = PH_Status_Error; + } + __HAL_UART_CLEAR_IDLEFLAG( ph->uarthelper->huart ); + } + HAL_UART_IRQHandler( ph->uarthelper->huart ); +} + +int PH_Init( ) +{ + ph = (PH_TypeDef *)malloc(sizeof(PH_TypeDef)); + + UartInterface_TypeDef *interface = UartInterface_Init( ); + UartHelper_TypeDef *uarthelper = UartHelper_Init(); + + PH_Set_Uarthelper( ph, uarthelper ); + PH_Set_Interface( ph, interface ); + PH_Set_Huart( ph, pPHUart ); + + /* set_GPIO UartInterface */ + UartInterface_Set_Sel_GPIO_Pin( ph->uarthelper->interface, my_pH.sel_gpio, my_pH.sel_pin ); + UartInterface_Set_Dplx_GPIO_Pin( ph->uarthelper->interface, my_pH.dplx_gpio, my_pH.dplx_pin ); + UartInterface_Set_DE485_GPIO_Pin( ph->uarthelper->interface, my_pH.de_gpio, my_pH.de_pin ); + + /* interface type */ + PH_Set_Interface_Type( ph, my_pH.interface_type ); + PH_Set_RsMode_232_485 ( ph, my_pH.mode_232_485 ); // max3160 的232 485选择 + PH_Set_Trans_Type( ph, my_pH.trans_type ) ; + PH_Set_Rcv_Type ( ph, my_pH.rcv_type ) ; + PH_Set_Idle_Enable (ph, my_pH.idle_enable_disable ) ; + // UartHelper_Setup_Interface_type( ph ,my_pH.interface_type); + + // check + if ( ph->uarthelper->huart == pPHUart ){ + log_i ( "ph set huart ok. trans_type -> %d rcv_type -> %d ( 0 :polling, 1: IT 2: DMA) ",ph->trans_type ,ph->rcv_type ) ; + log_i( " interface-> %d %d (0:default, 1:485, 2:3160) " ,ph->uarthelper->interface_type ,ph->uarthelper->interface->interface_type ); + log_i( "ph 232_485 -> %d %d (0:232 ,1: 485) " ,ph->uarthelper->mode_232_485, ph->uarthelper->interface->mode_232_485 ); + }else{ + log_e ( "ph set huart failure " ) ; + } + + PH_Set_Timeout( ph, 500 ); + PH_Set_Sendbuf( ph, PH_SND_Buf, 8 ); + PH_Set_Rcvbuf( ph, PH_RCV_Buf, sizeof(PH_RCV_Buf) ); + + // set paras; + ph->timebase = 0; + // ph->timeout_ms = 1000; + ph->send_status = Uart_Status_Ready; + ph->send_flag = 0; + ph->command_seq = 4; + ph->mode = 2; + ph->data_begin_flag = 0; + ph->state = PH_Status_Waiting; + return 0; +} + + +void PH_Port( ) +{ + phHandle = osThreadNew( PH_Task, NULL, &PH_attributes ); +} + +void PH_Task( ) +{ + // log_i( " ph tran mode : %d ", ph->->trans_mode ); + memset( PH_RCV_Buf, 0, 2*PH_Rcv_Buf_Size ); /* ph*3 ph *2 否则内存泄漏 */ + uint64_t time_ticks; + // log_i( " ph tran mode : %d %d " , ph->trans_mode , ph->mode ); + + for ( ; ; ) + { + switch (ph->state) + { + case PH_Status_Waiting: + osDelay(20); + break; + case PH_Status_Ready: + log_i(" pH send .................. "); + my_pH.ph_val = 0; + my_pH.temp_val = 0; + memset( ph->rcv_buf, 0, 2*PH_Rcv_Buf_Size ); + PH_Begin_Rcv( ph, ph->rcv_buf, ph->size_rcv ); + // HAL_UARTEx_ReceiveToIdle_DMA( &huart3, PH_RCV_Buf, PH_Rcv_Buf_Size ); + // HAL_UART_Receive_DMA ( &huart3, ph->rcv_buf, ph->size_rcv ); + // __HAL_UART_ENABLE_IT( &huart3, UART_IT_IDLE ); + + ph->timebase = osKernelGetTickCount( ); + // max3160_485_send_mode(); + ph->state = PH_Status_Sending ; + PH_Send( ph, ph->send_buf, ph->size_send ); + break; + case PH_Status_Sending: + time_ticks = osKernelGetTickCount() ; + // log_i( " time_ticks :%d %d" , time_ticks, ph->timebase); + if ( ( time_ticks - ph->timebase ) > ph->timeout_ms) + { + ph->state = PH_Status_Timeout ; + } + osDelay(5); + break; + case PH_Status_Send_Cplt: + time_ticks = osKernelGetTickCount() ; + log_i( "PH_Status_Send_Cplt ..... " ); + if ( (time_ticks - ph->timebase ) > ph->timeout_ms) + { + ph->state = PH_Status_Timeout ; + } + osDelay(5); + break; + case PH_Status_RCV_OK: + if ( my_pH.ph_val == 0 & my_pH.temp_val==0 ) + { + my_pH.ph_val = ph->rcv_buf[3]*256 + ph->rcv_buf[4]; + my_pH.temp_val = ph->rcv_buf[5]*256 + ph->rcv_buf[6]; + + log_i( "PH_Status_RCV_OK ..... ph %d temp %d " , my_pH.ph_val, my_pH.temp_val); + ph->state = PH_Status_DATA_OK ; + } + // TODO 停止DMA + HAL_UART_DMAStop( ph->uarthelper->huart ); + osDelay(20); + break; + case PH_Status_DATA_OK: + osDelay(20); + break; + case PH_Status_Timeout: + log_e( " pH timeout ..... " ); + ph->state = PH_Status_Waiting ; + HAL_UART_DMAStop( ph->uarthelper->huart ); + osDelay(5); + break; + case PH_Status_Error: + log_e( " pH error ..... " ); + ph->state = PH_Status_Waiting ; + HAL_UART_DMAStop( ph->uarthelper->huart ); + osDelay(5); + break; + default: + break; + } + + osDelay(20); + } +} + +int PH_Test( ) +{ + HAL_UART_Transmit_IT( &huart3, ph->send_buf, ph->size_send ); + osDelay(20); + if ( HAL_UART_Receive ( &huart3, ph->rcv_buf, ph->size_rcv ,0xFF) != HAL_OK ){ + return -1; + } + return 0; +} +void PH_Start( ) +{ + // log_e( " pH PH_Start ..... " ); + ph->state = PH_Status_Ready; +} +void PH_Stop( ) +{ + ph->state = PH_Status_Waiting; +} + +/****************** 接口 *******************/ + + +void PH_Set_Uarthelper( PH_TypeDef *ph, UartHelper_TypeDef * uarthelper) +{ + ph->uarthelper = uarthelper; +} +void PH_Set_Interface( PH_TypeDef *ph, UartInterface_TypeDef * interface ) +{ + UartHelper_Set_Interface( ph->uarthelper, interface ); +} +void PH_Set_Huart( PH_TypeDef *ph, UART_HandleTypeDef * huart ) +{ + ph->uarthelper->huart = huart; + // UartHelper_Set_Huart( ph->uarthelper, huart ); +} +void PH_Set_Interface_Type( PH_TypeDef *ph, Uart_Interface_Type_Typedef interface_type ) +{ + ph->interface_type = interface_type; + ph->uarthelper->interface_type = interface_type; + UartInterface_Setup_Interface_type( ph->uarthelper->interface ,ph->interface_type); +} +void PH_Set_RsMode_232_485( PH_TypeDef *ph, Uart_RS_Mode_TypeDef rs_232_485 ) +{ + ph->mode_232_485 = rs_232_485; + ph->uarthelper->mode_232_485 = rs_232_485; + UartInterface_Setup_Mode_232_485( ph->uarthelper->interface, my_pH.mode_232_485 ); + +} +void PH_Set_Trans_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_type ) +{ + ph->trans_type = trans_type; +} +void PH_Set_Rcv_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef rcv_type ) +{ + ph->rcv_type = rcv_type; + +} +void PH_Set_Idle_Enable( PH_TypeDef *ph, Uart_IDLE_Enable_TypeDef idle_enable_disable ) +{ + ph->idle_enable_disable = idle_enable_disable; +} + +void PH_Set_TransMode( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_mode ) +{ + ph->trans_type = trans_mode; + ph->rcv_type = trans_mode; +} + +void PH_Set_Timeout( PH_TypeDef *ph, uint16_t timeout_ms) +{ + ph->timeout_ms = timeout_ms; +} +void PH_Set_Sendbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size) +{ + ph->send_buf = buf; + ph->size_send = size; + // log_i( " size_send %d", sensor->size_send); +} + +void PH_Set_Rcvbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size) +{ + ph->rcv_buf = buf; + ph->size_rcv = size; + // log_i( " size_rcv %d", demo->size_rcv); +} + +int PH_Send( PH_TypeDef *ph, uint8_t * buf, uint16_t size ) +{ + // log_i( "SensorSend size_ %d", demo->size_send ); + ph->timebase = HAL_GetTick(); + UartInterface_Set_GPIO_For_Transmit( ph->uarthelper->interface ); + // UartHelper_Send_TxPrepare_Callback( ph->uarthelper ); + // ph->send_status = 1; + if ( ph->trans_type == 0 ) + return HAL_UART_Transmit( ph->uarthelper->huart, buf, size ,0XFF); + if ( ph->trans_type == 1 ) + return HAL_UART_Transmit_IT( ph->uarthelper->huart, buf, size ); + if ( ph->trans_type == 2 ) + return HAL_UART_Transmit_DMA( ph->uarthelper->huart, buf, size ); + return -1; + // ph->send_flag = 0; +} + + +void PH_Begin_Rcv( PH_TypeDef *ph, uint8_t * buf, uint16_t size) +{ + /* 是否开启空闲中断*/ + if ( ph->idle_enable_disable == 1 ) + { + // log_i(" ** idle enable..."); + __HAL_UART_ENABLE_IT( ph->uarthelper->huart, UART_IT_IDLE ); + } + + if ( ph->trans_type == 0 ) + { + // TODO 发生错误怎么处理 + HAL_UART_Receive( ph->uarthelper->huart, buf, size ,0X0FFF); + } + + if ( ph->trans_type == 1 ) + { + HAL_UART_Receive_IT( ph->uarthelper->huart, buf, size); + } + + if ( ph->trans_type == 2 ) + { + HAL_UART_Receive_DMA( ph->uarthelper->huart, buf, size); + } +} + +void PH_Send_Cplt_Callback( PH_TypeDef *ph ) +{ + // ph->timebase = HAL_GetTick(); + ph->status = Uart_Status_Send_Cplt; + if ( ph->interface_type != 0 ) + { + UartInterface_Set_GPIO_For_Trans_Cplt( ph->uarthelper->interface ); + // UartHelper_Set_GPIO_For_Trans_Cplt( ph->uarthelper ); + } + +} + +void PH_Rcv_Idle_Callback( PH_TypeDef *ph ) +{ + /* 搬运 数据到 kfifo*/ + ph->status = 0; + ph->send_flag = 0; +} + + + +void PH_Rcv_Cplt_Callback( PH_TypeDef *ph ) +{ + /* 搬运 数据到 kfifo*/ + log_i( " PH_Rcv_Cplt_Callback 1 .... " ); + ph->rcv_ok = 1 ; + // ph->status = 0; + // ph->send_flag = 1; + // if ( ph->mode < 2 ) + // ph->command_seq++; +} + +int PH_Get_Data_OK( PH_TypeDef *ph ) +{ + return ph->rcv_ok; +} +void PH_Set_Send_Flag( PH_TypeDef *ph ) +{ + // vPortEnterCritical(); + ph->send_flag = 1; + ph->command_seq = 0; + ph->data_ok = 0; + // vPortExitCritical( ); +} + +#endif + + + + // UartHelper_Set_232 485 UartInterface + // UartInterface_Setup_Mode_232_485( ph->uarthelper->interface, my_pH.mode_232_485 ); + // if (ph->interface_type == 0) + // UartInterface_Set_232( ph->uarthelper->interface); + // if (ph->interface_type == 1) + // UartInterface_Set_485( ph->uarthelper->interface); + // if (ph->interface_type ==2 && my_pH.mode_232_485 ==Uart_RSMODE_232) + // UartInterface_Set_232( ph->uarthelper->interface); + // if (ph->interface_type ==2 && my_pH.mode_232_485 ==Uart_RSMODE_485) + // UartInterface_Set_485( ph->uarthelper->interface); + // log_i( " interface-> %d %d (0:default, 1:485, 2:3160) " ,ph->uarthelper->interface_type ,ph->uarthelper->interface->interface_type ); + // log_i( "ph 232_485 -> %d %d (0:232 ,1: 485) " ,ph->uarthelper->mode_232_485, ph->uarthelper->interface->mode_232_485 ); diff --git a/Code/base/Src/test_port.c b/Code/base/Src/test_port.c index 6dedb2d..1a4d418 100644 --- a/Code/base/Src/test_port.c +++ b/Code/base/Src/test_port.c @@ -21,8 +21,6 @@ const osThreadAttr_t test_attributes = { uint32_t test_flag =0; void Test_Port() { - - testHandle = osThreadNew(Test_Task, NULL, &test_attributes); } diff --git a/Code/device/Inc/eeprom.h b/Code/device/Inc/eeprom.h new file mode 100644 index 0000000..20d9864 --- /dev/null +++ b/Code/device/Inc/eeprom.h @@ -0,0 +1,167 @@ +#ifndef EEPROM_H_ +#define EEPROM_H_ +/* +* 两种方法: +* 一种直接调用读写多字节, 多任务下可能导致阻塞 +* 一种设置size send_buf 实现 +*/ +#include "main.h" +// #include "platform.h" +#include "i2c.h" +#include "i2c_helper.h" + +#include "FreeRTOSConfig.h" +#include "cmsis_os2.h" +#include "elog.h" + +#define EEPROM_BYTE_DELAY_ENABLE 1 + +typedef enum { + EEPROM_EVT_WRITE, + EEPROM_EVT_READ, + EEPROM_EVT_WRITE_BYTE_DELAY, +}EEPROM_EVT_TypeDef; + +typedef enum { + EEPROM_STATE_READY, + EEPROM_STATE_WRITE, + EEPROM_STATE_READ, +}EEPROM_STATE_TypeDef; + +typedef enum { + EEPROM_MEM_ADDR_TYPE_Bit8, + EEPROM_MEM_ADDR_BIT_TYPE_Bit16, +}EEPROM_MEM_ADDR_TypeDef; + +typedef enum { + EEPROM_MEM_ADDR_BIT_8, + EEPROM_MEM_ADDR_BIT_16, +}EEPROM_MEM_ADDR_BIT_TypeDef; + +typedef enum { + EEPROM_DEV_ADDR_BIT_8, + EEPROM_DEV_ADDR_BIT_10, +} EEPROM_DEV_ADDR_TypeDef; + +typedef enum { + AT24C01 =127, // 8bit mem_addr + AT24C02 =255, + AT24C04 =511, // 16bit mem_addr,先发 high8 后 low8 + AT24C08 =1023, + AT24C16 =2047, + AT24C32 =4095, + AT24C64 =8191, + AT24C128 =16383, + AT24C256 =32767, +}EEPROM_MODEL_TypeDef; + +// typedef void (*read_callback)(); +// typedef void (*write_callback)(); +typedef struct +{ + I2C_HandleTypeDef *hi2c; + // I2CHelper_TypeDef *i2chelper; + EEPROM_MODEL_TypeDef model; // AT24C01 AT24C02 AT24C256 + EEPROM_MEM_ADDR_TypeDef mem_addr_type; // 1: 8bit 2: 16bit I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT + // EEPROM_MEM_ADDR_BIT_TypeDef mem_addr_bit; // 1: 7bit 2: 10bit + EEPROM_DEV_ADDR_TypeDef dev_addr; // 8bit 写地址 + uint8_t page_addr; + + volatile EEPROM_STATE_TypeDef state; + uint8_t write_delay_ms; // 5-8ms + uint32_t time_base; // 从系统获得一个systick的毫秒数 + + uint8_t mode; // polling 0 , it 1, dma 2 + uint8_t writeCplt; + uint8_t readCplt; + + // 设置任务参数 发送一个 mem_addr++ send_buf++ size-- + uint8_t *send_buf; + uint16_t size; + uint16_t mem_addr; + uint8_t is_busy; + uint8_t error; + + HAL_I2C_StateTypeDef stat; +}EEPROM_TypeDef; +extern EEPROM_TypeDef *eeprom; + +typedef struct +{ + void (*init)(void); + void (*deinit)(void); + void (*port)(void) ; + EEPROM_MODEL_TypeDef model; // AT24C01 AT24C02 AT24C256 + EEPROM_MEM_ADDR_TypeDef mem_addr_type; + // EEPROM_MEM_ADDR_BIT_TypeDef data_addr_bit; + EEPROM_DEV_ADDR_TypeDef dev_addr; + uint8_t page_addr; +}My_EEPROM_TypeDef; +extern My_EEPROM_TypeDef my_eeprom; + +void Eeprom_Init( ); +void Eeprom_DeInit( ); +void Eeprom_Port( ); +int Eeprom_SET_I2CHelper( EEPROM_TypeDef *eeprom, I2CHelper_TypeDef *i2chelper ); +int Eeprom_SET_Device_Model( EEPROM_TypeDef *eeprom, EEPROM_MODEL_TypeDef model ); +int Eeprom_SET_Device_Addr( EEPROM_TypeDef *eeprom, uint8_t dev_addr ); +int Eeprom_SET_Mem_Addr ( EEPROM_TypeDef *eeprom, uint16_t mem_addr ); +int Eeprom_SET_Mem_Addr_Type( EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_TypeDef mem_addr_type ); +int Eeprom_SET_Mem_Addr_Bit_Type( EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_BIT_TypeDef mem_addr_bit ); + +int Eeprom_SET_WorkMode( EEPROM_TypeDef *eeprom, I2C_HELPER_MODE_TypeDef mem_addr_type); +int Eeprom_SET_Write_Delay_ms( EEPROM_TypeDef *eeprom, uint8_t write_delay_ms); + +// int Eeprom_Transmit(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size); +// int Eeprom_Begin_Rcv(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size); + +int Eeprom_Read(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size ); +// int Eeprom_Write(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size ); + +void Eeprom_Set_Sendbuf_Size(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size); + +int Eeprom_Test( ); + +#ifdef EEPROM_BYTE_DELAY_ENABLE +int Eeprom_Write_By_Byte_Delay(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size); +#endif + +#endif + + + +/** + * @brief 用非阻塞方法写 EEPROM 会写不进去--> 写数据到EEPROM,每个字节加5-8ms 延时 + * 还是用阻塞的方法区写, 读可以考虑非阻塞 --> IT DMA + * 不用 i2chelper 直接用hi2c, + * + * Eeprom_SET_Mem_Addr 设置eeprom数据地址 + * Eeprom_Set_Sendbuf_Size 设置buf size 进行写入 EEprom + * + * 读取 + * Eeprom_SET_Mem_Addr 设置eeprom数据地址 + * HAL_I2C_Mem_Read + * @details + * + * uint8_t buf1[4] ={0x05, 0x03 , 0x04, 0x05}; + uint8_t buf2[4] = {0x08,0x08,0x08,0x08} ; + int st; + // Eeprom_Set_Sendbuf_Size(eeprom, buf1, 4); + // my_eeprom.port(); + Eeprom_SET_Mem_Addr( eeprom, 0 ); + st = HAL_I2C_Mem_Write(eeprom->hi2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, buf1, 4, eeprom->write_delay_ms); + osDelay( 10 ); + // Eeprom_Read( eeprom, buf2, 4); + // st = HAL_I2C_Mem_Read(eeprom->hi2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, buf2, 4, eeprom->write_delay_ms); + + Eeprom_SET_Mem_Addr( eeprom, 0 ); + if ( Eeprom_Read(eeprom, buf2, 4) != 0 ) + { + log_i(" Eeprom Read Config Error "); + }else{ + log_i(" Eeprom Read Config OK! "); + } + + osDelay(10); + log_i( "buf2 %d %d ", buf2[0] , buf2[1]); + */ \ No newline at end of file diff --git a/Code/device/Inc/i2c_helper.h b/Code/device/Inc/i2c_helper.h new file mode 100644 index 0000000..3cbface --- /dev/null +++ b/Code/device/Inc/i2c_helper.h @@ -0,0 +1,118 @@ +#ifndef __I2C_HELPER_H +#define __I2C_HELPER_H +/** +* 封装 Master模式 +*/ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "i2c.h" +#include +/* 回调函数,将数据返回上层 */ +typedef void (*it_callback)(void *obj,uint8_t *buf, uint32_t buf_size ); + +/* 由于可能存在多个外设,考虑将 事件类型封装在helper, 事件定义初始化不必放这里*/ +typedef enum +{ + I2C_HELPER_Event_READY, /*!< Startup finished. */ + I2C_HELPER_Event_INIT, + I2C_HELPER_Event_INIT_SUCCESS, + I2C_HELPER_Event_TRANS_ONLY, + I2C_HELPER_Event_TRANS_FOR_DATA, + I2C_HELPER_Event_DATA_RCV, +} I2C_HELPER_Event_TypeDef; + +typedef enum +{ + I2C_HELPER_TRANS_POLLING, + I2C_HELPER_TRANS_IT, + I2C_HELPER_TRANS_DMA +}I2C_HELPER_TRANS_TypeDef; + +typedef enum +{ + I2C_HELPER_RCV_POLLING, + I2C_HELPER_RCV_IT, + I2C_HELPER_RCV_DMA +}I2C_HELPER_RCV_TypeDef; + +typedef enum +{ + I2C_HELPER_MODE_MASTER, + I2C_HELPER_MODE_SLAVE +}I2C_HELPER_MODE_TypeDef; + +typedef struct +{ + I2C_HandleTypeDef *hi2c; + uint8_t i2c_write_address; + uint8_t i2c_read_address; + I2C_HELPER_TRANS_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/ + I2C_HELPER_RCV_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/ + I2C_HELPER_MODE_TypeDef mode; + + uint8_t *trans_buf; + volatile uint32_t trans_size; + volatile uint32_t trans_data_con; + + uint8_t *receive_buf; + volatile uint32_t receive_size; + volatile uint8_t receive_data_con; + + // volatile uint8_t receive_buf_con; + // uint32_t receive_buf_half_len; + // uint8_t half_flag; /*0 : 未半满, 1:半满, 2: 半满已经处理*/ + + // volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/ + + void * obj; + it_callback callback; + + +}I2CHelper_TypeDef; + +I2CHelper_TypeDef * I2CHelper_Init( ); +void I2CHelper_Set_Hi2c( I2CHelper_TypeDef *i2chelper, I2C_HandleTypeDef * hi2c ); +void I2CHelper_Set_Mode( I2CHelper_TypeDef *i2chelper, I2C_HELPER_MODE_TypeDef mode ); +void I2CHelper_Set_Trans_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_TRANS_TypeDef trans_type ); +void I2CHelper_Set_Rcv_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_RCV_TypeDef rcv_type ); + +// void I2CHelper_Set_timeout( I2CHelper_TypeDef *i2chelper, uint32_t timeout_ms ); + +int I2CHelper_Set_callback_func_obj( I2CHelper_TypeDef *i2chelper, void * obj, it_callback callback ); + +void I2CHelper_Set_rcv_buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ); +void I2CHelper_Set_Trans_Buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ); + +int I2CHelper_Write( I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size); +int I2CHelper_Read(I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size); + +void I2CHelper_Snd_Cplt_Callback( ); +void I2CHelper_Rcv_Cplt_Callback( ); + +// int I2CHelper_Flags_Set(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type ); +// int I2CHelper_Flags_Clear(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type ); +// int I2CHelper_Flags_Wait(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type ); + + +// void I2CHelper_Set_GPIO_For_Trans_Cplt( I2CHelper_TypeDef *i2chelper ); +// void I2CHelper_Rcv_Cplt_Callback( I2CHelper_TypeDef *i2chelper ); +// void I2CHelper_Rcv_Idle_Callback( I2CHelper_TypeDef *i2chelper ); +// void I2CHelper_Rcv_DMA_Half_Callback( I2CHelper_TypeDef *i2chelper ); + +int I2CHelper_copy( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ); +int I2CHelper_isbusy( I2CHelper_TypeDef *i2chelper ); +void I2CHelper_error( I2CHelper_TypeDef *i2chelper ); + + +// uint16_t Get_Crc16(const char *buf, uint16_t len); +// uint8_t Check_Crc16(uint8_t *buf, uint16_t length); +#ifdef __cplusplus + } +#endif + +#endif + + \ No newline at end of file diff --git a/Code/device/Inc/spi_helper.h b/Code/device/Inc/spi_helper.h new file mode 100644 index 0000000..1eefa8e --- /dev/null +++ b/Code/device/Inc/spi_helper.h @@ -0,0 +1,125 @@ +#ifndef __SPI_HELPER_H +#define __SPI_HELPER_H +/** +* 封装 uart 发送接收操作 +* ?? 是否用到buf? +*/ + +#if 0 + +#ifdef __cplusplus + extern "C" { +#endif + + + +#include "spi.h" +#include +/* 回调函数,将数据返回上层 */ +typedef void (*it_callback)(void *obj,uint8_t *buf, uint32_t buf_size ); + +/* 由于可能存在多个外设,考虑将 事件类型封装在helper, 事件定义初始化不必放这里*/ +typedef enum +{ + SPI_HELPER_Event_READY, /*!< Startup finished. */ + SPI_HELPER_Event_INIT, + SPI_HELPER_Event_INIT_SUCCESS, + SPI_HELPER_Event_TRANS_ONLY, + SPI_HELPER_Event_TRANS_FOR_DATA, + SPI_HELPER_Event_DATA_RCV, +} SPI_HELPER_Event_TypeDef; + +typedef enum +{ + SPI_HELPER_TRANS_POLLING, + SPI_HELPER_TRANS_IT, + SPI_HELPER_TRANS_DMA +}SPI_HELPER_TRANS_TypeDef; + +typedef enum +{ + SPI_HELPER_RCV_POLLING, + SPI_HELPER_RCV_IT, + SPI_HELPER_RCV_DMA +}SPI_HELPER_RCV_TypeDef; + +typedef enum +{ + SPI_HELPER_MODE_MASTER, + SPI_HELPER_MODE_SLAVE +}SPI_HELPER_MODE_TypeDef; + +typedef struct +{ + SPI_HandleTypeDef *hspi; + uint8_t i2c_write_address; + uint8_t i2c_read_address; + SPI_HELPER_TRANS_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/ + SPI_HELPER_RCV_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/ + SPI_HELPER_MODE_TypeDef mode; + + uint8_t *trans_buf; + volatile uint32_t trans_size; + volatile uint32_t trans_data_con; + + uint8_t *receive_buf; + volatile uint32_t receive_size; + volatile uint8_t receive_data_con; + + // volatile uint8_t receive_buf_con; + // uint32_t receive_buf_half_len; + // uint8_t half_flag; /*0 : 未半满, 1:半满, 2: 半满已经处理*/ + + // volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/ + + void * obj; + it_callback callback; + + +}SPIHelper_TypeDef; + +SPIHelper_TypeDef * SPIHelper_Init( ); +void SPIHelper_Set_hspi( SPIHelper_TypeDef *spihelper, SPI_HandleTypeDef * hspi ); +void SPIHelper_Set_Mode( SPIHelper_TypeDef *spihelper, SPI_HELPER_MODE_TypeDef mode ); +void SPIHelper_Set_Trans_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_TRANS_TypeDef trans_type ); +void SPIHelper_Set_Rcv_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_RCV_TypeDef rcv_type ); + +// void SPIHelper_Set_timeout( SPIHelper_TypeDef *spihelper, uint32_t timeout_ms ); + +int SPIHelper_Set_callback_func_obj( SPIHelper_TypeDef *spihelper, void * obj, it_callback callback ); + +void SPIHelper_Set_rcv_buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ); +void SPIHelper_Set_Trans_Buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ); + +int SPIHelper_Transmit( SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size); +int SPIHelper_Begin_Rcv(SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size); + +// int SPIHelper_Flags_Set(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type ); +// int SPIHelper_Flags_Clear(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type ); +// int SPIHelper_Flags_Wait(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type ); + + + +void SPIHelper_Set_GPIO_For_Trans_Cplt( SPIHelper_TypeDef *spihelper ); +void SPIHelper_Rcv_Cplt_Callback( SPIHelper_TypeDef *spihelper ); +void SPIHelper_Rcv_Idle_Callback( SPIHelper_TypeDef *spihelper ); +void SPIHelper_Rcv_DMA_Half_Callback( SPIHelper_TypeDef *spihelper ); + +int SPIHelper_copy(SPIHelper_TypeDef *spihelper,uint8_t *buf,uint32_t buf_size); +int SPIHelper_isbusy(SPIHelper_TypeDef *spihelper ); +void SPIHelper_error(SPIHelper_TypeDef *spihelper ); + + + + +// uint16_t Get_Crc16(const char *buf, uint16_t len); +// uint8_t Check_Crc16(uint8_t *buf, uint16_t length); +#ifdef __cplusplus + } +#endif + +#endif + +#endif + + \ No newline at end of file diff --git a/Code/device/Inc/uart_helper.h b/Code/device/Inc/uart_helper.h new file mode 100644 index 0000000..3a14b91 --- /dev/null +++ b/Code/device/Inc/uart_helper.h @@ -0,0 +1,89 @@ +#ifndef __UART_HELPER_H +#define __UART_HANDLE_H +/** +* 封装 uart 发送接收操作 +* ?? 是否用到buf? +*/ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "uart_interface.h" + +/* 回调函数,将数据返回上层 */ +typedef void (*it_callback)(void *obj,uint8_t *buf, uint32_t buf_size ); + +// typedef struct uart_tx_record +// { +// uint32_t size; +// uint8_t *buf; +// } Uart_Trans_Record_TypeDef; + +typedef struct +{ + UART_HandleTypeDef *huart; + UartInterface_TypeDef *interface; + uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/ + uint8_t mode_232_485; /* 0: common, 1: 485 */ + uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/ + uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/ + uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */ + uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/ + + volatile uint32_t trans_size; + uint8_t *trans_buf; + + volatile uint8_t receive_buf_con; + // volatile uint8_t transferring_flag; + volatile uint32_t receive_data_size; + uint8_t *receive_buf; + uint32_t receive_buf_half_len; + uint8_t half_flag; /*0 : 未半满, 1:半满, 2: 半满已经处理*/ + + volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/ + + void * obj; + it_callback callback; + +}UartHelper_TypeDef; + +UartHelper_TypeDef * UartHelper_Init( ); +void UartHelper_Set_Interface( UartHelper_TypeDef *uarthelper, UartInterface_TypeDef * interface ); +void UartHelper_Set_Huart( UartHelper_TypeDef *uarthelper, UART_HandleTypeDef * huart ); +void UartHelper_Set_Interface_Type( UartHelper_TypeDef *uarthelper, Uart_Interface_Type_Typedef interface_type ); +void UartHelper_Set_Trans_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_type ); +void UartHelper_Set_Rcv_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef rcv_type ); +void UartHelper_Set_Idle_Enable( UartHelper_TypeDef *uarthelper, Uart_IDLE_Enable_TypeDef idle_enable_disable ); +void UartHelper_Set_TransMode( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_mode ); +void UartHelper_Set_RsMode_232_485( UartHelper_TypeDef *uarthelper, Uart_RS_Mode_TypeDef mode_232_485 ); +// void UartHelper_Set_timeout( UartHelper_TypeDef *uarthelper, uint32_t timeout_ms ); + +int UartHelper_Set_callback_func_obj( UartHelper_TypeDef *uarthelper, void * obj, it_callback callback ); + + +void UartHelper_Set_rcv_buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ); +void UartHelper_Set_Trans_Buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ); + +int UartHelper_Transmit( UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size); +int UartHelper_Begin_Rcv(UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size); + +void UartHelper_Set_GPIO_For_Trans_Cplt( UartHelper_TypeDef *uarthelper ); +void UartHelper_Rcv_Cplt_Callback( UartHelper_TypeDef *uarthelper ); +void UartHelper_Rcv_Idle_Callback( UartHelper_TypeDef *uarthelper ); +void UartHelper_Rcv_DMA_Half_Callback( UartHelper_TypeDef *uarthelper ); + +int UartHelper_copy(UartHelper_TypeDef *uarthelper,uint8_t *buf,uint32_t buf_size); +int UartHelper_isbusy(UartHelper_TypeDef *uarthelper ); +void UartHelper_error(UartHelper_TypeDef *uarthelper ); + + +uint16_t Get_Crc16(const char *buf, uint16_t len); +uint8_t Check_Crc16(uint8_t *buf, uint16_t length); +#ifdef __cplusplus + } +#endif + +#endif + + \ No newline at end of file diff --git a/Code/device/Inc/uart_interface.h b/Code/device/Inc/uart_interface.h new file mode 100644 index 0000000..9374245 --- /dev/null +++ b/Code/device/Inc/uart_interface.h @@ -0,0 +1,153 @@ +#ifndef __UART_INTERFACE_H +#define __UART_INTERFACE_H +/** +* 封装不同使用类型串口 232 485 max3160 +* 封装对应的 GPIO操作 +*/ +/* 485 3160 启用一个, 两个接口都有 MAX3160_ENABLE */ + + +#ifdef __cplusplus + extern "C" { +#endif + +#include +#include "main.h" + +#define MAX485_ENABLE 0 +#define MAX3160_ENABLE 1 + +typedef enum +{ + Uart_Status_Ready = 0x00U, + Uart_Status_Sending = 0x01U, + Uart_Status_Send_Cplt = 0x02U, + Uart_Status_Timeout = 0x10U, + Uart_Status_Error = 0x11U, +} Uart_Status_TypeDef; + +typedef enum +{ + Uart_Interface_Default = 0x00U, + Uart_Interface_485 = 0x01U, + Uart_Interface_Max3160 = 0x02U, +} Uart_Interface_Type_Typedef; + + +typedef enum +{ + Uart_Trans_Polling = 0x00U, + Uart_Trans_IT = 0x01U, + Uart_Trans_DMA = 0x02U, +} Uart_Transmode_TypeDef; + + +typedef enum +{ + Uart_RSMODE_232 = 0x00U, + Uart_RSMODE_485 = 0x01U, +} Uart_RS_Mode_TypeDef; + + +typedef enum +{ + Uart_IDLE_IT_DISABLE = 0x00U, + Uart_IDLE_IT_ENABLE = 0x01U, +} Uart_IDLE_Enable_TypeDef; + + + +#if MAX3160_ENABLE + +typedef enum{ + SEL_232 = 0, + SEL_485 = 1, +}Max3160_Sel_TypeDef; + +typedef enum{ + DUPLEX_FULL = 0, + DUPLEX_HALF = 1, +}Max3160_Duplex_TypeDef; /* 发送时切换全双工(拉低),否则回显, 接收为半双工(拉高 默认)*/ + +typedef enum{ + DISABLE_485_SEND = 0, + ENABLE_485_SEND = 1, +}Max3160_DE_TypeDef; + +# endif + +#if MAX485_ENABLE +typedef enum{ + DISABLE_485_SEND = 0, + ENABLE_485_SEND = 1, +}Max_DE_TypeDef; +# endif + + + +typedef struct +{ + // UART_HandleTypeDef *huart; + uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/ + uint8_t mode_232_485; /* 0: common, 1: 485 */ + +#if MAX485_ENABLE + GPIO_TypeDef *de485_gpio; + uint16_t de485_pin; + uint8_t de485; +#endif + +#if MAX3160_ENABLE + GPIO_TypeDef *de485_gpio; + uint16_t de485_pin; + GPIO_TypeDef *sel_gpio; + GPIO_TypeDef *dplx_gpio; + uint16_t sel_pin; + uint16_t dplx_pin; + uint8_t sel; + uint8_t dplx; +#endif + uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/ + + +}UartInterface_TypeDef; + +// extern UartInterface_TypeDef *uart_helper; + +UartInterface_TypeDef * UartInterface_Init( ); + +int UartInterface_Setup_Mode_232_485( UartInterface_TypeDef * interface, Uart_RS_Mode_TypeDef mode_232_485 ); +int UartInterface_Setup_Transmod( UartInterface_TypeDef * interface, Uart_Transmode_TypeDef trans_mode ); +int UartInterface_Setup_Interface_type( UartInterface_TypeDef * interface, Uart_Interface_Type_Typedef interface_type ); +// int UartInterface_Setup_Woek_Mode( UartInterface_TypeDef * interface, uint8_t rs_232_485 ); + +void UartInterface_Set_Sel_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin); +void UartInterface_Set_Dplx_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin); +void UartInterface_Set_DE485_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin); + +void UartInterface_Set_232(UartInterface_TypeDef * interface); +void UartInterface_Set_485(UartInterface_TypeDef * interface); + +int UartInterface_Set_GPIO_For_Transmit( UartInterface_TypeDef * interface ); +int UartInterface_Set_GPIO_For_Trans_Cplt( UartInterface_TypeDef * interface ); + +/* 接收方式 也有三种类型 */ +// int UartInterface_Start_Rcv(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size); +// void UartInterface_Set_Huart(UartInterface_TypeDef * interface, UART_HandleTypeDef *huart); +// int UartInterface_Send(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size); +// int __UartInterface_Send(UartInterface_TypeDef * interface , uint8_t *buf, uint16_t size); +#ifdef __cplusplus + } +#endif + +#endif + +/** +// int UartInterface_Send(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size); +// int __UartInterface_Send(UartInterface_TypeDef * interface , uint8_t *buf, uint16_t size); + +// int UartInterface_Send_TxCplt_Callback( UartInterface_TypeDef * interface ); + +// int UartInterface_Send_Cplt(UartInterface_TypeDef * interface); +// void UartInterface_Set_tc_flag(UartInterface_TypeDef * interface); + */ \ No newline at end of file diff --git a/Code/device/Src/eeprom.c b/Code/device/Src/eeprom.c new file mode 100644 index 0000000..e6d966d --- /dev/null +++ b/Code/device/Src/eeprom.c @@ -0,0 +1,529 @@ +/** + * @file eeprom.c + * @author Chen Jihang (embedded@eseaoptics.com) + * @brief EEPROM驱动 + * @version 1.0 + * @date 2023-01-04 + * + * @copyright ESEA (c) 2020 + * + */ + +// osEventFlagsId_t eepromEventHandle; +// const osEventFlagsAttr_t eepromEvent_attributes = { +// .name = "eepromEvent" +// }; + + +#include "eeprom.h" +#define pEepromI2C &hi2c1 +EEPROM_TypeDef *eeprom; + + +My_EEPROM_TypeDef my_eeprom= +{ + Eeprom_Init, + Eeprom_DeInit, + Eeprom_Port, + AT24C02, + EEPROM_MEM_ADDR_TYPE_Bit8, + // EEPROM_MEM_ADDR_BIT_10, + 0xA0, // 7+1 bit or 10 + 1 bit, EEPROM 8bit , write A0 , read A1 + 0, +}; + +void Eeprom_Init() +{ + eeprom = (EEPROM_TypeDef *)malloc(sizeof(EEPROM_TypeDef)); + if ( eeprom == NULL ) + { + return NULL; + } + eeprom->hi2c = pEepromI2C; + // eeprom->i2chelper = I2CHelper_Init( ); + // I2CHelper_Set_Hi2c( eeprom->i2chelper, pEepromI2C ); + Eeprom_SET_Device_Model( eeprom, my_eeprom.model ); + Eeprom_SET_Device_Addr( eeprom, my_eeprom.dev_addr ); + Eeprom_SET_Mem_Addr_Type( eeprom, my_eeprom.mem_addr_type ); + + eeprom->writeCplt = 0; + eeprom->readCplt = 0; + eeprom->size = 0; + eeprom->is_busy = 0; + eeprom->time_base = 0; + eeprom->write_delay_ms = 5; + eeprom->mem_addr = 0; + return 0; +} + +void Eeprom_DeInit( ) +{ + free(eeprom); +} + +void Eeprom_Port( ) +{ + uint32_t i; + int st; + for (;;) + { + /* 判断size, size 大于零才开始工作*/ + if (eeprom->size == 0) + { + eeprom->send_buf = NULL; + eeprom->is_busy == 0; + // log_i("eeprom port func..."); + osDelay(100); + }; + + /* size> 0, 写入一个数据 */ + if ( eeprom->size > 0 && eeprom->writeCplt == 0 && eeprom->is_busy == 0 ) + { + eeprom->time_base = osKernelGetTickCount( ); + eeprom->is_busy = 1; + // log_i("eeporm write ... "); + st = HAL_I2C_Mem_Write(eeprom->hi2c, eeprom->dev_addr, AT24C02, eeprom->mem_addr_type, eeprom->send_buf, 1, eeprom->write_delay_ms); + if (st != HAL_OK) { + log_e(" Eeprom Write error"); + eeprom->size = 0; + eeprom->send_buf = NULL; + eeprom->is_busy = 0; + break; + } + // I2CHelper_Write( eeprom->i2chelper, eeprom->send_buf, 1 ); + continue; + }; + + /* 等待 eeprom->write_delay_ms ,写入数据*/ + if ( eeprom->size > 0 && eeprom->writeCplt == 0 && eeprom->is_busy == 1 ) + { + if( (osKernelGetTickCount( ) - eeprom->time_base) > eeprom->write_delay_ms) + { + // log_i("eeporm write ... 5ms "); + eeprom->writeCplt = 1 ; + } + continue; + }; + + /* 写完成,处理数据等待进入下一组 */ + if ( eeprom->size > 0 && eeprom->writeCplt == 1 ) + { + eeprom->send_buf++; + eeprom->mem_addr++; + eeprom->size--; + eeprom->is_busy = 0; + eeprom->writeCplt = 0; + continue; + }; + osDelay( 1); + } +} + +// int Eeprom_SET_I2CHelper( EEPROM_TypeDef *eeprom, I2CHelper_TypeDef *i2chelper ) +// { +// eeprom->i2chelper = i2chelper; +// return 0; +// } + +int Eeprom_SET_Device_Model(EEPROM_TypeDef *eeprom, EEPROM_MODEL_TypeDef model) +{ + eeprom->model = model; + if (eeprom->model < AT24C04 ) + { + eeprom->mem_addr_type = I2C_MEMADD_SIZE_8BIT; + }else{ + eeprom->mem_addr_type = I2C_MEMADD_SIZE_16BIT; + } + return 0; +} + +int Eeprom_SET_Device_Addr(EEPROM_TypeDef *eeprom, uint8_t dev_addr) +{ + eeprom->dev_addr = dev_addr; + // TODO: 需要对I2C 进行设置 + return 0; +} + +int Eeprom_SET_Mem_Addr ( EEPROM_TypeDef *eeprom, uint16_t mem_addr ) +{ + eeprom->mem_addr = mem_addr; + return 0; +} + +int Eeprom_SET_Mem_Addr_Type(EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_TypeDef mem_addr_type) +{ + eeprom->mem_addr_type = mem_addr_type; + return 0; +} + +int Eeprom_SET_Mem_Addr_Bit(EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_BIT_TypeDef mem_addr_bit) +{ + // eeprom->mem_addr_bit = mem_addr_bit; + return 0; +} + +// int Eeprom_SET_WorkMode( EEPROM_TypeDef *eeprom, I2C_HELPER_MODE_TypeDef mode ) +// { +// eeprom->mode = mode; +// I2CHelper_Set_Mode( eeprom->i2chelper, mode ); +// return 0; +// } + +int Eeprom_SET_Write_Delay_ms( EEPROM_TypeDef *eeprom, uint8_t write_delay_ms) +{ + eeprom->write_delay_ms = write_delay_ms; + return 0; +} + +// int Eeprom_Transmit(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) +// { +// // HAL_I2C_Master_Transmit_DMA ( eeprom->i2chelper->hi2c, eeprom->dev_addr, buf ,size ); +// } + +// int Eeprom_Begin_Rcv(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) +// { +// // HAL_I2C_Master_Receive_IT( eeprom->i2chelper->hi2c, eeprom->dev_addr, buf ,size ); +// // I2CHelper_Begin_Rcv(eeprom->i2chelper, buf, size); + +// // HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); +// // HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); + +// } + +int Eeprom_Read(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) +{ + // osEventFlagsGet(eepromEventHandle, EEPROM_EVT_READ); + eeprom->readCplt = 0; + int st; + st = HAL_I2C_Mem_Read( eeprom->hi2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, buf, size, 0xFFFF); + if ( st != HAL_OK ) { + return -1; + } + return 0; + // HAL_I2C_Master_Transmit_IT (eeprom->hi2c, eeprom->dev_addr, buf ,size); +} + +// int Eeprom_Write(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) +// { +// // osEventFlagsGet(eepromEventHandle, EEPROM_EVT_WRITE); +// eeprom->writeCplt = 0; +// // HAL_I2C_Master_Transmit_IT (eeprom->i2chelper->hi2c, eeprom->dev_addr, buf ,size); +// } + +void Eeprom_Set_Sendbuf_Size(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) +{ + eeprom->send_buf = buf; + eeprom->size = size; + return ; +} + +int Eeprom_Test( ) +{ + uint8_t test_send[1] = { 0xFF }; // 不同model,地址不同 方法也不同 + uint8_t test_rcv = 0; + int st; + + // st = Eeprom_Write( eeprom, test_send, 1 ); + st = HAL_I2C_Mem_Write(eeprom->hi2c, eeprom->dev_addr, AT24C02, eeprom->mem_addr_type, test_send, 1, eeprom->write_delay_ms); + osDelay( 10 ); + + // st = Eeprom_Read( eeprom, &test_rcv, 1); + st = HAL_I2C_Mem_Read(eeprom->hi2c, eeprom->dev_addr, AT24C02, eeprom->mem_addr_type, &test_rcv, 1, eeprom->write_delay_ms); + osDelay( 5 ); + + if ( test_rcv == 255 ){ + // log_i( " Test Result : PASS " ); + return 0; + } + // log_i( " Test Result : Error st %d val %d " , st, test_rcv ); + return -1; +} + +// //主机模式发送回调函数 +// void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) +// { +// if (I2cHandle == pEepromI2C) +// { +// eeprom->writeCplt =1; +// log_i("send cplt"); +// } +// } +// //主机模式接收回调函数 +// void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) +// { +// if (I2cHandle == pEepromI2C) +// { +// eeprom->readCplt =1; +// log_i("rcv cplt"); +// } +// } + + +// https://blog.csdn.net/qq_35496059/article/details/101279408 +// void I2C3_EV_IRQHandler(void) +// { +// /* USER CODE BEGIN I2C3_EV_IRQn 0 */ + +// /* USER CODE END I2C3_EV_IRQn 0 */ +// loop1: +// HAL_I2C_EV_IRQHandler(&hi2c3); +// /* USER CODE BEGIN I2C3_EV_IRQn 1 */ +// if((((I2C3->ISR)&0x08)>>3)==1)//判断是addr触发的中断 +// { +// I2C3->ISR|=0x01;//TXE=1 +// I2C3->ICR|=0x08;//清除addr +// } + +// //读写处理 +// { + +// if((((I2C3->ISR)&0x10000)>>16)==1)//dir +// { +// int i=0; +// int j=0; +// while(((((I2C3->ISR)&0x32)>>5)==0))//detect stop +// { +// if(((((I2C3->ISR)&0x10000)>>16)==0)||((((I2C3->ISR)&0x08)>>3)==1))//addr or read +// goto loop1; +// if(((((I2C3->ISR)&0x02)>>1)==1))TXIS +// { +// if(I2C3->RXDR==0x00) +// I2C3->TXDR=ppp1[i]; +// if(I2C3->RXDR==0x12) +// { +// I2C3->TXDR=ppp2[i]; + +// } + +// //[i]=I2C3->RXDR; +// i++; + +// } +// if(i==21) +// { +// //21个字节 退出 +// ppp2[0]++; +// return; +// } + +// } + +// //x=HAL_I2C_Slave_Receive(&hi2c3,ppp,2,5); +// I2C3->ICR=(I2C3->ICR)|0x32;//clear stop + +// else//read +// { +// int i=0; +// while(((((I2C3->ISR)&0x32)>>5)==0))//detect stop +// { +// if(((((I2C3->ISR)&0x10000)>>16)==1)||((((I2C3->ISR)&0x08)>>3)==1)) +// goto loop1; +// if(((((I2C3->ISR)&0x04)>>2)==1))//RXNE +// { +// ppp[i]=I2C3->RXDR; +// i++; +// } +// } +// //x=HAL_I2C_Slave_Receive(&hi2c3,ppp,2,5); +// I2C3->ICR=(I2C3->ICR)|0x32; +// } + +// } + +// // I2C3->CR1|=0x08; + +// // /* USER CODE END I2C3_EV_IRQn 1 */ +// } + +// 寄存器说明 +// ISR: +// |bit23…17|ADDCODE ----|主机地址----------| +// |bit16…|DIR------------------|0读/1写------------|在addr=1时更新 +// |bit15…|BUSY---------------| ---------------------|起始信号=1,检测到stop=0 +// |bit5…|STOPF---------------|----------------------|检测到stop +// |bit3…|ADDR----------------|----------------------|匹配到地址 +// |bit2…|RXNE----------------|----------------------|RXDR不为空 +// |bit1…|TXIS------------------|-------------------- -|发送标志 +// |bit0…|TXE------------------|-----------------------|TXDR为空 + + + + + + + + + + + + + + + + + + +// uint8_t Eeprom_SET_I2C(eeprom_t *eeprom, I2C_HandleTypeDef *i2c) +// { +// eeprom->i2c = i2c; +// eeprom->stat = HAL_I2C_STATE_READY; +// return 0; +// } +// uint8_t Eeprom_SET_Device_Model(eeprom_t *eeprom, uint16_t model) +// { +// eeprom->model = model; +// // if (eeprom->model < AT24C16) +// // { +// // eeprom->mem_addr_type = I2C_MEMADD_SIZE_8BIT; +// // } +// // else +// // { +// // eeprom->mem_addr_type = I2C_MEMADD_SIZE_16BIT; +// // } +// return 0; +// } + +// uint8_t Eeprom_SET_Device_Addr(eeprom_t *eeprom, uint8_t dev_addr) +// { +// eeprom->dev_addr = dev_addr; +// return 0; +// } + +// uint8_t Eeprom_SET_Mem_Addr_Type(eeprom_t *eeprom, uint8_t mem_addr_type) +// { +// eeprom->mem_addr_type = mem_addr_type; +// return 0; +// } + +// uint8_t Eeprom_SET_Workmode(eeprom_t *eeprom, uint8_t workmode) +// { +// eeprom->WORKMODE = workmode; +// return 0; +// } + +// uint8_t Eeprom_Read_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +// { +// // eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1); +// return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); +// } + +// uint8_t Eeprom_Write_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +// { +// return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); + +// } + +// uint8_t Eeprom_Read_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +// { +// // eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1); +// eeprom->size = 0; +// return HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 ); +// } + +// uint8_t Eeprom_Write_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +// { +// eeprom->size = 0; +// return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 ); +// } + +// uint8_t Eeprom_Read_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ) +// { +// // eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size); +// return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout); + +// } + +// uint8_t Eeprom_Write_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ) +// { +// return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout); + +// } + +// uint8_t Eeprom_Read_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ) +// { +// // eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size); +// eeprom->stat =HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size ); +// // LOG(" readstat %d",eeprom->stat); +// return eeprom->stat; + +// } + +// uint8_t Eeprom_Write_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ) +// { +// // 写入数据前端循环调用 Eeprom_send_callback +// // return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size ); +// eeprom->send_buf = buf; +// eeprom->size = size; +// eeprom->mem_addr = mem_addr; +// return 0; + +// } + +// /** +// * @brief EEPROM发送回调,须循环调用单字节写入 +// * +// * @param eeprom EEPROM描述符 +// * @return int 0 +// */ +// uint8_t Eeprom_send(eeprom_t *eeprom) +// { +// if (eeprom->size == 0) +// { +// eeprom->send_buf = NULL; +// } +// if (eeprom->send_buf == NULL) +// { +// return 0; +// } +// if ( HAL_I2C_GetState(eeprom->i2c) == 1 ) +// { +// return 0; +// } +// if ( (osKernelGetTickCount() -eeprom->time_base) < eeprom->write_delay_ms ) +// { +// return 0; +// } +// if ( HAL_I2C_GetState(eeprom->i2c) == 2 ) +// { +// // __HAL_I2C_CLEAR_FLAG(eeprom->i2c,I2C_FLAG_AF); // 清除非应答状态 +// eeprom->i2c->State = HAL_I2C_STATE_READY; +// // i2c_clear_state(eeprom->i2c); +// eeprom->mem_addr--; +// eeprom->send_buf--; +// eeprom->size++; +// } +// if (eeprom->size == 0) +// { +// eeprom->send_buf = NULL; +// return 0; +// } + +// // 单个字节写入 ?? 为什么指向的地址内容发送变化了,静态声明 +// // LOG( " send buf : %02x %d", *eeprom->send_buf, eeprom->send_buf); +// HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, eeprom->send_buf, 1 ); +// // i2c_write_memory(eeprom->i2c,eeprom->dev_addr+eeprom->page_addr,eeprom->mem_addr,eeprom->mem_addr_size,eeprom->send_buf,1); +// // eeprom->time_base = __get_tick_milliseconds(); +// eeprom->time_base = osKernelGetTickCount(); +// eeprom->mem_addr++; +// eeprom->send_buf++; +// eeprom->size--; +// return 0; +// } + +// void Eeprom_send_callback(eeprom_t *eeprom) +// { +// Eeprom_send(eeprom); +// } + +// uint8_t Eeprom_get_state(eeprom_t *eeprom) +// { +// if (eeprom->send_buf != NULL) +// { +// return 1; +// } +// if ( HAL_I2C_GetState(eeprom->i2c) == HAL_I2C_STATE_READY ) +// { +// return 0; +// }; +// return 2; +// } \ No newline at end of file diff --git a/Code/device/Src/i2c_helper.c b/Code/device/Src/i2c_helper.c new file mode 100644 index 0000000..e8452e9 --- /dev/null +++ b/Code/device/Src/i2c_helper.c @@ -0,0 +1,142 @@ +#include "i2c_helper.h" + +// static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1; + +// osEventFlagsId_t i2chelperEventHandle; +// const osEventFlagsAttr_t i2chelperEvent_attributes = { +// .name = "i2chelperEvent" +// }; + +I2CHelper_TypeDef * I2CHelper_Init( ) +{ + I2CHelper_TypeDef *Handle = (I2CHelper_TypeDef *)malloc(sizeof(I2CHelper_TypeDef)); + if (Handle == NULL) + { + return NULL; + } + // Handle->delaytime_trans_byte = 0; + return Handle; +} +void I2CHelper_Set_Hi2c( I2CHelper_TypeDef *i2chelper, I2C_HandleTypeDef * hi2c ) +{ + i2chelper->hi2c = hi2c; +} +void I2CHelper_Set_Mode( I2CHelper_TypeDef *i2chelper, I2C_HELPER_MODE_TypeDef mode ) +{ + i2chelper->mode = mode; +} +void I2CHelper_Set_Trans_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_TRANS_TypeDef trans_type ) +{ + i2chelper->trans_type = trans_type; +} +void I2CHelper_Set_Rcv_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_RCV_TypeDef rcv_type ) +{ + i2chelper->rcv_type = rcv_type; +} + +int I2CHelper_Set_callback_func_obj( I2CHelper_TypeDef *i2chelper, void * obj, it_callback callback ) +{ + i2chelper->obj = obj; + i2chelper->callback = callback; + return 0; +} + +void I2CHelper_Set_rcv_buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ) +{ + i2chelper->receive_buf = buf; + i2chelper->receive_size = buf_size; + i2chelper->receive_data_con = 0; + +} +void I2CHelper_Set_Trans_Buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ) +{ + i2chelper->trans_buf = buf; + i2chelper->trans_size = buf_size; + i2chelper->trans_data_con = 0; +} + +int I2CHelper_Write( I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size) +{ + // 考虑主从机模式 + int st = -1; + switch ( i2chelper->mode == I2C_HELPER_MODE_MASTER ) + { + case I2C_HELPER_MODE_MASTER: + if ( i2chelper->trans_type == I2C_HELPER_TRANS_POLLING ) + { + st = HAL_I2C_Master_Transmit( i2chelper->hi2c, i2chelper->i2c_write_address + , buf, size, 0xFFFF ); + } + if ( i2chelper->trans_type == I2C_HELPER_TRANS_IT ) + { + // st = HAL_I2C_Master_Transmit_IT( i2chelper->hi2c, i2chelper->i2c_write_address + // , buf, size ); + st = HAL_I2C_Master_Transmit_IT( i2chelper->hi2c, i2chelper->i2c_write_address, buf,size ); + } + if ( i2chelper->trans_type == I2C_HELPER_TRANS_DMA ) + { + // st = HAL_I2C_Master_Transmit_DMA( i2chelper->hi2c, i2chelper->i2c_write_address + // , buf, size ); + st = HAL_I2C_Master_Transmit_DMA( i2chelper->hi2c, i2chelper->i2c_write_address, buf, size ); + } + break; + case I2C_HELPER_MODE_SLAVE: + break; + default: + break; + } + return st; +} + +int I2CHelper_Read(I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size) +{ + int st = -1; + switch ( i2chelper->mode == I2C_HELPER_MODE_MASTER ) + { + case I2C_HELPER_MODE_MASTER: + if ( i2chelper->rcv_type == I2C_HELPER_TRANS_POLLING ) + { + st = HAL_I2C_Master_Receive( i2chelper->hi2c, i2chelper->i2c_write_address + , buf, size, 0xFFFF ); + } + if ( i2chelper->rcv_type == I2C_HELPER_TRANS_IT ) + { + // st = HAL_I2C_Master_Transmit_IT( i2chelper->hi2c, i2chelper->i2c_write_address + // , buf, size ); + st = HAL_I2C_Master_Receive_IT( i2chelper->hi2c, i2chelper->i2c_write_address + , buf, size ); + } + if ( i2chelper->rcv_type == I2C_HELPER_TRANS_DMA ) + { + // st = HAL_I2C_Master_Transmit_DMA( i2chelper->hi2c, i2chelper->i2c_write_address + // , buf, size ); + st = HAL_I2C_Master_Receive_DMA( i2chelper->hi2c, i2chelper->i2c_write_address + , buf, size ); + } + break; + case I2C_HELPER_MODE_SLAVE: + break; + default: + break; + } + return st; +} + +int I2CHelper_Flags_Set(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type ) +{ + return osEventFlagsSet(i2chelper, evt_type); +} + +// int I2CHelper_Flags_Clear(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type ) +// { +// return osEventFlagsClear(i2chelper, evt_type); +// } + +// int I2CHelper_Flags_Wait(I2CHelper_TypeDef *i2chelper, uint32_t delay ) +// { +// return osEventFlagsWait ( +// i2chelperEventHandle +// , I2C_HELPER_Event_READY|I2C_HELPER_Event_INIT|I2C_HELPER_Event_TRANS_ONLY|I2C_HELPER_Event_DATA_RCV +// , 0 +// , delay ); +// } \ No newline at end of file diff --git a/Code/device/Src/spi_helper.c b/Code/device/Src/spi_helper.c new file mode 100644 index 0000000..27ea98e --- /dev/null +++ b/Code/device/Src/spi_helper.c @@ -0,0 +1,147 @@ +#include "spi_helper.h" + +#if 0 +// static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1; + +// osEventFlagsId_t spihelperEventHandle; +// const osEventFlagsAttr_t spihelperEvent_attributes = { +// .name = "spihelperEvent" +// }; + +SPIHelper_TypeDef * SPIHelper_Init( ) +{ + SPIHelper_TypeDef *Handle = (SPIHelper_TypeDef *)malloc(sizeof(SPIHelper_TypeDef)); + if (Handle == NULL) + { + return NULL; + } + // Handle->delaytime_trans_byte = 0; + return Handle; +} +void SPIHelper_Set_hspi( SPIHelper_TypeDef *spihelper, SPI_HandleTypeDef * hspi ) +{ + spihelper->hspi = hspi; +} +void SPIHelper_Set_Mode( SPIHelper_TypeDef *spihelper, SPI_HELPER_MODE_TypeDef mode ) +{ + spihelper->mode = mode; +} +void SPIHelper_Set_Trans_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_TRANS_TypeDef trans_type ) +{ + spihelper->trans_type = trans_type; +} +void SPIHelper_Set_Rcv_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_RCV_TypeDef rcv_type ) +{ + spihelper->rcv_type = rcv_type; +} + +int SPIHelper_Set_callback_func_obj( SPIHelper_TypeDef *spihelper, void * obj, it_callback callback ) +{ + spihelper->obj = obj; + spihelper->callback = callback; + return 0; +} + +void SPIHelper_Set_rcv_buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ) +{ + spihelper->receive_buf = buf; + spihelper->receive_size = buf_size; + spihelper->receive_data_con = 0; + +} +void SPIHelper_Set_Trans_Buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ) +{ + spihelper->trans_buf = buf; + spihelper->trans_size = buf_size; + spihelper->trans_data_con = 0; +} + +int SPIHelper_Transmit( SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size) +{ + // 考虑主从机模式 + int st = -1; + // switch ( spihelper->mode == SPI_HELPER_MODE_MASTER ) + // { + // case SPI_HELPER_MODE_MASTER: + // if ( spihelper->trans_type == SPI_HELPER_TRANS_POLLING ) + // { + // st = HAL_I2C_Master_Transmit( spihelper->hi2c, spihelper->i2c_write_address + // , buf, size, 0xFFFF ); + // } + // if ( spihelper->trans_type == SPI_HELPER_TRANS_IT ) + // { + // // st = HAL_I2C_Master_Transmit_IT( spihelper->hi2c, spihelper->i2c_write_address + // // , buf, size ); + // st = HAL_I2C_Master_Seq_Transmit_IT( spihelper->hi2c, spihelper->i2c_write_address + // , buf, size, I2C_FIRST_FRAME ); + // } + // if ( spihelper->trans_type == SPI_HELPER_TRANS_DMA ) + // { + // // st = HAL_I2C_Master_Transmit_DMA( spihelper->hi2c, spihelper->i2c_write_address + // // , buf, size ); + // st = HAL_I2C_Master_Seq_Transmit_DMA( spihelper->hi2c, spihelper->i2c_write_address + // , buf, size, I2C_FIRST_FRAME ); + + // } + // break; + // case SPI_HELPER_MODE_SLAVE: + // break; + // default: + // break; + // } + return st; +} +int SPIHelper_Begin_Rcv(SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size) +{ + int st = -1; + // switch ( spihelper->mode == SPI_HELPER_MODE_MASTER ) + // { + // case SPI_HELPER_MODE_MASTER: + // if ( spihelper->rcv_type == SPI_HELPER_TRANS_POLLING ) + // { + // st = HAL_I2C_Master_Receive( spihelper->hi2c, spihelper->i2c_write_address + // , buf, size, 0xFFFF ); + // } + // if ( spihelper->rcv_type == SPI_HELPER_TRANS_IT ) + // { + // // st = HAL_I2C_Master_Transmit_IT( spihelper->hi2c, spihelper->i2c_write_address + // // , buf, size ); + // st = HAL_I2C_Master_Seq_Receive_IT( spihelper->hi2c, spihelper->i2c_write_address + // , buf, size, I2C_FIRST_FRAME ); + // } + // if ( spihelper->rcv_type == SPI_HELPER_TRANS_DMA ) + // { + // // st = HAL_I2C_Master_Transmit_DMA( spihelper->hi2c, spihelper->i2c_write_address + // // , buf, size ); + // st = HAL_I2C_Master_Seq_Receive_DMA( spihelper->hi2c, spihelper->i2c_write_address + // , buf, size, I2C_FIRST_FRAME ); + // } + // break; + // case SPI_HELPER_MODE_SLAVE: + // break; + // default: + // break; + // } + return st; +} + +int SPIHelper_Flags_Set(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type ) +{ + return osEventFlagsSet(spihelper, evt_type); +} + +// int SPIHelper_Flags_Clear(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type ) +// { +// return osEventFlagsClear(spihelper, evt_type); +// } + +// int SPIHelper_Flags_Wait(SPIHelper_TypeDef *spihelper, uint32_t delay ) +// { +// return osEventFlagsWait ( +// spihelperEventHandle +// , SPI_HELPER_Event_READY|SPI_HELPER_Event_INIT|SPI_HELPER_Event_TRANS_ONLY|SPI_HELPER_Event_DATA_RCV +// , 0 +// , delay ); +// } + +#endif \ No newline at end of file diff --git a/Code/device/Src/uart_helper.c b/Code/device/Src/uart_helper.c new file mode 100644 index 0000000..3d30e4e --- /dev/null +++ b/Code/device/Src/uart_helper.c @@ -0,0 +1,315 @@ +#include "uart_helper.h" +#include "elog.h" + + +UartHelper_TypeDef * UartHelper_Init( ) +{ + UartHelper_TypeDef *Handle = (UartHelper_TypeDef *)malloc(sizeof(UartHelper_TypeDef)); + if (Handle == NULL) + { + return NULL; + } + + // Handle->interface = UartInterface_Init(); + Handle->interface = UartInterface_Init(); + // Handle->interface_type = 0; + + Handle->interface_type = 0; /* 0: common, 1: 485 ,2:3160*/ + Handle->mode_232_485 = 0; /* 0: common, 1: 485 */ + Handle->trans_type = 2; /* 0 :polling, 1: IT 2: DMA*/ + Handle->rcv_type = 2; /* 0 :polling, 1: IT 2: DMA*/ + Handle->idle_enable_disable = 1; /* 0 不开启空闲中断 , 1 开启空闲中断 */ + Handle->trans_mode = 2; /* 0 :polling, 1: IT 2: DMA*/ + Handle->status = Uart_Status_Ready; /* 0 :polling, 1: IT 2: DMA*/ + Handle->huart = NULL; + Handle->obj = NULL; + Handle->callback = NULL; + // Handle->timeout_enable = 0; + // Handle->timeout_ms = 0; + // Handle->timebase_ticks = 0; + return Handle; + +} + +void UartHelper_Set_Interface( UartHelper_TypeDef *uarthelper, UartInterface_TypeDef * interface ) +{ + uarthelper->interface = interface; +} +void UartHelper_Set_Huart( UartHelper_TypeDef *uarthelper, UART_HandleTypeDef * huart ) +{ + uarthelper->huart = huart; +} +void UartHelper_Set_Interface_Type( UartHelper_TypeDef *uarthelper, Uart_Interface_Type_Typedef interface_type ) +{ + uarthelper->interface_type = interface_type; +} +void UartHelper_Set_Trans_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_type ) +{ + uarthelper->trans_type = trans_type; +} +void UartHelper_Set_Rcv_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef rcv_type ) +{ + uarthelper->rcv_type = rcv_type; +} +void UartHelper_Set_Idle_Enable( UartHelper_TypeDef *uarthelper, Uart_IDLE_Enable_TypeDef idle_enable_disable ) +{ + uarthelper->idle_enable_disable = idle_enable_disable; +} +void UartHelper_Set_TransMode( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_mode ) +{ + uarthelper->trans_mode = trans_mode; +} +void UartHelper_Set_RsMode_232_485( UartHelper_TypeDef *uarthelper, Uart_RS_Mode_TypeDef mode_232_485 ) +{ + uarthelper->mode_232_485 = mode_232_485; + UartInterface_Setup_Mode_232_485( uarthelper->interface, uarthelper->mode_232_485); +} + +// void UartHelper_Set_timeout( UartHelper_TypeDef *uarthelper, uint32_t timeout_ms ) +// { +// uarthelper->timeout_ms = timeout_ms; +// uarthelper->timeout_enable = 1; +// } + +int UartHelper_Set_callback_func_obj( UartHelper_TypeDef *uarthelper, void * obj, it_callback callback ) +{ + if(uarthelper==NULL || callback==NULL || obj==NULL){ + return -1; + } + uarthelper->callback =callback; + uarthelper->obj =obj; + return 0; +} + +void UartHelper_Set_rcv_buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ) +{ + uarthelper->receive_buf = buf; + uarthelper->receive_buf_half_len = buf_size/2; +} + +void UartHelper_Set_Trans_Buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ) +{ + uarthelper->trans_buf = buf; + uarthelper->trans_size = buf_size; +} + +int UartHelper_Transmit( UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size) +{ + // log_i( "SensorSend size_ " ); + // set gpio + UartInterface_Set_GPIO_For_Transmit( uarthelper->interface ); + // it idle start + // if ( uarthelper->idle_enable_disable == 1 ) + // { + // log_i( "start idle .... "); + // __HAL_UART_ENABLE_IT(uarthelper->huart, UART_IT_IDLE); + // } + + /* 开启 transmit */ + if (buf!=NULL ) + { + uarthelper->status = Uart_Status_Sending; + if ( uarthelper->trans_type == 0 ) + return HAL_UART_Transmit( uarthelper->huart, buf, size ,0x0FFF); + if ( uarthelper->trans_type == 1 ) + return HAL_UART_Transmit_IT( uarthelper->huart, buf, size ); + if ( uarthelper->trans_type == 2 ) + return HAL_UART_Transmit_DMA( uarthelper->huart, buf, size ); + } + if (buf==NULL && uarthelper->trans_buf !=NULL) + { + uarthelper->status = Uart_Status_Sending; + + if ( uarthelper->trans_type == 0 ) + return HAL_UART_Transmit( uarthelper->huart, uarthelper->trans_buf, uarthelper->trans_size ,0x0FFF); + if ( uarthelper->trans_type == 1 ) + return HAL_UART_Transmit_IT( uarthelper->huart, uarthelper->trans_buf, uarthelper->trans_size); + if ( uarthelper->trans_type == 2 ) + return HAL_UART_Transmit_DMA( uarthelper->huart, uarthelper->trans_buf, uarthelper->trans_size); + } + return -1; +} + + +int UartHelper_Begin_Rcv(UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size) +{ + /* 是否开启空闲中断*/ + if ( uarthelper->idle_enable_disable == 1 ) + { + __HAL_UART_ENABLE_IT( uarthelper->huart, UART_IT_IDLE ); + } + + if ( uarthelper->rcv_type == 0 ) + { + // TODO 发生错误怎么处理 + HAL_UART_Receive( uarthelper->huart, buf, size ,0X0FFF); + } + + if ( uarthelper->rcv_type == 1 ) + { + HAL_UART_Receive_IT( uarthelper->huart, buf, size); + } + + if ( uarthelper->rcv_type == 2 ) + { + // log_i( "start dma rcv.... . "); + HAL_UART_Receive_DMA( uarthelper->huart, buf, size); + } +} + + +void UartHelper_Set_GPIO_For_Trans_Cplt( UartHelper_TypeDef *uarthelper ) +{ + uarthelper->status = Uart_Status_Ready; + // log_i(" UartHelper_Set_GPIO_For_Trans_Cplt ... %d %d", uarthelper->interface_type, uarthelper->mode_232_485); + if (uarthelper->interface_type != Uart_Interface_Default && uarthelper->mode_232_485 ==Uart_RSMODE_485) + { + // log_i(" UartHelper_Set_GPIO_For_Trans_Cplt ... 111111"); + UartHelper_Set_GPIO_For_Trans_Cplt( uarthelper->interface ); + } +} + +void UartHelper_Rcv_Cplt_Callback( UartHelper_TypeDef *uarthelper ) +{ + // TODO 超时 --> 尽量用空闲中断代替 接收指定长度完成中断 + + // TODO 拷贝数据 + +} + +void UartHelper_Rcv_Idle_Callback( UartHelper_TypeDef *uarthelper ) +{ + /* 搬运 数据到 kfifo*/ + + log_i("SC6....huart3 IDLE...."); + + uint16_t count = __HAL_DMA_GET_COUNTER( uarthelper->huart->hdmarx ); + uint16_t data_length = 2*uarthelper->receive_data_size - count; + + // if (count != 0 && data_length != 0) + if ( data_length != 0 ) + { + // TODO 拷贝数据 最后一位 datalenth-1 + HAL_UART_DMAStop( uarthelper->huart ); + uarthelper->callback( uarthelper->obj, uarthelper->receive_buf, data_length); + + } + +} + +void UartHelper_Rcv_DMA_Half_Callback( UartHelper_TypeDef *uarthelper ) +{ + /* 循环模式才有 半满中断 */ +} + + +int UartHelper_copy(UartHelper_TypeDef *uarthelper,uint8_t *buf,uint32_t buf_size) +{ + int data_len; + if(uarthelper==NULL || buf==NULL){ + return -1; + } + data_len = uarthelper->receive_data_size; + if(buf_sizereceive_data_size=0; + } + return data_len; + +} +int UartHelper_isbusy(UartHelper_TypeDef *uarthelper ) +{ + if (uarthelper->status==Uart_Status_Sending) + return 1; + return 0; +} +void UartHelper_error(UartHelper_TypeDef *uarthelper ) +{ + while(1); +} + +uint16_t Get_Crc16(const char *buf, uint16_t len) +{ + int crc = 0xffff; + for (int i = 0; i < len; i++) + { + crc ^= buf[i]; + for (int j = 0; j < 8; j++) + { + if (crc & 1 == 1) + { + crc >>= 1; + crc ^= 0xa001; + } + else + { + crc >>= 1; + } + } + } + uint8_t cs1 = crc & 0xff; // 校验码的低字节 + uint8_t cs2 = (crc & 0xff00) >> 8; // 校验码的高字节 + return crc; +}; + + +uint8_t Check_Crc16(uint8_t *buf, uint16_t length){ + uint16_t len = length-2; + int crc = 0xffff; + for (int i = 0; i < len; i++) + { + crc ^= buf[i]; + for (int j = 0; j < 8; j++) + { + if (crc & 1 == 1) + { + crc >>= 1; + crc ^= 0xa001; + } + else + { + crc >>= 1; + } + } + } + uint8_t cs1 = crc & 0xff; // 校验码的低字节 + uint8_t cs2 = (crc & 0xff00) >> 8; // 校验码的高字节 + log_i( " %d %d %d ",crc ,cs1, cs2 ) ; + log_i( " %d %d %d ",crc ,buf[length-2], buf[length-1] ) ; + + if ( (crc & 0xff) == buf[length-2] && ((crc & 0xff00) >> 8) == buf[length-1]) + { + return 1; + } + else + { + return 0; + } +} + + + // // HAL_UART_DMAStop HAL_UART_Receive_DMA 成对使用,可从指定指针开始 + // // HAL_UART_DMAPause HAL_UART_DMAResume 成对使用 + // HAL_UART_DMAStop( sc6->huart ); + // memcpy(sc6->SC6_Data_Buf, sc6->SC6_Raw_Buf, data_length); + // sc6->size_received = data_length; + // log_i(" IDLE.... count %d data_length %d ",count,data_length ); + // log_i(" IDLE.... -> %02X %02X %02X %02X ", sc6->SC6_Data_Buf[0] , sc6->SC6_Data_Buf[1], sc6->SC6_Data_Buf[2] , sc6->SC6_Data_Buf[3]); + // log_i(" IDLE.... -> %02X %02X %02X %02X ", + // sc6->SC6_Data_Buf[data_length] , sc6->SC6_Data_Buf[data_length-1], sc6->SC6_Data_Buf[data_length-2] , sc6->SC6_Data_Buf[data_length-3]); + // log_i(" IDLE.... -> %s ", sc6->SC6_Data_Buf ); + // // TODO数据清零 DMA指针指向开始的地方 或双缓冲 + // // memset(sc6->SC6_Data_Buf, 0, sizeof(sc6->SC6_Data_Buf)); + // memset(sc6->SC6_Raw_Buf, 0, sizeof(sc6->SC6_Raw_Buf)); + // // HAL_UART_DMAStop( sc6->myuart->huart ); + // // SC6_Begin_Rcv( sc6, sc6->SC6_Raw_Buf, sizeof(sc6->SC6_Raw_Buf)); + // __HAL_UART_ENABLE_IT( sc6->huart, UART_IT_IDLE); + // HAL_UART_Receive_DMA( sc6->huart, sc6->SC6_Raw_Buf, sizeof(sc6->SC6_Raw_Buf)); + // // HAL_UART_DMAResume( sc6->myuart->huart ); + + /* 再次开启DMA接收 重新接收 */ + // HAL_UART_Receive_DMA(&UartHandle, UartHandle.pRxBuffPtr, UartHandle.RxXferSize); \ No newline at end of file diff --git a/Code/device/Src/uart_interface.c b/Code/device/Src/uart_interface.c new file mode 100644 index 0000000..6736eb7 --- /dev/null +++ b/Code/device/Src/uart_interface.c @@ -0,0 +1,241 @@ +#include "uart_interface.h" +#include "elog.h" + +UartInterface_TypeDef * UartInterface_Init( ) +{ + UartInterface_TypeDef *Handle = (UartInterface_TypeDef *)malloc(sizeof(UartInterface_TypeDef)); + if (Handle == NULL) + { + return NULL; + } + + // Handle->send_status = 0; + Handle->interface_type = 0; + +#if MAX485_ENABLE + Handle->de485_gpio = NULL; + Handle->interface_type = 1; +#endif + +#if MAX3160_ENABLE + Handle->de485_gpio = NULL; + Handle->sel_gpio = NULL; + Handle->dplx_gpio = NULL; + Handle->interface_type = 2; +#endif + + return Handle; +} + +/** + * @brief interface-> 0:default, 1:485, 2:3160 + * @param [in] myuart + * @param [in] interface + * @return int + * + * @details + */ +int UartInterface_Setup_Interface_type( UartInterface_TypeDef * interface, Uart_Interface_Type_Typedef interface_type ) +{ + interface->interface_type = interface_type; + return 0; +} + +int UartInterface_Setup_Mode_232_485( UartInterface_TypeDef * interface, Uart_RS_Mode_TypeDef mode_232_485 ) +{ + interface->mode_232_485 = mode_232_485; + if (interface->interface_type == 0) + UartInterface_Set_232( interface); + if (interface->interface_type == 1) + UartInterface_Set_485( interface); + if (interface->interface_type ==2 && interface->mode_232_485 ==Uart_RSMODE_232) + UartInterface_Set_232( interface); + if (interface->interface_type ==2 && interface->mode_232_485 ==Uart_RSMODE_485) + UartInterface_Set_485( interface); + + return 0; +} +void UartInterface_Set_Sel_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin) +{ + if (gpio!=NULL && pin>=0) + { +#if MAX3160_ENABLE + interface->sel_gpio = gpio; + interface->sel_pin = pin; +#endif + } + +} + +void UartInterface_Set_Dplx_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin) +{ + if (gpio!=NULL && pin>=0) + { +#if MAX3160_ENABLE + interface->dplx_gpio = gpio; + interface->dplx_pin = pin; +#endif + } +// #if MAX3160_ENABLE +// interface->dplx_gpio = gpio; +// interface->dplx_pin = pin; +// #endif +} + +void UartInterface_Set_DE485_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin) +{ + if (gpio!=NULL && pin>=0) + { +#if MAX3160_ENABLE + interface->de485_gpio = gpio; + interface->de485_pin = pin; +#endif +#if MAX485_ENABLE + interface->de485_gpio = gpio; + interface->de485_pin = pin; +#endif + } + // interface->de485_gpio = gpio; + // interface->de485_pin = pin; +} + +void UartInterface_Set_232(UartInterface_TypeDef * interface) +{ + interface->mode_232_485 = Uart_RSMODE_232; +#if MAX3160_ENABLE + if (interface->sel_gpio != NULL) + HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); + interface->sel = SEL_232; + if (interface->sel_gpio != NULL) + HAL_GPIO_WritePin( interface->sel_gpio, interface->sel_pin, interface->sel ); +#endif +// interface->mode_232_485 = 0; +} + +void UartInterface_Set_485(UartInterface_TypeDef * interface) +{ + interface->mode_232_485 = Uart_RSMODE_485; + + // log_i(".......set 485 "); + +#if MAX3160_ENABLE + interface->sel = SEL_485; + if (interface->sel_gpio != NULL) + // log_i(".......set 485 set dplx "); + HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_HALF); + if (interface->de485_gpio != NULL) + // log_i(".......set 485 set de "); + HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND ); + if (interface->sel_gpio != NULL) + // log_i(".......set 485 set sel... "); + HAL_GPIO_WritePin( interface->sel_gpio, interface->sel_pin, interface->sel ); + // log_i(" UartInterface_Set_485 222 interface->sel : %d duplex: %d ",interface->sel , HAL_GPIO_ReadPin(interface->dplx_gpio,interface->dplx_pin) ); +#endif + +#if MAX485_ENABLE + if (interface->de485_gpio != NULL) + // log_i(".......set 485 set de "); + HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND ); + +#endif + +} + + +/** + * @brief 发送前操作 GPIO + * @param [in] myuart + * @return int + * + * @details + */ +int UartInterface_Set_GPIO_For_Transmit( UartInterface_TypeDef * interface ) +// int UartInterface_Send_TxPrepare_Callback( UartInterface_TypeDef * interface ) +{ +#if MAX3160_ENABLE + if (interface->mode_232_485 == 0) + { + HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); + + }; + if ( interface->interface_type == 2 && interface->mode_232_485 == 1 ) + { + // log_i( " ---- UartInterface_Set_GPIO_For_Transmit " ); + HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); // 全双工启动发送 + HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND); + return 0; + } + +#endif +#if MAX485_ENABLE + if (interface->interface_type == 1) + { + HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND); + } +#endif + return 0; + +// #if MAX3160_ENABLE +// if (interface->interface_type == 2 && ) +// { +// switch (interface->sel) +// { +// case SEL_232: +// HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); +// // return __UartInterface_Send(myuart,buf,size); +// break; +// case SEL_485: +// log_i(" 485 mode writepin...... "); +// HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); +// HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND); +// // return __UartInterface_Send(myuart,buf,size); +// break; +// default: +// break; +// } +// } + +// #endif + +// #if MAX485_ENABLE +// if (interface->interface_type == 1) +// { +// HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); +// HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND); // return __Max3160_Send(max3160,buf,size); +// } +// #endif +} + +/** + * @brief 发送完成后操作 GPIO + * @param [in] myuart + * @return int + * + * @details + */ +// 接收完成,切换到接收状态, 全双工接收 +int UartInterface_Set_GPIO_For_Trans_Cplt( UartInterface_TypeDef * interface ) +{ + // interface->send_status = 0; + +#if MAX3160_ENABLE + if ( interface->interface_type == 2 && interface->mode_232_485 == 1) + { + HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_HALF); // 半双工接收 + HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND); + return 0; + } + if (interface->mode_232_485 == 0) return -1; +#endif +#if MAX485_ENABLE + if (interface->interface_type == 1) + { + HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND); + return 0; + } + if (interface->mode_232_485 == 0) return -1; +#endif + + return 0; +} + diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 50d0b9f..3a25445 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -56,14 +56,14 @@ #define CMSIS_device_header "stm32f4xx.h" #endif /* CMSIS_device_header */ -#define configENABLE_FPU 0 +#define configENABLE_FPU 1 #define configENABLE_MPU 0 #define configUSE_PREEMPTION 1 #define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_DYNAMIC_ALLOCATION 1 -#define configUSE_IDLE_HOOK 1 -#define configUSE_TICK_HOOK 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES ( 56 ) @@ -74,7 +74,6 @@ #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 -#define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 29a8282..cf9590b 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -65,14 +65,12 @@ void Error_Handler(void); #define SCLK_1302_GPIO_Port GPIOE #define PUMP_EN_Pin GPIO_PIN_0 #define PUMP_EN_GPIO_Port GPIOF -#define MAX3242_EN_Pin GPIO_PIN_4 -#define MAX3242_EN_GPIO_Port GPIOA -#define SENSOR2_EN_Pin GPIO_PIN_6 -#define SENSOR2_EN_GPIO_Port GPIOA -#define SENSOR4_EN_Pin GPIO_PIN_7 -#define SENSOR4_EN_GPIO_Port GPIOA -#define BOOT1_Pin GPIO_PIN_2 -#define BOOT1_GPIO_Port GPIOB +#define UART_EN_Pin GPIO_PIN_4 +#define UART_EN_GPIO_Port GPIOA +#define SENSOR4_EN_Pin GPIO_PIN_4 +#define SENSOR4_EN_GPIO_Port GPIOC +#define SENSOR2_EN_Pin GPIO_PIN_5 +#define SENSOR2_EN_GPIO_Port GPIOC #define SENSOR3_EN_Pin GPIO_PIN_12 #define SENSOR3_EN_GPIO_Port GPIOE #define DE485_Pin GPIO_PIN_13 @@ -81,9 +79,9 @@ void Error_Handler(void); #define HDPLX_GPIO_Port GPIOE #define SEL_232_485_Pin GPIO_PIN_15 #define SEL_232_485_GPIO_Port GPIOE -#define SENSOR6_EN_Pin GPIO_PIN_4 +#define SENSOR6_EN_Pin GPIO_PIN_7 #define SENSOR6_EN_GPIO_Port GPIOG -#define R_W_Pin GPIO_PIN_5 +#define R_W_Pin GPIO_PIN_8 #define R_W_GPIO_Port GPIOG #define CDZ_Pin GPIO_PIN_15 #define CDZ_GPIO_Port GPIOA diff --git a/Core/Inc/stm32f4xx_hal_conf.h b/Core/Inc/stm32f4xx_hal_conf.h index 64e0010..e2b8363 100644 --- a/Core/Inc/stm32f4xx_hal_conf.h +++ b/Core/Inc/stm32f4xx_hal_conf.h @@ -148,7 +148,7 @@ * @brief This is the HAL system configuration section */ #define VDD_VALUE 3300U /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */ +#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */ #define USE_RTOS 0U #define PREFETCH_ENABLE 1U #define INSTRUCTION_CACHE_ENABLE 1U diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index fe317ee..b4a134a 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -56,13 +56,14 @@ void DMA1_Stream1_IRQHandler(void); void DMA1_Stream3_IRQHandler(void); void DMA1_Stream5_IRQHandler(void); void DMA1_Stream6_IRQHandler(void); +void I2C1_EV_IRQHandler(void); +void I2C1_ER_IRQHandler(void); void SDIO_IRQHandler(void); void TIM6_DAC_IRQHandler(void); void DMA2_Stream2_IRQHandler(void); void DMA2_Stream3_IRQHandler(void); void DMA2_Stream6_IRQHandler(void); void DMA2_Stream7_IRQHandler(void); -void OTG_HS_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/Core/Inc/usb_otg.h b/Core/Inc/usb_otg.h new file mode 100644 index 0000000..157a869 --- /dev/null +++ b/Core/Inc/usb_otg.h @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usb_otg.h + * @brief This file contains all the function prototypes for + * the usb_otg.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 __USB_OTG_H__ +#define __USB_OTG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern PCD_HandleTypeDef hpcd_USB_OTG_FS; + +extern PCD_HandleTypeDef hpcd_USB_OTG_HS; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_USB_OTG_FS_PCD_Init(void); +void MX_USB_OTG_HS_PCD_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_OTG_H__ */ + diff --git a/Core/Src/dma.c b/Core/Src/dma.c index 25e51f9..855ec1c 100644 --- a/Core/Src/dma.c +++ b/Core/Src/dma.c @@ -60,10 +60,10 @@ void MX_DMA_Init(void) HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); /* DMA2_Stream3_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 10, 0); + HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn); /* DMA2_Stream6_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 10, 0); + HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn); /* DMA2_Stream7_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 5, 0); diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 6d9565c..640696e 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -55,7 +55,6 @@ const osThreadAttr_t defaultTask_attributes = { .priority = (osPriority_t) osPriorityNormal, }; - /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ @@ -63,49 +62,8 @@ const osThreadAttr_t defaultTask_attributes = { void StartDefaultTask(void *argument); -extern void MX_USB_DEVICE_Init(void); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ -/* Hook prototypes */ -void vApplicationIdleHook(void); -void vApplicationTickHook(void); -void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName); - -/* USER CODE BEGIN 2 */ -void vApplicationIdleHook( void ) -{ - /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set - to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle - task. It is essential that code added to this hook function never attempts - to block in any way (for example, call xQueueReceive() with a block time - specified, or call vTaskDelay()). If the application makes use of the - vTaskDelete() API function (as this demo application does) then it is also - important that vApplicationIdleHook() is permitted to return to its calling - function, because it is the responsibility of the idle task to clean up - memory allocated by the kernel to any task that has since been deleted. */ -} -/* USER CODE END 2 */ - -/* USER CODE BEGIN 3 */ -void vApplicationTickHook( void ) -{ - /* This function will be called by each tick interrupt if - configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be - added here, but the tick hook is called from an interrupt context, so - code must not attempt to block, and only the interrupt safe FreeRTOS API - functions can be used (those that end in FromISR()). */ -} -/* USER CODE END 3 */ - -/* USER CODE BEGIN 4 */ -void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) -{ - /* Run time stack overflow checking is performed if - configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is - called if a stack overflow is detected. */ -} -/* USER CODE END 4 */ - /** * @brief FreeRTOS initialization * @param None @@ -124,8 +82,6 @@ void MX_FREERTOS_Init(void) { /* add semaphores, ... */ /* USER CODE END RTOS_SEMAPHORES */ - /* Create the timer(s) */ - /* creation of measureTimer */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ @@ -157,8 +113,6 @@ void MX_FREERTOS_Init(void) { /* USER CODE END Header_StartDefaultTask */ __weak void StartDefaultTask(void *argument) { - /* init code for USB_DEVICE */ - MX_USB_DEVICE_Init(); /* USER CODE BEGIN StartDefaultTask */ /* Infinite loop */ for(;;) @@ -168,8 +122,6 @@ __weak void StartDefaultTask(void *argument) /* USER CODE END StartDefaultTask */ } - - /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index a011df3..d66bfa2 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -49,9 +49,9 @@ void MX_GPIO_Init(void) __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin Output Level */ @@ -63,13 +63,13 @@ void MX_GPIO_Init(void) HAL_GPIO_WritePin(PUMP_EN_GPIO_Port, PUMP_EN_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, MAX3242_EN_Pin|SENSOR2_EN_Pin|SENSOR4_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOC, SENSOR4_EN_Pin|SENSOR2_EN_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOG, SENSOR6_EN_Pin|R_W_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, ADDR_Pin|RDY_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(ADDR_GPIO_Port, ADDR_Pin, GPIO_PIN_RESET); /*Configure GPIO pins : PEPin PEPin PEPin PEPin PEPin PEPin PEPin PEPin */ @@ -94,18 +94,18 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(PUMP_EN_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pins : PAPin PAPin PAPin */ - GPIO_InitStruct.Pin = MAX3242_EN_Pin|SENSOR2_EN_Pin|SENSOR4_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + /*Configure GPIO pins : PAPin PAPin */ + GPIO_InitStruct.Pin = UART_EN_Pin|CDZ_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = BOOT1_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + /*Configure GPIO pins : PCPin PCPin */ + GPIO_InitStruct.Pin = SENSOR4_EN_Pin|SENSOR2_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pins : PGPin PGPin */ GPIO_InitStruct.Pin = SENSOR6_EN_Pin|R_W_Pin; @@ -115,17 +115,17 @@ void MX_GPIO_Init(void) HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = CDZ_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(CDZ_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin */ - GPIO_InitStruct.Pin = ADDR_Pin|RDY_Pin; + GPIO_InitStruct.Pin = ADDR_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(ADDR_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : PtPin */ + GPIO_InitStruct.Pin = RDY_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(RDY_GPIO_Port, &GPIO_InitStruct); } diff --git a/Core/Src/i2c.c b/Core/Src/i2c.c index c31a6e5..c218ee7 100644 --- a/Core/Src/i2c.c +++ b/Core/Src/i2c.c @@ -80,6 +80,12 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) /* I2C1 clock enable */ __HAL_RCC_I2C1_CLK_ENABLE(); + + /* I2C1 interrupt Init */ + HAL_NVIC_SetPriority(I2C1_EV_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(I2C1_EV_IRQn); + HAL_NVIC_SetPriority(I2C1_ER_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(I2C1_ER_IRQn); /* USER CODE BEGIN I2C1_MspInit 1 */ /* USER CODE END I2C1_MspInit 1 */ @@ -105,6 +111,9 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7); + /* I2C1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(I2C1_EV_IRQn); + HAL_NVIC_DisableIRQ(I2C1_ER_IRQn); /* USER CODE BEGIN I2C1_MspDeInit 1 */ /* USER CODE END I2C1_MspDeInit 1 */ diff --git a/Core/Src/main.c b/Core/Src/main.c index cad4ca2..6b826c9 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -25,7 +25,7 @@ #include "sdio.h" #include "tim.h" #include "usart.h" -#include "usb_device.h" +#include "usb_otg.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ @@ -105,9 +105,11 @@ int main(void) MX_USART2_UART_Init(); MX_USART3_UART_Init(); MX_USART6_UART_Init(); + MX_USB_OTG_FS_PCD_Init(); + MX_USB_OTG_HS_PCD_Init(); + MX_TIM2_Init(); MX_TIM7_Init(); MX_FATFS_Init(); - MX_TIM2_Init(); /* USER CODE BEGIN 2 */ MY_INIT( ); /* USER CODE END 2 */ diff --git a/Core/Src/sdio.c b/Core/Src/sdio.c index 3b75541..83576cd 100644 --- a/Core/Src/sdio.c +++ b/Core/Src/sdio.c @@ -46,7 +46,7 @@ void MX_SDIO_SD_Init(void) hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; hsd.Init.BusWide = SDIO_BUS_WIDE_4B; hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; - hsd.Init.ClockDiv = 6; + hsd.Init.ClockDiv = 0; /* USER CODE BEGIN SDIO_Init 2 */ /* USER CODE END SDIO_Init 2 */ @@ -134,7 +134,7 @@ void HAL_SD_MspInit(SD_HandleTypeDef* sdHandle) __HAL_LINKDMA(sdHandle,hdmatx,hdma_sdio_tx); /* SDIO interrupt Init */ - HAL_NVIC_SetPriority(SDIO_IRQn, 9, 0); + HAL_NVIC_SetPriority(SDIO_IRQn, 5, 0); HAL_NVIC_EnableIRQ(SDIO_IRQn); /* USER CODE BEGIN SDIO_MspInit 1 */ diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index c50af2a..11f555a 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -55,7 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ -extern PCD_HandleTypeDef hpcd_USB_OTG_HS; +extern I2C_HandleTypeDef hi2c1; extern DMA_HandleTypeDef hdma_sdio_rx; extern DMA_HandleTypeDef hdma_sdio_tx; extern SD_HandleTypeDef hsd; @@ -225,6 +225,34 @@ void DMA1_Stream6_IRQHandler(void) /* USER CODE END DMA1_Stream6_IRQn 1 */ } +/** + * @brief This function handles I2C1 event interrupt. + */ +void I2C1_EV_IRQHandler(void) +{ + /* USER CODE BEGIN I2C1_EV_IRQn 0 */ + + /* USER CODE END I2C1_EV_IRQn 0 */ + HAL_I2C_EV_IRQHandler(&hi2c1); + /* USER CODE BEGIN I2C1_EV_IRQn 1 */ + + /* USER CODE END I2C1_EV_IRQn 1 */ +} + +/** + * @brief This function handles I2C1 error interrupt. + */ +void I2C1_ER_IRQHandler(void) +{ + /* USER CODE BEGIN I2C1_ER_IRQn 0 */ + + /* USER CODE END I2C1_ER_IRQn 0 */ + HAL_I2C_ER_IRQHandler(&hi2c1); + /* USER CODE BEGIN I2C1_ER_IRQn 1 */ + + /* USER CODE END I2C1_ER_IRQn 1 */ +} + /** * @brief This function handles SDIO global interrupt. */ @@ -309,20 +337,6 @@ void DMA2_Stream7_IRQHandler(void) /* USER CODE END DMA2_Stream7_IRQn 1 */ } -/** - * @brief This function handles USB On The Go HS global interrupt. - */ -void OTG_HS_IRQHandler(void) -{ - /* USER CODE BEGIN OTG_HS_IRQn 0 */ - - /* USER CODE END OTG_HS_IRQn 0 */ - HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); - /* USER CODE BEGIN OTG_HS_IRQn 1 */ - - /* USER CODE END OTG_HS_IRQn 1 */ -} - /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index 20097e5..d65d6a3 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -42,9 +42,9 @@ void MX_TIM2_Init(void) /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; - htim2.Init.Prescaler = 8400-1; + htim2.Init.Prescaler = 0; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 10000-1; + htim2.Init.Period = 4294967295; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) @@ -81,9 +81,9 @@ void MX_TIM7_Init(void) /* USER CODE END TIM7_Init 1 */ htim7.Instance = TIM7; - htim7.Init.Prescaler = 8400-1; + htim7.Init.Prescaler = 0; htim7.Init.CounterMode = TIM_COUNTERMODE_UP; - htim7.Init.Period = 50-1; + htim7.Init.Period = 65535; htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim7) != HAL_OK) { diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 2edb57d..f5b9aa4 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -425,7 +425,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* USART6 interrupt Init */ - HAL_NVIC_SetPriority(USART6_IRQn, 7, 0); + HAL_NVIC_SetPriority(USART6_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART6_IRQn); /* USER CODE BEGIN USART6_MspInit 1 */ diff --git a/Core/Src/usb_otg.c b/Core/Src/usb_otg.c new file mode 100644 index 0000000..26921c7 --- /dev/null +++ b/Core/Src/usb_otg.c @@ -0,0 +1,191 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usb_otg.c + * @brief This file provides code for the configuration + * of the USB_OTG instances. + ****************************************************************************** + * @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 "usb_otg.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +PCD_HandleTypeDef hpcd_USB_OTG_FS; +PCD_HandleTypeDef hpcd_USB_OTG_HS; + +/* USB_OTG_FS init function */ + +void MX_USB_OTG_FS_PCD_Init(void) +{ + + /* USER CODE BEGIN USB_OTG_FS_Init 0 */ + + /* USER CODE END USB_OTG_FS_Init 0 */ + + /* USER CODE BEGIN USB_OTG_FS_Init 1 */ + + /* USER CODE END USB_OTG_FS_Init 1 */ + 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 = DISABLE; + 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 = DISABLE; + hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USB_OTG_FS_Init 2 */ + + /* USER CODE END USB_OTG_FS_Init 2 */ + +} +/* USB_OTG_HS init function */ + +void MX_USB_OTG_HS_PCD_Init(void) +{ + + /* USER CODE BEGIN USB_OTG_HS_Init 0 */ + + /* USER CODE END USB_OTG_HS_Init 0 */ + + /* USER CODE BEGIN USB_OTG_HS_Init 1 */ + + /* USER CODE END USB_OTG_HS_Init 1 */ + hpcd_USB_OTG_HS.Instance = USB_OTG_HS; + hpcd_USB_OTG_HS.Init.dev_endpoints = 6; + hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_OTG_HS.Init.dma_enable = DISABLE; + hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY; + hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE; + hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE; + hpcd_USB_OTG_HS.Init.lpm_enable = DISABLE; + hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE; + hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE; + hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_OTG_HS) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USB_OTG_HS_Init 2 */ + + /* USER CODE END USB_OTG_HS_Init 2 */ + +} + +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(pcdHandle->Instance==USB_OTG_FS) + { + /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ + + /* USER CODE END USB_OTG_FS_MspInit 0 */ + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USB_OTG_FS GPIO Configuration + PA11 ------> USB_OTG_FS_DM + PA12 ------> USB_OTG_FS_DP + */ + GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USB_OTG_FS clock enable */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ + + /* USER CODE END USB_OTG_FS_MspInit 1 */ + } + else if(pcdHandle->Instance==USB_OTG_HS) + { + /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */ + + /* USER CODE END USB_OTG_HS_MspInit 0 */ + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**USB_OTG_HS GPIO Configuration + PB14 ------> USB_OTG_HS_DM + PB15 ------> USB_OTG_HS_DP + */ + GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USB_OTG_HS clock enable */ + __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); + /* USER CODE BEGIN USB_OTG_HS_MspInit 1 */ + + /* USER CODE END USB_OTG_HS_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 + PA11 ------> USB_OTG_FS_DM + PA12 ------> USB_OTG_FS_DP + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + + /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ + + /* USER CODE END USB_OTG_FS_MspDeInit 1 */ + } + else if(pcdHandle->Instance==USB_OTG_HS) + { + /* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */ + + /* USER CODE END USB_OTG_HS_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); + + /**USB_OTG_HS GPIO Configuration + PB14 ------> USB_OTG_HS_DM + PB15 ------> USB_OTG_HS_DP + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15); + + /* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */ + + /* USER CODE END USB_OTG_HS_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Drivers/STM32F4xx_HAL_Driver/License.md b/Drivers/STM32F4xx_HAL_Driver/License.md new file mode 100644 index 0000000..f64c6c0 --- /dev/null +++ b/Drivers/STM32F4xx_HAL_Driver/License.md @@ -0,0 +1,3 @@ +# Copyright (c) 2016 STMicroelectronics + +This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). \ No newline at end of file diff --git a/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c b/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c index c2a8eb7..d418d2a 100644 --- a/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c +++ b/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c @@ -1728,7 +1728,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t De { __IO uint32_t count = 0U; - if (hi2c->State == HAL_I2C_STATE_READY) + if ( hi2c->State == HAL_I2C_STATE_READY ) { /* Wait until BUSY flag is reset */ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); diff --git a/FATFS/Target/ffconf.h b/FATFS/Target/ffconf.h index 863b826..a897802 100644 --- a/FATFS/Target/ffconf.h +++ b/FATFS/Target/ffconf.h @@ -71,7 +71,7 @@ /* This option switches attribute manipulation functions, f_chmod() and f_utime(). / (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */ -#define _USE_LABEL 1 +#define _USE_LABEL 0 /* This option switches volume label functions, f_getlabel() and f_setlabel(). / (0:Disable or 1:Enable) */ @@ -210,7 +210,7 @@ / Instead of private sector buffer eliminated from the file object, common sector / buffer in the file system object (FATFS) is used for the file data transfer. */ -#define _FS_EXFAT 1 +#define _FS_EXFAT 0 /* This option switches support of exFAT file system. (0:Disable or 1:Enable) / When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) / Note that enabling exFAT discards C89 compatibility. */ diff --git a/H2S.ioc b/H2S.ioc index b882e56..e10387a 100644 --- a/H2S.ioc +++ b/H2S.ioc @@ -2,107 +2,105 @@ CAD.formats= CAD.pinconfig= CAD.provider= -Dma.Request0=USART1_RX -Dma.Request1=USART1_TX -Dma.Request2=USART2_RX -Dma.Request3=USART2_TX -Dma.Request4=USART3_RX -Dma.Request5=USART3_TX -Dma.Request6=SDIO_RX -Dma.Request7=SDIO_TX +Dma.Request0=SDIO_RX +Dma.Request1=SDIO_TX +Dma.Request2=USART1_RX +Dma.Request3=USART1_TX +Dma.Request4=USART2_RX +Dma.Request5=USART2_TX +Dma.Request6=USART3_RX +Dma.Request7=USART3_TX Dma.RequestsNb=8 -Dma.SDIO_RX.6.Direction=DMA_PERIPH_TO_MEMORY -Dma.SDIO_RX.6.FIFOMode=DMA_FIFOMODE_ENABLE -Dma.SDIO_RX.6.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL -Dma.SDIO_RX.6.Instance=DMA2_Stream3 -Dma.SDIO_RX.6.MemBurst=DMA_MBURST_INC4 -Dma.SDIO_RX.6.MemDataAlignment=DMA_MDATAALIGN_WORD -Dma.SDIO_RX.6.MemInc=DMA_MINC_ENABLE -Dma.SDIO_RX.6.Mode=DMA_PFCTRL -Dma.SDIO_RX.6.PeriphBurst=DMA_PBURST_INC4 -Dma.SDIO_RX.6.PeriphDataAlignment=DMA_PDATAALIGN_WORD -Dma.SDIO_RX.6.PeriphInc=DMA_PINC_DISABLE -Dma.SDIO_RX.6.Priority=DMA_PRIORITY_LOW -Dma.SDIO_RX.6.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst -Dma.SDIO_TX.7.Direction=DMA_MEMORY_TO_PERIPH -Dma.SDIO_TX.7.FIFOMode=DMA_FIFOMODE_ENABLE -Dma.SDIO_TX.7.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL -Dma.SDIO_TX.7.Instance=DMA2_Stream6 -Dma.SDIO_TX.7.MemBurst=DMA_MBURST_INC4 -Dma.SDIO_TX.7.MemDataAlignment=DMA_MDATAALIGN_WORD -Dma.SDIO_TX.7.MemInc=DMA_MINC_ENABLE -Dma.SDIO_TX.7.Mode=DMA_PFCTRL -Dma.SDIO_TX.7.PeriphBurst=DMA_PBURST_INC4 -Dma.SDIO_TX.7.PeriphDataAlignment=DMA_PDATAALIGN_WORD -Dma.SDIO_TX.7.PeriphInc=DMA_PINC_DISABLE -Dma.SDIO_TX.7.Priority=DMA_PRIORITY_LOW -Dma.SDIO_TX.7.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst -Dma.USART1_RX.0.Direction=DMA_PERIPH_TO_MEMORY -Dma.USART1_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE -Dma.USART1_RX.0.Instance=DMA2_Stream2 -Dma.USART1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.USART1_RX.0.MemInc=DMA_MINC_ENABLE -Dma.USART1_RX.0.Mode=DMA_NORMAL -Dma.USART1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -Dma.USART1_RX.0.PeriphInc=DMA_PINC_DISABLE -Dma.USART1_RX.0.Priority=DMA_PRIORITY_LOW -Dma.USART1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH -Dma.USART1_TX.1.FIFOMode=DMA_FIFOMODE_DISABLE -Dma.USART1_TX.1.Instance=DMA2_Stream7 -Dma.USART1_TX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.USART1_TX.1.MemInc=DMA_MINC_ENABLE -Dma.USART1_TX.1.Mode=DMA_NORMAL -Dma.USART1_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -Dma.USART1_TX.1.PeriphInc=DMA_PINC_DISABLE -Dma.USART1_TX.1.Priority=DMA_PRIORITY_LOW -Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -Dma.USART2_RX.2.Direction=DMA_PERIPH_TO_MEMORY -Dma.USART2_RX.2.FIFOMode=DMA_FIFOMODE_DISABLE -Dma.USART2_RX.2.Instance=DMA1_Stream5 -Dma.USART2_RX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.USART2_RX.2.MemInc=DMA_MINC_ENABLE -Dma.USART2_RX.2.Mode=DMA_NORMAL -Dma.USART2_RX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -Dma.USART2_RX.2.PeriphInc=DMA_PINC_DISABLE -Dma.USART2_RX.2.Priority=DMA_PRIORITY_LOW -Dma.USART2_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -Dma.USART2_TX.3.Direction=DMA_MEMORY_TO_PERIPH -Dma.USART2_TX.3.FIFOMode=DMA_FIFOMODE_DISABLE -Dma.USART2_TX.3.Instance=DMA1_Stream6 -Dma.USART2_TX.3.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.USART2_TX.3.MemInc=DMA_MINC_ENABLE -Dma.USART2_TX.3.Mode=DMA_NORMAL -Dma.USART2_TX.3.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -Dma.USART2_TX.3.PeriphInc=DMA_PINC_DISABLE -Dma.USART2_TX.3.Priority=DMA_PRIORITY_LOW -Dma.USART2_TX.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -Dma.USART3_RX.4.Direction=DMA_PERIPH_TO_MEMORY -Dma.USART3_RX.4.FIFOMode=DMA_FIFOMODE_DISABLE -Dma.USART3_RX.4.Instance=DMA1_Stream1 -Dma.USART3_RX.4.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.USART3_RX.4.MemInc=DMA_MINC_ENABLE -Dma.USART3_RX.4.Mode=DMA_NORMAL -Dma.USART3_RX.4.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -Dma.USART3_RX.4.PeriphInc=DMA_PINC_DISABLE -Dma.USART3_RX.4.Priority=DMA_PRIORITY_LOW -Dma.USART3_RX.4.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -Dma.USART3_TX.5.Direction=DMA_MEMORY_TO_PERIPH -Dma.USART3_TX.5.FIFOMode=DMA_FIFOMODE_DISABLE -Dma.USART3_TX.5.Instance=DMA1_Stream3 -Dma.USART3_TX.5.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.USART3_TX.5.MemInc=DMA_MINC_ENABLE -Dma.USART3_TX.5.Mode=DMA_NORMAL -Dma.USART3_TX.5.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -Dma.USART3_TX.5.PeriphInc=DMA_PINC_DISABLE -Dma.USART3_TX.5.Priority=DMA_PRIORITY_LOW -Dma.USART3_TX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.SDIO_RX.0.Direction=DMA_PERIPH_TO_MEMORY +Dma.SDIO_RX.0.FIFOMode=DMA_FIFOMODE_ENABLE +Dma.SDIO_RX.0.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL +Dma.SDIO_RX.0.Instance=DMA2_Stream3 +Dma.SDIO_RX.0.MemBurst=DMA_MBURST_INC4 +Dma.SDIO_RX.0.MemDataAlignment=DMA_MDATAALIGN_WORD +Dma.SDIO_RX.0.MemInc=DMA_MINC_ENABLE +Dma.SDIO_RX.0.Mode=DMA_PFCTRL +Dma.SDIO_RX.0.PeriphBurst=DMA_PBURST_INC4 +Dma.SDIO_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_WORD +Dma.SDIO_RX.0.PeriphInc=DMA_PINC_DISABLE +Dma.SDIO_RX.0.Priority=DMA_PRIORITY_LOW +Dma.SDIO_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst +Dma.SDIO_TX.1.Direction=DMA_MEMORY_TO_PERIPH +Dma.SDIO_TX.1.FIFOMode=DMA_FIFOMODE_ENABLE +Dma.SDIO_TX.1.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL +Dma.SDIO_TX.1.Instance=DMA2_Stream6 +Dma.SDIO_TX.1.MemBurst=DMA_MBURST_INC4 +Dma.SDIO_TX.1.MemDataAlignment=DMA_MDATAALIGN_WORD +Dma.SDIO_TX.1.MemInc=DMA_MINC_ENABLE +Dma.SDIO_TX.1.Mode=DMA_PFCTRL +Dma.SDIO_TX.1.PeriphBurst=DMA_PBURST_INC4 +Dma.SDIO_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_WORD +Dma.SDIO_TX.1.PeriphInc=DMA_PINC_DISABLE +Dma.SDIO_TX.1.Priority=DMA_PRIORITY_LOW +Dma.SDIO_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst +Dma.USART1_RX.2.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART1_RX.2.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART1_RX.2.Instance=DMA2_Stream2 +Dma.USART1_RX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART1_RX.2.MemInc=DMA_MINC_ENABLE +Dma.USART1_RX.2.Mode=DMA_NORMAL +Dma.USART1_RX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART1_RX.2.PeriphInc=DMA_PINC_DISABLE +Dma.USART1_RX.2.Priority=DMA_PRIORITY_LOW +Dma.USART1_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART1_TX.3.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART1_TX.3.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART1_TX.3.Instance=DMA2_Stream7 +Dma.USART1_TX.3.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART1_TX.3.MemInc=DMA_MINC_ENABLE +Dma.USART1_TX.3.Mode=DMA_NORMAL +Dma.USART1_TX.3.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART1_TX.3.PeriphInc=DMA_PINC_DISABLE +Dma.USART1_TX.3.Priority=DMA_PRIORITY_LOW +Dma.USART1_TX.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART2_RX.4.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART2_RX.4.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART2_RX.4.Instance=DMA1_Stream5 +Dma.USART2_RX.4.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART2_RX.4.MemInc=DMA_MINC_ENABLE +Dma.USART2_RX.4.Mode=DMA_NORMAL +Dma.USART2_RX.4.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART2_RX.4.PeriphInc=DMA_PINC_DISABLE +Dma.USART2_RX.4.Priority=DMA_PRIORITY_LOW +Dma.USART2_RX.4.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART2_TX.5.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART2_TX.5.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART2_TX.5.Instance=DMA1_Stream6 +Dma.USART2_TX.5.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART2_TX.5.MemInc=DMA_MINC_ENABLE +Dma.USART2_TX.5.Mode=DMA_NORMAL +Dma.USART2_TX.5.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART2_TX.5.PeriphInc=DMA_PINC_DISABLE +Dma.USART2_TX.5.Priority=DMA_PRIORITY_LOW +Dma.USART2_TX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART3_RX.6.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART3_RX.6.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART3_RX.6.Instance=DMA1_Stream1 +Dma.USART3_RX.6.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART3_RX.6.MemInc=DMA_MINC_ENABLE +Dma.USART3_RX.6.Mode=DMA_NORMAL +Dma.USART3_RX.6.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART3_RX.6.PeriphInc=DMA_PINC_DISABLE +Dma.USART3_RX.6.Priority=DMA_PRIORITY_LOW +Dma.USART3_RX.6.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART3_TX.7.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART3_TX.7.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART3_TX.7.Instance=DMA1_Stream3 +Dma.USART3_TX.7.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART3_TX.7.MemInc=DMA_MINC_ENABLE +Dma.USART3_TX.7.Mode=DMA_NORMAL +Dma.USART3_TX.7.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART3_TX.7.PeriphInc=DMA_PINC_DISABLE +Dma.USART3_TX.7.Priority=DMA_PRIORITY_LOW +Dma.USART3_TX.7.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode FATFS.BSP.number=1 -FATFS.IPParameters=_CODE_PAGE,_USE_LFN,_USE_LABEL,_MAX_SS,_FS_EXFAT +FATFS.IPParameters=_CODE_PAGE,_USE_LFN,_MAX_SS FATFS._CODE_PAGE=936 -FATFS._FS_EXFAT=1 FATFS._MAX_SS=4096 -FATFS._USE_LABEL=1 FATFS._USE_LFN=2 FATFS0.BSP.STBoard=false FATFS0.BSP.api=Unknown @@ -115,15 +113,13 @@ FATFS0.BSP.name=Detect_SDIO FATFS0.BSP.semaphore= FATFS0.BSP.solution=PA15 FREERTOS.FootprintOK=true -FREERTOS.IPParameters=Tasks01,FootprintOK,configCHECK_FOR_STACK_OVERFLOW,configUSE_IDLE_HOOK,configUSE_TICK_HOOK +FREERTOS.IPParameters=Tasks01,FootprintOK,configENABLE_FPU FREERTOS.Tasks01=defaultTask,24,1024,StartDefaultTask,As weak,NULL,Dynamic,NULL,NULL -FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2 -FREERTOS.configUSE_IDLE_HOOK=1 -FREERTOS.configUSE_TICK_HOOK=1 +FREERTOS.configENABLE_FPU=1 File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false -Mcu.CPN=STM32F407ZET6 +Mcu.CPN=STM32F407ZGT6 Mcu.Family=STM32F4 Mcu.IP0=DMA Mcu.IP1=FATFS @@ -132,7 +128,7 @@ Mcu.IP11=USART1 Mcu.IP12=USART2 Mcu.IP13=USART3 Mcu.IP14=USART6 -Mcu.IP15=USB_DEVICE +Mcu.IP15=USB_OTG_FS Mcu.IP16=USB_OTG_HS Mcu.IP2=FREERTOS Mcu.IP3=I2C1 @@ -148,47 +144,47 @@ Mcu.Package=LQFP144 Mcu.Pin0=PE4 Mcu.Pin1=PE5 Mcu.Pin10=PA4 -Mcu.Pin11=PA6 -Mcu.Pin12=PA7 -Mcu.Pin13=PB2 -Mcu.Pin14=PE12 -Mcu.Pin15=PE13 -Mcu.Pin16=PE14 -Mcu.Pin17=PE15 -Mcu.Pin18=PB10 -Mcu.Pin19=PB11 +Mcu.Pin11=PC4 +Mcu.Pin12=PC5 +Mcu.Pin13=PE12 +Mcu.Pin14=PE13 +Mcu.Pin15=PE14 +Mcu.Pin16=PE15 +Mcu.Pin17=PB10 +Mcu.Pin18=PB11 +Mcu.Pin19=PB14 Mcu.Pin2=PE6 -Mcu.Pin20=PB14 -Mcu.Pin21=PB15 -Mcu.Pin22=PG4 -Mcu.Pin23=PG5 -Mcu.Pin24=PC6 -Mcu.Pin25=PC7 -Mcu.Pin26=PC8 -Mcu.Pin27=PC9 -Mcu.Pin28=PA9 -Mcu.Pin29=PA10 +Mcu.Pin20=PB15 +Mcu.Pin21=PG7 +Mcu.Pin22=PG8 +Mcu.Pin23=PC6 +Mcu.Pin24=PC7 +Mcu.Pin25=PC8 +Mcu.Pin26=PC9 +Mcu.Pin27=PA9 +Mcu.Pin28=PA10 +Mcu.Pin29=PA11 Mcu.Pin3=PF0 -Mcu.Pin30=PA13 -Mcu.Pin31=PA14 -Mcu.Pin32=PA15 -Mcu.Pin33=PC10 -Mcu.Pin34=PC11 -Mcu.Pin35=PC12 -Mcu.Pin36=PD2 -Mcu.Pin37=PB4 -Mcu.Pin38=PB5 -Mcu.Pin39=PB6 +Mcu.Pin30=PA12 +Mcu.Pin31=PA13 +Mcu.Pin32=PA14 +Mcu.Pin33=PA15 +Mcu.Pin34=PC10 +Mcu.Pin35=PC11 +Mcu.Pin36=PC12 +Mcu.Pin37=PD2 +Mcu.Pin38=PB4 +Mcu.Pin39=PB5 Mcu.Pin4=PH0-OSC_IN -Mcu.Pin40=PB7 -Mcu.Pin41=PE0 -Mcu.Pin42=PE1 -Mcu.Pin43=VP_FATFS_VS_SDIO -Mcu.Pin44=VP_FREERTOS_VS_CMSIS_V2 -Mcu.Pin45=VP_SYS_VS_tim6 -Mcu.Pin46=VP_TIM2_VS_ClockSourceINT -Mcu.Pin47=VP_TIM7_VS_ClockSourceINT -Mcu.Pin48=VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS +Mcu.Pin40=PB6 +Mcu.Pin41=PB7 +Mcu.Pin42=PE0 +Mcu.Pin43=PE1 +Mcu.Pin44=VP_FATFS_VS_SDIO +Mcu.Pin45=VP_FREERTOS_VS_CMSIS_V2 +Mcu.Pin46=VP_SYS_VS_tim6 +Mcu.Pin47=VP_TIM2_VS_ClockSourceINT +Mcu.Pin48=VP_TIM7_VS_ClockSourceINT Mcu.Pin5=PH1-OSC_OUT Mcu.Pin6=PA0-WKUP Mcu.Pin7=PA1 @@ -197,7 +193,7 @@ Mcu.Pin9=PA3 Mcu.PinsNb=49 Mcu.ThirdPartyNb=0 Mcu.UserConstants= -Mcu.UserName=STM32F407ZETx +Mcu.UserName=STM32F407ZGTx MxCube.Version=6.8.1 MxDb.Version=DB.6.0.81 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false @@ -206,33 +202,34 @@ NVIC.DMA1_Stream3_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DMA1_Stream5_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DMA1_Stream6_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DMA2_Stream2_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true -NVIC.DMA2_Stream3_IRQn=true\:10\:0\:true\:false\:true\:true\:false\:true\:true -NVIC.DMA2_Stream6_IRQn=true\:10\:0\:true\:false\:true\:true\:false\:true\:true +NVIC.DMA2_Stream3_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DMA2_Stream6_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DMA2_Stream7_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.ForceEnableDMAVector=true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.I2C1_ER_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true +NVIC.I2C1_EV_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false -NVIC.OTG_HS_IRQn=true\:11\:0\:true\:false\:true\:true\:false\:true\:true NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SDIO_IRQn=true\:9\:0\:true\:false\:true\:true\:true\:true\:true +NVIC.SDIO_IRQn=true\:5\:0\:false\:false\:true\:false\:true\:true\:true NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false NVIC.SavedPendsvIrqHandlerGenerated=true NVIC.SavedSvcallIrqHandlerGenerated=true NVIC.SavedSystickIrqHandlerGenerated=true NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false -NVIC.TIM2_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true -NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true -NVIC.TIM7_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.TIM2_IRQn=true\:5\:0\:false\:false\:false\:false\:true\:true\:true +NVIC.TIM6_DAC_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true\:true +NVIC.TIM7_IRQn=true\:5\:0\:false\:false\:false\:false\:true\:true\:true NVIC.TimeBase=TIM6_DAC_IRQn NVIC.TimeBaseIP=TIM6 -NVIC.UART4_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true -NVIC.USART1_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true -NVIC.USART2_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true -NVIC.USART3_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true -NVIC.USART6_IRQn=true\:7\:0\:true\:false\:false\:true\:true\:true\:true +NVIC.UART4_IRQn=true\:5\:0\:false\:false\:false\:false\:true\:true\:true +NVIC.USART1_IRQn=true\:5\:0\:false\:false\:false\:false\:true\:true\:true +NVIC.USART2_IRQn=true\:5\:0\:false\:false\:false\:false\:true\:true\:true +NVIC.USART3_IRQn=true\:5\:0\:false\:false\:false\:false\:true\:true\:true +NVIC.USART6_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false PA0-WKUP.Mode=Asynchronous PA0-WKUP.Signal=UART4_TX @@ -240,6 +237,10 @@ PA1.Mode=Asynchronous PA1.Signal=UART4_RX PA10.Mode=Asynchronous PA10.Signal=USART1_RX +PA11.Mode=Device_Only +PA11.Signal=USB_OTG_FS_DM +PA12.Mode=Device_Only +PA12.Signal=USB_OTG_FS_DP PA13.Mode=Serial_Wire PA13.Signal=SYS_JTMS-SWDIO PA14.Mode=Serial_Wire @@ -248,40 +249,24 @@ PA15.GPIOParameters=GPIO_Label PA15.GPIO_Label=CDZ PA15.Locked=true PA15.Signal=GPIO_Input -PA2.Locked=true PA2.Mode=Asynchronous PA2.Signal=USART2_TX -PA3.Locked=true PA3.Mode=Asynchronous PA3.Signal=USART2_RX PA4.GPIOParameters=GPIO_Label -PA4.GPIO_Label=MAX3242_EN +PA4.GPIO_Label=UART_EN PA4.Locked=true -PA4.Signal=GPIO_Output -PA6.GPIOParameters=GPIO_Label -PA6.GPIO_Label=SENSOR2_EN -PA6.Locked=true -PA6.Signal=GPIO_Output -PA7.GPIOParameters=GPIO_Label -PA7.GPIO_Label=SENSOR4_EN -PA7.Locked=true -PA7.Signal=GPIO_Output +PA4.Signal=GPIO_Input PA9.Mode=Asynchronous PA9.Signal=USART1_TX -PB10.Locked=true PB10.Mode=Asynchronous PB10.Signal=USART3_TX -PB11.Locked=true PB11.Mode=Asynchronous PB11.Signal=USART3_RX PB14.Mode=Device_Only_FS PB14.Signal=USB_OTG_HS_DM PB15.Mode=Device_Only_FS PB15.Signal=USB_OTG_HS_DP -PB2.GPIOParameters=GPIO_Label -PB2.GPIO_Label=BOOT1 -PB2.Locked=true -PB2.Signal=GPIO_Input PB4.GPIOParameters=GPIO_Label PB4.GPIO_Label=ADDR PB4.Locked=true @@ -289,13 +274,15 @@ PB4.Signal=GPIO_Output PB5.GPIOParameters=GPIO_Label PB5.GPIO_Label=RDY PB5.Locked=true -PB5.Signal=GPIO_Output +PB5.Signal=GPIO_Input PB6.GPIOParameters=GPIO_Pu PB6.GPIO_Pu=GPIO_PULLUP +PB6.Locked=true PB6.Mode=I2C PB6.Signal=I2C1_SCL PB7.GPIOParameters=GPIO_Pu PB7.GPIO_Pu=GPIO_PULLUP +PB7.Locked=true PB7.Mode=I2C PB7.Signal=I2C1_SDA PC10.Mode=SD_4_bits_Wide_bus @@ -304,6 +291,14 @@ PC11.Mode=SD_4_bits_Wide_bus PC11.Signal=SDIO_D3 PC12.Mode=SD_4_bits_Wide_bus PC12.Signal=SDIO_CK +PC4.GPIOParameters=GPIO_Label +PC4.GPIO_Label=SENSOR4_EN +PC4.Locked=true +PC4.Signal=GPIO_Output +PC5.GPIOParameters=GPIO_Label +PC5.GPIO_Label=SENSOR2_EN +PC5.Locked=true +PC5.Signal=GPIO_Output PC6.Locked=true PC6.Mode=Asynchronous PC6.Signal=USART6_TX @@ -357,14 +352,14 @@ PF0.GPIOParameters=GPIO_Label PF0.GPIO_Label=PUMP_EN PF0.Locked=true PF0.Signal=GPIO_Output -PG4.GPIOParameters=GPIO_Label -PG4.GPIO_Label=SENSOR6_EN -PG4.Locked=true -PG4.Signal=GPIO_Output -PG5.GPIOParameters=GPIO_Label -PG5.GPIO_Label=R/W -PG5.Locked=true -PG5.Signal=GPIO_Output +PG7.GPIOParameters=GPIO_Label +PG7.GPIO_Label=SENSOR6_EN +PG7.Locked=true +PG7.Signal=GPIO_Output +PG8.GPIOParameters=GPIO_Label +PG8.GPIO_Label=R/W +PG8.Locked=true +PG8.Signal=GPIO_Output PH0-OSC_IN.Mode=HSE-External-Oscillator PH0-OSC_IN.Signal=RCC_OSC_IN PH1-OSC_OUT.Mode=HSE-External-Oscillator @@ -378,11 +373,11 @@ ProjectManager.CoupleFile=true ProjectManager.CustomerFirmwarePackage= ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32F407ZETx +ProjectManager.DeviceId=STM32F407ZGTx ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.27.1 ProjectManager.FreePins=false ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x1000 +ProjectManager.HeapSize=0x800 ProjectManager.KeepUserCode=true ProjectManager.LastFirmware=true ProjectManager.LibraryCopy=0 @@ -394,11 +389,11 @@ ProjectManager.ProjectFileName=H2S.ioc ProjectManager.ProjectName=H2S ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x1500 +ProjectManager.StackSize=0x1000 ProjectManager.TargetToolchain=Makefile ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_SDIO_SD_Init-SDIO-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_USART2_UART_Init-USART2-false-HAL-true,9-MX_USART3_UART_Init-USART3-false-HAL-true,10-MX_USART6_UART_Init-USART6-false-HAL-true,11-MX_TIM7_Init-TIM7-false-HAL-true,12-MX_FATFS_Init-FATFS-false-HAL-false,13-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,14-MX_TIM2_Init-TIM2-false-HAL-true +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_SDIO_SD_Init-SDIO-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_USART2_UART_Init-USART2-false-HAL-true,9-MX_USART3_UART_Init-USART3-false-HAL-true,10-MX_USART6_UART_Init-USART6-false-HAL-true,11-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,12-MX_USB_OTG_HS_PCD_Init-USB_OTG_HS-false-HAL-true,13-MX_TIM2_Init-TIM2-false-HAL-true,14-MX_TIM7_Init-TIM7-false-HAL-true,15-MX_FATFS_Init-FATFS-false-HAL-false RCC.48MHZClocksFreq_Value=48000000 RCC.AHBFreq_Value=168000000 RCC.APB1CLKDivider=RCC_HCLK_DIV4 @@ -432,31 +427,19 @@ RCC.VCOI2SOutputFreq_Value=384000000 RCC.VCOInputFreq_Value=2000000 RCC.VCOOutputFreq_Value=336000000 RCC.VcooutputI2S=192000000 -SDIO.ClockDiv=6 -SDIO.IPParameters=ClockDiv -TIM2.IPParameters=Prescaler,Period -TIM2.Period=10000-1 -TIM2.Prescaler=8400-1 -TIM7.IPParameters=Prescaler,Period -TIM7.Period=50-1 -TIM7.Prescaler=8400-1 UART4.IPParameters=VirtualMode UART4.VirtualMode=Asynchronous USART1.IPParameters=VirtualMode USART1.VirtualMode=VM_ASYNC USART2.IPParameters=VirtualMode USART2.VirtualMode=VM_ASYNC -USART3.BaudRate=9600 -USART3.IPParameters=VirtualMode,BaudRate +USART3.IPParameters=VirtualMode USART3.VirtualMode=VM_ASYNC USART6.BaudRate=19200 USART6.IPParameters=VirtualMode,BaudRate USART6.VirtualMode=VM_ASYNC -USB_DEVICE.CLASS_NAME_HS=MSC -USB_DEVICE.IPParameters=VirtualMode-MSC_HS,VirtualModeHS,CLASS_NAME_HS,MSC_MEDIA_PACKET-MSC_HS -USB_DEVICE.MSC_MEDIA_PACKET-MSC_HS=4096 -USB_DEVICE.VirtualMode-MSC_HS=Msc -USB_DEVICE.VirtualModeHS=Msc_HS +USB_OTG_FS.IPParameters=VirtualMode +USB_OTG_FS.VirtualMode=Device_Only USB_OTG_HS.IPParameters=VirtualMode-Device_Only_FS USB_OTG_HS.VirtualMode-Device_Only_FS=Device_Only_FS VP_FATFS_VS_SDIO.Mode=SDIO @@ -469,7 +452,5 @@ VP_TIM2_VS_ClockSourceINT.Mode=Internal VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT VP_TIM7_VS_ClockSourceINT.Mode=Enable_Timer VP_TIM7_VS_ClockSourceINT.Signal=TIM7_VS_ClockSourceINT -VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS.Mode=MSC_HS -VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS.Signal=USB_DEVICE_VS_USB_DEVICE_MSC_HS board=custom rtos.0.ip=FREERTOS diff --git a/H2S_backup.ioc b/H2S_backup.ioc new file mode 100644 index 0000000..b882e56 --- /dev/null +++ b/H2S_backup.ioc @@ -0,0 +1,475 @@ +#MicroXplorer Configuration settings - do not modify +CAD.formats= +CAD.pinconfig= +CAD.provider= +Dma.Request0=USART1_RX +Dma.Request1=USART1_TX +Dma.Request2=USART2_RX +Dma.Request3=USART2_TX +Dma.Request4=USART3_RX +Dma.Request5=USART3_TX +Dma.Request6=SDIO_RX +Dma.Request7=SDIO_TX +Dma.RequestsNb=8 +Dma.SDIO_RX.6.Direction=DMA_PERIPH_TO_MEMORY +Dma.SDIO_RX.6.FIFOMode=DMA_FIFOMODE_ENABLE +Dma.SDIO_RX.6.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL +Dma.SDIO_RX.6.Instance=DMA2_Stream3 +Dma.SDIO_RX.6.MemBurst=DMA_MBURST_INC4 +Dma.SDIO_RX.6.MemDataAlignment=DMA_MDATAALIGN_WORD +Dma.SDIO_RX.6.MemInc=DMA_MINC_ENABLE +Dma.SDIO_RX.6.Mode=DMA_PFCTRL +Dma.SDIO_RX.6.PeriphBurst=DMA_PBURST_INC4 +Dma.SDIO_RX.6.PeriphDataAlignment=DMA_PDATAALIGN_WORD +Dma.SDIO_RX.6.PeriphInc=DMA_PINC_DISABLE +Dma.SDIO_RX.6.Priority=DMA_PRIORITY_LOW +Dma.SDIO_RX.6.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst +Dma.SDIO_TX.7.Direction=DMA_MEMORY_TO_PERIPH +Dma.SDIO_TX.7.FIFOMode=DMA_FIFOMODE_ENABLE +Dma.SDIO_TX.7.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL +Dma.SDIO_TX.7.Instance=DMA2_Stream6 +Dma.SDIO_TX.7.MemBurst=DMA_MBURST_INC4 +Dma.SDIO_TX.7.MemDataAlignment=DMA_MDATAALIGN_WORD +Dma.SDIO_TX.7.MemInc=DMA_MINC_ENABLE +Dma.SDIO_TX.7.Mode=DMA_PFCTRL +Dma.SDIO_TX.7.PeriphBurst=DMA_PBURST_INC4 +Dma.SDIO_TX.7.PeriphDataAlignment=DMA_PDATAALIGN_WORD +Dma.SDIO_TX.7.PeriphInc=DMA_PINC_DISABLE +Dma.SDIO_TX.7.Priority=DMA_PRIORITY_LOW +Dma.SDIO_TX.7.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst +Dma.USART1_RX.0.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART1_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART1_RX.0.Instance=DMA2_Stream2 +Dma.USART1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART1_RX.0.MemInc=DMA_MINC_ENABLE +Dma.USART1_RX.0.Mode=DMA_NORMAL +Dma.USART1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART1_RX.0.PeriphInc=DMA_PINC_DISABLE +Dma.USART1_RX.0.Priority=DMA_PRIORITY_LOW +Dma.USART1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART1_TX.1.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART1_TX.1.Instance=DMA2_Stream7 +Dma.USART1_TX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART1_TX.1.MemInc=DMA_MINC_ENABLE +Dma.USART1_TX.1.Mode=DMA_NORMAL +Dma.USART1_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART1_TX.1.PeriphInc=DMA_PINC_DISABLE +Dma.USART1_TX.1.Priority=DMA_PRIORITY_LOW +Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART2_RX.2.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART2_RX.2.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART2_RX.2.Instance=DMA1_Stream5 +Dma.USART2_RX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART2_RX.2.MemInc=DMA_MINC_ENABLE +Dma.USART2_RX.2.Mode=DMA_NORMAL +Dma.USART2_RX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART2_RX.2.PeriphInc=DMA_PINC_DISABLE +Dma.USART2_RX.2.Priority=DMA_PRIORITY_LOW +Dma.USART2_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART2_TX.3.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART2_TX.3.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART2_TX.3.Instance=DMA1_Stream6 +Dma.USART2_TX.3.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART2_TX.3.MemInc=DMA_MINC_ENABLE +Dma.USART2_TX.3.Mode=DMA_NORMAL +Dma.USART2_TX.3.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART2_TX.3.PeriphInc=DMA_PINC_DISABLE +Dma.USART2_TX.3.Priority=DMA_PRIORITY_LOW +Dma.USART2_TX.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART3_RX.4.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART3_RX.4.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART3_RX.4.Instance=DMA1_Stream1 +Dma.USART3_RX.4.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART3_RX.4.MemInc=DMA_MINC_ENABLE +Dma.USART3_RX.4.Mode=DMA_NORMAL +Dma.USART3_RX.4.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART3_RX.4.PeriphInc=DMA_PINC_DISABLE +Dma.USART3_RX.4.Priority=DMA_PRIORITY_LOW +Dma.USART3_RX.4.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.USART3_TX.5.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART3_TX.5.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.USART3_TX.5.Instance=DMA1_Stream3 +Dma.USART3_TX.5.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART3_TX.5.MemInc=DMA_MINC_ENABLE +Dma.USART3_TX.5.Mode=DMA_NORMAL +Dma.USART3_TX.5.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART3_TX.5.PeriphInc=DMA_PINC_DISABLE +Dma.USART3_TX.5.Priority=DMA_PRIORITY_LOW +Dma.USART3_TX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +FATFS.BSP.number=1 +FATFS.IPParameters=_CODE_PAGE,_USE_LFN,_USE_LABEL,_MAX_SS,_FS_EXFAT +FATFS._CODE_PAGE=936 +FATFS._FS_EXFAT=1 +FATFS._MAX_SS=4096 +FATFS._USE_LABEL=1 +FATFS._USE_LFN=2 +FATFS0.BSP.STBoard=false +FATFS0.BSP.api=Unknown +FATFS0.BSP.component= +FATFS0.BSP.condition= +FATFS0.BSP.instance=PA15 +FATFS0.BSP.ip=GPIO +FATFS0.BSP.mode=Input +FATFS0.BSP.name=Detect_SDIO +FATFS0.BSP.semaphore= +FATFS0.BSP.solution=PA15 +FREERTOS.FootprintOK=true +FREERTOS.IPParameters=Tasks01,FootprintOK,configCHECK_FOR_STACK_OVERFLOW,configUSE_IDLE_HOOK,configUSE_TICK_HOOK +FREERTOS.Tasks01=defaultTask,24,1024,StartDefaultTask,As weak,NULL,Dynamic,NULL,NULL +FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2 +FREERTOS.configUSE_IDLE_HOOK=1 +FREERTOS.configUSE_TICK_HOOK=1 +File.Version=6 +GPIO.groupedBy=Group By Peripherals +KeepUserPlacement=false +Mcu.CPN=STM32F407ZET6 +Mcu.Family=STM32F4 +Mcu.IP0=DMA +Mcu.IP1=FATFS +Mcu.IP10=UART4 +Mcu.IP11=USART1 +Mcu.IP12=USART2 +Mcu.IP13=USART3 +Mcu.IP14=USART6 +Mcu.IP15=USB_DEVICE +Mcu.IP16=USB_OTG_HS +Mcu.IP2=FREERTOS +Mcu.IP3=I2C1 +Mcu.IP4=NVIC +Mcu.IP5=RCC +Mcu.IP6=SDIO +Mcu.IP7=SYS +Mcu.IP8=TIM2 +Mcu.IP9=TIM7 +Mcu.IPNb=17 +Mcu.Name=STM32F407Z(E-G)Tx +Mcu.Package=LQFP144 +Mcu.Pin0=PE4 +Mcu.Pin1=PE5 +Mcu.Pin10=PA4 +Mcu.Pin11=PA6 +Mcu.Pin12=PA7 +Mcu.Pin13=PB2 +Mcu.Pin14=PE12 +Mcu.Pin15=PE13 +Mcu.Pin16=PE14 +Mcu.Pin17=PE15 +Mcu.Pin18=PB10 +Mcu.Pin19=PB11 +Mcu.Pin2=PE6 +Mcu.Pin20=PB14 +Mcu.Pin21=PB15 +Mcu.Pin22=PG4 +Mcu.Pin23=PG5 +Mcu.Pin24=PC6 +Mcu.Pin25=PC7 +Mcu.Pin26=PC8 +Mcu.Pin27=PC9 +Mcu.Pin28=PA9 +Mcu.Pin29=PA10 +Mcu.Pin3=PF0 +Mcu.Pin30=PA13 +Mcu.Pin31=PA14 +Mcu.Pin32=PA15 +Mcu.Pin33=PC10 +Mcu.Pin34=PC11 +Mcu.Pin35=PC12 +Mcu.Pin36=PD2 +Mcu.Pin37=PB4 +Mcu.Pin38=PB5 +Mcu.Pin39=PB6 +Mcu.Pin4=PH0-OSC_IN +Mcu.Pin40=PB7 +Mcu.Pin41=PE0 +Mcu.Pin42=PE1 +Mcu.Pin43=VP_FATFS_VS_SDIO +Mcu.Pin44=VP_FREERTOS_VS_CMSIS_V2 +Mcu.Pin45=VP_SYS_VS_tim6 +Mcu.Pin46=VP_TIM2_VS_ClockSourceINT +Mcu.Pin47=VP_TIM7_VS_ClockSourceINT +Mcu.Pin48=VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS +Mcu.Pin5=PH1-OSC_OUT +Mcu.Pin6=PA0-WKUP +Mcu.Pin7=PA1 +Mcu.Pin8=PA2 +Mcu.Pin9=PA3 +Mcu.PinsNb=49 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32F407ZETx +MxCube.Version=6.8.1 +MxDb.Version=DB.6.0.81 +NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.DMA1_Stream1_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DMA1_Stream3_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DMA1_Stream5_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DMA1_Stream6_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DMA2_Stream2_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DMA2_Stream3_IRQn=true\:10\:0\:true\:false\:true\:true\:false\:true\:true +NVIC.DMA2_Stream6_IRQn=true\:10\:0\:true\:false\:true\:true\:false\:true\:true +NVIC.DMA2_Stream7_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true +NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.OTG_HS_IRQn=true\:11\:0\:true\:false\:true\:true\:false\:true\:true +NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.SDIO_IRQn=true\:9\:0\:true\:false\:true\:true\:true\:true\:true +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false +NVIC.SavedPendsvIrqHandlerGenerated=true +NVIC.SavedSvcallIrqHandlerGenerated=true +NVIC.SavedSystickIrqHandlerGenerated=true +NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false +NVIC.TIM2_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true +NVIC.TIM7_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 +NVIC.UART4_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.USART1_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.USART2_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.USART3_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true +NVIC.USART6_IRQn=true\:7\:0\:true\:false\:false\:true\:true\:true\:true +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +PA0-WKUP.Mode=Asynchronous +PA0-WKUP.Signal=UART4_TX +PA1.Mode=Asynchronous +PA1.Signal=UART4_RX +PA10.Mode=Asynchronous +PA10.Signal=USART1_RX +PA13.Mode=Serial_Wire +PA13.Signal=SYS_JTMS-SWDIO +PA14.Mode=Serial_Wire +PA14.Signal=SYS_JTCK-SWCLK +PA15.GPIOParameters=GPIO_Label +PA15.GPIO_Label=CDZ +PA15.Locked=true +PA15.Signal=GPIO_Input +PA2.Locked=true +PA2.Mode=Asynchronous +PA2.Signal=USART2_TX +PA3.Locked=true +PA3.Mode=Asynchronous +PA3.Signal=USART2_RX +PA4.GPIOParameters=GPIO_Label +PA4.GPIO_Label=MAX3242_EN +PA4.Locked=true +PA4.Signal=GPIO_Output +PA6.GPIOParameters=GPIO_Label +PA6.GPIO_Label=SENSOR2_EN +PA6.Locked=true +PA6.Signal=GPIO_Output +PA7.GPIOParameters=GPIO_Label +PA7.GPIO_Label=SENSOR4_EN +PA7.Locked=true +PA7.Signal=GPIO_Output +PA9.Mode=Asynchronous +PA9.Signal=USART1_TX +PB10.Locked=true +PB10.Mode=Asynchronous +PB10.Signal=USART3_TX +PB11.Locked=true +PB11.Mode=Asynchronous +PB11.Signal=USART3_RX +PB14.Mode=Device_Only_FS +PB14.Signal=USB_OTG_HS_DM +PB15.Mode=Device_Only_FS +PB15.Signal=USB_OTG_HS_DP +PB2.GPIOParameters=GPIO_Label +PB2.GPIO_Label=BOOT1 +PB2.Locked=true +PB2.Signal=GPIO_Input +PB4.GPIOParameters=GPIO_Label +PB4.GPIO_Label=ADDR +PB4.Locked=true +PB4.Signal=GPIO_Output +PB5.GPIOParameters=GPIO_Label +PB5.GPIO_Label=RDY +PB5.Locked=true +PB5.Signal=GPIO_Output +PB6.GPIOParameters=GPIO_Pu +PB6.GPIO_Pu=GPIO_PULLUP +PB6.Mode=I2C +PB6.Signal=I2C1_SCL +PB7.GPIOParameters=GPIO_Pu +PB7.GPIO_Pu=GPIO_PULLUP +PB7.Mode=I2C +PB7.Signal=I2C1_SDA +PC10.Mode=SD_4_bits_Wide_bus +PC10.Signal=SDIO_D2 +PC11.Mode=SD_4_bits_Wide_bus +PC11.Signal=SDIO_D3 +PC12.Mode=SD_4_bits_Wide_bus +PC12.Signal=SDIO_CK +PC6.Locked=true +PC6.Mode=Asynchronous +PC6.Signal=USART6_TX +PC7.Locked=true +PC7.Mode=Asynchronous +PC7.Signal=USART6_RX +PC8.Mode=SD_4_bits_Wide_bus +PC8.Signal=SDIO_D0 +PC9.Mode=SD_4_bits_Wide_bus +PC9.Signal=SDIO_D1 +PD2.Mode=SD_4_bits_Wide_bus +PD2.Signal=SDIO_CMD +PE0.GPIOParameters=GPIO_Label +PE0.GPIO_Label=LED0 +PE0.Locked=true +PE0.Signal=GPIO_Output +PE1.GPIOParameters=GPIO_Label +PE1.GPIO_Label=LED1 +PE1.Locked=true +PE1.Signal=GPIO_Output +PE12.GPIOParameters=GPIO_Label +PE12.GPIO_Label=SENSOR3_EN +PE12.Locked=true +PE12.Signal=GPIO_Output +PE13.GPIOParameters=GPIO_Label +PE13.GPIO_Label=DE485 +PE13.Locked=true +PE13.Signal=GPIO_Output +PE14.GPIOParameters=GPIO_Label +PE14.GPIO_Label=HDPLX +PE14.Locked=true +PE14.Signal=GPIO_Output +PE15.GPIOParameters=GPIO_Label +PE15.GPIO_Label=SEL_232/485 +PE15.Locked=true +PE15.Signal=GPIO_Output +PE4.GPIOParameters=GPIO_Label +PE4.GPIO_Label=EN_1302 +PE4.Locked=true +PE4.Signal=GPIO_Output +PE5.GPIOParameters=GPIO_Label,GPIO_ModeDefaultOutputPP +PE5.GPIO_Label=DA_1302 +PE5.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD +PE5.Locked=true +PE5.Signal=GPIO_Output +PE6.GPIOParameters=GPIO_Label +PE6.GPIO_Label=SCLK_1302 +PE6.Locked=true +PE6.Signal=GPIO_Output +PF0.GPIOParameters=GPIO_Label +PF0.GPIO_Label=PUMP_EN +PF0.Locked=true +PF0.Signal=GPIO_Output +PG4.GPIOParameters=GPIO_Label +PG4.GPIO_Label=SENSOR6_EN +PG4.Locked=true +PG4.Signal=GPIO_Output +PG5.GPIOParameters=GPIO_Label +PG5.GPIO_Label=R/W +PG5.Locked=true +PG5.Signal=GPIO_Output +PH0-OSC_IN.Mode=HSE-External-Oscillator +PH0-OSC_IN.Signal=RCC_OSC_IN +PH1-OSC_OUT.Mode=HSE-External-Oscillator +PH1-OSC_OUT.Signal=RCC_OSC_OUT +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32F407ZETx +ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.27.1 +ProjectManager.FreePins=false +ProjectManager.HalAssertFull=false +ProjectManager.HeapSize=0x1000 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=0 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain= +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=H2S.ioc +ProjectManager.ProjectName=H2S +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x1500 +ProjectManager.TargetToolchain=Makefile +ProjectManager.ToolChainLocation= +ProjectManager.UnderRoot=false +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_SDIO_SD_Init-SDIO-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_USART2_UART_Init-USART2-false-HAL-true,9-MX_USART3_UART_Init-USART3-false-HAL-true,10-MX_USART6_UART_Init-USART6-false-HAL-true,11-MX_TIM7_Init-TIM7-false-HAL-true,12-MX_FATFS_Init-FATFS-false-HAL-false,13-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,14-MX_TIM2_Init-TIM2-false-HAL-true +RCC.48MHZClocksFreq_Value=48000000 +RCC.AHBFreq_Value=168000000 +RCC.APB1CLKDivider=RCC_HCLK_DIV4 +RCC.APB1Freq_Value=42000000 +RCC.APB1TimFreq_Value=84000000 +RCC.APB2CLKDivider=RCC_HCLK_DIV2 +RCC.APB2Freq_Value=84000000 +RCC.APB2TimFreq_Value=168000000 +RCC.CortexFreq_Value=168000000 +RCC.EthernetFreq_Value=168000000 +RCC.FCLKCortexFreq_Value=168000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=168000000 +RCC.HSE_VALUE=8000000 +RCC.HSI_VALUE=16000000 +RCC.I2SClocksFreq_Value=192000000 +RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S +RCC.LSE_VALUE=32768 +RCC.LSI_VALUE=32000 +RCC.MCO2PinFreq_Value=168000000 +RCC.PLLCLKFreq_Value=168000000 +RCC.PLLM=4 +RCC.PLLN=168 +RCC.PLLQ=7 +RCC.PLLQCLKFreq_Value=48000000 +RCC.RTCFreq_Value=32000 +RCC.RTCHSEDivFreq_Value=4000000 +RCC.SYSCLKFreq_VALUE=168000000 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.VCOI2SOutputFreq_Value=384000000 +RCC.VCOInputFreq_Value=2000000 +RCC.VCOOutputFreq_Value=336000000 +RCC.VcooutputI2S=192000000 +SDIO.ClockDiv=6 +SDIO.IPParameters=ClockDiv +TIM2.IPParameters=Prescaler,Period +TIM2.Period=10000-1 +TIM2.Prescaler=8400-1 +TIM7.IPParameters=Prescaler,Period +TIM7.Period=50-1 +TIM7.Prescaler=8400-1 +UART4.IPParameters=VirtualMode +UART4.VirtualMode=Asynchronous +USART1.IPParameters=VirtualMode +USART1.VirtualMode=VM_ASYNC +USART2.IPParameters=VirtualMode +USART2.VirtualMode=VM_ASYNC +USART3.BaudRate=9600 +USART3.IPParameters=VirtualMode,BaudRate +USART3.VirtualMode=VM_ASYNC +USART6.BaudRate=19200 +USART6.IPParameters=VirtualMode,BaudRate +USART6.VirtualMode=VM_ASYNC +USB_DEVICE.CLASS_NAME_HS=MSC +USB_DEVICE.IPParameters=VirtualMode-MSC_HS,VirtualModeHS,CLASS_NAME_HS,MSC_MEDIA_PACKET-MSC_HS +USB_DEVICE.MSC_MEDIA_PACKET-MSC_HS=4096 +USB_DEVICE.VirtualMode-MSC_HS=Msc +USB_DEVICE.VirtualModeHS=Msc_HS +USB_OTG_HS.IPParameters=VirtualMode-Device_Only_FS +USB_OTG_HS.VirtualMode-Device_Only_FS=Device_Only_FS +VP_FATFS_VS_SDIO.Mode=SDIO +VP_FATFS_VS_SDIO.Signal=FATFS_VS_SDIO +VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2 +VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2 +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 +VP_TIM2_VS_ClockSourceINT.Mode=Internal +VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT +VP_TIM7_VS_ClockSourceINT.Mode=Enable_Timer +VP_TIM7_VS_ClockSourceINT.Signal=TIM7_VS_ClockSourceINT +VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS.Mode=MSC_HS +VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS.Signal=USB_DEVICE_VS_USB_DEVICE_MSC_HS +board=custom +rtos.0.ip=FREERTOS diff --git a/Makefile b/Makefile index 033895e..cff9251 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Fri Sep 01 12:25:19 CST 2023] +# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Tue Sep 19 20:39:52 CST 2023] ########################################################################################################################## # ------------------------------------------------ @@ -51,10 +51,6 @@ FATFS/Target/bsp_driver_sd.c \ FATFS/Target/sd_diskio.c \ FATFS/Target/fatfs_platform.c \ FATFS/App/fatfs.c \ -USB_DEVICE/App/usb_device.c \ -USB_DEVICE/App/usbd_desc.c \ -USB_DEVICE/App/usbd_storage_if.c \ -USB_DEVICE/Target/usbd_conf.c \ Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c \ Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c \ Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \ @@ -94,13 +90,7 @@ Middlewares/Third_Party/FreeRTOS/Source/timers.c \ Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ -Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \ -Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \ -Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ -Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c \ -Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c \ -Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c \ -Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c +Core/Src/usb_otg.c # ASM sources ASM_SOURCES = \ @@ -161,16 +151,12 @@ C_INCLUDES = \ -ICore/Inc \ -IFATFS/Target \ -IFATFS/App \ --IUSB_DEVICE/App \ --IUSB_DEVICE/Target \ -IDrivers/STM32F4xx_HAL_Driver/Inc \ -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ -IMiddlewares/Third_Party/FreeRTOS/Source/include \ -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \ -IMiddlewares/Third_Party/FatFs/src \ --IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \ --IMiddlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc \ -IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ -IDrivers/CMSIS/Include @@ -193,7 +179,7 @@ CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" # LDFLAGS ####################################### # link script -LDSCRIPT = STM32F407ZETx_FLASH.ld +LDSCRIPT = STM32F407ZGTx_FLASH.ld # libraries LIBS = -lc -lm -lnosys diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h deleted file mode 100644 index e55fef4..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h +++ /dev/null @@ -1,130 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc.h - * @author MCD Application Team - * @brief Header for the usbd_msc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_MSC_H -#define __USBD_MSC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_msc_bot.h" -#include "usbd_msc_scsi.h" -#include "usbd_ioreq.h" - -/** @addtogroup USBD_MSC_BOT - * @{ - */ - -/** @defgroup USBD_MSC - * @brief This file is the Header file for usbd_msc.c - * @{ - */ - - -/** @defgroup USBD_BOT_Exported_Defines - * @{ - */ -/* MSC Class Config */ -#ifndef MSC_MEDIA_PACKET -#define MSC_MEDIA_PACKET 512U -#endif /* MSC_MEDIA_PACKET */ - -#define MSC_MAX_FS_PACKET 0x40U -#define MSC_MAX_HS_PACKET 0x200U - -#define BOT_GET_MAX_LUN 0xFE -#define BOT_RESET 0xFF -#define USB_MSC_CONFIG_DESC_SIZ 32 - -#ifndef MSC_EPIN_ADDR -#define MSC_EPIN_ADDR 0x81U -#endif /* MSC_EPIN_ADDR */ - -#ifndef MSC_EPOUT_ADDR -#define MSC_EPOUT_ADDR 0x01U -#endif /* MSC_EPOUT_ADDR */ - -/** - * @} - */ - -/** @defgroup USB_CORE_Exported_Types - * @{ - */ -typedef struct _USBD_STORAGE -{ - int8_t (* Init)(uint8_t lun); - int8_t (* GetCapacity)(uint8_t lun, uint32_t *block_num, uint16_t *block_size); - int8_t (* IsReady)(uint8_t lun); - int8_t (* IsWriteProtected)(uint8_t lun); - int8_t (* Read)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); - int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); - int8_t (* GetMaxLun)(void); - int8_t *pInquiry; - -} USBD_StorageTypeDef; - - -typedef struct -{ - uint32_t max_lun; - uint32_t interface; - uint8_t bot_state; - uint8_t bot_status; - uint32_t bot_data_length; - uint8_t bot_data[MSC_MEDIA_PACKET]; - USBD_MSC_BOT_CBWTypeDef cbw; - USBD_MSC_BOT_CSWTypeDef csw; - - USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH]; - uint8_t scsi_sense_head; - uint8_t scsi_sense_tail; - uint8_t scsi_medium_state; - - uint16_t scsi_blk_size; - uint32_t scsi_blk_nbr; - - uint32_t scsi_blk_addr; - uint32_t scsi_blk_len; -} USBD_MSC_BOT_HandleTypeDef; - -/* Structure for MSC process */ -extern USBD_ClassTypeDef USBD_MSC; -#define USBD_MSC_CLASS &USBD_MSC - -uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, - USBD_StorageTypeDef *fops); -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_MSC_H */ -/** - * @} - */ diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h deleted file mode 100644 index 8550a39..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h +++ /dev/null @@ -1,146 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc_bot.h - * @author MCD Application Team - * @brief Header for the usbd_msc_bot.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_MSC_BOT_H -#define __USBD_MSC_BOT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup MSC_BOT - * @brief This file is the Header file for usbd_msc_bot.c - * @{ - */ - - -/** @defgroup USBD_CORE_Exported_Defines - * @{ - */ -#define USBD_BOT_IDLE 0U /* Idle state */ -#define USBD_BOT_DATA_OUT 1U /* Data Out state */ -#define USBD_BOT_DATA_IN 2U /* Data In state */ -#define USBD_BOT_LAST_DATA_IN 3U /* Last Data In Last */ -#define USBD_BOT_SEND_DATA 4U /* Send Immediate data */ -#define USBD_BOT_NO_DATA 5U /* No data Stage */ - -#define USBD_BOT_CBW_SIGNATURE 0x43425355U -#define USBD_BOT_CSW_SIGNATURE 0x53425355U -#define USBD_BOT_CBW_LENGTH 31U -#define USBD_BOT_CSW_LENGTH 13U -#define USBD_BOT_MAX_DATA 256U - -/* CSW Status Definitions */ -#define USBD_CSW_CMD_PASSED 0x00U -#define USBD_CSW_CMD_FAILED 0x01U -#define USBD_CSW_PHASE_ERROR 0x02U - -/* BOT Status */ -#define USBD_BOT_STATUS_NORMAL 0U -#define USBD_BOT_STATUS_RECOVERY 1U -#define USBD_BOT_STATUS_ERROR 2U - - -#define USBD_DIR_IN 0U -#define USBD_DIR_OUT 1U -#define USBD_BOTH_DIR 2U - -/** - * @} - */ - -/** @defgroup MSC_CORE_Private_TypesDefinitions - * @{ - */ - -typedef struct -{ - uint32_t dSignature; - uint32_t dTag; - uint32_t dDataLength; - uint8_t bmFlags; - uint8_t bLUN; - uint8_t bCBLength; - uint8_t CB[16]; - uint8_t ReservedForAlign; -} USBD_MSC_BOT_CBWTypeDef; - - -typedef struct -{ - uint32_t dSignature; - uint32_t dTag; - uint32_t dDataResidue; - uint8_t bStatus; - uint8_t ReservedForAlign[3]; -} USBD_MSC_BOT_CSWTypeDef; - -/** - * @} - */ - - -/** @defgroup USBD_CORE_Exported_Types - * @{ - */ - -/** - * @} - */ -/** @defgroup USBD_CORE_Exported_FunctionsPrototypes - * @{ - */ -void MSC_BOT_Init(USBD_HandleTypeDef *pdev); -void MSC_BOT_Reset(USBD_HandleTypeDef *pdev); -void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev); -void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, - uint8_t epnum); - -void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, - uint8_t epnum); - -void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, - uint8_t CSW_Status); - -void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, - uint8_t epnum); -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_MSC_BOT_H */ -/** - * @} - */ - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h deleted file mode 100644 index f946b95..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc_data.h - * @author MCD Application Team - * @brief Header for the usbd_msc_data.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_MSC_DATA_H -#define __USBD_MSC_DATA_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_conf.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USB_INFO - * @brief general defines for the usb device library file - * @{ - */ - -/** @defgroup USB_INFO_Exported_Defines - * @{ - */ -#define MODE_SENSE6_LEN 0x17U -#define MODE_SENSE10_LEN 0x1BU -#define LENGTH_INQUIRY_PAGE00 0x06U -#define LENGTH_INQUIRY_PAGE80 0x08U -#define LENGTH_FORMAT_CAPACITIES 0x14U - -/** - * @} - */ - - -/** @defgroup USBD_INFO_Exported_TypesDefinitions - * @{ - */ -/** - * @} - */ - - - -/** @defgroup USBD_INFO_Exported_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_INFO_Exported_Variables - * @{ - */ -extern uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00]; -extern uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80]; -extern uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN]; -extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN]; - -/** - * @} - */ - -/** @defgroup USBD_INFO_Exported_FunctionsPrototype - * @{ - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_MSC_DATA_H */ - -/** - * @} - */ - -/** - * @} - */ diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h deleted file mode 100644 index 0d0bbc5..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h +++ /dev/null @@ -1,182 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc_scsi.h - * @author MCD Application Team - * @brief Header for the usbd_msc_scsi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_MSC_SCSI_H -#define __USBD_MSC_SCSI_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_SCSI - * @brief header file for the storage disk file - * @{ - */ - -/** @defgroup USBD_SCSI_Exported_Defines - * @{ - */ - -#define SENSE_LIST_DEEPTH 4U - -/* SCSI Commands */ -#define SCSI_FORMAT_UNIT 0x04U -#define SCSI_INQUIRY 0x12U -#define SCSI_MODE_SELECT6 0x15U -#define SCSI_MODE_SELECT10 0x55U -#define SCSI_MODE_SENSE6 0x1AU -#define SCSI_MODE_SENSE10 0x5AU -#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1EU -#define SCSI_READ6 0x08U -#define SCSI_READ10 0x28U -#define SCSI_READ12 0xA8U -#define SCSI_READ16 0x88U - -#define SCSI_READ_CAPACITY10 0x25U -#define SCSI_READ_CAPACITY16 0x9EU - -#define SCSI_REQUEST_SENSE 0x03U -#define SCSI_START_STOP_UNIT 0x1BU -#define SCSI_TEST_UNIT_READY 0x00U -#define SCSI_WRITE6 0x0AU -#define SCSI_WRITE10 0x2AU -#define SCSI_WRITE12 0xAAU -#define SCSI_WRITE16 0x8AU - -#define SCSI_VERIFY10 0x2FU -#define SCSI_VERIFY12 0xAFU -#define SCSI_VERIFY16 0x8FU - -#define SCSI_SEND_DIAGNOSTIC 0x1DU -#define SCSI_READ_FORMAT_CAPACITIES 0x23U - -#define NO_SENSE 0U -#define RECOVERED_ERROR 1U -#define NOT_READY 2U -#define MEDIUM_ERROR 3U -#define HARDWARE_ERROR 4U -#define ILLEGAL_REQUEST 5U -#define UNIT_ATTENTION 6U -#define DATA_PROTECT 7U -#define BLANK_CHECK 8U -#define VENDOR_SPECIFIC 9U -#define COPY_ABORTED 10U -#define ABORTED_COMMAND 11U -#define VOLUME_OVERFLOW 13U -#define MISCOMPARE 14U - - -#define INVALID_CDB 0x20U -#define INVALID_FIELED_IN_COMMAND 0x24U -#define PARAMETER_LIST_LENGTH_ERROR 0x1AU -#define INVALID_FIELD_IN_PARAMETER_LIST 0x26U -#define ADDRESS_OUT_OF_RANGE 0x21U -#define MEDIUM_NOT_PRESENT 0x3AU -#define MEDIUM_HAVE_CHANGED 0x28U -#define WRITE_PROTECTED 0x27U -#define UNRECOVERED_READ_ERROR 0x11U -#define WRITE_FAULT 0x03U - -#define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU -#define READ_CAPACITY10_DATA_LEN 0x08U -#define REQUEST_SENSE_DATA_LEN 0x12U -#define STANDARD_INQUIRY_DATA_LEN 0x24U -#define BLKVFY 0x04U - -#define SCSI_MEDIUM_UNLOCKED 0x00U -#define SCSI_MEDIUM_LOCKED 0x01U -#define SCSI_MEDIUM_EJECTED 0x02U -/** - * @} - */ - - -/** @defgroup USBD_SCSI_Exported_TypesDefinitions - * @{ - */ - -typedef struct _SENSE_ITEM -{ - uint8_t Skey; - union - { - struct _ASCs - { - uint8_t ASC; - uint8_t ASCQ; - } b; - uint8_t ASC; - uint8_t *pData; - } w; -} USBD_SCSI_SenseTypeDef; -/** - * @} - */ - -/** @defgroup USBD_SCSI_Exported_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_SCSI_Exported_Variables - * @{ - */ - -/** - * @} - */ -/** @defgroup USBD_SCSI_Exported_FunctionsPrototype - * @{ - */ -int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd); - -void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, - uint8_t ASC); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_MSC_SCSI_H */ -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c deleted file mode 100644 index ad5daeb..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c +++ /dev/null @@ -1,579 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc.c - * @author MCD Application Team - * @brief This file provides all the MSC core functions. - * - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - * @verbatim - * - * =================================================================== - * MSC Class Description - * =================================================================== - * This module manages the MSC class V1.0 following the "Universal - * Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0 - * Sep. 31, 1999". - * This driver implements the following aspects of the specification: - * - Bulk-Only Transport protocol - * - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3)) - * - * @endverbatim - * - ****************************************************************************** - */ - -/* BSPDependencies -- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" -- "stm32xxxxx_{eval}{discovery}_io.c" -- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" -EndBSPDependencies */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_msc.h" - - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup MSC_CORE - * @brief Mass storage core module - * @{ - */ - -/** @defgroup MSC_CORE_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_CORE_Private_Defines - * @{ - */ - -/** - * @} - */ - - -/** @defgroup MSC_CORE_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_CORE_Private_FunctionPrototypes - * @{ - */ -uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx); -uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx); -uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); -uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); - -#ifndef USE_USBD_COMPOSITE -uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length); -uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length); -uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length); -uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length); -#endif /* USE_USBD_COMPOSITE */ -/** - * @} - */ - - -/** @defgroup MSC_CORE_Private_Variables - * @{ - */ - - -USBD_ClassTypeDef USBD_MSC = -{ - USBD_MSC_Init, - USBD_MSC_DeInit, - USBD_MSC_Setup, - NULL, /*EP0_TxSent*/ - NULL, /*EP0_RxReady*/ - USBD_MSC_DataIn, - USBD_MSC_DataOut, - NULL, /*SOF */ - NULL, - NULL, -#ifdef USE_USBD_COMPOSITE - NULL, - NULL, - NULL, - NULL, -#else - USBD_MSC_GetHSCfgDesc, - USBD_MSC_GetFSCfgDesc, - USBD_MSC_GetOtherSpeedCfgDesc, - USBD_MSC_GetDeviceQualifierDescriptor, -#endif /* USE_USBD_COMPOSITE */ -}; - -/* USB Mass storage device Configuration Descriptor */ -#ifndef USE_USBD_COMPOSITE -/* USB Mass storage device Configuration Descriptor */ -/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ -__ALIGN_BEGIN static uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = -{ - 0x09, /* bLength: Configuration Descriptor size */ - USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ - USB_MSC_CONFIG_DESC_SIZ, - - 0x00, - 0x01, /* bNumInterfaces: 1 interface */ - 0x01, /* bConfigurationValue */ - 0x04, /* iConfiguration */ -#if (USBD_SELF_POWERED == 1U) - 0xC0, /* bmAttributes: Bus Powered according to user configuration */ -#else - 0x80, /* bmAttributes: Bus Powered according to user configuration */ -#endif /* USBD_SELF_POWERED */ - USBD_MAX_POWER, /* MaxPower (mA) */ - - /******************** Mass Storage interface ********************/ - 0x09, /* bLength: Interface Descriptor size */ - 0x04, /* bDescriptorType: */ - 0x00, /* bInterfaceNumber: Number of Interface */ - 0x00, /* bAlternateSetting: Alternate setting */ - 0x02, /* bNumEndpoints */ - 0x08, /* bInterfaceClass: MSC Class */ - 0x06, /* bInterfaceSubClass : SCSI transparent*/ - 0x50, /* nInterfaceProtocol */ - 0x05, /* iInterface: */ - /******************** Mass Storage Endpoints ********************/ - 0x07, /* Endpoint descriptor length = 7 */ - 0x05, /* Endpoint descriptor type */ - MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */ - 0x02, /* Bulk endpoint type */ - LOBYTE(MSC_MAX_FS_PACKET), - HIBYTE(MSC_MAX_FS_PACKET), - 0x00, /* Polling interval in milliseconds */ - - 0x07, /* Endpoint descriptor length = 7 */ - 0x05, /* Endpoint descriptor type */ - MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */ - 0x02, /* Bulk endpoint type */ - LOBYTE(MSC_MAX_FS_PACKET), - HIBYTE(MSC_MAX_FS_PACKET), - 0x00 /* Polling interval in milliseconds */ -}; - -/* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ - USB_LEN_DEV_QUALIFIER_DESC, - USB_DESC_TYPE_DEVICE_QUALIFIER, - 0x00, - 0x02, - 0x00, - 0x00, - 0x00, - MSC_MAX_FS_PACKET, - 0x01, - 0x00, -}; -#endif /* USE_USBD_COMPOSITE */ - -uint8_t MSCInEpAdd = MSC_EPIN_ADDR; -uint8_t MSCOutEpAdd = MSC_EPOUT_ADDR; - -/** - * @} - */ - - -/** @defgroup MSC_CORE_Private_Functions - * @{ - */ - -/** - * @brief USBD_MSC_Init - * Initialize the mass storage configuration - * @param pdev: device instance - * @param cfgidx: configuration index - * @retval status - */ -uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - UNUSED(cfgidx); - USBD_MSC_BOT_HandleTypeDef *hmsc; - - hmsc = (USBD_MSC_BOT_HandleTypeDef *)USBD_malloc(sizeof(USBD_MSC_BOT_HandleTypeDef)); - - if (hmsc == NULL) - { - pdev->pClassDataCmsit[pdev->classId] = NULL; - return (uint8_t)USBD_EMEM; - } - - pdev->pClassDataCmsit[pdev->classId] = (void *)hmsc; - pdev->pClassData = pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Open EP OUT */ - (void)USBD_LL_OpenEP(pdev, MSCOutEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET); - pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 1U; - - /* Open EP IN */ - (void)USBD_LL_OpenEP(pdev, MSCInEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET); - pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 1U; - } - else - { - /* Open EP OUT */ - (void)USBD_LL_OpenEP(pdev, MSCOutEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET); - pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 1U; - - /* Open EP IN */ - (void)USBD_LL_OpenEP(pdev, MSCInEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET); - pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 1U; - } - - /* Init the BOT layer */ - MSC_BOT_Init(pdev); - - return (uint8_t)USBD_OK; -} - -/** - * @brief USBD_MSC_DeInit - * DeInitialize the mass storage configuration - * @param pdev: device instance - * @param cfgidx: configuration index - * @retval status - */ -uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - UNUSED(cfgidx); - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - /* Close MSC EPs */ - (void)USBD_LL_CloseEP(pdev, MSCOutEpAdd); - pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 0U; - - /* Close EP IN */ - (void)USBD_LL_CloseEP(pdev, MSCInEpAdd); - pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 0U; - - /* Free MSC Class Resources */ - if (pdev->pClassDataCmsit[pdev->classId] != NULL) - { - /* De-Init the BOT layer */ - MSC_BOT_DeInit(pdev); - - (void)USBD_free(pdev->pClassDataCmsit[pdev->classId]); - pdev->pClassDataCmsit[pdev->classId] = NULL; - pdev->pClassData = NULL; - } - - return (uint8_t)USBD_OK; -} -/** - * @brief USBD_MSC_Setup - * Handle the MSC specific requests - * @param pdev: device instance - * @param req: USB request - * @retval status - */ -uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - USBD_StatusTypeDef ret = USBD_OK; - uint16_t status_info = 0U; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return (uint8_t)USBD_FAIL; - } - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - /* Class request */ - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case BOT_GET_MAX_LUN: - if ((req->wValue == 0U) && (req->wLength == 1U) && - ((req->bmRequest & 0x80U) == 0x80U)) - { - hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetMaxLun(); - (void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case BOT_RESET : - if ((req->wValue == 0U) && (req->wLength == 0U) && - ((req->bmRequest & 0x80U) != 0x80U)) - { - MSC_BOT_Reset(pdev); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - default: - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - break; - } - break; - /* Interface & Endpoint request */ - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->interface, 1U); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hmsc->interface = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_CLEAR_FEATURE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (req->wValue == USB_FEATURE_EP_HALT) - { - /* Flush the FIFO */ - (void)USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex); - - /* Handle BOT error */ - MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); - } - } - 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_MSC_DataIn - * handle data IN Stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - MSC_BOT_DataIn(pdev, epnum); - - return (uint8_t)USBD_OK; -} - -/** - * @brief USBD_MSC_DataOut - * handle data OUT Stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - MSC_BOT_DataOut(pdev, epnum); - - return (uint8_t)USBD_OK; -} -#ifndef USE_USBD_COMPOSITE -/** - * @brief USBD_MSC_GetHSCfgDesc - * return configuration descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length) -{ - USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR); - USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR); - - if (pEpInDesc != NULL) - { - pEpInDesc->wMaxPacketSize = MSC_MAX_HS_PACKET; - } - - if (pEpOutDesc != NULL) - { - pEpOutDesc->wMaxPacketSize = MSC_MAX_HS_PACKET; - } - - *length = (uint16_t)sizeof(USBD_MSC_CfgDesc); - return USBD_MSC_CfgDesc; -} - -/** - * @brief USBD_MSC_GetFSCfgDesc - * return configuration descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length) -{ - USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR); - USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR); - - if (pEpInDesc != NULL) - { - pEpInDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; - } - - if (pEpOutDesc != NULL) - { - pEpOutDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; - } - - *length = (uint16_t)sizeof(USBD_MSC_CfgDesc); - return USBD_MSC_CfgDesc; -} - -/** - * @brief USBD_MSC_GetOtherSpeedCfgDesc - * return other speed configuration descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length) -{ - USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR); - USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR); - - if (pEpInDesc != NULL) - { - pEpInDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; - } - - if (pEpOutDesc != NULL) - { - pEpOutDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; - } - - *length = (uint16_t)sizeof(USBD_MSC_CfgDesc); - return USBD_MSC_CfgDesc; -} -/** - * @brief DeviceQualifierDescriptor - * return Device Qualifier descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length) -{ - *length = (uint16_t)sizeof(USBD_MSC_DeviceQualifierDesc); - - return USBD_MSC_DeviceQualifierDesc; -} -#endif /* USE_USBD_COMPOSITE */ -/** - * @brief USBD_MSC_RegisterStorage - * @param fops: storage callback - * @retval status - */ -uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops) -{ - if (fops == NULL) - { - return (uint8_t)USBD_FAIL; - } - - pdev->pUserData[pdev->classId] = fops; - - return (uint8_t)USBD_OK; -} - -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c deleted file mode 100644 index 0816de9..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c +++ /dev/null @@ -1,478 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc_bot.c - * @author MCD Application Team - * @brief This file provides all the BOT protocol core functions. - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* BSPDependencies -- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" -- "stm32xxxxx_{eval}{discovery}_io.c" -- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" -EndBSPDependencies */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_msc_bot.h" -#include "usbd_msc.h" -#include "usbd_msc_scsi.h" -#include "usbd_ioreq.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup MSC_BOT - * @brief BOT protocol module - * @{ - */ - -/** @defgroup MSC_BOT_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_BOT_Private_Defines - * @{ - */ - -/** - * @} - */ - - -/** @defgroup MSC_BOT_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_BOT_Private_Variables - * @{ - */ -extern uint8_t MSCInEpAdd; -extern uint8_t MSCOutEpAdd; -/** - * @} - */ - - -/** @defgroup MSC_BOT_Private_FunctionPrototypes - * @{ - */ -static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); -static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev); -static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); -/** - * @} - */ - - -/** @defgroup MSC_BOT_Private_Functions - * @{ - */ - - -/** - * @brief MSC_BOT_Init - * Initialize the BOT Process - * @param pdev: device instance - * @retval None - */ -void MSC_BOT_Init(USBD_HandleTypeDef *pdev) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - hmsc->bot_state = USBD_BOT_IDLE; - hmsc->bot_status = USBD_BOT_STATUS_NORMAL; - - hmsc->scsi_sense_tail = 0U; - hmsc->scsi_sense_head = 0U; - hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; - - ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Init(0U); - - (void)USBD_LL_FlushEP(pdev, MSCOutEpAdd); - (void)USBD_LL_FlushEP(pdev, MSCInEpAdd); - - /* Prepare EP to Receive First BOT Cmd */ - (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); -} - -/** - * @brief MSC_BOT_Reset - * Reset the BOT Machine - * @param pdev: device instance - * @retval None - */ -void MSC_BOT_Reset(USBD_HandleTypeDef *pdev) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - hmsc->bot_state = USBD_BOT_IDLE; - hmsc->bot_status = USBD_BOT_STATUS_RECOVERY; - - (void)USBD_LL_ClearStallEP(pdev, MSCInEpAdd); - (void)USBD_LL_ClearStallEP(pdev, MSCOutEpAdd); - - /* Prepare EP to Receive First BOT Cmd */ - (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); -} - -/** - * @brief MSC_BOT_DeInit - * DeInitialize the BOT Machine - * @param pdev: device instance - * @retval None - */ -void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc != NULL) - { - hmsc->bot_state = USBD_BOT_IDLE; - } -} - -/** - * @brief MSC_BOT_DataIn - * Handle BOT IN data stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval None - */ -void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - UNUSED(epnum); - - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return; - } - - switch (hmsc->bot_state) - { - case USBD_BOT_DATA_IN: - if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); - } - break; - - case USBD_BOT_SEND_DATA: - case USBD_BOT_LAST_DATA_IN: - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); - break; - - default: - break; - } -} -/** - * @brief MSC_BOT_DataOut - * Process MSC OUT data - * @param pdev: device instance - * @param epnum: endpoint index - * @retval None - */ -void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - UNUSED(epnum); - - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return; - } - - switch (hmsc->bot_state) - { - case USBD_BOT_IDLE: - MSC_BOT_CBW_Decode(pdev); - break; - - case USBD_BOT_DATA_OUT: - if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); - } - break; - - default: - break; - } -} - -/** - * @brief MSC_BOT_CBW_Decode - * Decode the CBW command and set the BOT state machine accordingly - * @param pdev: device instance - * @retval None - */ -static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - hmsc->csw.dTag = hmsc->cbw.dTag; - hmsc->csw.dDataResidue = hmsc->cbw.dDataLength; - - if ((USBD_LL_GetRxDataSize(pdev, MSCOutEpAdd) != USBD_BOT_CBW_LENGTH) || - (hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) || - (hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) || - (hmsc->cbw.bCBLength > 16U)) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - - hmsc->bot_status = USBD_BOT_STATUS_ERROR; - MSC_BOT_Abort(pdev); - } - else - { - if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) - { - if (hmsc->bot_state == USBD_BOT_NO_DATA) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); - } - else - { - MSC_BOT_Abort(pdev); - } - } - /* Burst xfer handled internally */ - else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && - (hmsc->bot_state != USBD_BOT_DATA_OUT) && - (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) - { - if (hmsc->bot_data_length > 0U) - { - MSC_BOT_SendData(pdev, hmsc->bot_data, hmsc->bot_data_length); - } - else if (hmsc->bot_data_length == 0U) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); - } - else - { - MSC_BOT_Abort(pdev); - } - } - else - { - return; - } - } -} - -/** - * @brief MSC_BOT_SendData - * Send the requested data - * @param pdev: device instance - * @param buf: pointer to data buffer - * @param len: Data Length - * @retval None - */ -static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - uint32_t length; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - length = MIN(hmsc->cbw.dDataLength, len); - - hmsc->csw.dDataResidue -= len; - hmsc->csw.bStatus = USBD_CSW_CMD_PASSED; - hmsc->bot_state = USBD_BOT_SEND_DATA; - - (void)USBD_LL_Transmit(pdev, MSCInEpAdd, pbuf, length); -} - -/** - * @brief MSC_BOT_SendCSW - * Send the Command Status Wrapper - * @param pdev: device instance - * @param status : CSW status - * @retval None - */ -void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE; - hmsc->csw.bStatus = CSW_Status; - hmsc->bot_state = USBD_BOT_IDLE; - - (void)USBD_LL_Transmit(pdev, MSCInEpAdd, (uint8_t *)&hmsc->csw, - USBD_BOT_CSW_LENGTH); - - /* Prepare EP to Receive next Cmd */ - (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); -} - -/** - * @brief MSC_BOT_Abort - * Abort the current transfer - * @param pdev: device instance - * @retval status - */ - -static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - if ((hmsc->cbw.bmFlags == 0U) && - (hmsc->cbw.dDataLength != 0U) && - (hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) - { - (void)USBD_LL_StallEP(pdev, MSCOutEpAdd); - } - - (void)USBD_LL_StallEP(pdev, MSCInEpAdd); - - if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) - { - (void)USBD_LL_StallEP(pdev, MSCInEpAdd); - (void)USBD_LL_StallEP(pdev, MSCOutEpAdd); - } -} - -/** - * @brief MSC_BOT_CplClrFeature - * Complete the clear feature request - * @param pdev: device instance - * @param epnum: endpoint index - * @retval None - */ - -void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc == NULL) - { - return; - } - - if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */ - { - (void)USBD_LL_StallEP(pdev, MSCInEpAdd); - (void)USBD_LL_StallEP(pdev, MSCOutEpAdd); - } - else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); - } - else - { - return; - } -} -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c deleted file mode 100644 index fabd835..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c +++ /dev/null @@ -1,181 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc_data.c - * @author MCD Application Team - * @brief This file provides all the vital inquiry pages and sense data. - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* BSPDependencies -- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" -- "stm32xxxxx_{eval}{discovery}_io.c" -- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" -EndBSPDependencies */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_msc_data.h" - - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup MSC_DATA - * @brief Mass storage info/data module - * @{ - */ - -/** @defgroup MSC_DATA_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_DATA_Private_Defines - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_DATA_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_DATA_Private_Variables - * @{ - */ - -/* USB Mass storage Page 0 Inquiry Data */ -uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00] = -{ - 0x00, - 0x00, - 0x00, - (LENGTH_INQUIRY_PAGE00 - 4U), - 0x00, - 0x80 -}; - -/* USB Mass storage VPD Page 0x80 Inquiry Data for Unit Serial Number */ -uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80] = -{ - 0x00, - 0x80, - 0x00, - LENGTH_INQUIRY_PAGE80, - 0x20, /* Put Product Serial number */ - 0x20, - 0x20, - 0x20 -}; - -/* USB Mass storage sense 6 Data */ -uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] = -{ - 0x22, - 0x00, - 0x00, - 0x00, - 0x08, - 0x12, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 -}; - - -/* USB Mass storage sense 10 Data */ -uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] = -{ - 0x00, - 0x26, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x08, - 0x12, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 -}; -/** - * @} - */ - - -/** @defgroup MSC_DATA_Private_FunctionPrototypes - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_DATA_Private_Functions - * @{ - */ - -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c b/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c deleted file mode 100644 index af7a0d5..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c +++ /dev/null @@ -1,1203 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_msc_scsi.c - * @author MCD Application Team - * @brief This file provides all the USBD SCSI layer functions. - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* BSPDependencies -- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" -- "stm32xxxxx_{eval}{discovery}_io.c" -- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" -EndBSPDependencies */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_msc_bot.h" -#include "usbd_msc_scsi.h" -#include "usbd_msc.h" -#include "usbd_msc_data.h" - - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup MSC_SCSI - * @brief Mass storage SCSI layer module - * @{ - */ - -/** @defgroup MSC_SCSI_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_SCSI_Private_Defines - * @{ - */ - -/** - * @} - */ - - -/** @defgroup MSC_SCSI_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup MSC_SCSI_Private_Variables - * @{ - */ -extern uint8_t MSCInEpAdd; -extern uint8_t MSCOutEpAdd; -/** - * @} - */ - - -/** @defgroup MSC_SCSI_Private_FunctionPrototypes - * @{ - */ -static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, - uint32_t blk_offset, uint32_t blk_nbr); - -static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun); -static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun); - -static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, - uint8_t *pBuff, uint16_t length); -/** - * @} - */ - - -/** @defgroup MSC_SCSI_Private_Functions - * @{ - */ - - -/** - * @brief SCSI_ProcessCmd - * Process SCSI commands - * @param pdev: device instance - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) -{ - int8_t ret; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - switch (cmd[0]) - { - case SCSI_TEST_UNIT_READY: - ret = SCSI_TestUnitReady(pdev, lun, cmd); - break; - - case SCSI_REQUEST_SENSE: - ret = SCSI_RequestSense(pdev, lun, cmd); - break; - - case SCSI_INQUIRY: - ret = SCSI_Inquiry(pdev, lun, cmd); - break; - - case SCSI_START_STOP_UNIT: - ret = SCSI_StartStopUnit(pdev, lun, cmd); - break; - - case SCSI_ALLOW_MEDIUM_REMOVAL: - ret = SCSI_AllowPreventRemovable(pdev, lun, cmd); - break; - - case SCSI_MODE_SENSE6: - ret = SCSI_ModeSense6(pdev, lun, cmd); - break; - - case SCSI_MODE_SENSE10: - ret = SCSI_ModeSense10(pdev, lun, cmd); - break; - - case SCSI_READ_FORMAT_CAPACITIES: - ret = SCSI_ReadFormatCapacity(pdev, lun, cmd); - break; - - case SCSI_READ_CAPACITY10: - ret = SCSI_ReadCapacity10(pdev, lun, cmd); - break; - - case SCSI_READ_CAPACITY16: - ret = SCSI_ReadCapacity16(pdev, lun, cmd); - break; - - case SCSI_READ10: - ret = SCSI_Read10(pdev, lun, cmd); - break; - - case SCSI_READ12: - ret = SCSI_Read12(pdev, lun, cmd); - break; - - case SCSI_WRITE10: - ret = SCSI_Write10(pdev, lun, cmd); - break; - - case SCSI_WRITE12: - ret = SCSI_Write12(pdev, lun, cmd); - break; - - case SCSI_VERIFY10: - ret = SCSI_Verify10(pdev, lun, cmd); - break; - - default: - SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB); - hmsc->bot_status = USBD_BOT_STATUS_ERROR; - ret = -1; - break; - } - - return ret; -} - - -/** - * @brief SCSI_TestUnitReady - * Process SCSI Test Unit Ready Command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(params); - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - /* case 9 : Hi > D0 */ - if (hmsc->cbw.dDataLength != 0U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - - return -1; - } - - if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - hmsc->bot_state = USBD_BOT_NO_DATA; - return -1; - } - - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - hmsc->bot_state = USBD_BOT_NO_DATA; - - return -1; - } - hmsc->bot_data_length = 0U; - - return 0; -} - - -/** - * @brief SCSI_Inquiry - * Process Inquiry command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - uint8_t *pPage; - uint16_t len; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if (hmsc->cbw.dDataLength == 0U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - if ((params[1] & 0x01U) != 0U) /* Evpd is set */ - { - if (params[2] == 0U) /* Request for Supported Vital Product Data Pages*/ - { - (void)SCSI_UpdateBotData(hmsc, MSC_Page00_Inquiry_Data, LENGTH_INQUIRY_PAGE00); - } - else if (params[2] == 0x80U) /* Request for VPD page 0x80 Unit Serial Number */ - { - (void)SCSI_UpdateBotData(hmsc, MSC_Page80_Inquiry_Data, LENGTH_INQUIRY_PAGE80); - } - else /* Request Not supported */ - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, - INVALID_FIELED_IN_COMMAND); - - return -1; - } - } - else - { - - pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; - len = (uint16_t)pPage[4] + 5U; - - if (params[4] <= len) - { - len = params[4]; - } - - (void)SCSI_UpdateBotData(hmsc, pPage, len); - } - - return 0; -} - - -/** - * @brief SCSI_ReadCapacity10 - * Process Read Capacity 10 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(params); - int8_t ret; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size); - - if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - hmsc->bot_data[0] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24); - hmsc->bot_data[1] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16); - hmsc->bot_data[2] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8); - hmsc->bot_data[3] = (uint8_t)(hmsc->scsi_blk_nbr - 1U); - - hmsc->bot_data[4] = (uint8_t)(hmsc->scsi_blk_size >> 24); - hmsc->bot_data[5] = (uint8_t)(hmsc->scsi_blk_size >> 16); - hmsc->bot_data[6] = (uint8_t)(hmsc->scsi_blk_size >> 8); - hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_size); - - hmsc->bot_data_length = 8U; - - return 0; - -} - - -/** - * @brief SCSI_ReadCapacity16 - * Process Read Capacity 16 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(params); - uint8_t idx; - int8_t ret; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size); - - if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - hmsc->bot_data_length = ((uint32_t)params[10] << 24) | - ((uint32_t)params[11] << 16) | - ((uint32_t)params[12] << 8) | - (uint32_t)params[13]; - - for (idx = 0U; idx < hmsc->bot_data_length; idx++) - { - hmsc->bot_data[idx] = 0U; - } - - hmsc->bot_data[4] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24); - hmsc->bot_data[5] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16); - hmsc->bot_data[6] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8); - hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_nbr - 1U); - - hmsc->bot_data[8] = (uint8_t)(hmsc->scsi_blk_size >> 24); - hmsc->bot_data[9] = (uint8_t)(hmsc->scsi_blk_size >> 16); - hmsc->bot_data[10] = (uint8_t)(hmsc->scsi_blk_size >> 8); - hmsc->bot_data[11] = (uint8_t)(hmsc->scsi_blk_size); - - hmsc->bot_data_length = ((uint32_t)params[10] << 24) | - ((uint32_t)params[11] << 16) | - ((uint32_t)params[12] << 8) | - (uint32_t)params[13]; - - return 0; -} - - -/** - * @brief SCSI_ReadFormatCapacity - * Process Read Format Capacity command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(params); - uint16_t blk_size; - uint32_t blk_nbr; - uint16_t i; - int8_t ret; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &blk_nbr, &blk_size); - - if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - for (i = 0U; i < 12U ; i++) - { - hmsc->bot_data[i] = 0U; - } - - hmsc->bot_data[3] = 0x08U; - hmsc->bot_data[4] = (uint8_t)((blk_nbr - 1U) >> 24); - hmsc->bot_data[5] = (uint8_t)((blk_nbr - 1U) >> 16); - hmsc->bot_data[6] = (uint8_t)((blk_nbr - 1U) >> 8); - hmsc->bot_data[7] = (uint8_t)(blk_nbr - 1U); - - hmsc->bot_data[8] = 0x02U; - hmsc->bot_data[9] = (uint8_t)(blk_size >> 16); - hmsc->bot_data[10] = (uint8_t)(blk_size >> 8); - hmsc->bot_data[11] = (uint8_t)(blk_size); - - hmsc->bot_data_length = 12U; - - return 0; -} - - -/** - * @brief SCSI_ModeSense6 - * Process Mode Sense6 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(lun); - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - uint16_t len = MODE_SENSE6_LEN; - - if (hmsc == NULL) - { - return -1; - } - - if (params[4] <= len) - { - len = params[4]; - } - - (void)SCSI_UpdateBotData(hmsc, MSC_Mode_Sense6_data, len); - - return 0; -} - - -/** - * @brief SCSI_ModeSense10 - * Process Mode Sense10 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(lun); - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - uint16_t len = MODE_SENSE10_LEN; - - if (hmsc == NULL) - { - return -1; - } - - if (params[8] <= len) - { - len = params[8]; - } - - (void)SCSI_UpdateBotData(hmsc, MSC_Mode_Sense10_data, len); - - return 0; -} - - -/** - * @brief SCSI_RequestSense - * Process Request Sense command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(lun); - uint8_t i; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if (hmsc->cbw.dDataLength == 0U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - for (i = 0U; i < REQUEST_SENSE_DATA_LEN; i++) - { - hmsc->bot_data[i] = 0U; - } - - hmsc->bot_data[0] = 0x70U; - hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U; - - if ((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) - { - hmsc->bot_data[2] = (uint8_t)hmsc->scsi_sense[hmsc->scsi_sense_head].Skey; - hmsc->bot_data[12] = (uint8_t)hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASC; - hmsc->bot_data[13] = (uint8_t)hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASCQ; - hmsc->scsi_sense_head++; - - if (hmsc->scsi_sense_head == SENSE_LIST_DEEPTH) - { - hmsc->scsi_sense_head = 0U; - } - } - - hmsc->bot_data_length = REQUEST_SENSE_DATA_LEN; - - if (params[4] <= REQUEST_SENSE_DATA_LEN) - { - hmsc->bot_data_length = params[4]; - } - - return 0; -} - - -/** - * @brief SCSI_SenseCode - * Load the last error code in the error list - * @param lun: Logical unit number - * @param sKey: Sense Key - * @param ASC: Additional Sense Code - * @retval none - - */ -void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC) -{ - UNUSED(lun); - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return; - } - - hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey; - hmsc->scsi_sense[hmsc->scsi_sense_tail].w.b.ASC = ASC; - hmsc->scsi_sense[hmsc->scsi_sense_tail].w.b.ASCQ = 0U; - hmsc->scsi_sense_tail++; - - if (hmsc->scsi_sense_tail == SENSE_LIST_DEEPTH) - { - hmsc->scsi_sense_tail = 0U; - } -} - - -/** - * @brief SCSI_StartStopUnit - * Process Start Stop Unit command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(lun); - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if ((hmsc->scsi_medium_state == SCSI_MEDIUM_LOCKED) && ((params[4] & 0x3U) == 2U)) - { - SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); - - return -1; - } - - if ((params[4] & 0x3U) == 0x1U) /* START=1 */ - { - hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; - } - else if ((params[4] & 0x3U) == 0x2U) /* START=0 and LOEJ Load Eject=1 */ - { - hmsc->scsi_medium_state = SCSI_MEDIUM_EJECTED; - } - else if ((params[4] & 0x3U) == 0x3U) /* START=1 and LOEJ Load Eject=1 */ - { - hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; - } - else - { - /* .. */ - } - hmsc->bot_data_length = 0U; - - return 0; -} - - -/** - * @brief SCSI_AllowPreventRemovable - * Process Allow Prevent Removable medium command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - UNUSED(lun); - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if (params[4] == 0U) - { - hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; - } - else - { - hmsc->scsi_medium_state = SCSI_MEDIUM_LOCKED; - } - - hmsc->bot_data_length = 0U; - - return 0; -} - - -/** - * @brief SCSI_Read10 - * Process Read10 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ - { - /* case 10 : Ho <> Di */ - if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - - return -1; - } - - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | - ((uint32_t)params[3] << 16) | - ((uint32_t)params[4] << 8) | - (uint32_t)params[5]; - - hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8]; - - if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { - return -1; /* error */ - } - - /* cases 4,5 : Hi <> Dn */ - if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - hmsc->bot_state = USBD_BOT_DATA_IN; - } - hmsc->bot_data_length = MSC_MEDIA_PACKET; - - return SCSI_ProcessRead(pdev, lun); -} - - -/** - * @brief SCSI_Read12 - * Process Read12 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ - { - /* case 10 : Ho <> Di */ - if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | - ((uint32_t)params[3] << 16) | - ((uint32_t)params[4] << 8) | - (uint32_t)params[5]; - - hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) | - ((uint32_t)params[7] << 16) | - ((uint32_t)params[8] << 8) | - (uint32_t)params[9]; - - if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { - return -1; /* error */ - } - - /* cases 4,5 : Hi <> Dn */ - if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - hmsc->bot_state = USBD_BOT_DATA_IN; - } - hmsc->bot_data_length = MSC_MEDIA_PACKET; - - return SCSI_ProcessRead(pdev, lun); -} - - -/** - * @brief SCSI_Write10 - * Process Write10 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - uint32_t len; - - if (hmsc == NULL) - { - return -1; - } - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ - { - if (hmsc->cbw.dDataLength == 0U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - /* case 8 : Hi <> Do */ - if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - /* Check whether Media is ready */ - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - return -1; - } - - /* Check If media is write-protected */ - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED); - return -1; - } - - hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | - ((uint32_t)params[3] << 16) | - ((uint32_t)params[4] << 8) | - (uint32_t)params[5]; - - hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | - (uint32_t)params[8]; - - /* check if LBA address is in the right range */ - if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { - return -1; /* error */ - } - - len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; - - /* cases 3,11,13 : Hn,Ho <> D0 */ - if (hmsc->cbw.dDataLength != len) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - len = MIN(len, MSC_MEDIA_PACKET); - - /* Prepare EP to receive first data packet */ - hmsc->bot_state = USBD_BOT_DATA_OUT; - (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len); - } - else /* Write Process ongoing */ - { - return SCSI_ProcessWrite(pdev, lun); - } - - return 0; -} - - -/** - * @brief SCSI_Write12 - * Process Write12 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - uint32_t len; - - if (hmsc == NULL) - { - return -1; - } -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ - { - if (hmsc->cbw.dDataLength == 0U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - /* case 8 : Hi <> Do */ - if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - /* Check whether Media is ready */ - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); - hmsc->bot_state = USBD_BOT_NO_DATA; - return -1; - } - - /* Check If media is write-protected */ - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) - { - SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED); - hmsc->bot_state = USBD_BOT_NO_DATA; - return -1; - } - - hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | - ((uint32_t)params[3] << 16) | - ((uint32_t)params[4] << 8) | - (uint32_t)params[5]; - - hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) | - ((uint32_t)params[7] << 16) | - ((uint32_t)params[8] << 8) | - (uint32_t)params[9]; - - /* check if LBA address is in the right range */ - if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { - return -1; /* error */ - } - - len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; - - /* cases 3,11,13 : Hn,Ho <> D0 */ - if (hmsc->cbw.dDataLength != len) - { - SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); - return -1; - } - - len = MIN(len, MSC_MEDIA_PACKET); - - /* Prepare EP to receive first data packet */ - hmsc->bot_state = USBD_BOT_DATA_OUT; - (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len); - } - else /* Write Process ongoing */ - { - return SCSI_ProcessWrite(pdev, lun); - } - - return 0; -} - - -/** - * @brief SCSI_Verify10 - * Process Verify10 command - * @param lun: Logical unit number - * @param params: Command parameters - * @retval status - */ -static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if ((params[1] & 0x02U) == 0x02U) - { - SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); - return -1; /* Error, Verify Mode Not supported*/ - } - - if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) - { - return -1; /* error */ - } - - hmsc->bot_data_length = 0U; - - return 0; -} - -/** - * @brief SCSI_CheckAddressRange - * Check address range - * @param lun: Logical unit number - * @param blk_offset: first block address - * @param blk_nbr: number of block to be processed - * @retval status - */ -static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, - uint32_t blk_offset, uint32_t blk_nbr) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - - if (hmsc == NULL) - { - return -1; - } - - if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr) - { - SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE); - return -1; - } - - return 0; -} - -/** - * @brief SCSI_ProcessRead - * Handle Read Process - * @param lun: Logical unit number - * @retval status - */ -static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - uint32_t len; - - if (hmsc == NULL) - { - return -1; - } - - len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - len = MIN(len, MSC_MEDIA_PACKET); - - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Read(lun, hmsc->bot_data, - hmsc->scsi_blk_addr, - (len / hmsc->scsi_blk_size)) < 0) - { - SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR); - return -1; - } - - (void)USBD_LL_Transmit(pdev, MSCInEpAdd, hmsc->bot_data, len); - - hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size); - hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size); - - /* case 6 : Hi = Di */ - hmsc->csw.dDataResidue -= len; - - if (hmsc->scsi_blk_len == 0U) - { - hmsc->bot_state = USBD_BOT_LAST_DATA_IN; - } - - return 0; -} - -/** - * @brief SCSI_ProcessWrite - * Handle Write Process - * @param lun: Logical unit number - * @retval status - */ -static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun) -{ - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; - uint32_t len; - - if (hmsc == NULL) - { - return -1; - } - - len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; - -#ifdef USE_USBD_COMPOSITE - /* Get the Endpoints addresses allocated for this class instance */ - MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); -#endif /* USE_USBD_COMPOSITE */ - - len = MIN(len, MSC_MEDIA_PACKET); - - if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Write(lun, hmsc->bot_data, - hmsc->scsi_blk_addr, - (len / hmsc->scsi_blk_size)) < 0) - { - SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT); - return -1; - } - - hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size); - hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size); - - /* case 12 : Ho = Do */ - hmsc->csw.dDataResidue -= len; - - if (hmsc->scsi_blk_len == 0U) - { - MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); - } - else - { - len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET); - - /* Prepare EP to Receive next packet */ - (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len); - } - - return 0; -} - - -/** - * @brief SCSI_UpdateBotData - * fill the requested Data to transmit buffer - * @param hmsc handler - * @param pBuff: Data buffer - * @param length: Data length - * @retval status - */ -static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, - uint8_t *pBuff, uint16_t length) -{ - uint16_t len = length; - - if (hmsc == NULL) - { - return -1; - } - - hmsc->bot_data_length = len; - - while (len != 0U) - { - len--; - hmsc->bot_data[len] = pBuff[len]; - } - - return 0; -} -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h b/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h deleted file mode 100644 index 7b7dff5..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h +++ /dev/null @@ -1,172 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_core.h - * @author MCD Application Team - * @brief Header file for usbd_core.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CORE_H -#define __USBD_CORE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_conf.h" -#include "usbd_def.h" -#include "usbd_ioreq.h" -#include "usbd_ctlreq.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_CORE - * @brief This file is the Header file for usbd_core.c file - * @{ - */ - - -/** @defgroup USBD_CORE_Exported_Defines - * @{ - */ -#ifndef USBD_DEBUG_LEVEL -#define USBD_DEBUG_LEVEL 0U -#endif /* USBD_DEBUG_LEVEL */ -/** - * @} - */ - - -/** @defgroup USBD_CORE_Exported_TypesDefinitions - * @{ - */ - - -/** - * @} - */ - - - -/** @defgroup USBD_CORE_Exported_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Exported_Variables - * @{ - */ -#define USBD_SOF USBD_LL_SOF -/** - * @} - */ - -/** @defgroup USBD_CORE_Exported_FunctionsPrototype - * @{ - */ -USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); -USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); - -#ifdef USE_USBD_COMPOSITE -USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass, - USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr); - -USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev); -uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type); -#endif /* USE_USBD_COMPOSITE */ - -uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index); -uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index); - -USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); -USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); - -USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); -USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); -USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); - -USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); -USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); - -USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); -USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); - -USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); - -/* USBD Low Level Driver */ -USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); - -USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, - uint8_t ep_type, uint16_t ep_mps); - -USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); - -USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, - uint8_t *pbuf, uint32_t size); - -USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, - uint8_t *pbuf, uint32_t size); - -#ifdef USBD_HS_TESTMODE_ENABLE -USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode); -#endif /* USBD_HS_TESTMODE_ENABLE */ - -uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); -uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); - -void USBD_LL_Delay(uint32_t Delay); - -void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr); -USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CORE_H */ - -/** - * @} - */ - -/** - * @} - */ - - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h b/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h deleted file mode 100644 index 6c45d6c..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_req.h - * @author MCD Application Team - * @brief Header file for the usbd_req.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_REQUEST_H -#define __USB_REQUEST_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_REQ - * @brief header file for the usbd_req.c file - * @{ - */ - -/** @defgroup USBD_REQ_Exported_Defines - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_REQ_Exported_Types - * @{ - */ -/** - * @} - */ - - - -/** @defgroup USBD_REQ_Exported_Macros - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_REQ_Exported_Variables - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_REQ_Exported_FunctionsPrototype - * @{ - */ - -USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - -void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); -void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_REQUEST_H */ - -/** - * @} - */ - -/** - * @} - */ - - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h b/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h deleted file mode 100644 index 3c1902f..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h +++ /dev/null @@ -1,514 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_def.h - * @author MCD Application Team - * @brief General defines for the usb device library - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_DEF_H -#define __USBD_DEF_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_conf.h" - -/** @addtogroup STM32_USBD_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USB_DEF - * @brief general defines for the usb device library file - * @{ - */ - -/** @defgroup USB_DEF_Exported_Defines - * @{ - */ - -#ifndef NULL -#define NULL 0U -#endif /* NULL */ - -#ifndef USBD_MAX_NUM_INTERFACES -#define USBD_MAX_NUM_INTERFACES 1U -#endif /* USBD_MAX_NUM_CONFIGURATION */ - -#ifndef USBD_MAX_NUM_CONFIGURATION -#define USBD_MAX_NUM_CONFIGURATION 1U -#endif /* USBD_MAX_NUM_CONFIGURATION */ - -#ifdef USE_USBD_COMPOSITE -#ifndef USBD_MAX_SUPPORTED_CLASS -#define USBD_MAX_SUPPORTED_CLASS 4U -#endif /* USBD_MAX_SUPPORTED_CLASS */ -#else -#ifndef USBD_MAX_SUPPORTED_CLASS -#define USBD_MAX_SUPPORTED_CLASS 1U -#endif /* USBD_MAX_SUPPORTED_CLASS */ -#endif /* USE_USBD_COMPOSITE */ - -#ifndef USBD_MAX_CLASS_ENDPOINTS -#define USBD_MAX_CLASS_ENDPOINTS 5U -#endif /* USBD_MAX_CLASS_ENDPOINTS */ - -#ifndef USBD_MAX_CLASS_INTERFACES -#define USBD_MAX_CLASS_INTERFACES 5U -#endif /* USBD_MAX_CLASS_INTERFACES */ - -#ifndef USBD_LPM_ENABLED -#define USBD_LPM_ENABLED 0U -#endif /* USBD_LPM_ENABLED */ - -#ifndef USBD_SELF_POWERED -#define USBD_SELF_POWERED 1U -#endif /*USBD_SELF_POWERED */ - -#ifndef USBD_MAX_POWER -#define USBD_MAX_POWER 0x32U /* 100 mA */ -#endif /* USBD_MAX_POWER */ - -#ifndef USBD_SUPPORT_USER_STRING_DESC -#define USBD_SUPPORT_USER_STRING_DESC 0U -#endif /* USBD_SUPPORT_USER_STRING_DESC */ - -#ifndef USBD_CLASS_USER_STRING_DESC -#define USBD_CLASS_USER_STRING_DESC 0U -#endif /* USBD_CLASS_USER_STRING_DESC */ - -#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU -#define USB_LEN_DEV_DESC 0x12U -#define USB_LEN_CFG_DESC 0x09U -#define USB_LEN_IF_DESC 0x09U -#define USB_LEN_EP_DESC 0x07U -#define USB_LEN_OTG_DESC 0x03U -#define USB_LEN_LANGID_STR_DESC 0x04U -#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U - -#define USBD_IDX_LANGID_STR 0x00U -#define USBD_IDX_MFC_STR 0x01U -#define USBD_IDX_PRODUCT_STR 0x02U -#define USBD_IDX_SERIAL_STR 0x03U -#define USBD_IDX_CONFIG_STR 0x04U -#define USBD_IDX_INTERFACE_STR 0x05U - -#define USB_REQ_TYPE_STANDARD 0x00U -#define USB_REQ_TYPE_CLASS 0x20U -#define USB_REQ_TYPE_VENDOR 0x40U -#define USB_REQ_TYPE_MASK 0x60U - -#define USB_REQ_RECIPIENT_DEVICE 0x00U -#define USB_REQ_RECIPIENT_INTERFACE 0x01U -#define USB_REQ_RECIPIENT_ENDPOINT 0x02U -#define USB_REQ_RECIPIENT_MASK 0x03U - -#define USB_REQ_GET_STATUS 0x00U -#define USB_REQ_CLEAR_FEATURE 0x01U -#define USB_REQ_SET_FEATURE 0x03U -#define USB_REQ_SET_ADDRESS 0x05U -#define USB_REQ_GET_DESCRIPTOR 0x06U -#define USB_REQ_SET_DESCRIPTOR 0x07U -#define USB_REQ_GET_CONFIGURATION 0x08U -#define USB_REQ_SET_CONFIGURATION 0x09U -#define USB_REQ_GET_INTERFACE 0x0AU -#define USB_REQ_SET_INTERFACE 0x0BU -#define USB_REQ_SYNCH_FRAME 0x0CU - -#define USB_DESC_TYPE_DEVICE 0x01U -#define USB_DESC_TYPE_CONFIGURATION 0x02U -#define USB_DESC_TYPE_STRING 0x03U -#define USB_DESC_TYPE_INTERFACE 0x04U -#define USB_DESC_TYPE_ENDPOINT 0x05U -#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U -#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U -#define USB_DESC_TYPE_IAD 0x0BU -#define USB_DESC_TYPE_BOS 0x0FU - -#define USB_CONFIG_REMOTE_WAKEUP 0x02U -#define USB_CONFIG_SELF_POWERED 0x01U - -#define USB_FEATURE_EP_HALT 0x00U -#define USB_FEATURE_REMOTE_WAKEUP 0x01U -#define USB_FEATURE_TEST_MODE 0x02U - -#define USB_DEVICE_CAPABITY_TYPE 0x10U - -#define USB_CONF_DESC_SIZE 0x09U -#define USB_IF_DESC_SIZE 0x09U -#define USB_EP_DESC_SIZE 0x07U -#define USB_IAD_DESC_SIZE 0x08U - -#define USB_HS_MAX_PACKET_SIZE 512U -#define USB_FS_MAX_PACKET_SIZE 64U -#define USB_MAX_EP0_SIZE 64U - -/* Device Status */ -#define USBD_STATE_DEFAULT 0x01U -#define USBD_STATE_ADDRESSED 0x02U -#define USBD_STATE_CONFIGURED 0x03U -#define USBD_STATE_SUSPENDED 0x04U - - -/* EP0 State */ -#define USBD_EP0_IDLE 0x00U -#define USBD_EP0_SETUP 0x01U -#define USBD_EP0_DATA_IN 0x02U -#define USBD_EP0_DATA_OUT 0x03U -#define USBD_EP0_STATUS_IN 0x04U -#define USBD_EP0_STATUS_OUT 0x05U -#define USBD_EP0_STALL 0x06U - -#define USBD_EP_TYPE_CTRL 0x00U -#define USBD_EP_TYPE_ISOC 0x01U -#define USBD_EP_TYPE_BULK 0x02U -#define USBD_EP_TYPE_INTR 0x03U - -#ifdef USE_USBD_COMPOSITE -#define USBD_EP_IN 0x80U -#define USBD_EP_OUT 0x00U -#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U -#define USBD_DESC_SUBTYPE_ACM 0x0FU -#define USBD_DESC_ECM_BCD_LOW 0x00U -#define USBD_DESC_ECM_BCD_HIGH 0x10U -#endif /* USE_USBD_COMPOSITE */ -/** - * @} - */ - - -/** @defgroup USBD_DEF_Exported_TypesDefinitions - * @{ - */ - -typedef struct usb_setup_req -{ - uint8_t bmRequest; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; -} USBD_SetupReqTypedef; - -typedef struct -{ - uint8_t bLength; - uint8_t bDescriptorType; - uint16_t wTotalLength; - uint8_t bNumInterfaces; - uint8_t bConfigurationValue; - uint8_t iConfiguration; - uint8_t bmAttributes; - uint8_t bMaxPower; -} __PACKED USBD_ConfigDescTypeDef; - -typedef struct -{ - uint8_t bLength; - uint8_t bDescriptorType; - uint16_t wTotalLength; - uint8_t bNumDeviceCaps; -} USBD_BosDescTypeDef; - -typedef struct -{ - uint8_t bLength; - uint8_t bDescriptorType; - uint8_t bEndpointAddress; - uint8_t bmAttributes; - uint16_t wMaxPacketSize; - uint8_t bInterval; -} __PACKED USBD_EpDescTypeDef; - -typedef struct -{ - uint8_t bLength; - uint8_t bDescriptorType; - uint8_t bDescriptorSubType; -} USBD_DescHeaderTypeDef; - -struct _USBD_HandleTypeDef; - -typedef struct _Device_cb -{ - uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); - uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); - /* Control Endpoints*/ - uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev); - uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev); - /* Class Specific Endpoints*/ - uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev); - uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - - uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); - uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); - uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); - uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); -#if (USBD_SUPPORT_USER_STRING_DESC == 1U) - uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); -#endif /* USBD_SUPPORT_USER_STRING_DESC */ - -} USBD_ClassTypeDef; - -/* Following USB Device Speed */ -typedef enum -{ - USBD_SPEED_HIGH = 0U, - USBD_SPEED_FULL = 1U, - USBD_SPEED_LOW = 2U, -} USBD_SpeedTypeDef; - -/* Following USB Device status */ -typedef enum -{ - USBD_OK = 0U, - USBD_BUSY, - USBD_EMEM, - USBD_FAIL, -} USBD_StatusTypeDef; - -/* USB Device descriptors structure */ -typedef struct -{ - uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); -#if (USBD_CLASS_USER_STRING_DESC == 1) - uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); -#endif /* USBD_CLASS_USER_STRING_DESC */ -#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1)) - uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); -#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */ -} USBD_DescriptorsTypeDef; - -/* USB Device handle structure */ -typedef struct -{ - uint32_t status; - uint32_t total_length; - uint32_t rem_length; - uint32_t maxpacket; - uint16_t is_used; - uint16_t bInterval; -} USBD_EndpointTypeDef; - -#ifdef USE_USBD_COMPOSITE -typedef enum -{ - CLASS_TYPE_NONE = 0, - CLASS_TYPE_HID = 1, - CLASS_TYPE_CDC = 2, - CLASS_TYPE_MSC = 3, - CLASS_TYPE_DFU = 4, - CLASS_TYPE_CHID = 5, - CLASS_TYPE_AUDIO = 6, - CLASS_TYPE_ECM = 7, - CLASS_TYPE_RNDIS = 8, - CLASS_TYPE_MTP = 9, - CLASS_TYPE_VIDEO = 10, - CLASS_TYPE_PRINTER = 11, - CLASS_TYPE_CCID = 12, -} USBD_CompositeClassTypeDef; - - -/* USB Device handle structure */ -typedef struct -{ - uint8_t add; - uint8_t type; - uint8_t size; - uint8_t is_used; -} USBD_EPTypeDef; - -/* USB Device handle structure */ -typedef struct -{ - USBD_CompositeClassTypeDef ClassType; - uint32_t ClassId; - uint32_t Active; - uint32_t NumEps; - USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS]; - uint8_t *EpAdd; - uint32_t NumIf; - uint8_t Ifs[USBD_MAX_CLASS_INTERFACES]; - uint32_t CurrPcktSze; -} USBD_CompositeElementTypeDef; -#endif /* USE_USBD_COMPOSITE */ - -/* USB Device handle structure */ -typedef struct _USBD_HandleTypeDef -{ - uint8_t id; - uint32_t dev_config; - uint32_t dev_default_config; - uint32_t dev_config_status; - USBD_SpeedTypeDef dev_speed; - USBD_EndpointTypeDef ep_in[16]; - USBD_EndpointTypeDef ep_out[16]; - __IO uint32_t ep0_state; - uint32_t ep0_data_len; - __IO uint8_t dev_state; - __IO uint8_t dev_old_state; - uint8_t dev_address; - uint8_t dev_connection_status; - uint8_t dev_test_mode; - uint32_t dev_remote_wakeup; - uint8_t ConfIdx; - - USBD_SetupReqTypedef request; - USBD_DescriptorsTypeDef *pDesc; - USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS]; - void *pClassData; - void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS]; - void *pUserData[USBD_MAX_SUPPORTED_CLASS]; - void *pData; - void *pBosDesc; - void *pConfDesc; - uint32_t classId; - uint32_t NumClasses; -#ifdef USE_USBD_COMPOSITE - USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS]; -#endif /* USE_USBD_COMPOSITE */ -} USBD_HandleTypeDef; - -/* USB Device endpoint direction */ -typedef enum -{ - OUT = 0x00, - IN = 0x80, -} USBD_EPDirectionTypeDef; - -typedef enum -{ - NETWORK_CONNECTION = 0x00, - RESPONSE_AVAILABLE = 0x01, - CONNECTION_SPEED_CHANGE = 0x2A -} USBD_CDC_NotifCodeTypeDef; -/** - * @} - */ - - - -/** @defgroup USBD_DEF_Exported_Macros - * @{ - */ -__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr) -{ - uint16_t _SwapVal, _Byte1, _Byte2; - uint8_t *_pbuff = addr; - - _Byte1 = *(uint8_t *)_pbuff; - _pbuff++; - _Byte2 = *(uint8_t *)_pbuff; - - _SwapVal = (_Byte2 << 8) | _Byte1; - - return _SwapVal; -} - -#ifndef LOBYTE -#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU)) -#endif /* LOBYTE */ - -#ifndef HIBYTE -#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U)) -#endif /* HIBYTE */ - -#ifndef MIN -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif /* MIN */ - -#ifndef MAX -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif /* MAX */ - -#if defined ( __GNUC__ ) -#ifndef __weak -#define __weak __attribute__((weak)) -#endif /* __weak */ -#ifndef __packed -#define __packed __attribute__((__packed__)) -#endif /* __packed */ -#endif /* __GNUC__ */ - - -/* In HS mode and when the DMA is used, all variables and data structures dealing - with the DMA during the transaction process should be 4-bytes aligned */ - -#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ -#ifndef __ALIGN_END -#define __ALIGN_END __attribute__ ((aligned (4U))) -#endif /* __ALIGN_END */ -#ifndef __ALIGN_BEGIN -#define __ALIGN_BEGIN -#endif /* __ALIGN_BEGIN */ -#else -#ifndef __ALIGN_END -#define __ALIGN_END -#endif /* __ALIGN_END */ -#ifndef __ALIGN_BEGIN -#if defined (__CC_ARM) /* ARM Compiler */ -#define __ALIGN_BEGIN __align(4U) -#elif defined (__ICCARM__) /* IAR Compiler */ -#define __ALIGN_BEGIN -#endif /* __CC_ARM */ -#endif /* __ALIGN_BEGIN */ -#endif /* __GNUC__ */ - - -/** - * @} - */ - -/** @defgroup USBD_DEF_Exported_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_DEF_Exported_FunctionsPrototype - * @{ - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_DEF_H */ - -/** - * @} - */ - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h b/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h deleted file mode 100644 index 15197b9..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h +++ /dev/null @@ -1,113 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_ioreq.h - * @author MCD Application Team - * @brief Header file for the usbd_ioreq.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_IOREQ_H -#define __USBD_IOREQ_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" -#include "usbd_core.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_IOREQ - * @brief header file for the usbd_ioreq.c file - * @{ - */ - -/** @defgroup USBD_IOREQ_Exported_Defines - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_IOREQ_Exported_Types - * @{ - */ - - -/** - * @} - */ - - - -/** @defgroup USBD_IOREQ_Exported_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Exported_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype - * @{ - */ - -USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len); - -USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len); - -USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len); - -USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len); - -USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); - -uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_IOREQ_H */ - -/** - * @} - */ - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c b/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c deleted file mode 100644 index 544c2a9..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c +++ /dev/null @@ -1,1220 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_core.c - * @author MCD Application Team - * @brief This file provides all the USBD core functions. - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" - -#ifdef USE_USBD_COMPOSITE -#include "usbd_composite_builder.h" -#endif /* USE_USBD_COMPOSITE */ - -/** @addtogroup STM32_USBD_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup USBD_CORE - * @brief usbd core module - * @{ - */ - -/** @defgroup USBD_CORE_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_CORE_Private_Defines - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_CORE_Private_Macros - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_CORE_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Private_Variables - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_CORE_Private_Functions - * @{ - */ - -/** - * @brief USBD_Init - * Initializes the device stack and load the class driver - * @param pdev: device instance - * @param pdesc: Descriptor structure address - * @param id: Low level core index - * @retval None - */ -USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, - USBD_DescriptorsTypeDef *pdesc, uint8_t id) -{ - USBD_StatusTypeDef ret; - - /* Check whether the USB Host handle is valid */ - if (pdev == NULL) - { -#if (USBD_DEBUG_LEVEL > 1U) - USBD_ErrLog("Invalid Device handle"); -#endif /* (USBD_DEBUG_LEVEL > 1U) */ - return USBD_FAIL; - } - -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Unlink previous class*/ - pdev->pClass[i] = NULL; - pdev->pUserData[i] = NULL; - - /* Set class as inactive */ - pdev->tclasslist[i].Active = 0; - pdev->NumClasses = 0; - pdev->classId = 0; - } -#else - /* Unlink previous class*/ - pdev->pClass[0] = NULL; - pdev->pUserData[0] = NULL; -#endif /* USE_USBD_COMPOSITE */ - - pdev->pConfDesc = NULL; - - /* Assign USBD Descriptors */ - if (pdesc != NULL) - { - pdev->pDesc = pdesc; - } - - /* Set Device initial State */ - pdev->dev_state = USBD_STATE_DEFAULT; - pdev->id = id; - - /* Initialize low level driver */ - ret = USBD_LL_Init(pdev); - - return ret; -} - -/** - * @brief USBD_DeInit - * Re-Initialize the device library - * @param pdev: device instance - * @retval status: status - */ -USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) -{ - USBD_StatusTypeDef ret; - - /* Disconnect the USB Device */ - (void)USBD_LL_Stop(pdev); - - /* Set Default State */ - pdev->dev_state = USBD_STATE_DEFAULT; - -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - pdev->classId = i; - /* Free Class Resources */ - pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config); - } - } - } -#else - /* Free Class Resources */ - if (pdev->pClass[0] != NULL) - { - pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config); - } - - pdev->pUserData[0] = NULL; - -#endif /* USE_USBD_COMPOSITE */ - - /* Free Device descriptors resources */ - pdev->pDesc = NULL; - pdev->pConfDesc = NULL; - - /* DeInitialize low level driver */ - ret = USBD_LL_DeInit(pdev); - - return ret; -} - -/** - * @brief USBD_RegisterClass - * Link class driver to Device Core. - * @param pDevice : Device Handle - * @param pclass: Class handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) -{ - uint16_t len = 0U; - - if (pclass == NULL) - { -#if (USBD_DEBUG_LEVEL > 1U) - USBD_ErrLog("Invalid Class handle"); -#endif /* (USBD_DEBUG_LEVEL > 1U) */ - return USBD_FAIL; - } - - /* link the class to the USB Device handle */ - pdev->pClass[0] = pclass; - - /* Get Device Configuration Descriptor */ -#ifdef USE_USB_HS - if (pdev->pClass[pdev->classId]->GetHSConfigDescriptor != NULL) - { - pdev->pConfDesc = (void *)pdev->pClass[pdev->classId]->GetHSConfigDescriptor(&len); - } -#else /* Default USE_USB_FS */ - if (pdev->pClass[pdev->classId]->GetFSConfigDescriptor != NULL) - { - pdev->pConfDesc = (void *)pdev->pClass[pdev->classId]->GetFSConfigDescriptor(&len); - } -#endif /* USE_USB_FS */ - - /* Increment the NumClasses */ - pdev->NumClasses ++; - - return USBD_OK; -} - -#ifdef USE_USBD_COMPOSITE -/** - * @brief USBD_RegisterClassComposite - * Link class driver to Device Core. - * @param pdev : Device Handle - * @param pclass: Class handle - * @param classtype: Class type - * @param EpAddr: Endpoint Address handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass, - USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr) -{ - USBD_StatusTypeDef ret = USBD_OK; - uint16_t len = 0U; - - if ((pdev->classId < USBD_MAX_SUPPORTED_CLASS) && (pdev->NumClasses < USBD_MAX_SUPPORTED_CLASS)) - { - if ((uint32_t)pclass != 0U) - { - /* Link the class to the USB Device handle */ - pdev->pClass[pdev->classId] = pclass; - ret = USBD_OK; - - pdev->tclasslist[pdev->classId].EpAdd = EpAddr; - - /* Call the composite class builder */ - (void)USBD_CMPSIT_AddClass(pdev, pclass, classtype, 0); - - /* Increment the ClassId for the next occurrence */ - pdev->classId ++; - pdev->NumClasses ++; - } - else - { -#if (USBD_DEBUG_LEVEL > 1U) - USBD_ErrLog("Invalid Class handle"); -#endif /* (USBD_DEBUG_LEVEL > 1U) */ - ret = USBD_FAIL; - } - } - - if (ret == USBD_OK) - { - /* Get Device Configuration Descriptor */ -#ifdef USE_USB_HS - pdev->pConfDesc = USBD_CMPSIT.GetHSConfigDescriptor(&len); -#else /* Default USE_USB_FS */ - pdev->pConfDesc = USBD_CMPSIT.GetFSConfigDescriptor(&len); -#endif /* USE_USB_FS */ - } - - return ret; -} - -/** - * @brief USBD_UnRegisterClassComposite - * UnLink all composite class drivers from Device Core. - * @param pDevice : Device Handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev) -{ - USBD_StatusTypeDef ret = USBD_FAIL; - uint8_t idx1; - uint8_t idx2; - - /* Unroll all activated classes */ - for (idx1 = 0; idx1 < pdev->NumClasses; idx1++) - { - /* Check if the class correspond to the requested type and if it is active */ - if (pdev->tclasslist[idx1].Active == 1U) - { - /* Set the new class ID */ - pdev->classId = idx1; - - /* Free resources used by the selected class */ - if (pdev->pClass[pdev->classId] != NULL) - { - /* Free Class Resources */ - if (pdev->pClass[pdev->classId]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) - { -#if (USBD_DEBUG_LEVEL > 1U) - USBD_ErrLog("Class DeInit didn't succeed!, can't unregister selected class"); -#endif /* (USBD_DEBUG_LEVEL > 1U) */ - - ret = USBD_FAIL; - } - } - - /* Free the class pointer */ - pdev->pClass[pdev->classId] = NULL; - - /* Free the class location in classes table and reset its parameters to zero */ - pdev->tclasslist[pdev->classId].ClassType = CLASS_TYPE_NONE; - pdev->tclasslist[pdev->classId].ClassId = 0U; - pdev->tclasslist[pdev->classId].Active = 0U; - pdev->tclasslist[pdev->classId].NumEps = 0U; - pdev->tclasslist[pdev->classId].NumIf = 0U; - pdev->tclasslist[pdev->classId].CurrPcktSze = 0U; - - for (idx2 = 0U; idx2 < USBD_MAX_CLASS_ENDPOINTS; idx2++) - { - pdev->tclasslist[pdev->classId].Eps[idx2].add = 0U; - pdev->tclasslist[pdev->classId].Eps[idx2].type = 0U; - pdev->tclasslist[pdev->classId].Eps[idx2].size = 0U; - pdev->tclasslist[pdev->classId].Eps[idx2].is_used = 0U; - } - - for (idx2 = 0U; idx2 < USBD_MAX_CLASS_INTERFACES; idx2++) - { - pdev->tclasslist[pdev->classId].Ifs[idx2] = 0U; - } - } - } - - /* Reset the configuration descriptor */ - (void)USBD_CMPST_ClearConfDesc(pdev); - - /* Reset the class ID and number of classes */ - pdev->classId = 0U; - pdev->NumClasses = 0U; - - return ret; -} - - -#endif /* USE_USBD_COMPOSITE */ - -/** - * @brief USBD_Start - * Start the USB Device Core. - * @param pdev: Device Handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev) -{ -#ifdef USE_USBD_COMPOSITE - pdev->classId = 0U; -#endif /* USE_USBD_COMPOSITE */ - - /* Start the low level driver */ - return USBD_LL_Start(pdev); -} - -/** - * @brief USBD_Stop - * Stop the USB Device Core. - * @param pdev: Device Handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev) -{ - /* Disconnect USB Device */ - (void)USBD_LL_Stop(pdev); - - /* Free Class Resources */ -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - pdev->classId = i; - /* Free Class Resources */ - (void)pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config); - } - } - } - - /* Reset the class ID */ - pdev->classId = 0U; -#else - if (pdev->pClass[0] != NULL) - { - (void)pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config); - } -#endif /* USE_USBD_COMPOSITE */ - - return USBD_OK; -} - -/** - * @brief USBD_RunTestMode - * Launch test mode process - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev) -{ -#ifdef USBD_HS_TESTMODE_ENABLE - USBD_StatusTypeDef ret; - - /* Run USB HS test mode */ - ret = USBD_LL_SetTestMode(pdev, pdev->dev_test_mode); - - return ret; -#else - /* Prevent unused argument compilation warning */ - UNUSED(pdev); - - return USBD_OK; -#endif /* USBD_HS_TESTMODE_ENABLE */ -} - -/** - * @brief USBD_SetClassConfig - * Configure device and start the interface - * @param pdev: device instance - * @param cfgidx: configuration index - * @retval status - */ - -USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - USBD_StatusTypeDef ret = USBD_OK; - -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - pdev->classId = i; - /* Set configuration and Start the Class*/ - if (pdev->pClass[i]->Init(pdev, cfgidx) != 0U) - { - ret = USBD_FAIL; - } - } - } - } -#else - if (pdev->pClass[0] != NULL) - { - /* Set configuration and Start the Class */ - ret = (USBD_StatusTypeDef)pdev->pClass[0]->Init(pdev, cfgidx); - } -#endif /* USE_USBD_COMPOSITE */ - - return ret; -} - -/** - * @brief USBD_ClrClassConfig - * Clear current configuration - * @param pdev: device instance - * @param cfgidx: configuration index - * @retval status: USBD_StatusTypeDef - */ -USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - USBD_StatusTypeDef ret = USBD_OK; - -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - pdev->classId = i; - /* Clear configuration and De-initialize the Class process */ - if (pdev->pClass[i]->DeInit(pdev, cfgidx) != 0U) - { - ret = USBD_FAIL; - } - } - } - } -#else - /* Clear configuration and De-initialize the Class process */ - if (pdev->pClass[0]->DeInit(pdev, cfgidx) != 0U) - { - ret = USBD_FAIL; - } -#endif /* USE_USBD_COMPOSITE */ - - return ret; -} - - -/** - * @brief USBD_LL_SetupStage - * Handle the setup stage - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) -{ - USBD_StatusTypeDef ret; - - USBD_ParseSetupRequest(&pdev->request, psetup); - - pdev->ep0_state = USBD_EP0_SETUP; - - pdev->ep0_data_len = pdev->request.wLength; - - switch (pdev->request.bmRequest & 0x1FU) - { - case USB_REQ_RECIPIENT_DEVICE: - ret = USBD_StdDevReq(pdev, &pdev->request); - break; - - case USB_REQ_RECIPIENT_INTERFACE: - ret = USBD_StdItfReq(pdev, &pdev->request); - break; - - case USB_REQ_RECIPIENT_ENDPOINT: - ret = USBD_StdEPReq(pdev, &pdev->request); - break; - - default: - ret = USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); - break; - } - - return ret; -} - -/** - * @brief USBD_LL_DataOutStage - * Handle data OUT stage - * @param pdev: device instance - * @param epnum: endpoint index - * @param pdata: data pointer - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, - uint8_t epnum, uint8_t *pdata) -{ - USBD_EndpointTypeDef *pep; - USBD_StatusTypeDef ret = USBD_OK; - uint8_t idx; - - if (epnum == 0U) - { - pep = &pdev->ep_out[0]; - - if (pdev->ep0_state == USBD_EP0_DATA_OUT) - { - if (pep->rem_length > pep->maxpacket) - { - pep->rem_length -= pep->maxpacket; - - (void)USBD_CtlContinueRx(pdev, pdata, MIN(pep->rem_length, pep->maxpacket)); - } - else - { - /* Find the class ID relative to the current request */ - switch (pdev->request.bmRequest & 0x1FU) - { - case USB_REQ_RECIPIENT_DEVICE: - /* Device requests must be managed by the first instantiated class - (or duplicated by all classes for simplicity) */ - idx = 0U; - break; - - case USB_REQ_RECIPIENT_INTERFACE: - idx = USBD_CoreFindIF(pdev, LOBYTE(pdev->request.wIndex)); - break; - - case USB_REQ_RECIPIENT_ENDPOINT: - idx = USBD_CoreFindEP(pdev, LOBYTE(pdev->request.wIndex)); - break; - - default: - /* Back to the first class in case of doubt */ - idx = 0U; - break; - } - - if (idx < USBD_MAX_SUPPORTED_CLASS) - { - /* Setup the class ID and route the request to the relative class function */ - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass[idx]->EP0_RxReady != NULL) - { - pdev->classId = idx; - pdev->pClass[idx]->EP0_RxReady(pdev); - } - } - } - - (void)USBD_CtlSendStatus(pdev); - } - } - else - { -#if 0 - if (pdev->ep0_state == USBD_EP0_STATUS_OUT) - { - /* - * STATUS PHASE completed, update ep0_state to idle - */ - pdev->ep0_state = USBD_EP0_IDLE; - (void)USBD_LL_StallEP(pdev, 0U); - } -#endif - } - } - else - { - /* Get the class index relative to this interface */ - idx = USBD_CoreFindEP(pdev, (epnum & 0x7FU)); - - if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) - { - /* Call the class data out function to manage the request */ - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass[idx]->DataOut != NULL) - { - pdev->classId = idx; - ret = (USBD_StatusTypeDef)pdev->pClass[idx]->DataOut(pdev, epnum); - } - } - if (ret != USBD_OK) - { - return ret; - } - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_DataInStage - * Handle data in stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, - uint8_t epnum, uint8_t *pdata) -{ - USBD_EndpointTypeDef *pep; - USBD_StatusTypeDef ret; - uint8_t idx; - - if (epnum == 0U) - { - pep = &pdev->ep_in[0]; - - if (pdev->ep0_state == USBD_EP0_DATA_IN) - { - if (pep->rem_length > pep->maxpacket) - { - pep->rem_length -= pep->maxpacket; - - (void)USBD_CtlContinueSendData(pdev, pdata, pep->rem_length); - - /* Prepare endpoint for premature end of transfer */ - (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); - } - else - { - /* last packet is MPS multiple, so send ZLP packet */ - if ((pep->maxpacket == pep->rem_length) && - (pep->total_length >= pep->maxpacket) && - (pep->total_length < pdev->ep0_data_len)) - { - (void)USBD_CtlContinueSendData(pdev, NULL, 0U); - pdev->ep0_data_len = 0U; - - /* Prepare endpoint for premature end of transfer */ - (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); - } - else - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass[0]->EP0_TxSent != NULL) - { - pdev->classId = 0U; - pdev->pClass[0]->EP0_TxSent(pdev); - } - } - (void)USBD_LL_StallEP(pdev, 0x80U); - (void)USBD_CtlReceiveStatus(pdev); - } - } - } - else - { -#if 0 - if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || - (pdev->ep0_state == USBD_EP0_IDLE)) - { - (void)USBD_LL_StallEP(pdev, 0x80U); - } -#endif - } - - if (pdev->dev_test_mode != 0U) - { - (void)USBD_RunTestMode(pdev); - pdev->dev_test_mode = 0U; - } - } - else - { - /* Get the class index relative to this interface */ - idx = USBD_CoreFindEP(pdev, ((uint8_t)epnum | 0x80U)); - - if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) - { - /* Call the class data out function to manage the request */ - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass[idx]->DataIn != NULL) - { - pdev->classId = idx; - ret = (USBD_StatusTypeDef)pdev->pClass[idx]->DataIn(pdev, epnum); - - if (ret != USBD_OK) - { - return ret; - } - } - } - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_Reset - * Handle Reset event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) -{ - USBD_StatusTypeDef ret = USBD_OK; - - /* Upon Reset call user call back */ - pdev->dev_state = USBD_STATE_DEFAULT; - pdev->ep0_state = USBD_EP0_IDLE; - pdev->dev_config = 0U; - pdev->dev_remote_wakeup = 0U; - pdev->dev_test_mode = 0U; - -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - pdev->classId = i; - /* Clear configuration and De-initialize the Class process*/ - - if (pdev->pClass[i]->DeInit != NULL) - { - if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK) - { - ret = USBD_FAIL; - } - } - } - } - } -#else - - if (pdev->pClass[0] != NULL) - { - if (pdev->pClass[0]->DeInit != NULL) - { - if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK) - { - ret = USBD_FAIL; - } - } - } -#endif /* USE_USBD_COMPOSITE */ - - /* Open EP0 OUT */ - (void)USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); - pdev->ep_out[0x00U & 0xFU].is_used = 1U; - - pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; - - /* Open EP0 IN */ - (void)USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); - pdev->ep_in[0x80U & 0xFU].is_used = 1U; - - pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; - - return ret; -} - -/** - * @brief USBD_LL_SetSpeed - * Handle Reset event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, - USBD_SpeedTypeDef speed) -{ - pdev->dev_speed = speed; - - return USBD_OK; -} - -/** - * @brief USBD_LL_Suspend - * Handle Suspend event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) -{ - pdev->dev_old_state = pdev->dev_state; - pdev->dev_state = USBD_STATE_SUSPENDED; - - return USBD_OK; -} - -/** - * @brief USBD_LL_Resume - * Handle Resume event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) -{ - if (pdev->dev_state == USBD_STATE_SUSPENDED) - { - pdev->dev_state = pdev->dev_old_state; - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_SOF - * Handle SOF event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) -{ - /* The SOF event can be distributed for all classes that support it */ - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - if (pdev->pClass[i]->SOF != NULL) - { - pdev->classId = i; - (void)pdev->pClass[i]->SOF(pdev); - } - } - } - } -#else - if (pdev->pClass[0] != NULL) - { - if (pdev->pClass[0]->SOF != NULL) - { - (void)pdev->pClass[0]->SOF(pdev); - } - } -#endif /* USE_USBD_COMPOSITE */ - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_IsoINIncomplete - * Handle iso in incomplete event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, - uint8_t epnum) -{ - if (pdev->pClass[pdev->classId] == NULL) - { - return USBD_FAIL; - } - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass[pdev->classId]->IsoINIncomplete != NULL) - { - (void)pdev->pClass[pdev->classId]->IsoINIncomplete(pdev, epnum); - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_IsoOUTIncomplete - * Handle iso out incomplete event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, - uint8_t epnum) -{ - if (pdev->pClass[pdev->classId] == NULL) - { - return USBD_FAIL; - } - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass[pdev->classId]->IsoOUTIncomplete != NULL) - { - (void)pdev->pClass[pdev->classId]->IsoOUTIncomplete(pdev, epnum); - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_DevConnected - * Handle device connection event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev) -{ - /* Prevent unused argument compilation warning */ - UNUSED(pdev); - - return USBD_OK; -} - -/** - * @brief USBD_LL_DevDisconnected - * Handle device disconnection event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) -{ - USBD_StatusTypeDef ret = USBD_OK; - - /* Free Class Resources */ - pdev->dev_state = USBD_STATE_DEFAULT; - -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - if (pdev->pClass[i] != NULL) - { - pdev->classId = i; - /* Clear configuration and De-initialize the Class process*/ - if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) - { - ret = USBD_FAIL; - } - } - } - } -#else - if (pdev->pClass[0] != NULL) - { - if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) - { - ret = USBD_FAIL; - } - } -#endif /* USE_USBD_COMPOSITE */ - - return ret; -} - -/** - * @brief USBD_CoreFindIF - * return the class index relative to the selected interface - * @param pdev: device instance - * @param index : selected interface number - * @retval index of the class using the selected interface number. OxFF if no class found. - */ -uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index) -{ -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - /* Parse all interfaces listed in the current class */ - for (uint32_t j = 0U; j < pdev->tclasslist[i].NumIf; j++) - { - /* Check if requested Interface matches the current class interface */ - if (pdev->tclasslist[i].Ifs[j] == index) - { - if (pdev->pClass[i]->Setup != NULL) - { - return (uint8_t)i; - } - } - } - } - } - - return 0xFFU; -#else - UNUSED(pdev); - UNUSED(index); - - return 0x00U; -#endif /* USE_USBD_COMPOSITE */ -} - -/** - * @brief USBD_CoreFindEP - * return the class index relative to the selected endpoint - * @param pdev: device instance - * @param index : selected endpoint number - * @retval index of the class using the selected endpoint number. 0xFF if no class found. - */ -uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index) -{ -#ifdef USE_USBD_COMPOSITE - /* Parse the table of classes in use */ - for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) - { - /* Check if current class is in use */ - if ((pdev->tclasslist[i].Active) == 1U) - { - /* Parse all endpoints listed in the current class */ - for (uint32_t j = 0U; j < pdev->tclasslist[i].NumEps; j++) - { - /* Check if requested endpoint matches the current class endpoint */ - if (pdev->tclasslist[i].Eps[j].add == index) - { - if (pdev->pClass[i]->Setup != NULL) - { - return (uint8_t)i; - } - } - } - } - } - - return 0xFFU; -#else - UNUSED(pdev); - UNUSED(index); - - return 0x00U; -#endif /* USE_USBD_COMPOSITE */ -} - -#ifdef USE_USBD_COMPOSITE -/** - * @brief USBD_CoreGetEPAdd - * Get the endpoint address relative to a selected class - * @param pdev: device instance - * @param ep_dir: USBD_EP_IN or USBD_EP_OUT - * @param ep_type: USBD_EP_TYPE_CTRL, USBD_EP_TYPE_ISOC, USBD_EP_TYPE_BULK or USBD_EP_TYPE_INTR - * @retval Address of the selected endpoint or 0xFFU if no endpoint found. - */ -uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type) -{ - uint8_t idx; - - /* Find the EP address in the selected class table */ - for (idx = 0; idx < pdev->tclasslist[pdev->classId].NumEps; idx++) - { - if (((pdev->tclasslist[pdev->classId].Eps[idx].add & USBD_EP_IN) == ep_dir) && \ - (pdev->tclasslist[pdev->classId].Eps[idx].type == ep_type) && \ - (pdev->tclasslist[pdev->classId].Eps[idx].is_used != 0U)) - { - return (pdev->tclasslist[pdev->classId].Eps[idx].add); - } - } - - /* If reaching this point, then no endpoint was found */ - return 0xFFU; -} -#endif /* USE_USBD_COMPOSITE */ - -/** - * @brief USBD_GetEpDesc - * This function return the Endpoint descriptor - * @param pdev: device instance - * @param pConfDesc: pointer to Bos descriptor - * @param EpAddr: endpoint address - * @retval pointer to video endpoint descriptor - */ -void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr) -{ - USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc; - USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc; - USBD_EpDescTypeDef *pEpDesc = NULL; - uint16_t ptr; - - if (desc->wTotalLength > desc->bLength) - { - ptr = desc->bLength; - - while (ptr < desc->wTotalLength) - { - pdesc = USBD_GetNextDesc((uint8_t *)pdesc, &ptr); - - if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) - { - pEpDesc = (USBD_EpDescTypeDef *)(void *)pdesc; - - if (pEpDesc->bEndpointAddress == EpAddr) - { - break; - } - else - { - pEpDesc = NULL; - } - } - } - } - - return (void *)pEpDesc; -} - -/** - * @brief USBD_GetNextDesc - * This function return the next descriptor header - * @param buf: Buffer where the descriptor is available - * @param ptr: data pointer inside the descriptor - * @retval next header - */ -USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr) -{ - USBD_DescHeaderTypeDef *pnext = (USBD_DescHeaderTypeDef *)(void *)pbuf; - - *ptr += pnext->bLength; - pnext = (USBD_DescHeaderTypeDef *)(void *)(pbuf + pnext->bLength); - - return (pnext); -} - -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c b/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c deleted file mode 100644 index c733647..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c +++ /dev/null @@ -1,1051 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_req.c - * @author MCD Application Team - * @brief This file provides the standard USB requests following chapter 9. - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_ctlreq.h" -#include "usbd_ioreq.h" - -#ifdef USE_USBD_COMPOSITE -#include "usbd_composite_builder.h" -#endif /* USE_USBD_COMPOSITE */ - -/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup USBD_REQ - * @brief USB standard requests module - * @{ - */ - -/** @defgroup USBD_REQ_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_REQ_Private_Defines - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_REQ_Private_Macros - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_REQ_Private_Variables - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_REQ_Private_FunctionPrototypes - * @{ - */ -static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static uint8_t USBD_GetLen(uint8_t *buf); - -/** - * @} - */ - - -/** @defgroup USBD_REQ_Private_Functions - * @{ - */ - - -/** - * @brief USBD_StdDevReq - * Handle standard usb device requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_StatusTypeDef ret = USBD_OK; - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - ret = (USBD_StatusTypeDef)pdev->pClass[pdev->classId]->Setup(pdev, req); - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_DESCRIPTOR: - USBD_GetDescriptor(pdev, req); - break; - - case USB_REQ_SET_ADDRESS: - USBD_SetAddress(pdev, req); - break; - - case USB_REQ_SET_CONFIGURATION: - ret = USBD_SetConfig(pdev, req); - break; - - case USB_REQ_GET_CONFIGURATION: - USBD_GetConfig(pdev, req); - break; - - case USB_REQ_GET_STATUS: - USBD_GetStatus(pdev, req); - break; - - case USB_REQ_SET_FEATURE: - USBD_SetFeature(pdev, req); - break; - - case USB_REQ_CLEAR_FEATURE: - USBD_ClrFeature(pdev, req); - break; - - default: - USBD_CtlError(pdev, req); - break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } - - return ret; -} - -/** - * @brief USBD_StdItfReq - * Handle standard usb interface requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_StatusTypeDef ret = USBD_OK; - uint8_t idx; - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - case USB_REQ_TYPE_STANDARD: - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - - if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) - { - /* Get the class index relative to this interface */ - idx = USBD_CoreFindIF(pdev, LOBYTE(req->wIndex)); - if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) - { - /* Call the class data out function to manage the request */ - if (pdev->pClass[idx]->Setup != NULL) - { - pdev->classId = idx; - ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req)); - } - else - { - /* should never reach this condition */ - ret = USBD_FAIL; - } - } - else - { - /* No relative interface found */ - ret = USBD_FAIL; - } - - if ((req->wLength == 0U) && (ret == USBD_OK)) - { - (void)USBD_CtlSendStatus(pdev); - } - } - else - { - USBD_CtlError(pdev, req); - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } - - return ret; -} - -/** - * @brief USBD_StdEPReq - * Handle standard usb endpoint requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_EndpointTypeDef *pep; - uint8_t ep_addr; - uint8_t idx; - USBD_StatusTypeDef ret = USBD_OK; - - ep_addr = LOBYTE(req->wIndex); - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - /* Get the class index relative to this endpoint */ - idx = USBD_CoreFindEP(pdev, ep_addr); - if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) - { - pdev->classId = idx; - /* Call the class data out function to manage the request */ - if (pdev->pClass[idx]->Setup != NULL) - { - ret = (USBD_StatusTypeDef)pdev->pClass[idx]->Setup(pdev, req); - } - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_SET_FEATURE: - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - (void)USBD_LL_StallEP(pdev, ep_addr); - (void)USBD_LL_StallEP(pdev, 0x80U); - } - else - { - USBD_CtlError(pdev, req); - } - break; - - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_EP_HALT) - { - if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U)) - { - (void)USBD_LL_StallEP(pdev, ep_addr); - } - } - (void)USBD_CtlSendStatus(pdev); - - break; - - default: - USBD_CtlError(pdev, req); - break; - } - break; - - case USB_REQ_CLEAR_FEATURE: - - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - (void)USBD_LL_StallEP(pdev, ep_addr); - (void)USBD_LL_StallEP(pdev, 0x80U); - } - else - { - USBD_CtlError(pdev, req); - } - break; - - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_EP_HALT) - { - if ((ep_addr & 0x7FU) != 0x00U) - { - (void)USBD_LL_ClearStallEP(pdev, ep_addr); - } - (void)USBD_CtlSendStatus(pdev); - - /* Get the class index relative to this interface */ - idx = USBD_CoreFindEP(pdev, ep_addr); - if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) - { - pdev->classId = idx; - /* Call the class data out function to manage the request */ - if (pdev->pClass[idx]->Setup != NULL) - { - ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req)); - } - } - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } - break; - - case USB_REQ_GET_STATUS: - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - USBD_CtlError(pdev, req); - break; - } - pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \ - &pdev->ep_out[ep_addr & 0x7FU]; - - pep->status = 0x0000U; - - (void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U); - break; - - case USBD_STATE_CONFIGURED: - if ((ep_addr & 0x80U) == 0x80U) - { - if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U) - { - USBD_CtlError(pdev, req); - break; - } - } - else - { - if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U) - { - USBD_CtlError(pdev, req); - break; - } - } - - pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \ - &pdev->ep_out[ep_addr & 0x7FU]; - - if ((ep_addr == 0x00U) || (ep_addr == 0x80U)) - { - pep->status = 0x0000U; - } - else if (USBD_LL_IsStallEP(pdev, ep_addr) != 0U) - { - pep->status = 0x0001U; - } - else - { - pep->status = 0x0000U; - } - - (void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U); - break; - - default: - USBD_CtlError(pdev, req); - break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } - - return ret; -} - - -/** - * @brief USBD_GetDescriptor - * Handle Get Descriptor requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - uint16_t len = 0U; - uint8_t *pbuf = NULL; - uint8_t err = 0U; - - switch (req->wValue >> 8) - { -#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U)) - case USB_DESC_TYPE_BOS: - if (pdev->pDesc->GetBOSDescriptor != NULL) - { - pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; -#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U) */ - case USB_DESC_TYPE_DEVICE: - pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len); - break; - - case USB_DESC_TYPE_CONFIGURATION: - if (pdev->dev_speed == USBD_SPEED_HIGH) - { -#ifdef USE_USBD_COMPOSITE - if ((uint8_t)(pdev->NumClasses) > 0U) - { - pbuf = (uint8_t *)USBD_CMPSIT.GetHSConfigDescriptor(&len); - } - else -#endif /* USE_USBD_COMPOSITE */ - { - pbuf = (uint8_t *)pdev->pClass[0]->GetHSConfigDescriptor(&len); - } - pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - } - else - { -#ifdef USE_USBD_COMPOSITE - if ((uint8_t)(pdev->NumClasses) > 0U) - { - pbuf = (uint8_t *)USBD_CMPSIT.GetFSConfigDescriptor(&len); - } - else -#endif /* USE_USBD_COMPOSITE */ - { - pbuf = (uint8_t *)pdev->pClass[0]->GetFSConfigDescriptor(&len); - } - pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - } - break; - - case USB_DESC_TYPE_STRING: - switch ((uint8_t)(req->wValue)) - { - case USBD_IDX_LANGID_STR: - if (pdev->pDesc->GetLangIDStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - case USBD_IDX_MFC_STR: - if (pdev->pDesc->GetManufacturerStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - case USBD_IDX_PRODUCT_STR: - if (pdev->pDesc->GetProductStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - case USBD_IDX_SERIAL_STR: - if (pdev->pDesc->GetSerialStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - case USBD_IDX_CONFIG_STR: - if (pdev->pDesc->GetConfigurationStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - case USBD_IDX_INTERFACE_STR: - if (pdev->pDesc->GetInterfaceStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - default: -#if (USBD_SUPPORT_USER_STRING_DESC == 1U) - pbuf = NULL; - - - for (uint32_t idx = 0U; (idx < pdev->NumClasses); idx++) - { - if (pdev->pClass[idx]->GetUsrStrDescriptor != NULL) - { - pdev->classId = idx; - pbuf = pdev->pClass[idx]->GetUsrStrDescriptor(pdev, LOBYTE(req->wValue), &len); - - if (pbuf == NULL) /* This means that no class recognized the string index */ - { - continue; - } - else - { - break; - } - } - } - -#endif /* USBD_SUPPORT_USER_STRING_DESC */ - -#if (USBD_CLASS_USER_STRING_DESC == 1U) - if (pdev->pDesc->GetUserStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, (req->wValue), &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } -#endif /* USBD_SUPPORT_USER_STRING_DESC */ - -#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U)) - USBD_CtlError(pdev, req); - err++; -#endif /* (USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U) */ - break; - } - break; - - case USB_DESC_TYPE_DEVICE_QUALIFIER: - if (pdev->dev_speed == USBD_SPEED_HIGH) - { -#ifdef USE_USBD_COMPOSITE - if ((uint8_t)(pdev->NumClasses) > 0U) - { - pbuf = (uint8_t *)USBD_CMPSIT.GetDeviceQualifierDescriptor(&len); - } - else -#endif /* USE_USBD_COMPOSITE */ - { - pbuf = (uint8_t *)pdev->pClass[0]->GetDeviceQualifierDescriptor(&len); - } - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: - if (pdev->dev_speed == USBD_SPEED_HIGH) - { -#ifdef USE_USBD_COMPOSITE - if ((uint8_t)(pdev->NumClasses) > 0U) - { - pbuf = (uint8_t *)USBD_CMPSIT.GetOtherSpeedConfigDescriptor(&len); - } - else -#endif /* USE_USBD_COMPOSITE */ - { - pbuf = (uint8_t *)pdev->pClass[0]->GetOtherSpeedConfigDescriptor(&len); - } - pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; - - default: - USBD_CtlError(pdev, req); - err++; - break; - } - - if (err != 0U) - { - return; - } - - if (req->wLength != 0U) - { - if (len != 0U) - { - len = MIN(len, req->wLength); - (void)USBD_CtlSendData(pdev, pbuf, len); - } - else - { - USBD_CtlError(pdev, req); - } - } - else - { - (void)USBD_CtlSendStatus(pdev); - } -} - - -/** - * @brief USBD_SetAddress - * Set device address - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - uint8_t dev_addr; - - if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U)) - { - dev_addr = (uint8_t)(req->wValue) & 0x7FU; - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlError(pdev, req); - } - else - { - pdev->dev_address = dev_addr; - (void)USBD_LL_SetUSBAddress(pdev, dev_addr); - (void)USBD_CtlSendStatus(pdev); - - if (dev_addr != 0U) - { - pdev->dev_state = USBD_STATE_ADDRESSED; - } - else - { - pdev->dev_state = USBD_STATE_DEFAULT; - } - } - } - else - { - USBD_CtlError(pdev, req); - } -} - -/** - * @brief USBD_SetConfig - * Handle Set device configuration request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_StatusTypeDef ret = USBD_OK; - static uint8_t cfgidx; - - cfgidx = (uint8_t)(req->wValue); - - if (cfgidx > USBD_MAX_NUM_CONFIGURATION) - { - USBD_CtlError(pdev, req); - return USBD_FAIL; - } - - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if (cfgidx != 0U) - { - pdev->dev_config = cfgidx; - - ret = USBD_SetClassConfig(pdev, cfgidx); - - if (ret != USBD_OK) - { - USBD_CtlError(pdev, req); - pdev->dev_state = USBD_STATE_ADDRESSED; - } - else - { - (void)USBD_CtlSendStatus(pdev); - pdev->dev_state = USBD_STATE_CONFIGURED; - } - } - else - { - (void)USBD_CtlSendStatus(pdev); - } - break; - - case USBD_STATE_CONFIGURED: - if (cfgidx == 0U) - { - pdev->dev_state = USBD_STATE_ADDRESSED; - pdev->dev_config = cfgidx; - (void)USBD_ClrClassConfig(pdev, cfgidx); - (void)USBD_CtlSendStatus(pdev); - } - else if (cfgidx != pdev->dev_config) - { - /* Clear old configuration */ - (void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config); - - /* set new configuration */ - pdev->dev_config = cfgidx; - - ret = USBD_SetClassConfig(pdev, cfgidx); - - if (ret != USBD_OK) - { - USBD_CtlError(pdev, req); - (void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config); - pdev->dev_state = USBD_STATE_ADDRESSED; - } - else - { - (void)USBD_CtlSendStatus(pdev); - } - } - else - { - (void)USBD_CtlSendStatus(pdev); - } - break; - - default: - USBD_CtlError(pdev, req); - (void)USBD_ClrClassConfig(pdev, cfgidx); - ret = USBD_FAIL; - break; - } - - return ret; -} - -/** - * @brief USBD_GetConfig - * Handle Get device configuration request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - if (req->wLength != 1U) - { - USBD_CtlError(pdev, req); - } - else - { - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - pdev->dev_default_config = 0U; - (void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_default_config, 1U); - break; - - case USBD_STATE_CONFIGURED: - (void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_config, 1U); - break; - - default: - USBD_CtlError(pdev, req); - break; - } - } -} - -/** - * @brief USBD_GetStatus - * Handle Get Status request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - if (req->wLength != 0x2U) - { - USBD_CtlError(pdev, req); - break; - } - -#if (USBD_SELF_POWERED == 1U) - pdev->dev_config_status = USB_CONFIG_SELF_POWERED; -#else - pdev->dev_config_status = 0U; -#endif /* USBD_SELF_POWERED */ - - if (pdev->dev_remote_wakeup != 0U) - { - pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; - } - - (void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_config_status, 2U); - break; - - default: - USBD_CtlError(pdev, req); - break; - } -} - - -/** - * @brief USBD_SetFeature - * Handle Set device feature request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - pdev->dev_remote_wakeup = 1U; - (void)USBD_CtlSendStatus(pdev); - } - else if (req->wValue == USB_FEATURE_TEST_MODE) - { - pdev->dev_test_mode = req->wIndex >> 8; - (void)USBD_CtlSendStatus(pdev); - } - else - { - USBD_CtlError(pdev, req); - } -} - - -/** - * @brief USBD_ClrFeature - * Handle clear device feature request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - pdev->dev_remote_wakeup = 0U; - (void)USBD_CtlSendStatus(pdev); - } - break; - - default: - USBD_CtlError(pdev, req); - break; - } -} - - -/** - * @brief USBD_ParseSetupRequest - * Copy buffer into setup structure - * @param pdev: device instance - * @param req: usb request - * @retval None - */ -void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata) -{ - uint8_t *pbuff = pdata; - - req->bmRequest = *(uint8_t *)(pbuff); - - pbuff++; - req->bRequest = *(uint8_t *)(pbuff); - - pbuff++; - req->wValue = SWAPBYTE(pbuff); - - pbuff++; - pbuff++; - req->wIndex = SWAPBYTE(pbuff); - - pbuff++; - pbuff++; - req->wLength = SWAPBYTE(pbuff); -} - - -/** - * @brief USBD_CtlError - * Handle USB low level Error - * @param pdev: device instance - * @param req: usb request - * @retval None - */ -void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - UNUSED(req); - - (void)USBD_LL_StallEP(pdev, 0x80U); - (void)USBD_LL_StallEP(pdev, 0U); -} - - -/** - * @brief USBD_GetString - * Convert Ascii string into unicode one - * @param desc : descriptor buffer - * @param unicode : Formatted string buffer (unicode) - * @param len : descriptor length - * @retval None - */ -void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) -{ - uint8_t idx = 0U; - uint8_t *pdesc; - - if (desc == NULL) - { - return; - } - - pdesc = desc; - *len = ((uint16_t)USBD_GetLen(pdesc) * 2U) + 2U; - - unicode[idx] = *(uint8_t *)len; - idx++; - unicode[idx] = USB_DESC_TYPE_STRING; - idx++; - - while (*pdesc != (uint8_t)'\0') - { - unicode[idx] = *pdesc; - pdesc++; - idx++; - - unicode[idx] = 0U; - idx++; - } -} - - -/** - * @brief USBD_GetLen - * return the string length - * @param buf : pointer to the ascii string buffer - * @retval string length - */ -static uint8_t USBD_GetLen(uint8_t *buf) -{ - uint8_t len = 0U; - uint8_t *pbuff = buf; - - while (*pbuff != (uint8_t)'\0') - { - len++; - pbuff++; - } - - return len; -} -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c b/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c deleted file mode 100644 index 7c8004a..0000000 --- a/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c +++ /dev/null @@ -1,224 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_ioreq.c - * @author MCD Application Team - * @brief This file provides the IO requests APIs for control endpoints. - ****************************************************************************** - * @attention - * - * Copyright (c) 2015 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_ioreq.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - -/** @defgroup USBD_IOREQ - * @brief control I/O requests module - * @{ - */ - -/** @defgroup USBD_IOREQ_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_IOREQ_Private_Defines - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_IOREQ_Private_Macros - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_IOREQ_Private_Variables - * @{ - */ - -/** - * @} - */ - - -/** @defgroup USBD_IOREQ_Private_FunctionPrototypes - * @{ - */ -/** - * @} - */ - - -/** @defgroup USBD_IOREQ_Private_Functions - * @{ - */ - -/** - * @brief USBD_CtlSendData - * send data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be sent - * @retval status - */ -USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_DATA_IN; - pdev->ep_in[0].total_length = len; - -#ifdef USBD_AVOID_PACKET_SPLIT_MPS - pdev->ep_in[0].rem_length = 0U; -#else - pdev->ep_in[0].rem_length = len; -#endif /* USBD_AVOID_PACKET_SPLIT_MPS */ - - /* Start the transfer */ - (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlContinueSendData - * continue sending data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be sent - * @retval status - */ -USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len) -{ - /* Start the next transfer */ - (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlPrepareRx - * receive data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be received - * @retval status - */ -USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_DATA_OUT; - pdev->ep_out[0].total_length = len; - -#ifdef USBD_AVOID_PACKET_SPLIT_MPS - pdev->ep_out[0].rem_length = 0U; -#else - pdev->ep_out[0].rem_length = len; -#endif /* USBD_AVOID_PACKET_SPLIT_MPS */ - - /* Start the transfer */ - (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlContinueRx - * continue receive data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be received - * @retval status - */ -USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint32_t len) -{ - (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlSendStatus - * send zero lzngth packet on the ctl pipe - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_STATUS_IN; - - /* Start the transfer */ - (void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); - - return USBD_OK; -} - -/** - * @brief USBD_CtlReceiveStatus - * receive zero lzngth packet on the ctl pipe - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_STATUS_OUT; - - /* Start the transfer */ - (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); - - return USBD_OK; -} - -/** - * @brief USBD_GetRxCount - * returns the received data length - * @param pdev: device instance - * @param ep_addr: endpoint address - * @retval Rx Data blength - */ -uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - return USBD_LL_GetRxDataSize(pdev, ep_addr); -} - -/** - * @} - */ - - -/** - * @} - */ - - -/** - * @} - */ - diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/port.c b/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/port.c new file mode 100644 index 0000000..5a8572f --- /dev/null +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/port.c @@ -0,0 +1,656 @@ +/* + * FreeRTOS Kernel V10.3.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/*----------------------------------------------------------- + * Implementation of functions defined in portable.h for the ARM CM4F port. + *----------------------------------------------------------*/ + +/* IAR includes. */ +#include + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +#ifndef __ARMVFP__ + #error This port can only be used when the project options are configured to enable hardware floating point support. +#endif + +#if( configMAX_SYSCALL_INTERRUPT_PRIORITY == 0 ) + #error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html +#endif + +#ifndef configSYSTICK_CLOCK_HZ + #define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ + /* Ensure the SysTick is clocked at the same frequency as the core. */ + #define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL ) +#else + /* The way the SysTick is clocked is not modified in case it is not the same + as the core. */ + #define portNVIC_SYSTICK_CLK_BIT ( 0 ) +#endif + +/* Constants required to manipulate the core. Registers first... */ +#define portNVIC_SYSTICK_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000e010 ) ) +#define portNVIC_SYSTICK_LOAD_REG ( * ( ( volatile uint32_t * ) 0xe000e014 ) ) +#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) ) +#define portNVIC_SYSPRI2_REG ( * ( ( volatile uint32_t * ) 0xe000ed20 ) ) +/* ...then bits in the registers. */ +#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL ) +#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL ) +#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL ) +#define portNVIC_PENDSVCLEAR_BIT ( 1UL << 27UL ) +#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL ) + +/* Constants used to detect a Cortex-M7 r0p1 core, which should use the ARM_CM7 +r0p1 port. */ +#define portCPUID ( * ( ( volatile uint32_t * ) 0xE000ed00 ) ) +#define portCORTEX_M7_r0p1_ID ( 0x410FC271UL ) +#define portCORTEX_M7_r0p0_ID ( 0x410FC270UL ) + +#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL ) +#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL ) + +/* Constants required to check the validity of an interrupt priority. */ +#define portFIRST_USER_INTERRUPT_NUMBER ( 16 ) +#define portNVIC_IP_REGISTERS_OFFSET_16 ( 0xE000E3F0 ) +#define portAIRCR_REG ( * ( ( volatile uint32_t * ) 0xE000ED0C ) ) +#define portMAX_8_BIT_VALUE ( ( uint8_t ) 0xff ) +#define portTOP_BIT_OF_BYTE ( ( uint8_t ) 0x80 ) +#define portMAX_PRIGROUP_BITS ( ( uint8_t ) 7 ) +#define portPRIORITY_GROUP_MASK ( 0x07UL << 8UL ) +#define portPRIGROUP_SHIFT ( 8UL ) + +/* Masks off all bits but the VECTACTIVE bits in the ICSR register. */ +#define portVECTACTIVE_MASK ( 0xFFUL ) + +/* Constants required to manipulate the VFP. */ +#define portFPCCR ( ( volatile uint32_t * ) 0xe000ef34 ) /* Floating point context control register. */ +#define portASPEN_AND_LSPEN_BITS ( 0x3UL << 30UL ) + +/* Constants required to set up the initial stack. */ +#define portINITIAL_XPSR ( 0x01000000 ) +#define portINITIAL_EXC_RETURN ( 0xfffffffd ) + +/* The systick is a 24-bit counter. */ +#define portMAX_24_BIT_NUMBER ( 0xffffffUL ) + +/* A fiddle factor to estimate the number of SysTick counts that would have +occurred while the SysTick counter is stopped during tickless idle +calculations. */ +#define portMISSED_COUNTS_FACTOR ( 45UL ) + +/* For strict compliance with the Cortex-M spec the task start address should +have bit-0 clear, as it is loaded into the PC on exit from an ISR. */ +#define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL ) + +/* + * Setup the timer to generate the tick interrupts. The implementation in this + * file is weak to allow application writers to change the timer used to + * generate the tick interrupt. + */ +void vPortSetupTimerInterrupt( void ); + +/* + * Exception handlers. + */ +void xPortSysTickHandler( void ); + +/* + * Start first task is a separate function so it can be tested in isolation. + */ +extern void vPortStartFirstTask( void ); + +/* + * Turn the VFP on. + */ +extern void vPortEnableVFP( void ); + +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + +/*-----------------------------------------------------------*/ + +/* Each task maintains its own interrupt status in the critical nesting +variable. */ +static UBaseType_t uxCriticalNesting = 0xaaaaaaaa; + +/* + * The number of SysTick increments that make up one tick period. + */ +#if( configUSE_TICKLESS_IDLE == 1 ) + static uint32_t ulTimerCountsForOneTick = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * The maximum number of tick periods that can be suppressed is limited by the + * 24 bit resolution of the SysTick timer. + */ +#if( configUSE_TICKLESS_IDLE == 1 ) + static uint32_t xMaximumPossibleSuppressedTicks = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * Compensate for the CPU cycles that pass while the SysTick is stopped (low + * power functionality only. + */ +#if( configUSE_TICKLESS_IDLE == 1 ) + static uint32_t ulStoppedTimerCompensation = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure + * FreeRTOS API functions are not called from interrupts that have been assigned + * a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY. + */ +#if( configASSERT_DEFINED == 1 ) + static uint8_t ucMaxSysCallPriority = 0; + static uint32_t ulMaxPRIGROUPValue = 0; + static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * const ) portNVIC_IP_REGISTERS_OFFSET_16; +#endif /* configASSERT_DEFINED */ + +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) +{ + /* Simulate the stack frame as it would be created by a context switch + interrupt. */ + + /* Offset added to account for the way the MCU uses the stack on entry/exit + of interrupts, and to ensure alignment. */ + pxTopOfStack--; + + *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ + pxTopOfStack--; + *pxTopOfStack = ( ( StackType_t ) pxCode ) & portSTART_ADDRESS_MASK; /* PC */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) prvTaskExitError; /* LR */ + + /* Save code space by skipping register initialisation. */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ + *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ + + /* A save method is being used that requires each task to maintain its + own exec return value. */ + pxTopOfStack--; + *pxTopOfStack = portINITIAL_EXC_RETURN; + + pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */ + + return pxTopOfStack; +} +/*-----------------------------------------------------------*/ + +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + its caller as there is nothing to return to. If a task wants to exit it + should instead call vTaskDelete( NULL ). + + Artificially force an assert() to be triggered if configASSERT() is + defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + for( ;; ); +} +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +BaseType_t xPortStartScheduler( void ) +{ + /* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. + See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + configASSERT( configMAX_SYSCALL_INTERRUPT_PRIORITY ); + + /* This port can be used on all revisions of the Cortex-M7 core other than + the r0p1 parts. r0p1 parts should use the port from the + /source/portable/GCC/ARM_CM7/r0p1 directory. */ + configASSERT( portCPUID != portCORTEX_M7_r0p1_ID ); + configASSERT( portCPUID != portCORTEX_M7_r0p0_ID ); + + #if( configASSERT_DEFINED == 1 ) + { + volatile uint32_t ulOriginalPriority; + volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER ); + volatile uint8_t ucMaxPriorityValue; + + /* Determine the maximum priority from which ISR safe FreeRTOS API + functions can be called. ISR safe functions are those that end in + "FromISR". FreeRTOS maintains separate thread and ISR API functions to + ensure interrupt entry is as fast and simple as possible. + + Save the interrupt priority value that is about to be clobbered. */ + ulOriginalPriority = *pucFirstUserPriorityRegister; + + /* Determine the number of priority bits available. First write to all + possible bits. */ + *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE; + + /* Read the value back to see how many bits stuck. */ + ucMaxPriorityValue = *pucFirstUserPriorityRegister; + + /* Use the same mask on the maximum system call priority. */ + ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue; + + /* Calculate the maximum acceptable priority group value for the number + of bits read back. */ + ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS; + while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE ) + { + ulMaxPRIGROUPValue--; + ucMaxPriorityValue <<= ( uint8_t ) 0x01; + } + + #ifdef __NVIC_PRIO_BITS + { + /* Check the CMSIS configuration that defines the number of + priority bits matches the number of priority bits actually queried + from the hardware. */ + configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == __NVIC_PRIO_BITS ); + } + #endif + + #ifdef configPRIO_BITS + { + /* Check the FreeRTOS configuration that defines the number of + priority bits matches the number of priority bits actually queried + from the hardware. */ + configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == configPRIO_BITS ); + } + #endif + + /* Shift the priority group value back to its position within the AIRCR + register. */ + ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT; + ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK; + + /* Restore the clobbered interrupt priority register to its original + value. */ + *pucFirstUserPriorityRegister = ulOriginalPriority; + } + #endif /* conifgASSERT_DEFINED */ + + /* Make PendSV and SysTick the lowest priority interrupts. */ + portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI; + portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI; + + /* Start the timer that generates the tick ISR. Interrupts are disabled + here already. */ + vPortSetupTimerInterrupt(); + + /* Initialise the critical nesting count ready for the first task. */ + uxCriticalNesting = 0; + + /* Ensure the VFP is enabled - it should be anyway. */ + vPortEnableVFP(); + + /* Lazy save always. */ + *( portFPCCR ) |= portASPEN_AND_LSPEN_BITS; + + /* Start the first task. */ + vPortStartFirstTask(); + + /* Should not get here! */ + return 0; +} +/*-----------------------------------------------------------*/ + +void vPortEndScheduler( void ) +{ + /* Not implemented in ports where there is nothing to return to. + Artificially force an assert. */ + configASSERT( uxCriticalNesting == 1000UL ); +} +/*-----------------------------------------------------------*/ + +void vPortEnterCritical( void ) +{ + portDISABLE_INTERRUPTS(); + uxCriticalNesting++; + + /* This is not the interrupt safe version of the enter critical function so + assert() if it is being called from an interrupt context. Only API + functions that end in "FromISR" can be used in an interrupt. Only assert if + the critical nesting count is 1 to protect against recursive calls if the + assert function also uses a critical section. */ + if( uxCriticalNesting == 1 ) + { + configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 ); + } +} +/*-----------------------------------------------------------*/ + +void vPortExitCritical( void ) +{ + configASSERT( uxCriticalNesting ); + uxCriticalNesting--; + if( uxCriticalNesting == 0 ) + { + portENABLE_INTERRUPTS(); + } +} +/*-----------------------------------------------------------*/ + +void xPortSysTickHandler( void ) +{ + /* The SysTick runs at the lowest interrupt priority, so when this interrupt + executes all interrupts must be unmasked. There is therefore no need to + save and then restore the interrupt mask value as its value is already + known. */ + portDISABLE_INTERRUPTS(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { + /* A context switch is required. Context switching is performed in + the PendSV interrupt. Pend the PendSV interrupt. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; + } + } + portENABLE_INTERRUPTS(); +} +/*-----------------------------------------------------------*/ + +#if( configUSE_TICKLESS_IDLE == 1 ) + + __weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) + { + uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements; + TickType_t xModifiableIdleTime; + + /* Make sure the SysTick reload value does not overflow the counter. */ + if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks ) + { + xExpectedIdleTime = xMaximumPossibleSuppressedTicks; + } + + /* Stop the SysTick momentarily. The time the SysTick is stopped for + is accounted for as best it can be, but using the tickless mode will + inevitably result in some tiny drift of the time maintained by the + kernel with respect to calendar time. */ + portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT; + + /* Calculate the reload value required to wait xExpectedIdleTime + tick periods. -1 is used because this code will execute part way + through one of the tick periods. */ + ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) ); + if( ulReloadValue > ulStoppedTimerCompensation ) + { + ulReloadValue -= ulStoppedTimerCompensation; + } + + /* Enter a critical section but don't use the taskENTER_CRITICAL() + method as that will mask interrupts that should exit sleep mode. */ + __disable_interrupt(); + __DSB(); + __ISB(); + + /* If a context switch is pending or a task is waiting for the scheduler + to be unsuspended then abandon the low power entry. */ + if( eTaskConfirmSleepModeStatus() == eAbortSleep ) + { + /* Restart from whatever is left in the count register to complete + this tick period. */ + portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; + + /* Reset the reload register to the value required for normal tick + periods. */ + portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL; + + /* Re-enable interrupts - see comments above __disable_interrupt() + call above. */ + __enable_interrupt(); + } + else + { + /* Set the new reload value. */ + portNVIC_SYSTICK_LOAD_REG = ulReloadValue; + + /* Clear the SysTick count flag and set the count value back to + zero. */ + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; + + /* Sleep until something happens. configPRE_SLEEP_PROCESSING() can + set its parameter to 0 to indicate that its implementation contains + its own wait for interrupt or wait for event instruction, and so wfi + should not be executed again. However, the original expected idle + time variable must remain unmodified, so a copy is taken. */ + xModifiableIdleTime = xExpectedIdleTime; + configPRE_SLEEP_PROCESSING( xModifiableIdleTime ); + if( xModifiableIdleTime > 0 ) + { + __DSB(); + __WFI(); + __ISB(); + } + configPOST_SLEEP_PROCESSING( xExpectedIdleTime ); + + /* Re-enable interrupts to allow the interrupt that brought the MCU + out of sleep mode to execute immediately. see comments above + __disable_interrupt() call above. */ + __enable_interrupt(); + __DSB(); + __ISB(); + + /* Disable interrupts again because the clock is about to be stopped + and interrupts that execute while the clock is stopped will increase + any slippage between the time maintained by the RTOS and calendar + time. */ + __disable_interrupt(); + __DSB(); + __ISB(); + + /* Disable the SysTick clock without reading the + portNVIC_SYSTICK_CTRL_REG register to ensure the + portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again, + the time the SysTick is stopped for is accounted for as best it can + be, but using the tickless mode will inevitably result in some tiny + drift of the time maintained by the kernel with respect to calendar + time*/ + portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT ); + + /* Determine if the SysTick clock has already counted to zero and + been set back to the current reload value (the reload back being + correct for the entire expected idle time) or if the SysTick is yet + to count to zero (in which case an interrupt other than the SysTick + must have brought the system out of sleep mode). */ + if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 ) + { + uint32_t ulCalculatedLoadValue; + + /* The tick interrupt is already pending, and the SysTick count + reloaded with ulReloadValue. Reset the + portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick + period. */ + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG ); + + /* Don't allow a tiny value, or values that have somehow + underflowed because the post sleep hook did something + that took too long. */ + if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) ) + { + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ); + } + + portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue; + + /* As the pending tick will be processed as soon as this + function exits, the tick value maintained by the tick is stepped + forward by one less than the time spent waiting. */ + ulCompleteTickPeriods = xExpectedIdleTime - 1UL; + } + else + { + /* Something other than the tick interrupt ended the sleep. + Work out how long the sleep lasted rounded to complete tick + periods (not the ulReload value which accounted for part + ticks). */ + ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG; + + /* How many complete tick periods passed while the processor + was waiting? */ + ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick; + + /* The reload value is set to whatever fraction of a single tick + period remains. */ + portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements; + } + + /* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG + again, then set portNVIC_SYSTICK_LOAD_REG back to its standard + value. */ + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; + vTaskStepTick( ulCompleteTickPeriods ); + portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL; + + /* Exit with interrupts enabled. */ + __enable_interrupt(); + } + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*-----------------------------------------------------------*/ + +/* + * Setup the systick timer to generate the tick interrupts at the required + * frequency. + */ +__weak void vPortSetupTimerInterrupt( void ) +{ + /* Calculate the constants required to configure the tick interrupt. */ + #if( configUSE_TICKLESS_IDLE == 1 ) + { + ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ); + xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; + ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ); + } + #endif /* configUSE_TICKLESS_IDLE */ + + /* Stop and clear the SysTick. */ + portNVIC_SYSTICK_CTRL_REG = 0UL; + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + + /* Configure SysTick to interrupt at the requested rate. */ + portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; + portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ); +} +/*-----------------------------------------------------------*/ + +#if( configASSERT_DEFINED == 1 ) + + void vPortValidateInterruptPriority( void ) + { + uint32_t ulCurrentInterrupt; + uint8_t ucCurrentPriority; + + /* Obtain the number of the currently executing interrupt. */ + __asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" ); + + /* Is the interrupt number a user defined interrupt? */ + if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER ) + { + /* Look up the interrupt's priority. */ + ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ]; + + /* The following assertion will fail if a service routine (ISR) for + an interrupt that has been assigned a priority above + configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API + function. ISR safe FreeRTOS API functions must *only* be called + from interrupts that have been assigned a priority at or below + configMAX_SYSCALL_INTERRUPT_PRIORITY. + + Numerically low interrupt priority numbers represent logically high + interrupt priorities, therefore the priority of the interrupt must + be set to a value equal to or numerically *higher* than + configMAX_SYSCALL_INTERRUPT_PRIORITY. + + Interrupts that use the FreeRTOS API must not be left at their + default priority of zero as that is the highest possible priority, + which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY, + and therefore also guaranteed to be invalid. + + FreeRTOS maintains separate thread and ISR API functions to ensure + interrupt entry is as fast and simple as possible. + + The following links provide detailed information: + http://www.freertos.org/RTOS-Cortex-M3-M4.html + http://www.freertos.org/FAQHelp.html */ + configASSERT( ucCurrentPriority >= ucMaxSysCallPriority ); + } + + /* Priority grouping: The interrupt controller (NVIC) allows the bits + that define each interrupt's priority to be split between bits that + define the interrupt's pre-emption priority bits and bits that define + the interrupt's sub-priority. For simplicity all bits must be defined + to be pre-emption priority bits. The following assertion will fail if + this is not the case (if some bits represent a sub-priority). + + If the application only uses CMSIS libraries for interrupt + configuration then the correct setting can be achieved on all Cortex-M + devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the + scheduler. Note however that some vendor specific peripheral libraries + assume a non-zero priority group setting, in which cases using a value + of zero will result in unpredictable behaviour. */ + configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue ); + } + +#endif /* configASSERT_DEFINED */ + + + + + + + + + + + + + + + + + + + + + diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/portasm.s b/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/portasm.s new file mode 100644 index 0000000..ff37a2a --- /dev/null +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/portasm.s @@ -0,0 +1,149 @@ +/* + * FreeRTOS Kernel V10.3.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#include + + RSEG CODE:CODE(2) + thumb + + EXTERN pxCurrentTCB + EXTERN vTaskSwitchContext + + PUBLIC xPortPendSVHandler + PUBLIC vPortSVCHandler + PUBLIC vPortStartFirstTask + PUBLIC vPortEnableVFP + + +/*-----------------------------------------------------------*/ + +xPortPendSVHandler: + mrs r0, psp + isb + /* Get the location of the current TCB. */ + ldr r3, =pxCurrentTCB + ldr r2, [r3] + + /* Is the task using the FPU context? If so, push high vfp registers. */ + tst r14, #0x10 + it eq + vstmdbeq r0!, {s16-s31} + + /* Save the core registers. */ + stmdb r0!, {r4-r11, r14} + + /* Save the new top of stack into the first member of the TCB. */ + str r0, [r2] + + stmdb sp!, {r0, r3} + mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY + msr basepri, r0 + dsb + isb + bl vTaskSwitchContext + mov r0, #0 + msr basepri, r0 + ldmia sp!, {r0, r3} + + /* The first item in pxCurrentTCB is the task top of stack. */ + ldr r1, [r3] + ldr r0, [r1] + + /* Pop the core registers. */ + ldmia r0!, {r4-r11, r14} + + /* Is the task using the FPU context? If so, pop the high vfp registers + too. */ + tst r14, #0x10 + it eq + vldmiaeq r0!, {s16-s31} + + msr psp, r0 + isb + #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata */ + #if WORKAROUND_PMU_CM001 == 1 + push { r14 } + pop { pc } + #endif + #endif + + bx r14 + + +/*-----------------------------------------------------------*/ + +vPortSVCHandler: + /* Get the location of the current TCB. */ + ldr r3, =pxCurrentTCB + ldr r1, [r3] + ldr r0, [r1] + /* Pop the core registers. */ + ldmia r0!, {r4-r11, r14} + msr psp, r0 + isb + mov r0, #0 + msr basepri, r0 + bx r14 + +/*-----------------------------------------------------------*/ + +vPortStartFirstTask + /* Use the NVIC offset register to locate the stack. */ + ldr r0, =0xE000ED08 + ldr r0, [r0] + ldr r0, [r0] + /* Set the msp back to the start of the stack. */ + msr msp, r0 + /* Clear the bit that indicates the FPU is in use in case the FPU was used + before the scheduler was started - which would otherwise result in the + unnecessary leaving of space in the SVC stack for lazy saving of FPU + registers. */ + mov r0, #0 + msr control, r0 + /* Call SVC to start the first task. */ + cpsie i + cpsie f + dsb + isb + svc 0 + +/*-----------------------------------------------------------*/ + +vPortEnableVFP: + /* The FPU enable bits are in the CPACR. */ + ldr.w r0, =0xE000ED88 + ldr r1, [r0] + + /* Enable CP10 and CP11 coprocessors, then save back. */ + orr r1, r1, #( 0xf << 20 ) + str r1, [r0] + bx r14 + + + + END + diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/portmacro.h b/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/portmacro.h new file mode 100644 index 0000000..339e6f6 --- /dev/null +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/IAR/ARM_CM4F/portmacro.h @@ -0,0 +1,207 @@ +/* + * FreeRTOS Kernel V10.3.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef PORTMACRO_H +#define PORTMACRO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * Port specific definitions. + * + * The settings in this file configure FreeRTOS correctly for the + * given hardware and compiler. + * + * These settings should not be altered. + *----------------------------------------------------------- + */ + +/* IAR includes. */ +#include + +/* Type definitions. */ +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE uint32_t +#define portBASE_TYPE long + +typedef portSTACK_TYPE StackType_t; +typedef long BaseType_t; +typedef unsigned long UBaseType_t; + +#if( configUSE_16_BIT_TICKS == 1 ) + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff +#else + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL + + /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do + not need to be guarded with a critical section. */ + #define portTICK_TYPE_IS_ATOMIC 1 +#endif +/*-----------------------------------------------------------*/ + +/* Architecture specifics. */ +#define portSTACK_GROWTH ( -1 ) +#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) +#define portBYTE_ALIGNMENT 8 +/*-----------------------------------------------------------*/ + +/* Compiler directives. */ +#define portWEAK_SYMBOL __attribute__( ( weak ) ) + +/*-----------------------------------------------------------*/ + + +/* Scheduler utilities. */ +#define portYIELD() \ +{ \ + /* Set a PendSV to request a context switch. */ \ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \ + __DSB(); \ + __ISB(); \ +} + +#define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) +#define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) +#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() +#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) + +/*-----------------------------------------------------------*/ + +/* Architecture specific optimisations. */ +#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#endif + +#if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 ) + + /* Check the configuration. */ + #if( configMAX_PRIORITIES > 32 ) + #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. + #endif + + /* Store/clear the ready priorities in a bit map. */ + #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) + #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) + + /*-----------------------------------------------------------*/ + + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( ( uint32_t ) __CLZ( ( uxReadyPriorities ) ) ) ) + +#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ +/*-----------------------------------------------------------*/ + +/* Critical section management. */ +extern void vPortEnterCritical( void ); +extern void vPortExitCritical( void ); + +#define portDISABLE_INTERRUPTS() \ +{ \ + __set_BASEPRI( configMAX_SYSCALL_INTERRUPT_PRIORITY ); \ + __DSB(); \ + __ISB(); \ +} + +#define portENABLE_INTERRUPTS() __set_BASEPRI( 0 ) +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() +#define portSET_INTERRUPT_MASK_FROM_ISR() __get_BASEPRI(); portDISABLE_INTERRUPTS() +#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) __set_BASEPRI( x ) +/*-----------------------------------------------------------*/ + +/* Tickless idle/low power functionality. */ +#ifndef portSUPPRESS_TICKS_AND_SLEEP + extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) +#endif + +/*-----------------------------------------------------------*/ + +/* Task function macros as described on the FreeRTOS.org WEB site. These are +not necessary for to use this port. They are defined so the common demo files +(which build with all the ports) will build. */ +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) +/*-----------------------------------------------------------*/ + +#ifdef configASSERT + void vPortValidateInterruptPriority( void ); + #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority() +#endif + +/* portNOP() is not required by this port. */ +#define portNOP() + +#define portINLINE __inline + +#ifndef portFORCE_INLINE + #define portFORCE_INLINE inline __attribute__(( always_inline)) +#endif + +/*-----------------------------------------------------------*/ + +portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void ) +{ +uint32_t ulCurrentInterrupt; +BaseType_t xReturn; + + /* Obtain the number of the currently executing interrupt. */ + __asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" ); + + if( ulCurrentInterrupt == 0 ) + { + xReturn = pdFALSE; + } + else + { + xReturn = pdTRUE; + } + + return xReturn; +} + +/*-----------------------------------------------------------*/ + +/* Suppress warnings that are generated by the IAR tools, but cannot be fixed in +the source code because to do so would cause other compilers to generate +warnings. */ +#pragma diag_suppress=Pe191 +#pragma diag_suppress=Pa082 + +#ifdef __cplusplus +} +#endif + +#endif /* PORTMACRO_H */ + diff --git a/MyMakefile.mk b/MyMakefile.mk index acd67bd..ba90b68 100644 --- a/MyMakefile.mk +++ b/MyMakefile.mk @@ -4,14 +4,12 @@ ####################################### Easylogger := ON - MODBUS := ON # MODBUS_ASII := OFF # MODBUS_IP := OFF LVGL_On_Off := OFF - -FPU_OnOff := OFF +FPU_OnOff := ON ####################################### # 中文编码支持 @@ -24,8 +22,8 @@ C_DEFS += -DUSE_USB_HS # C_DEFS += -D__TARGET_FPU_VFP -DARM_MATH_CM4 # C_DEFS += -D__TARGET_FPU_VFP -D__FPU_USED=1 -D__FPU_PRESENT=1 -DARM_MATH_CM4 ####################################### -ifeq ($(FPU_OnOff),ON) -C_DEFS += -D__TARGET_FPU_VFP -DARM_MATH_CM4 +ifeq ( $(FPU_OnOff), ON ) +C_DEFS += -D__TARGET_FPU_VFP -D__FPU_USED=1 -DARM_MATH_CM4 endif ###################################### diff --git a/STM32F407ZETx_FLASH.ld b/STM32F407ZGTx_FLASH.ld similarity index 95% rename from STM32F407ZETx_FLASH.ld rename to STM32F407ZGTx_FLASH.ld index 9566f12..0978bfe 100644 --- a/STM32F407ZETx_FLASH.ld +++ b/STM32F407ZGTx_FLASH.ld @@ -6,8 +6,8 @@ ** ** Author : STM32CubeMX ** -** Abstract : Linker script for STM32F407ZETx series -** 512Kbytes FLASH and 192Kbytes RAM +** Abstract : Linker script for STM32F407ZGTx series +** 1024Kbytes FLASH and 192Kbytes RAM ** ** Set heap size, stack size and stack location according ** to application requirements. @@ -55,15 +55,15 @@ ENTRY(Reset_Handler) /* Highest address of the user mode stack */ _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x1000; /* required amount of heap */ -_Min_Stack_Size = 0x1500; /* required amount of stack */ +_Min_Heap_Size = 0x800; /* required amount of heap */ +_Min_Stack_Size = 0x1000; /* required amount of stack */ /* Specify the memory areas */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K } /* Define output sections */ diff --git a/USB_DEVICE/App/usb_device.c b/USB_DEVICE/App/usb_device.c deleted file mode 100644 index 0972286..0000000 --- a/USB_DEVICE/App/usb_device.c +++ /dev/null @@ -1,100 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usb_device.c - * @version : v1.0_Cube - * @brief : This file implements the USB Device - ****************************************************************************** - * @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 "usb_device.h" -#include "usbd_core.h" -#include "usbd_desc.h" -#include "usbd_msc.h" -#include "usbd_storage_if.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* USB Device Core handle declaration. */ -USBD_HandleTypeDef hUsbDeviceHS; - -/* - * -- Insert your variables declaration here -- - */ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* - * -- Insert your external function declaration here -- - */ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Init USB device Library, add supported class and start the library - * @retval None - */ -void MX_USB_DEVICE_Init(void) -{ - /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ - - /* USER CODE END USB_DEVICE_Init_PreTreatment */ - - /* Init Device Library, add supported class and start the library. */ - if (USBD_Init(&hUsbDeviceHS, &HS_Desc, DEVICE_HS) != USBD_OK) - { - Error_Handler(); - } - if (USBD_RegisterClass(&hUsbDeviceHS, &USBD_MSC) != USBD_OK) - { - Error_Handler(); - } - if (USBD_MSC_RegisterStorage(&hUsbDeviceHS, &USBD_Storage_Interface_fops_HS) != USBD_OK) - { - Error_Handler(); - } - if (USBD_Start(&hUsbDeviceHS) != USBD_OK) - { - Error_Handler(); - } - - /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ - - /* USER CODE END USB_DEVICE_Init_PostTreatment */ -} - -/** - * @} - */ - -/** - * @} - */ - diff --git a/USB_DEVICE/App/usb_device.h b/USB_DEVICE/App/usb_device.h deleted file mode 100644 index 5e8f722..0000000 --- a/USB_DEVICE/App/usb_device.h +++ /dev/null @@ -1,102 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usb_device.h - * @version : v1.0_Cube - * @brief : Header for usb_device.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 __USB_DEVICE__H__ -#define __USB_DEVICE__H__ - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx.h" -#include "stm32f4xx_hal.h" -#include "usbd_def.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup USBD_OTG_DRIVER - * @{ - */ - -/** @defgroup USBD_DEVICE USBD_DEVICE - * @brief Device file for Usb otg low level driver. - * @{ - */ - -/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables - * @brief Public variables. - * @{ - */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* - * -- Insert your variables declaration here -- - */ -/* USER CODE BEGIN VARIABLES */ - -/* USER CODE END VARIABLES */ -/** - * @} - */ - -/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ - -/** USB Device initialization function. */ -void MX_USB_DEVICE_Init(void); - -/* - * -- Insert functions declaration here -- - */ -/* USER CODE BEGIN FD */ - -/* USER CODE END FD */ -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_DEVICE__H__ */ diff --git a/USB_DEVICE/App/usbd_desc.c b/USB_DEVICE/App/usbd_desc.c deleted file mode 100644 index 406d132..0000000 --- a/USB_DEVICE/App/usbd_desc.c +++ /dev/null @@ -1,447 +0,0 @@ -/* 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_core.h" -#include "usbd_desc.h" -#include "usbd_conf.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @addtogroup USBD_DESC - * @{ - */ - -/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines - * @brief Private defines. - * @{ - */ - -#define USBD_VID 1155 -#define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" -#define USBD_PID_HS 22314 -#define USBD_PRODUCT_STRING_HS "STM32 Mass Storage" -#define USBD_CONFIGURATION_STRING_HS "MSC Config" -#define USBD_INTERFACE_STRING_HS "MSC Interface" - -#define USB_SIZ_BOS_DESC 0x0C - -/* USER CODE BEGIN PRIVATE_DEFINES */ - -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -static void Get_SerialNum(void); -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration for HS. - * @{ - */ - -uint8_t * USBD_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); - -#if (USBD_LPM_ENABLED == 1) -uint8_t * USBD_HS_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 HS_Desc = -{ - USBD_HS_DeviceDescriptor -, USBD_HS_LangIDStrDescriptor -, USBD_HS_ManufacturerStrDescriptor -, USBD_HS_ProductStrDescriptor -, USBD_HS_SerialStrDescriptor -, USBD_HS_ConfigStrDescriptor -, USBD_HS_InterfaceStrDescriptor -#if (USBD_LPM_ENABLED == 1) -, USBD_HS_USR_BOSDescriptor -#endif /* (USBD_LPM_ENABLED == 1) */ -}; - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ -/** USB standard device descriptor. */ -__ALIGN_BEGIN uint8_t USBD_HS_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_HS), /*idProduct*/ - HIBYTE(USBD_PID_HS), /*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*/ -}; - -/** BOS descriptor. */ -#if (USBD_LPM_ENABLED == 1) -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ -__ALIGN_BEGIN uint8_t USBD_HS_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_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_HS_DeviceDesc); - return USBD_HS_DeviceDesc; -} - -/** - * @brief Return the LangID string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; -} - -/** - * @brief Return the product string descriptor - * @param speed : current device speed - * @param length : pointer to data length variable - * @retval pointer to descriptor buffer - */ -uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the manufacturer string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; -} - -/** - * @brief Return the serial number string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = USB_SIZ_STRING_SERIAL; - - /* Update the serial number string descriptor with the data from the unique - * ID */ - Get_SerialNum(); - /* USER CODE BEGIN USBD_HS_SerialStrDescriptor */ - - /* USER CODE END USBD_HS_SerialStrDescriptor */ - - return (uint8_t *) USBD_StringSerial; -} - -/** - * @brief Return the configuration string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the interface string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -#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_HS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_HS_BOSDesc); - return (uint8_t*)USBD_HS_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; - } -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - diff --git a/USB_DEVICE/App/usbd_desc.h b/USB_DEVICE/App/usbd_desc.h deleted file mode 100644 index 36e4412..0000000 --- a/USB_DEVICE/App/usbd_desc.h +++ /dev/null @@ -1,143 +0,0 @@ -/* 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__ - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_DESC USBD_DESC - * @brief Usb device descriptors module. - * @{ - */ - -/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants - * @brief Constants. - * @{ - */ -#define DEVICE_ID1 (UID_BASE) -#define DEVICE_ID2 (UID_BASE + 0x4) -#define DEVICE_ID3 (UID_BASE + 0x8) - -#define USB_SIZ_STRING_SERIAL 0x1A - -/* USER CODE BEGIN EXPORTED_CONSTANTS */ - -/* USER CODE END EXPORTED_CONSTANTS */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines - * @brief Defines. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_DEFINES */ - -/* USER CODE END EXPORTED_DEFINES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions - * @brief Types. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_TYPES */ - -/* USER CODE END EXPORTED_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros - * @brief Aliases. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_MACRO */ - -/* USER CODE END EXPORTED_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables - * @brief Public variables. - * @{ - */ - -/** Descriptor for the Usb device. */ -extern USBD_DescriptorsTypeDef HS_Desc; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_FUNCTIONS */ - -/* USER CODE END EXPORTED_FUNCTIONS */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_DESC__C__ */ - diff --git a/USB_DEVICE/App/usbd_storage_if.c b/USB_DEVICE/App/usbd_storage_if.c deleted file mode 100644 index 0351b38..0000000 --- a/USB_DEVICE/App/usbd_storage_if.c +++ /dev/null @@ -1,294 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_storage_if.c - * @version : v1.0_Cube - * @brief : Memory management layer. - ****************************************************************************** - * @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_storage_if.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief Usb device. - * @{ - */ - -/** @defgroup USBD_STORAGE - * @brief Usb mass storage device module - * @{ - */ - -/** @defgroup USBD_STORAGE_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_STORAGE_Private_Defines - * @brief Private defines. - * @{ - */ - -#define STORAGE_LUN_NBR 1 -#define STORAGE_BLK_NBR 0x10000 -#define STORAGE_BLK_SIZ 0x200 - -/* USER CODE BEGIN PRIVATE_DEFINES */ - -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/** @defgroup USBD_STORAGE_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_STORAGE_Private_Variables - * @brief Private variables. - * @{ - */ - -/* USER CODE BEGIN INQUIRY_DATA_HS */ -/** USB Mass storage Standard Inquiry Data. */ -const int8_t STORAGE_Inquirydata_HS[] = {/* 36 */ - - /* LUN 0 */ - 0x00, - 0x80, - 0x02, - 0x02, - (STANDARD_INQUIRY_DATA_LEN - 5), - 0x00, - 0x00, - 0x00, - 'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */ - 'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */ - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - '0', '.', '0' ,'1' /* Version : 4 Bytes */ -}; -/* USER CODE END INQUIRY_DATA_HS */ - -/* USER CODE BEGIN PRIVATE_VARIABLES */ - -/* USER CODE END PRIVATE_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_STORAGE_Exported_Variables - * @brief Public variables. - * @{ - */ - -extern USBD_HandleTypeDef hUsbDeviceHS; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_STORAGE_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -static int8_t STORAGE_Init_HS(uint8_t lun); -static int8_t STORAGE_GetCapacity_HS(uint8_t lun, uint32_t *block_num, uint16_t *block_size); -static int8_t STORAGE_IsReady_HS(uint8_t lun); -static int8_t STORAGE_IsWriteProtected_HS(uint8_t lun); -static int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); -static int8_t STORAGE_Write_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); -static int8_t STORAGE_GetMaxLun_HS(void); - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ - -/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ - -/** - * @} - */ - -USBD_StorageTypeDef USBD_Storage_Interface_fops_HS = -{ - STORAGE_Init_HS, - STORAGE_GetCapacity_HS, - STORAGE_IsReady_HS, - STORAGE_IsWriteProtected_HS, - STORAGE_Read_HS, - STORAGE_Write_HS, - STORAGE_GetMaxLun_HS, - (int8_t *)STORAGE_Inquirydata_HS -}; - -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Initializes the storage unit (medium). - * @param lun: Logical unit number. - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -int8_t STORAGE_Init_HS(uint8_t lun) -{ - /* USER CODE BEGIN 9 */ - UNUSED(lun); - - return (USBD_OK); - /* USER CODE END 9 */ -} - -/** - * @brief Returns the medium capacity. - * @param lun: Logical unit number. - * @param block_num: Number of total block number. - * @param block_size: Block size. - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -int8_t STORAGE_GetCapacity_HS(uint8_t lun, uint32_t *block_num, uint16_t *block_size) -{ - /* USER CODE BEGIN 10 */ - UNUSED(lun); - - *block_num = STORAGE_BLK_NBR; - *block_size = STORAGE_BLK_SIZ; - return (USBD_OK); - /* USER CODE END 10 */ -} - -/** - * @brief Checks whether the medium is ready. - * @param lun: Logical unit number. - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -int8_t STORAGE_IsReady_HS(uint8_t lun) -{ - /* USER CODE BEGIN 11 */ - UNUSED(lun); - - return (USBD_OK); - /* USER CODE END 11 */ -} - -/** - * @brief Checks whether the medium is write protected. - * @param lun: Logical unit number. - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -int8_t STORAGE_IsWriteProtected_HS(uint8_t lun) -{ - /* USER CODE BEGIN 12 */ - return (USBD_OK); - /* USER CODE END 12 */ -} - -/** - * @brief Reads data from the medium. - * @param lun: Logical unit number. - * @param buf: data buffer. - * @param blk_addr: Logical block address. - * @param blk_len: Blocks number. - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -{ - /* USER CODE BEGIN 13 */ - UNUSED(lun); - UNUSED(buf); - UNUSED(blk_addr); - UNUSED(blk_len); - - return (USBD_OK); - /* USER CODE END 13 */ -} - -/** - * @brief Writes data into the medium. - * @param lun: Logical unit number. - * @param buf: data buffer. - * @param blk_addr: Logical block address. - * @param blk_len: Blocks number. - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -int8_t STORAGE_Write_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -{ - /* USER CODE BEGIN 14 */ - UNUSED(lun); - UNUSED(buf); - UNUSED(blk_addr); - UNUSED(blk_len); - - return (USBD_OK); - /* USER CODE END 14 */ -} - -/** - * @brief Returns the Max Supported LUNs. - * @param None - * @retval Lun(s) number. - */ -int8_t STORAGE_GetMaxLun_HS(void) -{ - /* USER CODE BEGIN 15 */ - return (STORAGE_LUN_NBR - 1); - /* USER CODE END 15 */ -} - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -/** - * @} - */ - -/** - * @} - */ - diff --git a/USB_DEVICE/App/usbd_storage_if.h b/USB_DEVICE/App/usbd_storage_if.h deleted file mode 100644 index 7962283..0000000 --- a/USB_DEVICE/App/usbd_storage_if.h +++ /dev/null @@ -1,127 +0,0 @@ -/* 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_HS; - -/* 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__ */ - diff --git a/USB_DEVICE/Target/usbd_conf.c b/USB_DEVICE/Target/usbd_conf.c deleted file mode 100644 index 3199911..0000000 --- a/USB_DEVICE/Target/usbd_conf.c +++ /dev/null @@ -1,680 +0,0 @@ -/* 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 "stm32f4xx.h" -#include "stm32f4xx_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_HS; -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) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(pcdHandle->Instance==USB_OTG_HS) - { - /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */ - - /* USER CODE END USB_OTG_HS_MspInit 0 */ - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**USB_OTG_HS GPIO Configuration - PB14 ------> USB_OTG_HS_DM - PB15 ------> USB_OTG_HS_DP - */ - GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* Peripheral clock enable */ - __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); - - /* Peripheral interrupt init */ - HAL_NVIC_SetPriority(OTG_HS_IRQn, 11, 0); - HAL_NVIC_EnableIRQ(OTG_HS_IRQn); - /* USER CODE BEGIN USB_OTG_HS_MspInit 1 */ - - /* USER CODE END USB_OTG_HS_MspInit 1 */ - } -} - -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -{ - if(pcdHandle->Instance==USB_OTG_HS) - { - /* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */ - - /* USER CODE END USB_OTG_HS_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); - - /**USB_OTG_HS GPIO Configuration - PB14 ------> USB_OTG_HS_DM - PB15 ------> USB_OTG_HS_DP - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15); - - /* Peripheral interrupt Deinit*/ - HAL_NVIC_DisableIRQ(OTG_HS_IRQn); - - /* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */ - - /* USER CODE END USB_OTG_HS_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_HS) { - /* Link the driver to the stack. */ - hpcd_USB_OTG_HS.pData = pdev; - pdev->pData = &hpcd_USB_OTG_HS; - - hpcd_USB_OTG_HS.Instance = USB_OTG_HS; - hpcd_USB_OTG_HS.Init.dev_endpoints = 6; - hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_OTG_HS.Init.dma_enable = DISABLE; - hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY; - hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE; - hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE; - hpcd_USB_OTG_HS.Init.lpm_enable = DISABLE; - hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE; - hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE; - hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE; - if (HAL_PCD_Init(&hpcd_USB_OTG_HS) != HAL_OK) - { - Error_Handler( ); - } - -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) - /* Register USB PCD CallBacks */ - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); - - HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_HS, PCD_DataOutStageCallback); - HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_HS, PCD_DataInStageCallback); - HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_HS, PCD_ISOOUTIncompleteCallback); - HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_HS, PCD_ISOINIncompleteCallback); -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200); - HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x80); - HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x174); - } - 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; -} diff --git a/USB_DEVICE/Target/usbd_conf.h b/USB_DEVICE/Target/usbd_conf.h deleted file mode 100644 index 5a760e7..0000000 --- a/USB_DEVICE/Target/usbd_conf.h +++ /dev/null @@ -1,175 +0,0 @@ -/* 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__ - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include -#include -#include -#include "main.h" -#include "stm32f4xx.h" -#include "stm32f4xx_hal.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup USBD_OTG_DRIVER - * @brief Driver for Usb device. - * @{ - */ - -/** @defgroup USBD_CONF USBD_CONF - * @brief Configuration file for Usb otg low level driver. - * @{ - */ - -/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables - * @brief Public variables. - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines - * @brief Defines for configuration of the Usb device. - * @{ - */ - -/*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 1U -/*---------- -----------*/ -#define USBD_MAX_NUM_CONFIGURATION 1U -/*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 512U -/*---------- -----------*/ -#define USBD_DEBUG_LEVEL 0U -/*---------- -----------*/ -#define USBD_LPM_ENABLED 0U -/*---------- -----------*/ -#define USBD_SELF_POWERED 1U -/*---------- -----------*/ -#define MSC_MEDIA_PACKET 4096U - -/****************************************/ -/* #define for FS and HS identification */ -#define DEVICE_FS 0 -#define DEVICE_HS 1 - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros - * @brief Aliases. - * @{ - */ -/* Memory management macros make sure to use static memory allocation */ -/** Alias for memory allocation. */ - -#define USBD_malloc (void *)USBD_static_malloc - -/** Alias for memory release. */ -#define USBD_free USBD_static_free - -/** Alias for memory set. */ -#define USBD_memset memset - -/** Alias for memory copy. */ -#define USBD_memcpy memcpy - -/** Alias for delay. */ -#define USBD_Delay HAL_Delay - -/* DEBUG macros */ - -#if (USBD_DEBUG_LEVEL > 0) -#define USBD_UsrLog(...) printf(__VA_ARGS__);\ - printf("\n"); -#else -#define USBD_UsrLog(...) -#endif /* (USBD_DEBUG_LEVEL > 0U) */ - -#if (USBD_DEBUG_LEVEL > 1) - -#define USBD_ErrLog(...) printf("ERROR: ");\ - printf(__VA_ARGS__);\ - printf("\n"); -#else -#define USBD_ErrLog(...) -#endif /* (USBD_DEBUG_LEVEL > 1U) */ - -#if (USBD_DEBUG_LEVEL > 2) -#define USBD_DbgLog(...) printf("DEBUG : ");\ - printf(__VA_ARGS__);\ - printf("\n"); -#else -#define USBD_DbgLog(...) -#endif /* (USBD_DEBUG_LEVEL > 2U) */ - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types - * @brief Types. - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ - -/* Exported functions -------------------------------------------------------*/ -void *USBD_static_malloc(uint32_t size); -void USBD_static_free(void *p); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CONF__H__ */ - diff --git a/backup/i2c_ads1115_1.c b/backup/i2c_ads1115_1.c deleted file mode 100644 index 936a9a6..0000000 --- a/backup/i2c_ads1115_1.c +++ /dev/null @@ -1,233 +0,0 @@ -// i2c_ads1115.c -#include "i2c_ads1115.h" -#include "stdlib.h" -#include "stdio.h" - -/* - 多路测量的话, 需要配置不同的 config_H config_L -*/ - -static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1; - -osThreadId_t ads1115TaskHandle; -const osThreadAttr_t ads1115Task_attributes = { - .name = "ads1115Task", - .stack_size = 256 * 4, - .priority = (osPriority_t) osPriorityNormal, -}; - -osEventFlagsId_t ads1115EventHandle; -const osEventFlagsAttr_t ads1115Event_attributes = { - .name = "ads1115Event" -}; - -// ads1115EventHandle = osEventFlagsNew (&ads1115Event_attributes); -// typedef enum -// { -// EV_READY, /*!< Startup finished. */ -// EV_FRAME_RECEIVED, /*!< Frame received. */ -// EV_EXECUTE, /*!< Execute function. */ -// EV_FRAME_SENT /*!< Frame sent. */ -// } eMBEventType; -// osEventFlagsSet(modbusEventHandle,eEvent); - // osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) -// recvedEvent = osEventFlagsWait (modbusEventHandle, -// EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | -// EV_FRAME_SENT, /* 接收任务感兴趣的事件 */ -// 0, -// portMAX_DELAY); /* 指定超时事件,无限等待 */ - -ADS1115_TypeDef my_ads1115 = - { - ads1115_init, - NULL, - ADS1115_REG_CONFIG_OS_START, - ADS1115_REG_CONFIG_MUX_SINGLE_0, - ADS1115_REG_CONFIG_PGA_4, - ADS1115_REG_CONFIG_MODE_SINGLE, - ADS1115_REG_CONFIG_DR_128, - ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL, - ADS1115_REG_CONFIG_COMP_POL_LOW, - ADS1115_REG_CONFIG_COMP_LAT_NONLATCH, - ADS1115_REG_CONFIG_COMP_QUE_DIS, - 0, - 0, - 0, - { 0, 0, 0 }, - ADS1115_OUTPUT_UNIT_mv, // 默认输出毫伏 -}; - -void ads1115_task(void) -{ - uint32_t event_flags; - for (;;) - { - // 启用中断发送,判断状态, - // 地址中断, 确认是哪I2C 设备通讯 - /* code */ - /* TODO 统一的超时机制 */ - - /* 事件来管理 */ - event_flags = osEventFlagsWait ( - ads1115EventHandle - , ADS1115_Event_READY|ADS1115_Event_INIT|ADS1115_Event_TRANS_ONLY|ADS1115_Event_DATA_RCV - , 0 - , portMAX_DELAY ); - if ( event_flags & (ADS1115_Event_READY|ADS1115_Event_INIT) - == (ADS1115_Event_READY|ADS1115_Event_INIT) ) - { - // if (HAL_I2C_GetError(&hi2c1)!= HAL_I2C_ERROR_AF) - // { - // Error_Handler(); - // } - // if (HAL_I2C_GetState(&hi2c1)!= HAL_I2C_STATE_READY) - // { - // Error_Handler(); - // } - - osEventFlagsClear(ads1115EventHandle, ADS1115_Event_INIT); - osEventFlagsSet(ads1115EventHandle, ADS1115_Event_INIT_SUCCESS); - } - - if ( event_flags & ( ADS1115_Event_READY|ADS1115_Event_TRANS_ONLY ) - == (ADS1115_Event_READY|ADS1115_Event_TRANS_ONLY) ) - { - osEventFlagsClear(ads1115EventHandle, ADS1115_Event_TRANS_ONLY); - - } - - if ( event_flags & ( ADS1115_Event_READY|ADS1115_Event_TRANS_FOR_DATA ) - == (ADS1115_Event_READY|ADS1115_Event_TRANS_FOR_DATA) ) - { - osEventFlagsClear(ads1115EventHandle, ADS1115_Event_TRANS_FOR_DATA); - osEventFlagsSet(ads1115EventHandle, ADS1115_Event_DATA_RCV); - - } - if ( event_flags & ( ADS1115_Event_READY|ADS1115_Event_DATA_RCV ) - == ( ADS1115_Event_READY|ADS1115_Event_DATA_RCV ) ) - { - osEventFlagsClear( ads1115EventHandle, ADS1115_Event_DATA_RCV ); - } - // __HAL_I2C_GET_FLAG(&hi2c1, I2C_FLAG_TXE) ; - osDelay(20); - } -} - -void ads1115_port(void) -{ - ads1115TaskHandle = osThreadNew(ads1115_task, NULL, &ads1115Task_attributes); - ads1115EventHandle = osEventFlagsNew (&ads1115Event_attributes); -} - -/** - * @brief - * @param [in] ads1115_I2cHandle - * @param [in] pointADD -- 读的寄存器地址 - * @param [in] configH - * @param [in] configL - * - * @details - */ -int ads1115_init() -{ - uint8_t reg_data[3]; - my_ads1115.hi2c= pADS1115_I2C; - my_ads1115.config_H = my_ads1115.config_os|my_ads1115.config_mux - |my_ads1115.config_PGA|my_ads1115.config_MODE; - my_ads1115.config_L = my_ads1115.config_DR|my_ads1115.config_COMP_MODE|my_ads1115.config_COMP_POL - |my_ads1115.config_COMP_LAT|my_ads1115.config_COMP_QUE ; - reg_data[0] = 0x01; // point addr 8bit 配置寄存器 - reg_data[1] = my_ads1115.config_H; // config_reg 高位 - reg_data[2] = my_ads1115.config_L; // config_reg 低位 - - // TODO 阻塞式, 改为 DMA 中断模式, 配合定时器 , 或启用中断等待 - // while (HAL_I2C_Master_Transmit(pADS1115_I2C, ADS1115_WRITE_ADDRESS, reg_data, 3, 2000) != HAL_OK) - // { - // if (HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF) - // { - // printf("ads1115 Config Register error!!!\r\n"); - // } - // } - - osEventFlagsSet ( ads1115TaskHandle, ADS1115_Event_INIT ); - if (HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, reg_data, 3 ) != HAL_OK) - { - return -1; - } - return 0; - -} - -int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux) -{ - my_ads1115.config_H &= ~0x70; - my_ads1115.config_H &= mux; - return 0; -} - -int16_t ads1115_read_data( ) -{ - int16_t data; - uint8_t rx_data[2] = {0}; - - // TODO 阻塞式, 改为 DMA 中断模式 - // 读寄存器 0x00 十六位 - while (HAL_I2C_Master_Transmit(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000) != HAL_OK) - { - if (HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF) - { - printf("ads1115 convert Register error!!!\r\n"); - } - } - // 读两位 - while (HAL_I2C_Master_Receive(pADS1115_I2C, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK) - { - if ( HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF ) - { - printf("ads1115 read data error!!!\r\n"); - } - } - data = rx_data[0] * 256 + rx_data[1]; - return data; -} - -double ads1115_get_voltage_val( ) -{ - double val; - int16_t ad_val; - // TODO 去掉延时,使用寄存器的指示, setup 和读取数据分开执行 - // ads1115_setup( pADS1115_I2C, pointADD, configH, configL ); - ads1115_setup( ADS1115_REG_CONFIG_MUX_SINGLE_0 ); - - HAL_Delay(10); - ad_val = ads1115_read_data( pADS1115_I2C ); - if ( (ad_val == 0x7FFF) | (ad_val == 0X8000)) // 是否超量程了 - { - ad_val = 0; - // printf("over PGA\r\n"); - } - switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率 - { - case (0x00): - val = (double)ad_val * 187.5 / 1000.0; // - break; - case (0x01): - val = (double)ad_val * 125 / 1000.0; - break; - case (0x02): - val = (double)ad_val * 62.5 / 1000.0; - break; - case (0x03): - val = (double)ad_val * 31.25 / 1000.0; - break; - case (0x04): - val = (double)ad_val * 15.625 / 1000.0; - break; - case (0x05): - val = (double)ad_val * 7.8125 / 1000.0; - break; - } - - return (my_ads1115.unit == ADS1115_OUTPUT_UNIT_mv)?val:(val/1000.0); - -} \ No newline at end of file diff --git a/backup/i2c_ads1115_1.h b/backup/i2c_ads1115_1.h deleted file mode 100644 index 185b21a..0000000 --- a/backup/i2c_ads1115_1.h +++ /dev/null @@ -1,249 +0,0 @@ -//i2c_ads1115.h -#ifndef __IIC_ADS1115_H -#define __IIC_ADS1115_H -#include "FreeRTOS.h" -#include "task.h" -#include "main.h" -#include "cmsis_os.h" -#include "i2c.h" - -#define ADS1115_WRITE_ADDRESS 0x90 -#define ADS1115_READ_ADDRESS 0x91 -//以下两个预处理作为配置寄存器预处理要更改其配在这里更改 -//也可以添加新的预处理对不同通道的采集或者选取不同的采样速率等 - -/*事件开始 set, 事件完成 clear */ -typedef enum -{ - ADS1115_Event_READY, /*!< Startup finished. */ - ADS1115_Event_INIT, - ADS1115_Event_INIT_SUCCESS, - ADS1115_Event_TRANS_ONLY, - ADS1115_Event_TRANS_FOR_DATA, - ADS1115_Event_DATA_RCV, -} ADS1115_Event_TypeDef; - -typedef enum { - ADS1115_WORK_STATE_WAITING, - ADS1115_WORK_STATE_START, - ADS1115_WORK_STATE_INIT, - ADS1115_WORK_STATE_READY_GET_DATA, - ADS1115_WORK_STATE_GET_DATA, - ADS1115_WORK_STATE_GET_DATA_OK, - ADS1115_WORK_STATE_ERROR, - ADS1115_WORK_STATE_STOP -}ADS1115_WORK_STATE_TypeDef; - -typedef enum { - ADS1115_OUTPUT_UNIT_v, - ADS1115_OUTPUT_UNIT_mv -}ADS1115_OUTPUT_UNIT_TypeDef; - - -//地址指针寄存器 -typedef enum -{ - ADS1115_REG_POINTER_CONVERT = 0x00, // 转换寄存器 - ADS1115_REG_POINTER_CONFIG = 0x01 , // 配置寄存器 16bit - ADS1115_REG_POINTER_LOWTHRESH = 0x02 , - ADS1115_REG_POINTER_HITHRESH = 0x03 -} ADS1115_REG_POINTER_TypeDef; - - -// 单次转换开始 -typedef enum -{ - ADS1115_REG_CONFIG_OS_START = (0x1U << 7),//设备单词转换开启 高字节的最高位 - ADS1115_REG_CONFIG_OS_NULL = (0x0U << 7) -} ADS1115_REG_CONFIG_OS_TypeDef; - - -//输入引脚选择和输入方式选择 -typedef enum -{ - ADS1115_REG_CONFIG_MUX_Diff_01 = (0x0U << 4), // 差分输入0引脚和1引脚 - ADS1115_REG_CONFIG_MUX_Diff_03 = (0x1U << 4), // 差分输入0引脚和3引脚 - ADS1115_REG_CONFIG_MUX_Diff_13 = (0x2U << 4), // 差分输入1引脚和3引脚 - ADS1115_REG_CONFIG_MUX_Diff_23 = (0x3U << 4), // 差分输入2引脚和3引脚 - ADS1115_REG_CONFIG_MUX_SINGLE_0= (0x4U << 4), //单端输入 0 - ADS1115_REG_CONFIG_MUX_SINGLE_1= (0x5U << 4), //单端输入 1 - ADS1115_REG_CONFIG_MUX_SINGLE_2= (0x6U << 4), //单端输入 2 - ADS1115_REG_CONFIG_MUX_SINGLE_3= (0x7U << 4) //单端输入 3 -} ADS1115_REG_CONFIG_MUX_Diff_TypeDef; - - - -//量程选择 -typedef enum -{ - ADS1115_REG_CONFIG_PGA_6 = (0x0U << 1), // +/- 6.1144 - ADS1115_REG_CONFIG_PGA_4 =(0x1U << 1), // +/- 4.096 - ADS1115_REG_CONFIG_PGA_2 = (0x2U << 1), // +/- 2.048 - ADS1115_REG_CONFIG_PGA_1 = (0x3U << 1) , // +/- 1.024 - ADS1115_REG_CONFIG_PGA_05 = (0x4U << 1) , // +/- 0.512 - ADS1115_REG_CONFIG_PGA_02 =(0x5U << 1) , // +/- 0.256 -} ADS1115_REG_CONFIG_PGA_TypeDef; - - -//运行方式 -typedef enum -{ - ADS1115_REG_CONFIG_MODE_SINGLE = (0x1U << 0) , // 单次 - ADS1115_REG_CONFIG_MODE_CONTIN = (0x0U << 0) //连续转换 -} ADS1115_REG_CONFIG_MODE_TypeDef; - - -//转换速率 -typedef enum -{ - ADS1115_REG_CONFIG_DR_8 = (0x0U << 5), - ADS1115_REG_CONFIG_DR_16= (0x1U << 5), - ADS1115_REG_CONFIG_DR_32 = (0x2U << 5), - ADS1115_REG_CONFIG_DR_64 = (0x3U << 5), - ADS1115_REG_CONFIG_DR_128 = (0x4U << 5), - ADS1115_REG_CONFIG_DR_250 = (0x5U << 5), - ADS1115_REG_CONFIG_DR_475 = (0x6U << 5), - ADS1115_REG_CONFIG_DR_860 = (0x7U << 5) -} ADS1115_REG_CONFIG_DR_TypeDef; - - - -//比较器模式 -typedef enum -{ - ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL = (0x0U << 4),//默认 - ADS1115_REG_CONFIG_COMP_MODE_WINDOW = (0x1U << 4) -} ADS1115_REG_CONFIG_COMP_MODE_TypeDef; - - -typedef enum -{ - ADS1115_REG_CONFIG_COMP_POL_LOW = (0x0U << 3),//默认 - ADS1115_REG_CONFIG_COMP_POL_HIG = (0x1U << 3) -} ADS1115_REG_CONFIG_COMP_POL_TypeDef; - - - -typedef enum -{ - ADS1115_REG_CONFIG_COMP_LAT_NONLATCH = (0x0U << 2), - ADS1115_REG_CONFIG_COMP_LAT_LATCH = (0x1U << 2) -} ADS1115_REG_CONFIG_COMP_LAT_TypeDef; - - -typedef enum -{ - ADS1115_REG_CONFIG_COMP_QUE_ONE= (0x0U << 0), - ADS1115_REG_CONFIG_COMP_QUE_TWO= (0x1U << 0), - ADS1115_REG_CONFIG_COMP_QUE_THR= (0x2U << 0), - ADS1115_REG_CONFIG_COMP_QUE_DIS= (0x3U << 0) -} ADS1115_REG_CONFIG_COMP_QUE_TypeDef; - - - -typedef struct{ - void (*init)(void); - I2C_HandleTypeDef *hi2c; - - uint8_t config_os; - uint8_t config_mux; - uint8_t config_PGA; - uint8_t config_MODE; - uint8_t config_DR; - uint8_t config_COMP_MODE; - uint8_t config_COMP_POL; - uint8_t config_COMP_LAT; - uint8_t config_COMP_QUE; - uint8_t point_ADDR; // 要读取的数据指针地址 - volatile uint8_t config_H; - volatile uint8_t config_L; - uint8_t reg_data[3]; - ADS1115_OUTPUT_UNIT_TypeDef unit; - double result[4]; -}ADS1115_TypeDef; - -extern ADS1115_TypeDef my_ads1115; - -int ads1115_init(); -int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux); -// void ads1115_config_register(I2C_HandleTypeDef *ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); -int16_t ads1115_read_data( ); -double ads1115_get_voltage_val( ); -#endif - -/***************/ -//配置寄存器说明 - - - -//config register -/*CRH[15:8](R/W) - BIT 15 14 13 12 11 10 9 8 - NAME OS MUX2 MUX1 MUX0 PGA2 PGA1 PGA0 MODE -CRL[7:0] (R/W) - BIT 7 6 5 4 3 2 1 0 - NAME DR0 DR1 DR0 COM_MODE COM_POL COM_LAT COM_QUE1 COM_QUE0 - - - ----------------------------------------------------------------------------------- - * 15 | OS | 运行状态会单词转换开始 - * | | 写时: - * | | 0 : 无效 - * | | 1 : 开始单次转换处于掉电状态时 - * | | 读时: - * | | 0 : 正在转换 - * | | 1 : 未执行转换 - * ----------------------------------------------------------------------------------- - * 14:12 | MUX [2:0] | 输入复用多路配置 -- 如果多路的话需要每次分开测量 - * | | 000 : AINP = AIN0 and AINN = AIN1 (default) - * | | 001 : AINP = AIN0 and AINN = AIN3 - * | | 010 : AINP = AIN1 and AINN = AIN3 - * | | 011 : AINP = AIN2 and AINN = AIN3 - * | | 100 : AINP = AIN0 and AINN = GND - * | | 101 : AINP = AIN1 and AINN = GND - * | | 110 : AINP = AIN2 and AINN = GND - * | | 111 : AINP = AIN3 and AINN = GND - * ----------------------------------------------------------------------------------- - * 11:9 | PGA [2:0] | 可编程增益放大器配置(FSR full scale range) - * | | 000 : FSR = В±6.144 V - * | | 001 : FSR = В±4.096 V - * | | 010 : FSR = В±2.048 V (默认) - * | | 011 : FSR = В±1.024 V - * | | 100 : FSR = В±0.512 V - * | | 101 : FSR = В±0.256 V - * | | 110 : FSR = В±0.256 V - * | | 111 : FSR = В±0.256 V - * ----------------------------------------------------------------------------------- - * 8 | MODE | 工作模式 - * | | 0 : 连续转换 - * | | 1 : 单词转换 - * ----------------------------------------------------------------------------------- - * 7:5 | DR [2:0] | 采样频率 - * | | 000 : 8 SPS - * | | 001 : 16 SPS - * | | 010 : 32 SPS - * | | 011 : 64 SPS - * | | 100 : 128 SPS (默认) - * | | 101 : 250 SPS - * | | 110 : 475 SPS - * | | 111 : 860 SPS - * ----------------------------------------------------------------------------------- - * 4 | COMP_MODE | 比较器模式 - * | | 0 : 传统比较器 (default) - * | | 1 : 窗口比较器 - * ----------------------------------------------------------------------------------- - * 3 | COMP_POL | Comparator polarity - * | | 0 : 低电平有效 (default) - * | | 1 : 高电平有效 - * ----------------------------------------------------------------------------------- - * 2 | COMP_LAT | Latching comparator - * | | 0 : 非锁存比较器. (default) - * | | 1 : 锁存比较器. - * ----------------------------------------------------------------------------------- - * 1:0 | COMP_QUE [1:0] | Comparator queue and disable - * | | 00 : Assert after one conversion - * | | 01 : Assert after two conversions - * | | 10 : Assert after four conversions - * | | 11 : 禁用比较器并将ALERT/RDY设置为高阻抗 (default) - * ----------------------------------------------------------------------------------- -*/ diff --git a/Code/base/Src/led_port.c b/backup/led_port.c similarity index 82% rename from Code/base/Src/led_port.c rename to backup/led_port.c index ec1135a..99d6e8f 100644 --- a/Code/base/Src/led_port.c +++ b/backup/led_port.c @@ -23,8 +23,8 @@ int Led_Port() { led_register(&led_0, LED0_GPIO_Port, LED0_Pin, LED_STATE_ON, RESET); - // led_register(&led_1, LED1_GPIO_Port, LED1_Pin, LED_STATE_ON, RESET); - // led_set_state(&led_1, LED_STATE_FLICKER_MEDIUM); + led_register(&led_1, LED1_GPIO_Port, LED1_Pin, LED_STATE_ON, RESET); + led_set_state(&led_1, LED_STATE_FLICKER_MEDIUM); led_set_state(&led_0, LED_STATE_FLICKER_MEDIUM); ledHandle = osThreadNew(Led_Task, NULL, &led_attributes); return 0; @@ -33,7 +33,7 @@ int Led_Port() void Led_Task() { - for (;;) + for ( ; ; ) { led_callback(); osDelay(200); diff --git a/backup/obolete/eeprom.c b/backup/obolete/eeprom.c new file mode 100644 index 0000000..97e094b --- /dev/null +++ b/backup/obolete/eeprom.c @@ -0,0 +1,194 @@ +/** + * @file eeprom.c + * @author Chen Jihang (embedded@eseaoptics.com) + * @brief EEPROM驱动 + * @version 1.0 + * @date 2023-01-04 + * + * @copyright ESEA (c) 2020 + * + */ + +#include "eeprom.h" +eeprom_t *eeprom; + +eeprom_t *Eeprom_init() +{ + eeprom_t *Handle = (eeprom_t *)malloc(sizeof(eeprom_t)); + if (Handle == NULL) + { + return NULL; + } + Handle->writeCplt = 0; + Handle->readCplt = 0; + Handle->write_delay_ms = 10; + Handle->size = 0; + Handle->WORKMODE = 1; /* IT mode*/ + Handle->stat = HAL_I2C_STATE_RESET; /* HAL_I2C_STATE_RESET 未初始化 */ + return Handle; +} + +uint8_t Eeprom_SET_I2C(eeprom_t *eeprom, I2C_HandleTypeDef *i2c) +{ + eeprom->i2c = i2c; + eeprom->stat = HAL_I2C_STATE_READY; + return 0; +} +uint8_t Eeprom_SET_Device_Model(eeprom_t *eeprom, uint16_t model) +{ + eeprom->model = model; + // if (eeprom->model < AT24C16) + // { + // eeprom->mem_addr_type = I2C_MEMADD_SIZE_8BIT; + // } + // else + // { + // eeprom->mem_addr_type = I2C_MEMADD_SIZE_16BIT; + // } + return 0; +} + +uint8_t Eeprom_SET_Device_Addr(eeprom_t *eeprom, uint8_t dev_addr) +{ + eeprom->dev_addr = dev_addr; + return 0; +} + +uint8_t Eeprom_SET_Mem_Addr_Type(eeprom_t *eeprom, uint8_t mem_addr_type) +{ + eeprom->mem_addr_type = mem_addr_type; + return 0; +} + +uint8_t Eeprom_SET_Workmode(eeprom_t *eeprom, uint8_t workmode) +{ + eeprom->WORKMODE = workmode; + return 0; +} + +uint8_t Eeprom_Read_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +{ + // eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1); + return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); +} + +uint8_t Eeprom_Write_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +{ + return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); + +} + +uint8_t Eeprom_Read_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +{ + // eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1); + eeprom->size = 0; + return HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 ); +} + +uint8_t Eeprom_Write_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) +{ + eeprom->size = 0; + return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 ); +} + +uint8_t Eeprom_Read_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ) +{ + // eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size); + return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout); + +} + +uint8_t Eeprom_Write_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ) +{ + return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout); + +} + +uint8_t Eeprom_Read_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ) +{ + // eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size); + eeprom->stat =HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size ); + // LOG(" readstat %d",eeprom->stat); + return eeprom->stat; + +} + +uint8_t Eeprom_Write_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ) +{ + // 写入数据前端循环调用 Eeprom_send_callback + // return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size ); + eeprom->send_buf = buf; + eeprom->size = size; + eeprom->mem_addr = mem_addr; + return 0; + +} + +/** + * @brief EEPROM发送回调,须循环调用单字节写入 + * + * @param eeprom EEPROM描述符 + * @return int 0 + */ +uint8_t Eeprom_send(eeprom_t *eeprom) +{ + if (eeprom->size == 0) + { + eeprom->send_buf = NULL; + } + if (eeprom->send_buf == NULL) + { + return 0; + } + if ( HAL_I2C_GetState(eeprom->i2c) == 1 ) + { + return 0; + } + if ( (osKernelGetTickCount() -eeprom->time_base) < eeprom->write_delay_ms ) + { + return 0; + } + if ( HAL_I2C_GetState(eeprom->i2c) == 2 ) + { + // __HAL_I2C_CLEAR_FLAG(eeprom->i2c,I2C_FLAG_AF); // 清除非应答状态 + eeprom->i2c->State = HAL_I2C_STATE_READY; + // i2c_clear_state(eeprom->i2c); + eeprom->mem_addr--; + eeprom->send_buf--; + eeprom->size++; + } + if (eeprom->size == 0) + { + eeprom->send_buf = NULL; + return 0; + } + + // 单个字节写入 ?? 为什么指向的地址内容发送变化了,静态声明 + // LOG( " send buf : %02x %d", *eeprom->send_buf, eeprom->send_buf); + HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, eeprom->send_buf, 1 ); + // i2c_write_memory(eeprom->i2c,eeprom->dev_addr+eeprom->page_addr,eeprom->mem_addr,eeprom->mem_addr_size,eeprom->send_buf,1); + // eeprom->time_base = __get_tick_milliseconds(); + eeprom->time_base = osKernelGetTickCount(); + eeprom->mem_addr++; + eeprom->send_buf++; + eeprom->size--; + return 0; +} + +void Eeprom_send_callback(eeprom_t *eeprom) +{ + Eeprom_send(eeprom); +} + +uint8_t Eeprom_get_state(eeprom_t *eeprom) +{ + if (eeprom->send_buf != NULL) + { + return 1; + } + if ( HAL_I2C_GetState(eeprom->i2c) == HAL_I2C_STATE_READY ) + { + return 0; + }; + return 2; +} \ No newline at end of file diff --git a/backup/obolete/eeprom.h b/backup/obolete/eeprom.h new file mode 100644 index 0000000..2a0d296 --- /dev/null +++ b/backup/obolete/eeprom.h @@ -0,0 +1,83 @@ +#ifndef EEPROM_H_ +#define EEPROM_H_ +#include +#include +#include +#include "main.h" +#include "stm32f407xx.h" + +#include "FreeRTOSConfig.h" +#include "cmsis_os2.h" +// #include "i2c.h" +// #include "time_clock.h" +// enum I2C_WORKMODE { + + +// enum MEM_ADDR_TYPE{ +// BIT8_MEM, +// BIT16_MEM +// }; + +// enum EEPROM_MODEL{ +// AT24C01=127, +// AT24C02=255, +// AT24C04=511, +// AT24C08=1023, +// AT24C16=2047, +// AT24C32=4095, +// AT24C64=8191, +// AT24C128=16383, +// AT24C256=32767, +// }; + + +// typedef void (*read_callback)(); +// typedef void (*write_callback)(); +typedef struct _eeprom +{ + I2C_HandleTypeDef *i2c; + uint16_t model; // AT24C01 AT24C02 AT24C256 + uint8_t mem_addr_type; // 1: 8bit 2: 16bit I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT + uint8_t dev_addr; + uint32_t time_base; // 从系统获得一个systick的毫秒数 + uint8_t page_addr; + + uint8_t *send_buf; // 将写的buf放到这里,然后让IIC自己工作 + uint16_t size; // 多少个字节 + uint16_t mem_addr; //?? + uint8_t write_delay_ms; // 5-8ms + uint8_t WORKMODE; // polling 0 , it 1, dma 2 + uint8_t writeCplt; + uint8_t readCplt; + + HAL_I2C_StateTypeDef stat; +}eeprom_t; + +extern eeprom_t *eeprom; + +eeprom_t *Eeprom_init( ); +uint8_t Eeprom_SET_I2C(eeprom_t *eeprom, I2C_HandleTypeDef *i2c); +uint8_t Eeprom_SET_Device_Model(eeprom_t *eeprom, uint16_t model); +uint8_t Eeprom_SET_Device_Addr(eeprom_t *eeprom, uint8_t dev_addr); +uint8_t Eeprom_SET_Mem_Addr_Type(eeprom_t *eeprom, uint8_t mem_addr_type); + +// eeprom_t *eeprom_init( eeprom_t *eeprom,struct i2c_buff *i2c,uint8_t dev_addr,uint8_t mem_addr_size,uint8_t write_delay_ms); +// uint8_t eeprom_write( eeprom_t *eeprom, uint8_t page_addr, uint16_t mem_addr, uint8_t *buf, uint32_t size ); +// uint8_t eeprom_read( eeprom_t *eeprom, uint8_t page_addr, uint16_t mem_addr, uint8_t *buf, uint32_t size ); +// uint8_t eeprom_send_callback( eeprom_t *eeprom); +// uint8_t eeprom_get_state( eeprom_t *eeprom); + +uint8_t Eeprom_Read_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); + +uint8_t Eeprom_Write_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); +uint8_t Eeprom_Read_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); + +uint8_t Eeprom_Write_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); + +uint8_t Eeprom_Read_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ); +uint8_t Eeprom_Write_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size , uint32_t timeout ); +uint8_t Eeprom_Read_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ); +uint8_t Eeprom_Write_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ); +void Eeprom_send_callback(eeprom_t *eeprom); +uint8_t Eeprom_send(eeprom_t *eeprom); +#endif \ No newline at end of file diff --git a/backup/obolete/eeprom_port.c b/backup/obolete/eeprom_port.c new file mode 100644 index 0000000..f114723 --- /dev/null +++ b/backup/obolete/eeprom_port.c @@ -0,0 +1,111 @@ +#include "eeprom.h" +#include "main.h" +#include "config.h" +#include "elog.h" + +extern int Eeprom_Port(); +extern void Eeprom_Task(); +extern int Config_Read_Eeprom( uint8_t numSeconds); +extern int Config_Write_Eeprom( ); + +osThreadId_t eeprom_taskHandle; +const osThreadAttr_t eeprom_task_attributes = { +.name = "eeprom_task", +.stack_size = 256, +.priority = (osPriority_t) osPriorityLow, +}; + +/* 1: 8bit 2: 16bit I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT */ + +enum EEPROM_MODEL{ + AT24C01 =127, + AT24C02 =255, + AT24C04 =511, + AT24C08 =1023, + AT24C16 =2047, + AT24C32 =4095, + AT24C64 =8191, + AT24C128 =16383, + AT24C256 =32767, +}; + +eeprom_t *eeprom; +extern I2C_HandleTypeDef hi2c1; +I2C_HandleTypeDef *Eeprom_I2C = &hi2c1; + +extern struct config config; +extern int Config_Read_Eeprom( uint8_t numSeconds); + +uint8_t eeprom_buf; + +int Eeprom_Port() +{ + eeprom = Eeprom_init(); + Eeprom_SET_I2C( eeprom, &hi2c1 ); + Eeprom_SET_Device_Model( eeprom, AT24C02 ); + Eeprom_SET_Device_Addr( eeprom, 0xA0 ); + if ( eeprom->model < AT24C16 ) + Eeprom_SET_Mem_Addr_Type( eeprom, I2C_MEMADD_SIZE_8BIT); + else + Eeprom_SET_Mem_Addr_Type( eeprom, I2C_MEMADD_SIZE_16BIT); + eeprom->stat = HAL_I2C_STATE_READY; + + eeprom_taskHandle = osThreadNew(Eeprom_Task, NULL, &eeprom_task_attributes); + // if (Config_Read_Eeprom( 8) == 0) + // { + // HAL_GPIO_TogglePin(RED_GPIO_Port,RED_Pin); + // // log_i( "ok>>>>>>>>"); + // } + + return 0; +} + +void Eeprom_Task() +{ + for ( ; ; ) + { + Eeprom_send( eeprom ); + } +} + +int Config_Read_Eeprom( uint8_t numSeconds) +{ + eeprom->stat= HAL_I2C_STATE_BUSY; + eeprom->time_base = osKernelGetTickCount(); + + uint8_t aa = Eeprom_Read_Multi_Byte_IT( eeprom, 0, (uint8_t *)&config, sizeof(config) ); + // uint8_t aa = HAL_I2C_Mem_Read_IT( eeprom->i2c, eeprom->dev_addr, 0, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&config, sizeof(config) ); + // uint8_t aa = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, 0, I2C_MEMADD_SIZE_8BIT, data, 1 ); + + while(HAL_I2C_GetState(eeprom->i2c)!=HAL_I2C_STATE_READY ){ + if (( osKernelGetTickCount() - eeprom->time_base) >numSeconds*1000) + { + return -1; + } + } + + log_i("eeprom init ok."); + + if(config_check()==0){ + return 0; + } + config_reset(); + return 0; + +} + +/* config 内容写道eeprom ,一个一个依据时间限写入,启用任务*/ +int Config_Write_Eeprom( ) +{ + // Eeprom_Port_Init(); + Eeprom_Write_Multi_Byte_IT( eeprom, 0, (uint8_t *)&config, sizeof(config) ); + for ( ; ; ) + { + if (eeprom->size > 0) + Eeprom_send_callback( eeprom ); + else + return -1; + } + return 0; + +} \ No newline at end of file diff --git a/backup/obolete/i2c_ads1115.c b/backup/obolete/i2c_ads1115.c new file mode 100644 index 0000000..a4c48f9 --- /dev/null +++ b/backup/obolete/i2c_ads1115.c @@ -0,0 +1,162 @@ +//i2c_ads1115.c +#include "i2c_ads1115.h" +#include +#include "i2c.h" +#include "main.h" +#include "elog.h" + +/* +* ads1115_get_voltage_val( hi2c1, 0x00, CONFIG_REG_H, CONFIG_REG_L ) +*/ + +extern I2C_HandleTypeDef hi2c1; +#define ADS1115_hi2c hi2c1 + +int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle) +{ + ads1115_config_register(ads1115_I2cHandle, 0x00, CONFIG_REG_H, CONFIG_REG_L); + return 0; +} + + +/** + * @brief + * @param [in] ads1115_I2cHandle + * @param [in] pointADD -- 0x01 写配置寄存器 + * @param [in] configH + * @param [in] configL + * + * @details + */ +void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL) +{ + uint8_t reg_data[3]={pointADD,configH,configL}; + log_i( "115 %d %d %d ", reg_data[0], reg_data[1], reg_data[2]); + while(HAL_I2C_Master_Transmit( &ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, reg_data, 3, 2000 ) != HAL_OK) + { + if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) + { + log_i( "ads1115 Config Register error!!!\r\n" ); + } + } +} + + +int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle) +{ + int16_t data; + uint8_t rx_data[2]={0}; + + while( HAL_I2C_Master_Transmit( &ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000 ) != HAL_OK ) + { + if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) + { + log_i( "ads1115 convert Register error!!!\r\n" ); + } + } + + while( HAL_I2C_Master_Receive(&ads1115_I2cHandle, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK ) + { + if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) + { + log_i( "ads1115 read data error!!!\r\n" ); + } + } + + data = rx_data[0]*256 + rx_data[1]; + return data; +} + + +double ads1115_get_voltage_val( I2C_HandleTypeDef ads1115_I2cHandle, uint8_t pointADD, uint8_t configH, uint8_t configL) +{ + double val; + int16_t ad_val; + double coeff_mv = 1000.0; /* 输出 毫伏*/ + double coeff_v = 1000000.0; /* 输出 伏*/ + + // ads1115_config_register( ads1115_I2cHandle, pointADD, configH, configL ); + // // HAL_Delay(10); + // osDelay(10); + + + // ad_val=ads1115_read_data( ads1115_I2cHandle ); + // if( (ad_val==0x7FFF)|(ad_val==0X8000) )//是否超量程了 + // { + // ad_val=0; + // log_i("over PGA\r\n"); + // } + + // switch( ( 0x0E&configH )>>1 )//量程对应的分辨率 + // { + // case(0x00): + // val=(double)ad_val*187.5/coeff_mv;// + // break; + // case(0x01): + // val=(double)ad_val*125/coeff_mv; + // break; + // case(0x02): + // val=(double)ad_val*62.5/coeff_mv; + // break; + // case(0x03): + // val=(double)ad_val*31.25/coeff_mv; + // break; + // case(0x04): + // val=(double)ad_val*15.625/coeff_mv; + // break; + // case(0x05): + // val=(double)ad_val*7.8125/coeff_mv; + // break; + // } + + + return coeff_mv; + +} + + +int ads1115_get ( I2C_HandleTypeDef ads1115_I2cHandle, uint8_t pointADD, uint8_t configH, uint8_t configL) +{ + double val; + int16_t ad_val; + double coeff_mv = 1000.0; /* 输出 毫伏*/ + double coeff_v = 1000000.0; /* 输出 伏*/ + + ads1115_config_register( ads1115_I2cHandle, pointADD, configH, configL ); + // HAL_Delay(10); + osDelay(10); + + + ad_val=ads1115_read_data( ads1115_I2cHandle ); + // if( (ad_val==0x7FFF)|(ad_val==0X8000) )//是否超量程了 + // { + // ad_val=0; + // log_i("over PGA\r\n"); + // } + + // switch( ( 0x0E&configH )>>1 )//量程对应的分辨率 + // { + // case(0x00): + // val=(double)ad_val*187.5/coeff_mv;// + // break; + // case(0x01): + // val=(double)ad_val*125/coeff_mv; + // break; + // case(0x02): + // val=(double)ad_val*62.5/coeff_mv; + // break; + // case(0x03): + // val=(double)ad_val*31.25/coeff_mv; + // break; + // case(0x04): + // val=(double)ad_val*15.625/coeff_mv; + // break; + // case(0x05): + // val=(double)ad_val*7.8125/coeff_mv; + // break; + // } + + + return ad_val; + +} \ No newline at end of file diff --git a/backup/obolete/i2c_ads1115.h b/backup/obolete/i2c_ads1115.h new file mode 100644 index 0000000..c0c7680 --- /dev/null +++ b/backup/obolete/i2c_ads1115.h @@ -0,0 +1,186 @@ +//i2c_ads1115.h +#ifndef __IIC_ADS1115_H +#define __IIC_ADS1115_H + +#include "i2c.h" +#include "i2chelper.h" + +#define ADS1115_WRITE_ADDRESS 0x90 +#define ADS1115_READ_ADDRESS 0x91 +//以下两个预处理作为配置寄存器预处理要更改其配在这里更改 +//也可以添加新的预处理对不同通道的采集或者选取不同的采样速率等 +#define CONFIG_REG_H ADS1115_REG_CONFIG_OS_START|\ + ADS1115_REG_CONFIG_MUX_SINGLE_0|\ + ADS1115_REG_CONFIG_PGA_4|\ + ADS1115_REG_CONFIG_MODE_SINGLE + +#define CONFIG_REG_L ADS1115_REG_CONFIG_DR_128|\ + ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL|\ + ADS1115_REG_CONFIG_COMP_POL_LOW|\ + ADS1115_REG_CONFIG_COMP_LAT_NONLATCH|\ + ADS1115_REG_CONFIG_COMP_QUE_DIS + + +/***************/ +//配置寄存器说明 + +//config register +/*CRH[15:8](R/W) + BIT 15 14 13 12 11 10 9 8 + NAME OS MUX2 MUX1 MUX0 PGA2 PGA1 PGA0 MODE +CRL[7:0] (R/W) + BIT 7 6 5 4 3 2 1 0 + NAME DR0 DR1 DR0 COM_MODE COM_POL COM_LAT COM_QUE1 COM_QUE0 + + + ----------------------------------------------------------------------------------- + * 15 | OS | 运行状态会单词转换开始 + * | | 写时: + * | | 0 : 无效 + * | | 1 : 开始单次转换处于掉电状态时 + * | | 读时: + * | | 0 : 正在转换 + * | | 1 : 未执行转换 + * ----------------------------------------------------------------------------------- + * 14:12 | MUX [2:0] | 输入复用多路配置 + * | | 000 : AINP = AIN0 and AINN = AIN1 (default) + * | | 001 : AINP = AIN0 and AINN = AIN3 + * | | 010 : AINP = AIN1 and AINN = AIN3 + * | | 011 : AINP = AIN2 and AINN = AIN3 + * | | 100 : AINP = AIN0 and AINN = GND + * | | 101 : AINP = AIN1 and AINN = GND + * | | 110 : AINP = AIN2 and AINN = GND + * | | 111 : AINP = AIN3 and AINN = GND + * ----------------------------------------------------------------------------------- + * 11:9 | PGA [2:0] | 可编程增益放大器配置(FSR full scale range) + * | | 000 : FSR = В±6.144 V + * | | 001 : FSR = В±4.096 V + * | | 010 : FSR = В±2.048 V (默认) + * | | 011 : FSR = В±1.024 V + * | | 100 : FSR = В±0.512 V + * | | 101 : FSR = В±0.256 V + * | | 110 : FSR = В±0.256 V + * | | 111 : FSR = В±0.256 V + * ----------------------------------------------------------------------------------- + * 8 | MODE | 工作模式 + * | | 0 : 连续转换 + * | | 1 : 单词转换 + * ----------------------------------------------------------------------------------- + * 7:5 | DR [2:0] | 采样频率 + * | | 000 : 8 SPS + * | | 001 : 16 SPS + * | | 010 : 32 SPS + * | | 011 : 64 SPS + * | | 100 : 128 SPS (默认) + * | | 101 : 250 SPS + * | | 110 : 475 SPS + * | | 111 : 860 SPS + * ----------------------------------------------------------------------------------- + * 4 | COMP_MODE | 比较器模式 + * | | 0 : 传统比较器 (default) + * | | 1 : 窗口比较器 + * ----------------------------------------------------------------------------------- + * 3 | COMP_POL | Comparator polarity + * | | 0 : 低电平有效 (default) + * | | 1 : 高电平有效 + * ----------------------------------------------------------------------------------- + * 2 | COMP_LAT | Latching comparator + * | | 0 : 非锁存比较器. (default) + * | | 1 : 锁存比较器. + * ----------------------------------------------------------------------------------- + * 1:0 | COMP_QUE [1:0] | Comparator queue and disable + * | | 00 : Assert after one conversion + * | | 01 : Assert after two conversions + * | | 10 : Assert after four conversions + * | | 11 : 禁用比较器并将ALERT/RDY设置为高阻抗 (default) + * ----------------------------------------------------------------------------------- +*/ + + + +//地址指针寄存器 + +#define ADS1015_REG_POINTER_CONVERT (0x00) +#define ADS1015_REG_POINTER_CONFIG (0x01) +#define ADS1015_REG_POINTER_LOWTHRESH (0x02) +#define ADS1015_REG_POINTER_HITHRESH (0x03) +// 单次转换开始 +#define ADS1115_REG_CONFIG_OS_START (0x1U << 7)//设备单次转换开启 高字节的最高位 +#define ADS1115_REG_CONFIG_OS_NULL (0x0U << 7) +//输入引脚选择和输入方式选择 +#define ADS1115_REG_CONFIG_MUX_Diff_01 (0x0U << 4) // 差分输入0引脚和1引脚 +#define ADS1115_REG_CONFIG_MUX_Diff_03 (0x1U << 4) // 差分输入0引脚和3引脚 +#define ADS1115_REG_CONFIG_MUX_Diff_13 (0x2U << 4) // 差分输入1引脚和3引脚 +#define ADS1115_REG_CONFIG_MUX_Diff_23 (0x3U << 4) // 差分输入2引脚和3引脚 +#define ADS1115_REG_CONFIG_MUX_SINGLE_0 (0x4U << 4) //单端输入 0 +#define ADS1115_REG_CONFIG_MUX_SINGLE_1 (0x5U << 4) //单端输入 1 +#define ADS1115_REG_CONFIG_MUX_SINGLE_2 (0x6U << 4) //单端输入 2 +#define ADS1115_REG_CONFIG_MUX_SINGLE_3 (0x7U << 4) //单端输入 3 + +//量程选择 +#define ADS1115_REG_CONFIG_PGA_6 (0x0U << 1) // +/- 6.1144 +#define ADS1115_REG_CONFIG_PGA_4 (0x1U << 1) // +/- 4.096 +#define ADS1115_REG_CONFIG_PGA_2 (0x2U << 1) // +/- 2.048 +#define ADS1115_REG_CONFIG_PGA_1 (0x3U << 1) // +/- 1.024 +#define ADS1115_REG_CONFIG_PGA_05 (0x4U << 1) // +/- 0.512 +#define ADS1115_REG_CONFIG_PGA_02 (0x5U << 1) // +/- 0.256 + +//运行方式 + +#define ADS1115_REG_CONFIG_MODE_SINGLE (0x1U << 0) // 单次 +#define ADS1115_REG_CONFIG_MODE_CONTIN (0x0U << 0) //连续转换 + +//转换速率 + +#define ADS1115_REG_CONFIG_DR_8 (0x0U << 5) +#define ADS1115_REG_CONFIG_DR_16 (0x1U << 5) +#define ADS1115_REG_CONFIG_DR_32 (0x2U << 5) +#define ADS1115_REG_CONFIG_DR_64 (0x3U << 5) +#define ADS1115_REG_CONFIG_DR_128 (0x4U << 5) +#define ADS1115_REG_CONFIG_DR_250 (0x5U << 5) +#define ADS1115_REG_CONFIG_DR_475 (0x6U << 5) +#define ADS1115_REG_CONFIG_DR_860 (0x7U << 5) + +//比较器模式 +#define ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL (0x0U << 4)//默认 +#define ADS1115_REG_CONFIG_COMP_MODE_WINDOW (0x1U << 4) + + +#define ADS1115_REG_CONFIG_COMP_POL_LOW (0x0U << 3)//默认 +#define ADS1115_REG_CONFIG_COMP_POL_HIG (0x1U << 3) + + +#define ADS1115_REG_CONFIG_COMP_LAT_NONLATCH (0x0U << 2) +#define ADS1115_REG_CONFIG_COMP_LAT_LATCH (0x1U << 2) + + +#define ADS1115_REG_CONFIG_COMP_QUE_ONE (0x0U << 0) +#define ADS1115_REG_CONFIG_COMP_QUE_TWO (0x1U << 0) +#define ADS1115_REG_CONFIG_COMP_QUE_THR (0x2U << 0) +#define ADS1115_REG_CONFIG_COMP_QUE_DIS (0x3U << 0) + +int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle); +void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); +int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle); +double ads1115_get_voltage_val(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); + +#endif + +/* +步骤一:write to config register(写配置寄存器) +1:发送从机地址0x90(写) +2:发送0x01 (指向配置寄存器) +3:配置config register +发送字节:0x84(高八位) +发送字节:0x83(低八位) + +步骤二:write to pointer register(转向转换寄存器) +1:发送从机地址0x90(写) +2:发送0x00(指向转换寄存器) + +步骤三:read conversion register(读取转换寄存器的数据) +1:发送从机地址0x91(读) +2:接收转换寄存器的高八位 +3:接收转换寄存器的低八位 + +*/ \ No newline at end of file diff --git a/backup/obolete/led.c b/backup/obolete/led.c new file mode 100644 index 0000000..b3bcaf7 --- /dev/null +++ b/backup/obolete/led.c @@ -0,0 +1,79 @@ +#include "led.h" + +static struct led *led_table[LED_MAX_NUM]; +static uint32_t p_led_table=0; +/** + * @brief 注册LED灯 + * + * @param led struct led 结构指针 + * @param gpio LED所在的GPIO + * @param pin LED所在的引脚 + * @param state LED初始状态 + * @param level_on LED点亮时的电平 1:高 0:低 + * @return int 0:成功 非0:失败 + */ +int led_register(struct led *led,GPIO_TypeDef *gpio,uint16_t pin,enum led_state state,uint16_t level_on) +{ + if(p_led_table>=LED_MAX_NUM-1){ + return -1; + } + led->gpio=gpio; + led->pin=pin; + led->state=state; + led->level_on=level_on; + led_table[p_led_table++]=led; + return 0; +} +/** + * @brief 设置LED状态 + * + * @param led struct led 结构指针 + * @param state LED状态 + * @return int 0:成功 + */ +int led_set_state(struct led *led,enum led_state state) +{ + led->state=state; + return 0; +} +/** + * @brief led回调函数 每100ms调用一次 + * + */ +void led_callback(void) +{ + int i; + static uint32_t tick_con=0; + tick_con++; + for(i=0;istate) + { + case LED_STATE_OFF: + HAL_GPIO_WritePin( led_table[i]->gpio,led_table[i]->pin,(~led_table[i]->level_on)&1 ); + // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,(~led_table[i]->level_on)&1); + break; + case LED_STATE_ON: + HAL_GPIO_WritePin( led_table[i]->gpio,led_table[i]->pin,led_table[i]->level_on&1 ); + // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,led_table[i]->level_on&1); + break; + case LED_STATE_FLICKER_QUICK: + HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); + // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin)); + break; + case LED_STATE_FLICKER_MEDIUM: + if((tick_con&0x01)==0){ + HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); + // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin)); + } + break; + case LED_STATE_FLICKER_SLOW: + if((tick_con&0x03)==0){ + HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); + // GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin)); + } + break; + default: + break; + } + } +} \ No newline at end of file diff --git a/backup/obolete/led.h b/backup/obolete/led.h new file mode 100644 index 0000000..7bf3c19 --- /dev/null +++ b/backup/obolete/led.h @@ -0,0 +1,35 @@ +#ifndef __LED_H +#define __LED_H + +#include "stdint.h" +#include "main.h" +#define LED_MAX_NUM 4 + +// 回调需要这个参数,控制时开关还是闪烁,闪烁快慢 +enum led_state{ + LED_STATE_ON, + LED_STATE_FLICKER_SLOW, + LED_STATE_FLICKER_MEDIUM, + LED_STATE_FLICKER_QUICK, + LED_STATE_OFF + +}; + +// 标准库的 GPIO_TypeDef, 改为HAL库 +struct led +{ + enum led_state state; + GPIO_TypeDef *gpio; + uint16_t pin; + uint16_t level_on; +}; + +// 依据GPIO 信息注册 +int led_register(struct led *led, GPIO_TypeDef *gpio, uint16_t pin, enum led_state state, uint16_t level_on ); + +// 初始化状态 +int led_set_state(struct led *led,enum led_state state); + +// 执行 -- 由状态决定 +void led_callback(void); +#endif