From 966a78095fdfc4079fc57c4c65167fccaff05ba9 Mon Sep 17 00:00:00 2001 From: Patrick W3AXL Date: Wed, 9 Oct 2024 15:46:05 -0400 Subject: [PATCH 01/17] initial transition to cmake and getting fw work for v2 started --- fw/.mxproject | 7 +- fw/CMakeLists.txt | 117 ++++++++++++ fw/CMakePresets.json | 60 ++++++ fw/Core/Inc/stm32f1xx_it.h | 1 + fw/Core/Inc/usart.h | 3 + fw/Core/Src/dma.c | 2 +- fw/Core/Src/main.c | 13 +- fw/Core/Src/stm32f1xx_hal_msp.c | 3 +- fw/Core/Src/stm32f1xx_it.c | 15 ++ fw/Core/Src/syscalls.c | 176 ++++++++++++++++++ fw/Core/Src/sysmem.c | 79 ++++++++ fw/Core/Src/tim.c | 2 +- fw/Core/Src/usart.c | 88 ++++++++- fw/DVM-V24-stm32f103.ioc | 70 ++++--- .../Device/ST/STM32F1xx/Include/stm32f1xx.h | 2 +- .../Inc/Legacy/stm32_hal_legacy.h | 91 ++++++--- .../Inc/stm32f1xx_hal_cortex.h | 2 + .../Inc/stm32f1xx_hal_tim.h | 35 ++-- .../Inc/stm32f1xx_ll_cortex.h | 2 +- .../Inc/stm32f1xx_ll_iwdg.h | 10 +- .../Inc/stm32f1xx_ll_tim.h | 25 ++- .../Inc/stm32f1xx_ll_usart.h | 114 ++++++------ .../Inc/stm32f1xx_ll_usb.h | 101 +++++----- .../Inc/stm32f1xx_ll_utils.h | 2 +- .../STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c | 2 +- .../Src/stm32f1xx_hal_cortex.c | 82 +++++--- .../Src/stm32f1xx_hal_flash.c | 5 - .../Src/stm32f1xx_hal_flash_ex.c | 3 - .../Src/stm32f1xx_hal_gpio.c | 2 +- .../Src/stm32f1xx_hal_iwdg.c | 3 +- .../Src/stm32f1xx_hal_pcd.c | 30 ++- .../Src/stm32f1xx_hal_tim.c | 62 +++--- .../Src/stm32f1xx_hal_tim_ex.c | 34 +--- .../Src/stm32f1xx_hal_uart.c | 61 +++--- .../Src/stm32f1xx_ll_usb.c | 88 ++++----- fw/Makefile | 9 +- fw/USB_DEVICE/App/usbd_cdc_if.c | 4 +- fw/USB_DEVICE/Target/usbd_conf.c | 4 +- fw/cmake/gcc-arm-none-eabi.cmake | 48 +++++ fw/cmake/stm32cubemx/CMakeLists.txt | 79 ++++++++ fw/v24/inc/config.h | 20 +- fw/v24/src/vcp.c | 5 +- 42 files changed, 1167 insertions(+), 394 deletions(-) create mode 100644 fw/CMakeLists.txt create mode 100644 fw/CMakePresets.json create mode 100644 fw/Core/Src/syscalls.c create mode 100644 fw/Core/Src/sysmem.c create mode 100644 fw/cmake/gcc-arm-none-eabi.cmake create mode 100644 fw/cmake/stm32cubemx/CMakeLists.txt diff --git a/fw/.mxproject b/fw/.mxproject index efcdfa5..a15ef9c 100644 --- a/fw/.mxproject +++ b/fw/.mxproject @@ -1,5 +1,5 @@ [PreviousLibFiles] -LibFiles=Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usb.h;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_def.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_bus.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_system.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_utils.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio_ex.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_uart.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usart.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\CDC\Inc\usbd_cdc.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usb.h;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_def.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_bus.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_system.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_utils.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio_ex.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_uart.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usart.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\CDC\Inc\usbd_cdc.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f103xb.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.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; +LibFiles=Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usb.h;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_def.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_bus.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_system.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_utils.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio_ex.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_uart.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usart.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\CDC\Inc\usbd_cdc.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pcd_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usb.h;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_def.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_bus.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_system.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_utils.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio_ex.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_iwdg.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_uart.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usart.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\CDC\Inc\usbd_cdc.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f103xb.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.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\dma.c;Core\Src\iwdg.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_cdc_if.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.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\CDC\Src\usbd_cdc.c; @@ -45,3 +45,8 @@ SourcePath#1=..\USB_DEVICE\App SourcePath#2=..\USB_DEVICE\Target SourceFiles=; +[PreviousUsedCMakes] +SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\iwdg.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_cdc_if.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.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\CDC\Src\usbd_cdc.c; +HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Middlewares\ST\STM32_USB_Device_Library\Core\Inc;Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Inc;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;USB_DEVICE\App;USB_DEVICE\Target; +CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER; + diff --git a/fw/CMakeLists.txt b/fw/CMakeLists.txt new file mode 100644 index 0000000..32dc175 --- /dev/null +++ b/fw/CMakeLists.txt @@ -0,0 +1,117 @@ +cmake_minimum_required(VERSION 3.22) + +# +# This file is generated only once, +# and is not re-generated if converter is called multiple times. +# +# User is free to modify the file as much as necessary +# + +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) + + +# Define the build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# Set the project name +set(CMAKE_PROJECT_NAME DVM-V24) +set(CMAKE_TARGET_V1 dvm-v24-v1) +set(CMAKE_TARGET_V2 dvm-v24-v2) + +# Include toolchain file +include("cmake/gcc-arm-none-eabi.cmake") + +# Enable compile command to ease indexing with e.g. clangd +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + +# Enable CMake support for ASM and C languages +enable_language(C ASM) + +# +# Set GIT_VER compiler directive +# +set(GIT_VER "") +set(GIT_VER_HASH "UNKNOWN") +execute_process(COMMAND git describe --abbrev=8 --dirty --always WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_VER OUTPUT_STRIP_TRAILING_WHITESPACE) +execute_process(COMMAND git describe --abbrev=8 --always WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_VER_HASH OUTPUT_STRIP_TRAILING_WHITESPACE) +message("Git Version: " ${GIT_VER}) +message("Git Hash: " ${GIT_VER_HASH}) + +# Core project settings +project(${CMAKE_PROJECT_NAME}) +message("Build type: " ${CMAKE_BUILD_TYPE}) + +# Create executables +add_executable(${CMAKE_TARGET_V1}) +add_executable(${CMAKE_TARGET_V2}) + +# Add STM32CubeMX generated sources +add_subdirectory(cmake/stm32cubemx) + +# Common source files +set(V24_SOURCES + v24/src/fault.c + v24/src/fifo.c + v24/src/hdlc.c + v24/src/log.c + v24/src/serial.c + v24/src/sync.c + v24/src/util.c + v24/src/vcp.c +) + +# Common includes +set(V24_INCLUDE v24/inc) + +# +# V1 Target Setup +# +target_link_directories(${CMAKE_TARGET_V1} PRIVATE +) + +target_sources(${CMAKE_TARGET_V1} PRIVATE + ${V24_SOURCES} +) + +target_include_directories(${CMAKE_TARGET_V1} PRIVATE + ${V24_INCLUDE} +) + +target_compile_definitions(${CMAKE_TARGET_V1} PRIVATE + DVM_V24_V1 + GIT_HASH="${GIT_VER_HASH}" +) + +# Add linked libraries +target_link_libraries(${CMAKE_TARGET_V1} + stm32cubemx +) + +# +# V2 Target Setup +# +target_link_directories(${CMAKE_TARGET_V2} PRIVATE +) + +target_sources(${CMAKE_TARGET_V2} PRIVATE + ${V24_SOURCES} +) + +target_include_directories(${CMAKE_TARGET_V2} PRIVATE + ${V24_INCLUDE} +) + +target_compile_definitions(${CMAKE_TARGET_V2} PRIVATE + DVM_V24_V2 + GIT_HASH="${GIT_VER_HASH}" +) + +# Add linked libraries +target_link_libraries(${CMAKE_TARGET_V2} + stm32cubemx +) \ No newline at end of file diff --git a/fw/CMakePresets.json b/fw/CMakePresets.json new file mode 100644 index 0000000..1ed4e19 --- /dev/null +++ b/fw/CMakePresets.json @@ -0,0 +1,60 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake", + "cacheVariables": { + } + }, + { + "name": "Debug", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "RelWithDebInfo", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "Release", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "MinSizeRel", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel" + } + } + ], + "buildPresets": [ + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "RelWithDebInfo", + "configurePreset": "RelWithDebInfo" + }, + { + "name": "Release", + "configurePreset": "Release" + }, + { + "name": "MinSizeRel", + "configurePreset": "MinSizeRel" + } + ] +} \ No newline at end of file diff --git a/fw/Core/Inc/stm32f1xx_it.h b/fw/Core/Inc/stm32f1xx_it.h index e3875ce..1bcc4c7 100644 --- a/fw/Core/Inc/stm32f1xx_it.h +++ b/fw/Core/Inc/stm32f1xx_it.h @@ -59,6 +59,7 @@ void DMA1_Channel7_IRQHandler(void); void USB_HP_CAN1_TX_IRQHandler(void); void USB_LP_CAN1_RX0_IRQHandler(void); void TIM2_IRQHandler(void); +void USART1_IRQHandler(void); void USART2_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/fw/Core/Inc/usart.h b/fw/Core/Inc/usart.h index ed6ebc8..16f95a5 100644 --- a/fw/Core/Inc/usart.h +++ b/fw/Core/Inc/usart.h @@ -32,12 +32,15 @@ extern "C" { /* USER CODE END Includes */ +extern UART_HandleTypeDef huart1; + extern UART_HandleTypeDef huart2; /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ +void MX_USART1_UART_Init(void); void MX_USART2_UART_Init(void); /* USER CODE BEGIN Prototypes */ diff --git a/fw/Core/Src/dma.c b/fw/Core/Src/dma.c index 4ca6834..04b3b67 100644 --- a/fw/Core/Src/dma.c +++ b/fw/Core/Src/dma.c @@ -44,7 +44,7 @@ void MX_DMA_Init(void) /* DMA interrupt init */ /* DMA1_Channel7_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_DMA, 0); + HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); } diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index 4edbb0f..ff57396 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -22,7 +22,9 @@ #include "iwdg.h" #include "tim.h" #include "usart.h" +#ifdef DVM_V24_V1 #include "usb_device.h" +#endif #include "gpio.h" /* Private includes ----------------------------------------------------------*/ @@ -105,6 +107,7 @@ void linkLED() */ int main(void) { + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ @@ -130,10 +133,12 @@ int main(void) MX_DMA_Init(); MX_USART2_UART_Init(); MX_TIM2_Init(); - MX_USB_DEVICE_Init(); - #ifndef DISABLE_WATCHDOG - MX_IWDG_Init(); + #ifdef DVM_V24_V2 + MX_USART1_UART_Init(); + #else + MX_USB_DEVICE_Init(); #endif + MX_IWDG_Init(); /* USER CODE BEGIN 2 */ // Init stuff log_set_uart(&huart2); @@ -142,7 +147,9 @@ int main(void) // Enumerate the VCP //log_info("Enumerating USB VCP"); + #ifdef DVM_V24_V1 VCPEnumerate(); + #endif // Start sync serial handler log_info("Starting synchronous serial handler"); diff --git a/fw/Core/Src/stm32f1xx_hal_msp.c b/fw/Core/Src/stm32f1xx_hal_msp.c index 2c48caa..14b9560 100644 --- a/fw/Core/Src/stm32f1xx_hal_msp.c +++ b/fw/Core/Src/stm32f1xx_hal_msp.c @@ -1,3 +1,4 @@ + /* USER CODE BEGIN Header */ /** ****************************************************************************** @@ -20,7 +21,6 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" - /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -63,6 +63,7 @@ */ void HAL_MspInit(void) { + /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ diff --git a/fw/Core/Src/stm32f1xx_it.c b/fw/Core/Src/stm32f1xx_it.c index 0fcd79b..f2a8336 100644 --- a/fw/Core/Src/stm32f1xx_it.c +++ b/fw/Core/Src/stm32f1xx_it.c @@ -59,6 +59,7 @@ extern PCD_HandleTypeDef hpcd_USB_FS; extern TIM_HandleTypeDef htim2; extern DMA_HandleTypeDef hdma_usart2_tx; +extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; /* USER CODE BEGIN EV */ @@ -265,6 +266,20 @@ void TIM2_IRQHandler(void) /* USER CODE END TIM2_IRQn 1 */ } +/** + * @brief This function handles USART1 global interrupt. + */ +void USART1_IRQHandler(void) +{ + /* USER CODE BEGIN USART1_IRQn 0 */ + + /* USER CODE END USART1_IRQn 0 */ + HAL_UART_IRQHandler(&huart1); + /* USER CODE BEGIN USART1_IRQn 1 */ + + /* USER CODE END USART1_IRQn 1 */ +} + /** * @brief This function handles USART2 global interrupt. */ diff --git a/fw/Core/Src/syscalls.c b/fw/Core/Src/syscalls.c new file mode 100644 index 0000000..e33a849 --- /dev/null +++ b/fw/Core/Src/syscalls.c @@ -0,0 +1,176 @@ +/** + ****************************************************************************** + * @file syscalls.c + * @author Auto-generated by STM32CubeMX + * @brief Minimal System calls file + * + * For more information about which c-functions + * need which of these lowlevel functions + * please consult the Newlib libc-manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2024 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 +#include +#include +#include +#include +#include +#include +#include + + +/* Variables */ +extern int __io_putchar(int ch) __attribute__((weak)); +extern int __io_getchar(void) __attribute__((weak)); + + +char *__env[1] = { 0 }; +char **environ = __env; + + +/* Functions */ +void initialise_monitor_handles() +{ +} + +int _getpid(void) +{ + return 1; +} + +int _kill(int pid, int sig) +{ + (void)pid; + (void)sig; + errno = EINVAL; + return -1; +} + +void _exit (int status) +{ + _kill(status, -1); + while (1) {} /* Make sure we hang here */ +} + +__attribute__((weak)) int _read(int file, char *ptr, int len) +{ + (void)file; + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + *ptr++ = __io_getchar(); + } + + return len; +} + +__attribute__((weak)) int _write(int file, char *ptr, int len) +{ + (void)file; + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + __io_putchar(*ptr++); + } + return len; +} + +int _close(int file) +{ + (void)file; + return -1; +} + + +int _fstat(int file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _isatty(int file) +{ + (void)file; + return 1; +} + +int _lseek(int file, int ptr, int dir) +{ + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +int _open(char *path, int flags, ...) +{ + (void)path; + (void)flags; + /* Pretend like we always fail */ + return -1; +} + +int _wait(int *status) +{ + (void)status; + errno = ECHILD; + return -1; +} + +int _unlink(char *name) +{ + (void)name; + errno = ENOENT; + return -1; +} + +int _times(struct tms *buf) +{ + (void)buf; + return -1; +} + +int _stat(char *file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _link(char *old, char *new) +{ + (void)old; + (void)new; + errno = EMLINK; + return -1; +} + +int _fork(void) +{ + errno = EAGAIN; + return -1; +} + +int _execve(char *name, char **argv, char **env) +{ + (void)name; + (void)argv; + (void)env; + errno = ENOMEM; + return -1; +} diff --git a/fw/Core/Src/sysmem.c b/fw/Core/Src/sysmem.c new file mode 100644 index 0000000..246470e --- /dev/null +++ b/fw/Core/Src/sysmem.c @@ -0,0 +1,79 @@ +/** + ****************************************************************************** + * @file sysmem.c + * @author Generated by STM32CubeMX + * @brief System Memory calls file + * + * For more information about which C functions + * need which of these lowlevel functions + * please consult the newlib libc manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2024 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 +#include + +/** + * Pointer to the current high watermark of the heap usage + */ +static uint8_t *__sbrk_heap_end = NULL; + +/** + * @brief _sbrk() allocates memory to the newlib heap and is used by malloc + * and others from the C library + * + * @verbatim + * ############################################################################ + * # .data # .bss # newlib heap # MSP stack # + * # # # # Reserved by _Min_Stack_Size # + * ############################################################################ + * ^-- RAM start ^-- _end _estack, RAM end --^ + * @endverbatim + * + * This implementation starts allocating at the '_end' linker symbol + * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack + * The implementation considers '_estack' linker symbol to be RAM end + * NOTE: If the MSP stack, at any point during execution, grows larger than the + * reserved size, please increase the '_Min_Stack_Size'. + * + * @param incr Memory size + * @return Pointer to allocated memory + */ +void *_sbrk(ptrdiff_t incr) +{ + extern uint8_t _end; /* Symbol defined in the linker script */ + extern uint8_t _estack; /* Symbol defined in the linker script */ + extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ + const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; + const uint8_t *max_heap = (uint8_t *)stack_limit; + uint8_t *prev_heap_end; + + /* Initialize heap end at first call */ + if (NULL == __sbrk_heap_end) + { + __sbrk_heap_end = &_end; + } + + /* Protect heap from growing into the reserved MSP stack */ + if (__sbrk_heap_end + incr > max_heap) + { + errno = ENOMEM; + return (void *)-1; + } + + prev_heap_end = __sbrk_heap_end; + __sbrk_heap_end += incr; + + return (void *)prev_heap_end; +} diff --git a/fw/Core/Src/tim.c b/fw/Core/Src/tim.c index 12ad70d..a246d92 100644 --- a/fw/Core/Src/tim.c +++ b/fw/Core/Src/tim.c @@ -79,7 +79,7 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) __HAL_RCC_TIM2_CLK_ENABLE(); /* TIM2 interrupt Init */ - HAL_NVIC_SetPriority(TIM2_IRQn, NVIC_PRI_TIM2, 0); + HAL_NVIC_SetPriority(TIM2_IRQn, 3, 0); HAL_NVIC_EnableIRQ(TIM2_IRQn); /* USER CODE BEGIN TIM2_MspInit 1 */ diff --git a/fw/Core/Src/usart.c b/fw/Core/Src/usart.c index a213794..c7d7e39 100644 --- a/fw/Core/Src/usart.c +++ b/fw/Core/Src/usart.c @@ -24,9 +24,39 @@ #include "config.h" /* USER CODE END 0 */ +UART_HandleTypeDef huart1; UART_HandleTypeDef huart2; DMA_HandleTypeDef hdma_usart2_tx; +/* USART1 init function */ + +void MX_USART1_UART_Init(void) +{ + + /* USER CODE BEGIN USART1_Init 0 */ + + /* USER CODE END USART1_Init 0 */ + + /* USER CODE BEGIN USART1_Init 1 */ + + /* USER CODE END USART1_Init 1 */ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USART1_Init 2 */ + + /* USER CODE END USART1_Init 2 */ + +} /* USART2 init function */ void MX_USART2_UART_Init(void) @@ -40,7 +70,7 @@ void MX_USART2_UART_Init(void) /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; - huart2.Init.BaudRate = 576000; + huart2.Init.BaudRate = 256000; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; @@ -61,7 +91,37 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==USART2) + if(uartHandle->Instance==USART1) + { + /* USER CODE BEGIN USART1_MspInit 0 */ + + /* USER CODE END USART1_MspInit 0 */ + /* USART1 clock enable */ + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART1 GPIO Configuration + PA9 ------> USART1_TX + PA10 ------> USART1_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USART1 interrupt Init */ + HAL_NVIC_SetPriority(USART1_IRQn, 4, 0); + HAL_NVIC_EnableIRQ(USART1_IRQn); + /* USER CODE BEGIN USART1_MspInit 1 */ + + /* USER CODE END USART1_MspInit 1 */ + } + else if(uartHandle->Instance==USART2) { /* USER CODE BEGIN USART2_MspInit 0 */ @@ -102,7 +162,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); /* USART2 interrupt Init */ - HAL_NVIC_SetPriority(USART2_IRQn, NVIC_PRI_USART, 0); + HAL_NVIC_SetPriority(USART2_IRQn, 6, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ @@ -113,7 +173,27 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if(uartHandle->Instance==USART2) + if(uartHandle->Instance==USART1) + { + /* USER CODE BEGIN USART1_MspDeInit 0 */ + + /* USER CODE END USART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART1_CLK_DISABLE(); + + /**USART1 GPIO Configuration + PA9 ------> USART1_TX + PA10 ------> USART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); + + /* USART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(USART1_IRQn); + /* USER CODE BEGIN USART1_MspDeInit 1 */ + + /* USER CODE END USART1_MspDeInit 1 */ + } + else if(uartHandle->Instance==USART2) { /* USER CODE BEGIN USART2_MspDeInit 0 */ diff --git a/fw/DVM-V24-stm32f103.ioc b/fw/DVM-V24-stm32f103.ioc index a5849ef..1e0d35e 100644 --- a/fw/DVM-V24-stm32f103.ioc +++ b/fw/DVM-V24-stm32f103.ioc @@ -27,44 +27,47 @@ Mcu.IP2=NVIC Mcu.IP3=RCC Mcu.IP4=SYS Mcu.IP5=TIM2 -Mcu.IP6=USART2 -Mcu.IP7=USB -Mcu.IP8=USB_DEVICE -Mcu.IPNb=9 +Mcu.IP6=USART1 +Mcu.IP7=USART2 +Mcu.IP8=USB +Mcu.IP9=USB_DEVICE +Mcu.IPNb=10 Mcu.Name=STM32F103C(8-B)Tx Mcu.Package=LQFP48 Mcu.Pin0=PC13-TAMPER-RTC Mcu.Pin1=PD0-OSC_IN -Mcu.Pin10=PA12 -Mcu.Pin11=PA13 -Mcu.Pin12=PA14 -Mcu.Pin13=PB3 -Mcu.Pin14=PB4 -Mcu.Pin15=PB5 -Mcu.Pin16=PB6 -Mcu.Pin17=PB7 -Mcu.Pin18=PB8 -Mcu.Pin19=PB9 +Mcu.Pin10=PA10 +Mcu.Pin11=PA11 +Mcu.Pin12=PA12 +Mcu.Pin13=PA13 +Mcu.Pin14=PA14 +Mcu.Pin15=PB3 +Mcu.Pin16=PB4 +Mcu.Pin17=PB5 +Mcu.Pin18=PB6 +Mcu.Pin19=PB7 Mcu.Pin2=PD1-OSC_OUT -Mcu.Pin20=VP_IWDG_VS_IWDG -Mcu.Pin21=VP_SYS_VS_Systick -Mcu.Pin22=VP_TIM2_VS_ClockSourceINT -Mcu.Pin23=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS +Mcu.Pin20=PB8 +Mcu.Pin21=PB9 +Mcu.Pin22=VP_IWDG_VS_IWDG +Mcu.Pin23=VP_SYS_VS_Systick +Mcu.Pin24=VP_TIM2_VS_ClockSourceINT +Mcu.Pin25=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS Mcu.Pin3=PA2 Mcu.Pin4=PA3 Mcu.Pin5=PB12 Mcu.Pin6=PB13 Mcu.Pin7=PB14 Mcu.Pin8=PB15 -Mcu.Pin9=PA11 -Mcu.PinsNb=24 +Mcu.Pin9=PA9 +Mcu.PinsNb=26 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F103C8Tx -MxCube.Version=6.10.0 -MxDb.Version=DB.6.0.100 +MxCube.Version=6.12.1 +MxDb.Version=DB.6.0.121 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.DMA1_Channel7_IRQn=true\:2\:0\:true\:false\:true\:false\:true\:true +NVIC.DMA1_Channel7_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.ForceEnableDMAVector=true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false @@ -74,11 +77,14 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:true\:false\:true\:false\:true\:false -NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.USART2_IRQn=true\:4\:0\:true\:false\:true\:true\:true\:true -NVIC.USB_HP_CAN1_TX_IRQn=true\:3\:0\:true\:false\:true\:true\:true\:true -NVIC.USB_LP_CAN1_RX0_IRQn=true\:3\:0\:true\:false\:true\:true\:true\:true +NVIC.TIM2_IRQn=true\:3\:0\:true\:false\:true\:true\:true\:true +NVIC.USART1_IRQn=true\:4\:0\:true\:false\:true\:true\:true\:true +NVIC.USART2_IRQn=true\:6\:0\:true\:false\:true\:true\:true\:true +NVIC.USB_HP_CAN1_TX_IRQn=true\:4\:0\:true\:false\:true\:true\:true\:true +NVIC.USB_LP_CAN1_RX0_IRQn=true\:4\:0\:true\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA10.Mode=Asynchronous +PA10.Signal=USART1_RX PA11.Locked=true PA11.Mode=Device PA11.Signal=USB_DM @@ -93,6 +99,8 @@ PA2.Mode=Asynchronous PA2.Signal=USART2_TX PA3.Mode=Asynchronous PA3.Signal=USART2_RX +PA9.Mode=Asynchronous +PA9.Signal=USART1_TX PB12.GPIOParameters=GPIO_Label PB12.GPIO_Label=LED_LINK PB12.Locked=true @@ -155,7 +163,7 @@ ProjectManager.CustomerFirmwarePackage= ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32F103C8Tx -ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.5 +ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.6 ProjectManager.FreePins=false ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x600 @@ -171,12 +179,12 @@ ProjectManager.ProjectName=DVM-V24-stm32f103 ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack= ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=Makefile +ProjectManager.TargetToolchain=CMake ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,7-MX_IWDG_Init-IWDG-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,7-MX_IWDG_Init-IWDG-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true RCC.ADCFreqValue=36000000 RCC.AHBFreq_Value=72000000 RCC.APB1CLKDivider=RCC_HCLK_DIV2 @@ -203,6 +211,8 @@ TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE TIM2.IPParameters=Prescaler,Period,AutoReloadPreload TIM2.Period=1875 TIM2.Prescaler=1 +USART1.IPParameters=VirtualMode +USART1.VirtualMode=VM_ASYNC USART2.BaudRate=256000 USART2.IPParameters=VirtualMode,Mode,BaudRate USART2.Mode=MODE_TX diff --git a/fw/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h b/fw/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h index bc1c89b..0f32778 100644 --- a/fw/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h +++ b/fw/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h @@ -93,7 +93,7 @@ */ #define __STM32F1_CMSIS_VERSION_MAIN (0x04) /*!< [31:24] main version */ #define __STM32F1_CMSIS_VERSION_SUB1 (0x03) /*!< [23:16] sub1 version */ -#define __STM32F1_CMSIS_VERSION_SUB2 (0x04) /*!< [15:8] sub2 version */ +#define __STM32F1_CMSIS_VERSION_SUB2 (0x05) /*!< [15:8] sub2 version */ #define __STM32F1_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */ #define __STM32F1_CMSIS_VERSION ((__STM32F1_CMSIS_VERSION_MAIN << 24)\ |(__STM32F1_CMSIS_VERSION_SUB1 << 16)\ diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h index b59ff6d..f71f5c2 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h @@ -37,16 +37,12 @@ extern "C" { #define AES_CLEARFLAG_CCF CRYP_CLEARFLAG_CCF #define AES_CLEARFLAG_RDERR CRYP_CLEARFLAG_RDERR #define AES_CLEARFLAG_WRERR CRYP_CLEARFLAG_WRERR -#if defined(STM32U5) || defined(STM32H7) || defined(STM32MP1) +#if defined(STM32H7) || defined(STM32MP1) #define CRYP_DATATYPE_32B CRYP_NO_SWAP #define CRYP_DATATYPE_16B CRYP_HALFWORD_SWAP #define CRYP_DATATYPE_8B CRYP_BYTE_SWAP #define CRYP_DATATYPE_1B CRYP_BIT_SWAP -#if defined(STM32U5) -#define CRYP_CCF_CLEAR CRYP_CLEAR_CCF -#define CRYP_ERR_CLEAR CRYP_CLEAR_RWEIF -#endif /* STM32U5 */ -#endif /* STM32U5 || STM32H7 || STM32MP1 */ +#endif /* STM32H7 || STM32MP1 */ /** * @} */ @@ -279,7 +275,7 @@ extern "C" { #define DAC_WAVEGENERATION_NOISE DAC_WAVE_NOISE #define DAC_WAVEGENERATION_TRIANGLE DAC_WAVE_TRIANGLE -#if defined(STM32G4) || defined(STM32L5) || defined(STM32H7) || defined (STM32U5) +#if defined(STM32G4) || defined(STM32H7) || defined (STM32U5) #define DAC_CHIPCONNECT_DISABLE DAC_CHIPCONNECT_EXTERNAL #define DAC_CHIPCONNECT_ENABLE DAC_CHIPCONNECT_INTERNAL #endif @@ -476,7 +472,9 @@ extern "C" { #define TYPEPROGRAMDATA_FASTBYTE FLASH_TYPEPROGRAMDATA_FASTBYTE #define TYPEPROGRAMDATA_FASTHALFWORD FLASH_TYPEPROGRAMDATA_FASTHALFWORD #define TYPEPROGRAMDATA_FASTWORD FLASH_TYPEPROGRAMDATA_FASTWORD +#if !defined(STM32F2) && !defined(STM32F4) && !defined(STM32F7) && !defined(STM32H7) #define PAGESIZE FLASH_PAGE_SIZE +#endif /* STM32F2 && STM32F4 && STM32F7 && STM32H7 */ #define TYPEPROGRAM_FASTBYTE FLASH_TYPEPROGRAM_BYTE #define TYPEPROGRAM_FASTHALFWORD FLASH_TYPEPROGRAM_HALFWORD #define TYPEPROGRAM_FASTWORD FLASH_TYPEPROGRAM_WORD @@ -552,6 +550,16 @@ extern "C" { #define OB_SRAM134_RST_ERASE OB_SRAM_RST_ERASE #define OB_SRAM134_RST_NOT_ERASE OB_SRAM_RST_NOT_ERASE #endif /* STM32U5 */ +#if defined(STM32U0) +#define OB_USER_nRST_STOP OB_USER_NRST_STOP +#define OB_USER_nRST_STDBY OB_USER_NRST_STDBY +#define OB_USER_nRST_SHDW OB_USER_NRST_SHDW +#define OB_USER_nBOOT_SEL OB_USER_NBOOT_SEL +#define OB_USER_nBOOT0 OB_USER_NBOOT0 +#define OB_USER_nBOOT1 OB_USER_NBOOT1 +#define OB_nBOOT0_RESET OB_NBOOT0_RESET +#define OB_nBOOT0_SET OB_NBOOT0_SET +#endif /* STM32U0 */ /** * @} @@ -800,6 +808,21 @@ extern "C" { #define GPIO_AF0_S2DSTOP GPIO_AF0_SRDSTOP #define GPIO_AF11_LPGPIO GPIO_AF11_LPGPIO1 #endif /* STM32U5 */ + +#if defined(STM32WBA) +#define GPIO_AF11_RF_ANTSW0 GPIO_AF11_RF +#define GPIO_AF11_RF_ANTSW1 GPIO_AF11_RF +#define GPIO_AF11_RF_ANTSW2 GPIO_AF11_RF +#define GPIO_AF11_RF_IO1 GPIO_AF11_RF +#define GPIO_AF11_RF_IO2 GPIO_AF11_RF +#define GPIO_AF11_RF_IO3 GPIO_AF11_RF +#define GPIO_AF11_RF_IO4 GPIO_AF11_RF +#define GPIO_AF11_RF_IO5 GPIO_AF11_RF +#define GPIO_AF11_RF_IO6 GPIO_AF11_RF +#define GPIO_AF11_RF_IO7 GPIO_AF11_RF +#define GPIO_AF11_RF_IO8 GPIO_AF11_RF +#define GPIO_AF11_RF_IO9 GPIO_AF11_RF +#endif /* STM32WBA */ /** * @} */ @@ -1243,10 +1266,10 @@ extern "C" { #define RTC_TAMPERPIN_PA0 RTC_TAMPERPIN_POS1 #define RTC_TAMPERPIN_PI8 RTC_TAMPERPIN_POS1 -#if defined(STM32H5) +#if defined(STM32H5) || defined(STM32H7RS) #define TAMP_SECRETDEVICE_ERASE_NONE TAMP_DEVICESECRETS_ERASE_NONE #define TAMP_SECRETDEVICE_ERASE_BKP_SRAM TAMP_DEVICESECRETS_ERASE_BKPSRAM -#endif /* STM32H5 */ +#endif /* STM32H5 || STM32H7RS */ #if defined(STM32WBA) #define TAMP_SECRETDEVICE_ERASE_NONE TAMP_DEVICESECRETS_ERASE_NONE @@ -1258,10 +1281,10 @@ extern "C" { #define TAMP_SECRETDEVICE_ERASE_ALL TAMP_DEVICESECRETS_ERASE_ALL #endif /* STM32WBA */ -#if defined(STM32H5) || defined(STM32WBA) +#if defined(STM32H5) || defined(STM32WBA) || defined(STM32H7RS) #define TAMP_SECRETDEVICE_ERASE_DISABLE TAMP_DEVICESECRETS_ERASE_NONE #define TAMP_SECRETDEVICE_ERASE_ENABLE TAMP_SECRETDEVICE_ERASE_ALL -#endif /* STM32H5 || STM32WBA */ +#endif /* STM32H5 || STM32WBA || STM32H7RS */ #if defined(STM32F7) #define RTC_TAMPCR_TAMPXE RTC_TAMPER_ENABLE_BITS_MASK @@ -1599,6 +1622,8 @@ extern "C" { #define ETH_MAC_SMALL_FIFO_RW_ACTIVE 0x00000006U /* MAC small FIFO read / write controllers active */ #define ETH_MAC_MII_RECEIVE_PROTOCOL_ACTIVE 0x00000001U /* MAC MII receive protocol engine active */ +#define ETH_TxPacketConfig ETH_TxPacketConfigTypeDef /* Transmit Packet Configuration structure definition */ + /** * @} */ @@ -1809,7 +1834,7 @@ extern "C" { #define HAL_FMPI2CEx_AnalogFilter_Config HAL_FMPI2CEx_ConfigAnalogFilter #define HAL_FMPI2CEx_DigitalFilter_Config HAL_FMPI2CEx_ConfigDigitalFilter -#define HAL_I2CFastModePlusConfig(SYSCFG_I2CFastModePlus, cmd) ((cmd == ENABLE)? \ +#define HAL_I2CFastModePlusConfig(SYSCFG_I2CFastModePlus, cmd) (((cmd) == ENABLE)? \ HAL_I2CEx_EnableFastModePlus(SYSCFG_I2CFastModePlus): \ HAL_I2CEx_DisableFastModePlus(SYSCFG_I2CFastModePlus)) @@ -1991,12 +2016,12 @@ extern "C" { /** @defgroup HAL_RTC_Aliased_Functions HAL RTC Aliased Functions maintained for legacy purpose * @{ */ -#if defined(STM32H5) || defined(STM32WBA) +#if defined(STM32H5) || defined(STM32WBA) || defined(STM32H7RS) #define HAL_RTCEx_SetBoothardwareKey HAL_RTCEx_LockBootHardwareKey #define HAL_RTCEx_BKUPBlock_Enable HAL_RTCEx_BKUPBlock #define HAL_RTCEx_BKUPBlock_Disable HAL_RTCEx_BKUPUnblock #define HAL_RTCEx_Erase_SecretDev_Conf HAL_RTCEx_ConfigEraseDeviceSecrets -#endif /* STM32H5 || STM32WBA */ +#endif /* STM32H5 || STM32WBA || STM32H7RS */ /** * @} @@ -2311,8 +2336,8 @@ extern "C" { #define __HAL_COMP_EXTI_CLEAR_FLAG(__FLAG__) (((__FLAG__) == COMP_EXTI_LINE_COMP2) ? __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() : \ ((__FLAG__) == COMP_EXTI_LINE_COMP4) ? __HAL_COMP_COMP4_EXTI_CLEAR_FLAG() : \ __HAL_COMP_COMP6_EXTI_CLEAR_FLAG()) -# endif -# if defined(STM32F302xE) || defined(STM32F302xC) +#endif +#if defined(STM32F302xE) || defined(STM32F302xC) #define __HAL_COMP_EXTI_RISING_IT_ENABLE(__EXTILINE__) (((__EXTILINE__) == COMP_EXTI_LINE_COMP1) ? __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() : \ ((__EXTILINE__) == COMP_EXTI_LINE_COMP2) ? __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() : \ ((__EXTILINE__) == COMP_EXTI_LINE_COMP4) ? __HAL_COMP_COMP4_EXTI_ENABLE_RISING_EDGE() : \ @@ -2345,8 +2370,8 @@ extern "C" { ((__FLAG__) == COMP_EXTI_LINE_COMP2) ? __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() : \ ((__FLAG__) == COMP_EXTI_LINE_COMP4) ? __HAL_COMP_COMP4_EXTI_CLEAR_FLAG() : \ __HAL_COMP_COMP6_EXTI_CLEAR_FLAG()) -# endif -# if defined(STM32F303xE) || defined(STM32F398xx) || defined(STM32F303xC) || defined(STM32F358xx) +#endif +#if defined(STM32F303xE) || defined(STM32F398xx) || defined(STM32F303xC) || defined(STM32F358xx) #define __HAL_COMP_EXTI_RISING_IT_ENABLE(__EXTILINE__) (((__EXTILINE__) == COMP_EXTI_LINE_COMP1) ? __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() : \ ((__EXTILINE__) == COMP_EXTI_LINE_COMP2) ? __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() : \ ((__EXTILINE__) == COMP_EXTI_LINE_COMP3) ? __HAL_COMP_COMP3_EXTI_ENABLE_RISING_EDGE() : \ @@ -2403,8 +2428,8 @@ extern "C" { ((__FLAG__) == COMP_EXTI_LINE_COMP5) ? __HAL_COMP_COMP5_EXTI_CLEAR_FLAG() : \ ((__FLAG__) == COMP_EXTI_LINE_COMP6) ? __HAL_COMP_COMP6_EXTI_CLEAR_FLAG() : \ __HAL_COMP_COMP7_EXTI_CLEAR_FLAG()) -# endif -# if defined(STM32F373xC) ||defined(STM32F378xx) +#endif +#if defined(STM32F373xC) ||defined(STM32F378xx) #define __HAL_COMP_EXTI_RISING_IT_ENABLE(__EXTILINE__) (((__EXTILINE__) == COMP_EXTI_LINE_COMP1) ? __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() : \ __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()) #define __HAL_COMP_EXTI_RISING_IT_DISABLE(__EXTILINE__) (((__EXTILINE__) == COMP_EXTI_LINE_COMP1) ? __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() : \ @@ -2421,7 +2446,7 @@ extern "C" { __HAL_COMP_COMP2_EXTI_GET_FLAG()) #define __HAL_COMP_EXTI_CLEAR_FLAG(__FLAG__) (((__FLAG__) == COMP_EXTI_LINE_COMP1) ? __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() : \ __HAL_COMP_COMP2_EXTI_CLEAR_FLAG()) -# endif +#endif #else #define __HAL_COMP_EXTI_RISING_IT_ENABLE(__EXTILINE__) (((__EXTILINE__) == COMP_EXTI_LINE_COMP1) ? __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() : \ __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()) @@ -2723,6 +2748,12 @@ extern "C" { #define __APB1_RELEASE_RESET __HAL_RCC_APB1_RELEASE_RESET #define __APB2_FORCE_RESET __HAL_RCC_APB2_FORCE_RESET #define __APB2_RELEASE_RESET __HAL_RCC_APB2_RELEASE_RESET +#if defined(STM32C0) +#define __HAL_RCC_APB1_FORCE_RESET __HAL_RCC_APB1_GRP1_FORCE_RESET +#define __HAL_RCC_APB1_RELEASE_RESET __HAL_RCC_APB1_GRP1_RELEASE_RESET +#define __HAL_RCC_APB2_FORCE_RESET __HAL_RCC_APB1_GRP2_FORCE_RESET +#define __HAL_RCC_APB2_RELEASE_RESET __HAL_RCC_APB1_GRP2_RELEASE_RESET +#endif /* STM32C0 */ #define __BKP_CLK_DISABLE __HAL_RCC_BKP_CLK_DISABLE #define __BKP_CLK_ENABLE __HAL_RCC_BKP_CLK_ENABLE #define __BKP_FORCE_RESET __HAL_RCC_BKP_FORCE_RESET @@ -3646,8 +3677,12 @@ extern "C" { #define RCC_MCOSOURCE_PLLCLK_NODIV RCC_MCO1SOURCE_PLLCLK #define RCC_MCOSOURCE_PLLCLK_DIV2 RCC_MCO1SOURCE_PLLCLK_DIV2 +#if defined(STM32U0) +#define RCC_SYSCLKSOURCE_STATUS_PLLR RCC_SYSCLKSOURCE_STATUS_PLLCLK +#endif + #if defined(STM32L4) || defined(STM32WB) || defined(STM32G0) || defined(STM32G4) || defined(STM32L5) || \ - defined(STM32WL) || defined(STM32C0) + defined(STM32WL) || defined(STM32C0) || defined(STM32H7RS) || defined(STM32U0) #define RCC_RTCCLKSOURCE_NO_CLK RCC_RTCCLKSOURCE_NONE #else #define RCC_RTCCLKSOURCE_NONE RCC_RTCCLKSOURCE_NO_CLK @@ -3749,8 +3784,10 @@ extern "C" { #define __HAL_RCC_GET_DFSDM_SOURCE __HAL_RCC_GET_DFSDM1_SOURCE #define RCC_DFSDM1CLKSOURCE_PCLK RCC_DFSDM1CLKSOURCE_PCLK2 #define RCC_SWPMI1CLKSOURCE_PCLK RCC_SWPMI1CLKSOURCE_PCLK1 +#if !defined(STM32U0) #define RCC_LPTIM1CLKSOURCE_PCLK RCC_LPTIM1CLKSOURCE_PCLK1 #define RCC_LPTIM2CLKSOURCE_PCLK RCC_LPTIM2CLKSOURCE_PCLK1 +#endif #define RCC_DFSDM1AUDIOCLKSOURCE_I2SAPB1 RCC_DFSDM1AUDIOCLKSOURCE_I2S1 #define RCC_DFSDM1AUDIOCLKSOURCE_I2SAPB2 RCC_DFSDM1AUDIOCLKSOURCE_I2S2 @@ -3896,7 +3933,8 @@ extern "C" { */ #if defined (STM32G0) || defined (STM32L5) || defined (STM32L412xx) || defined (STM32L422xx) || \ defined (STM32L4P5xx)|| defined (STM32L4Q5xx) || defined (STM32G4) || defined (STM32WL) || defined (STM32U5) || \ - defined (STM32WBA) || defined (STM32H5) || defined (STM32C0) + defined (STM32WBA) || defined (STM32H5) || \ + defined (STM32C0) || defined (STM32H7RS) || defined (STM32U0) #else #define __HAL_RTC_CLEAR_FLAG __HAL_RTC_EXTI_CLEAR_FLAG #endif @@ -3932,7 +3970,9 @@ extern "C" { #endif /* STM32F1 */ #if defined (STM32F0) || defined (STM32F2) || defined (STM32F3) || defined (STM32F4) || defined (STM32F7) || \ - defined (STM32L0) || defined (STM32L1) + defined (STM32H7) || \ + defined (STM32L0) || defined (STM32L1) || \ + defined (STM32WB) #define __HAL_RTC_TAMPER_GET_IT __HAL_RTC_TAMPER_GET_FLAG #endif @@ -4217,6 +4257,9 @@ extern "C" { #define __HAL_TIM_GetCompare __HAL_TIM_GET_COMPARE #define TIM_BREAKINPUTSOURCE_DFSDM TIM_BREAKINPUTSOURCE_DFSDM1 + +#define TIM_OCMODE_ASSYMETRIC_PWM1 TIM_OCMODE_ASYMMETRIC_PWM1 +#define TIM_OCMODE_ASSYMETRIC_PWM2 TIM_OCMODE_ASYMMETRIC_PWM2 /** * @} */ diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h index dfa69fe..7cfefbd 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h @@ -285,6 +285,8 @@ void HAL_SYSTICK_Callback(void); #if (__MPU_PRESENT == 1U) void HAL_MPU_Enable(uint32_t MPU_Control); void HAL_MPU_Disable(void); +void HAL_MPU_EnableRegion(uint32_t RegionNumber); +void HAL_MPU_DisableRegion(uint32_t RegionNumber); void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init); #endif /* __MPU_PRESENT */ /** diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h index 53951f7..ac72075 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h @@ -385,29 +385,28 @@ typedef struct */ typedef enum { - HAL_TIM_BASE_MSPINIT_CB_ID = 0x00U /*!< TIM Base MspInit Callback ID */ - , HAL_TIM_BASE_MSPDEINIT_CB_ID = 0x01U /*!< TIM Base MspDeInit Callback ID */ - , HAL_TIM_IC_MSPINIT_CB_ID = 0x02U /*!< TIM IC MspInit Callback ID */ - , HAL_TIM_IC_MSPDEINIT_CB_ID = 0x03U /*!< TIM IC MspDeInit Callback ID */ - , HAL_TIM_OC_MSPINIT_CB_ID = 0x04U /*!< TIM OC MspInit Callback ID */ - , HAL_TIM_OC_MSPDEINIT_CB_ID = 0x05U /*!< TIM OC MspDeInit Callback ID */ - , HAL_TIM_PWM_MSPINIT_CB_ID = 0x06U /*!< TIM PWM MspInit Callback ID */ - , HAL_TIM_PWM_MSPDEINIT_CB_ID = 0x07U /*!< TIM PWM MspDeInit Callback ID */ - , HAL_TIM_ONE_PULSE_MSPINIT_CB_ID = 0x08U /*!< TIM One Pulse MspInit Callback ID */ - , HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID = 0x09U /*!< TIM One Pulse MspDeInit Callback ID */ - , HAL_TIM_ENCODER_MSPINIT_CB_ID = 0x0AU /*!< TIM Encoder MspInit Callback ID */ - , HAL_TIM_ENCODER_MSPDEINIT_CB_ID = 0x0BU /*!< TIM Encoder MspDeInit Callback ID */ - , HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID = 0x0CU /*!< TIM Hall Sensor MspDeInit Callback ID */ - , HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID = 0x0DU /*!< TIM Hall Sensor MspDeInit Callback ID */ + HAL_TIM_BASE_MSPINIT_CB_ID = 0x00U /*!< TIM Base MspInit Callback ID */ + , HAL_TIM_BASE_MSPDEINIT_CB_ID = 0x01U /*!< TIM Base MspDeInit Callback ID */ + , HAL_TIM_IC_MSPINIT_CB_ID = 0x02U /*!< TIM IC MspInit Callback ID */ + , HAL_TIM_IC_MSPDEINIT_CB_ID = 0x03U /*!< TIM IC MspDeInit Callback ID */ + , HAL_TIM_OC_MSPINIT_CB_ID = 0x04U /*!< TIM OC MspInit Callback ID */ + , HAL_TIM_OC_MSPDEINIT_CB_ID = 0x05U /*!< TIM OC MspDeInit Callback ID */ + , HAL_TIM_PWM_MSPINIT_CB_ID = 0x06U /*!< TIM PWM MspInit Callback ID */ + , HAL_TIM_PWM_MSPDEINIT_CB_ID = 0x07U /*!< TIM PWM MspDeInit Callback ID */ + , HAL_TIM_ONE_PULSE_MSPINIT_CB_ID = 0x08U /*!< TIM One Pulse MspInit Callback ID */ + , HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID = 0x09U /*!< TIM One Pulse MspDeInit Callback ID */ + , HAL_TIM_ENCODER_MSPINIT_CB_ID = 0x0AU /*!< TIM Encoder MspInit Callback ID */ + , HAL_TIM_ENCODER_MSPDEINIT_CB_ID = 0x0BU /*!< TIM Encoder MspDeInit Callback ID */ + , HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID = 0x0CU /*!< TIM Hall Sensor MspDeInit Callback ID */ + , HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID = 0x0DU /*!< TIM Hall Sensor MspDeInit Callback ID */ , HAL_TIM_PERIOD_ELAPSED_CB_ID = 0x0EU /*!< TIM Period Elapsed Callback ID */ , HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID = 0x0FU /*!< TIM Period Elapsed half complete Callback ID */ , HAL_TIM_TRIGGER_CB_ID = 0x10U /*!< TIM Trigger Callback ID */ , HAL_TIM_TRIGGER_HALF_CB_ID = 0x11U /*!< TIM Trigger half complete Callback ID */ - , HAL_TIM_IC_CAPTURE_CB_ID = 0x12U /*!< TIM Input Capture Callback ID */ , HAL_TIM_IC_CAPTURE_HALF_CB_ID = 0x13U /*!< TIM Input Capture half complete Callback ID */ , HAL_TIM_OC_DELAY_ELAPSED_CB_ID = 0x14U /*!< TIM Output Compare Delay Elapsed Callback ID */ - , HAL_TIM_PWM_PULSE_FINISHED_CB_ID = 0x15U /*!< TIM PWM Pulse Finished Callback ID */ + , HAL_TIM_PWM_PULSE_FINISHED_CB_ID = 0x15U /*!< TIM PWM Pulse Finished Callback ID */ , HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID = 0x16U /*!< TIM PWM Pulse Finished half complete Callback ID */ , HAL_TIM_ERROR_CB_ID = 0x17U /*!< TIM Error Callback ID */ , HAL_TIM_COMMUTATION_CB_ID = 0x18U /*!< TIM Commutation Callback ID */ @@ -1707,7 +1706,6 @@ typedef void (*pTIM_CallbackTypeDef)(TIM_HandleTypeDef *htim); /*!< pointer to #define IS_TIM_BREAK_FILTER(__BRKFILTER__) ((__BRKFILTER__) <= 0xFUL) - #define IS_TIM_BREAK_STATE(__STATE__) (((__STATE__) == TIM_BREAK_ENABLE) || \ ((__STATE__) == TIM_BREAK_DISABLE)) @@ -2045,7 +2043,8 @@ HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_S HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig); HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig); HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, - uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength); + uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, + uint32_t BurstLength); HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength); diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_cortex.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_cortex.h index c8b503c..c1fb2c7 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_cortex.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_cortex.h @@ -587,7 +587,7 @@ __STATIC_INLINE void LL_MPU_ConfigRegion(uint32_t Region, uint32_t SubRegionDisa /* Set base address */ WRITE_REG(MPU->RBAR, (Address & 0xFFFFFFE0U)); /* Configure MPU */ - WRITE_REG(MPU->RASR, (MPU_RASR_ENABLE_Msk | Attributes | SubRegionDisable << MPU_RASR_SRD_Pos)); + WRITE_REG(MPU->RASR, (MPU_RASR_ENABLE_Msk | Attributes | (SubRegionDisable << MPU_RASR_SRD_Pos))); } /** diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_iwdg.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_iwdg.h index ea718ec..5dce390 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_iwdg.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_iwdg.h @@ -207,7 +207,7 @@ __STATIC_INLINE void LL_IWDG_SetPrescaler(IWDG_TypeDef *IWDGx, uint32_t Prescale * @arg @ref LL_IWDG_PRESCALER_128 * @arg @ref LL_IWDG_PRESCALER_256 */ -__STATIC_INLINE uint32_t LL_IWDG_GetPrescaler(IWDG_TypeDef *IWDGx) +__STATIC_INLINE uint32_t LL_IWDG_GetPrescaler(const IWDG_TypeDef *IWDGx) { return (READ_REG(IWDGx->PR)); } @@ -230,7 +230,7 @@ __STATIC_INLINE void LL_IWDG_SetReloadCounter(IWDG_TypeDef *IWDGx, uint32_t Coun * @param IWDGx IWDG Instance * @retval Value between Min_Data=0 and Max_Data=0x0FFF */ -__STATIC_INLINE uint32_t LL_IWDG_GetReloadCounter(IWDG_TypeDef *IWDGx) +__STATIC_INLINE uint32_t LL_IWDG_GetReloadCounter(const IWDG_TypeDef *IWDGx) { return (READ_REG(IWDGx->RLR)); } @@ -249,7 +249,7 @@ __STATIC_INLINE uint32_t LL_IWDG_GetReloadCounter(IWDG_TypeDef *IWDGx) * @param IWDGx IWDG Instance * @retval State of bit (1 or 0). */ -__STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_PVU(IWDG_TypeDef *IWDGx) +__STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_PVU(const IWDG_TypeDef *IWDGx) { return ((READ_BIT(IWDGx->SR, IWDG_SR_PVU) == (IWDG_SR_PVU)) ? 1UL : 0UL); } @@ -260,7 +260,7 @@ __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_PVU(IWDG_TypeDef *IWDGx) * @param IWDGx IWDG Instance * @retval State of bit (1 or 0). */ -__STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_RVU(IWDG_TypeDef *IWDGx) +__STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_RVU(const IWDG_TypeDef *IWDGx) { return ((READ_BIT(IWDGx->SR, IWDG_SR_RVU) == (IWDG_SR_RVU)) ? 1UL : 0UL); } @@ -272,7 +272,7 @@ __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_RVU(IWDG_TypeDef *IWDGx) * @param IWDGx IWDG Instance * @retval State of bits (1 or 0). */ -__STATIC_INLINE uint32_t LL_IWDG_IsReady(IWDG_TypeDef *IWDGx) +__STATIC_INLINE uint32_t LL_IWDG_IsReady(const IWDG_TypeDef *IWDGx) { return ((READ_BIT(IWDGx->SR, IWDG_SR_PVU | IWDG_SR_RVU) == 0U) ? 1UL : 0UL); } diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_tim.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_tim.h index f1bceb7..d54a00e 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_tim.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_tim.h @@ -556,10 +556,10 @@ typedef struct /** @defgroup TIM_LL_EC_COUNTERMODE Counter Mode * @{ */ -#define LL_TIM_COUNTERMODE_UP 0x00000000U /*!CR2, TIM_CR2_CCPC); } +/** + * @brief Indicates whether the capture/compare control bits (CCxE, CCxNE and OCxM) preload is enabled. + * @rmtoll CR2 CCPC LL_TIM_CC_IsEnabledPreload + * @param TIMx Timer instance + * @retval State of bit (1 or 0). + */ +__STATIC_INLINE uint32_t LL_TIM_CC_IsEnabledPreload(const TIM_TypeDef *TIMx) +{ + return ((READ_BIT(TIMx->CR2, TIM_CR2_CCPC) == (TIM_CR2_CCPC)) ? 1UL : 0UL); +} + /** * @brief Set the updated source of the capture/compare control bits (CCxE, CCxNE and OCxM). * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usart.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usart.h index ffe4192..6d37061 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usart.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usart.h @@ -347,7 +347,7 @@ typedef struct * @} */ -/** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper +/** @defgroup USART_LL_EM_Exported_Macros_Helper Exported Macros Helper * @{ */ @@ -636,7 +636,7 @@ __STATIC_INLINE uint32_t LL_USART_GetOverSampling(const USART_TypeDef *USARTx) #endif /* USART_OverSampling_Feature */ /** * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput * @param USARTx USART Instance @@ -653,7 +653,7 @@ __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint3 /** * @brief Retrieve Clock pulse of the last data bit output configuration * (Last bit Clock pulse output to the SCLK pin or not) - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput * @param USARTx USART Instance @@ -668,7 +668,7 @@ __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(const USART_TypeDef *USA /** * @brief Select the phase of the clock output on the SCLK pin in synchronous mode - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CPHA LL_USART_SetClockPhase * @param USARTx USART Instance @@ -684,7 +684,7 @@ __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t Cloc /** * @brief Return phase of the clock output on the SCLK pin in synchronous mode - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CPHA LL_USART_GetClockPhase * @param USARTx USART Instance @@ -699,7 +699,7 @@ __STATIC_INLINE uint32_t LL_USART_GetClockPhase(const USART_TypeDef *USARTx) /** * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CPOL LL_USART_SetClockPolarity * @param USARTx USART Instance @@ -715,7 +715,7 @@ __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t C /** * @brief Return polarity of the clock output on the SCLK pin in synchronous mode - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CPOL LL_USART_GetClockPolarity * @param USARTx USART Instance @@ -730,7 +730,7 @@ __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(const USART_TypeDef *USARTx) /** * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse) - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @note Call of this function is equivalent to following function call sequence : * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function @@ -758,7 +758,7 @@ __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, /** * @brief Enable Clock output on SCLK pin - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput * @param USARTx USART Instance @@ -771,7 +771,7 @@ __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx) /** * @brief Disable Clock output on SCLK pin - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput * @param USARTx USART Instance @@ -784,7 +784,7 @@ __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx) /** * @brief Indicate if Clock output on SCLK pin is enabled - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput * @param USARTx USART Instance @@ -886,7 +886,7 @@ __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(const USART_TypeDef *USARTx) /** * @brief Enable RTS HW Flow Control - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl * @param USARTx USART Instance @@ -899,7 +899,7 @@ __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx) /** * @brief Disable RTS HW Flow Control - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl * @param USARTx USART Instance @@ -912,7 +912,7 @@ __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx) /** * @brief Enable CTS HW Flow Control - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl * @param USARTx USART Instance @@ -925,7 +925,7 @@ __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx) /** * @brief Disable CTS HW Flow Control - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl * @param USARTx USART Instance @@ -938,7 +938,7 @@ __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx) /** * @brief Configure HW Flow Control mode (both CTS and RTS) - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n * CR3 CTSE LL_USART_SetHWFlowCtrl @@ -957,7 +957,7 @@ __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t Hard /** * @brief Return HW Flow Control configuration (both CTS and RTS) - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n * CR3 CTSE LL_USART_GetHWFlowCtrl @@ -1125,7 +1125,7 @@ __STATIC_INLINE uint32_t LL_USART_GetBaudRate(const USART_TypeDef *USARTx, uint3 /** * @brief Enable IrDA mode - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll CR3 IREN LL_USART_EnableIrda * @param USARTx USART Instance @@ -1138,7 +1138,7 @@ __STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx) /** * @brief Disable IrDA mode - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll CR3 IREN LL_USART_DisableIrda * @param USARTx USART Instance @@ -1151,7 +1151,7 @@ __STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx) /** * @brief Indicate if IrDA mode is enabled - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll CR3 IREN LL_USART_IsEnabledIrda * @param USARTx USART Instance @@ -1164,7 +1164,7 @@ __STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(const USART_TypeDef *USARTx) /** * @brief Configure IrDA Power Mode (Normal or Low Power) - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll CR3 IRLP LL_USART_SetIrdaPowerMode * @param USARTx USART Instance @@ -1180,7 +1180,7 @@ __STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t P /** * @brief Retrieve IrDA Power Mode configuration (Normal or Low Power) - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll CR3 IRLP LL_USART_GetIrdaPowerMode * @param USARTx USART Instance @@ -1196,7 +1196,7 @@ __STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(const USART_TypeDef *USARTx) /** * @brief Set Irda prescaler value, used for dividing the USART clock source * to achieve the Irda Low Power frequency (8 bits value) - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll GTPR PSC LL_USART_SetIrdaPrescaler * @param USARTx USART Instance @@ -1211,7 +1211,7 @@ __STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t P /** * @brief Return Irda prescaler value, used for dividing the USART clock source * to achieve the Irda Low Power frequency (8 bits value) - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @rmtoll GTPR PSC LL_USART_GetIrdaPrescaler * @param USARTx USART Instance @@ -1232,7 +1232,7 @@ __STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(const USART_TypeDef *USARTx) /** * @brief Enable Smartcard NACK transmission - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll CR3 NACK LL_USART_EnableSmartcardNACK * @param USARTx USART Instance @@ -1245,7 +1245,7 @@ __STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx) /** * @brief Disable Smartcard NACK transmission - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll CR3 NACK LL_USART_DisableSmartcardNACK * @param USARTx USART Instance @@ -1258,7 +1258,7 @@ __STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx) /** * @brief Indicate if Smartcard NACK transmission is enabled - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll CR3 NACK LL_USART_IsEnabledSmartcardNACK * @param USARTx USART Instance @@ -1271,7 +1271,7 @@ __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(const USART_TypeDef *US /** * @brief Enable Smartcard mode - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll CR3 SCEN LL_USART_EnableSmartcard * @param USARTx USART Instance @@ -1284,7 +1284,7 @@ __STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx) /** * @brief Disable Smartcard mode - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll CR3 SCEN LL_USART_DisableSmartcard * @param USARTx USART Instance @@ -1297,7 +1297,7 @@ __STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx) /** * @brief Indicate if Smartcard mode is enabled - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll CR3 SCEN LL_USART_IsEnabledSmartcard * @param USARTx USART Instance @@ -1311,7 +1311,7 @@ __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(const USART_TypeDef *USARTx /** * @brief Set Smartcard prescaler value, used for dividing the USART clock * source to provide the SMARTCARD Clock (5 bits value) - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll GTPR PSC LL_USART_SetSmartcardPrescaler * @param USARTx USART Instance @@ -1326,7 +1326,7 @@ __STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint3 /** * @brief Return Smartcard prescaler value, used for dividing the USART clock * source to provide the SMARTCARD Clock (5 bits value) - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll GTPR PSC LL_USART_GetSmartcardPrescaler * @param USARTx USART Instance @@ -1340,7 +1340,7 @@ __STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(const USART_TypeDef *USA /** * @brief Set Smartcard Guard time value, expressed in nb of baud clocks periods * (GT[7:0] bits : Guard time value) - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll GTPR GT LL_USART_SetSmartcardGuardTime * @param USARTx USART Instance @@ -1355,7 +1355,7 @@ __STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint3 /** * @brief Return Smartcard Guard time value, expressed in nb of baud clocks periods * (GT[7:0] bits : Guard time value) - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @rmtoll GTPR GT LL_USART_GetSmartcardGuardTime * @param USARTx USART Instance @@ -1376,7 +1376,7 @@ __STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(const USART_TypeDef *USA /** * @brief Enable Single Wire Half-Duplex mode - * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not * Half-Duplex mode is supported by the USARTx instance. * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex * @param USARTx USART Instance @@ -1389,7 +1389,7 @@ __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx) /** * @brief Disable Single Wire Half-Duplex mode - * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not * Half-Duplex mode is supported by the USARTx instance. * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex * @param USARTx USART Instance @@ -1402,7 +1402,7 @@ __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx) /** * @brief Indicate if Single Wire Half-Duplex mode is enabled - * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not * Half-Duplex mode is supported by the USARTx instance. * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex * @param USARTx USART Instance @@ -1423,7 +1423,7 @@ __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(const USART_TypeDef *USART /** * @brief Set LIN Break Detection Length - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LBDL LL_USART_SetLINBrkDetectionLen * @param USARTx USART Instance @@ -1439,7 +1439,7 @@ __STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint3 /** * @brief Return LIN Break Detection Length - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LBDL LL_USART_GetLINBrkDetectionLen * @param USARTx USART Instance @@ -1454,7 +1454,7 @@ __STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(const USART_TypeDef *USA /** * @brief Enable LIN mode - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LINEN LL_USART_EnableLIN * @param USARTx USART Instance @@ -1467,7 +1467,7 @@ __STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx) /** * @brief Disable LIN mode - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LINEN LL_USART_DisableLIN * @param USARTx USART Instance @@ -1480,7 +1480,7 @@ __STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx) /** * @brief Indicate if LIN mode is enabled - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LINEN LL_USART_IsEnabledLIN * @param USARTx USART Instance @@ -1541,7 +1541,7 @@ __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx) * - IREN bit in the USART_CR3 register, * - HDSEL bit in the USART_CR3 register. * This function also sets the USART in Synchronous mode. - * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not * Synchronous mode is supported by the USARTx instance. * @note Call of this function is equivalent to following function call sequence : * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function @@ -1579,7 +1579,7 @@ __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx) * - IREN bit in the USART_CR3 register, * - HDSEL bit in the USART_CR3 register. * This function also set the UART/USART in LIN mode. - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @note Call of this function is equivalent to following function call sequence : * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function @@ -1619,7 +1619,7 @@ __STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx) * - SCEN bit in the USART_CR3 register, * - IREN bit in the USART_CR3 register, * This function also sets the UART/USART in Half Duplex mode. - * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not * Half-Duplex mode is supported by the USARTx instance. * @note Call of this function is equivalent to following function call sequence : * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function @@ -1658,7 +1658,7 @@ __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx) * This function also configures Stop bits to 1.5 bits and * sets the USART in Smartcard mode (SCEN bit). * Clock Output is also enabled (CLKEN). - * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not * Smartcard feature is supported by the USARTx instance. * @note Call of this function is equivalent to following function call sequence : * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function @@ -1700,7 +1700,7 @@ __STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx) * - SCEN bit in the USART_CR3 register, * - HDSEL bit in the USART_CR3 register. * This function also sets the UART/USART in IRDA mode (IREN bit). - * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not * IrDA feature is supported by the USARTx instance. * @note Call of this function is equivalent to following function call sequence : * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function @@ -1866,7 +1866,7 @@ __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(const USART_TypeDef *USARTx) /** * @brief Check if the USART LIN Break Detection Flag is set or not - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll SR LBD LL_USART_IsActiveFlag_LBD * @param USARTx USART Instance @@ -1879,7 +1879,7 @@ __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(const USART_TypeDef *USARTx) /** * @brief Check if the USART CTS Flag is set or not - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll SR CTS LL_USART_IsActiveFlag_nCTS * @param USARTx USART Instance @@ -2031,7 +2031,7 @@ __STATIC_INLINE void LL_USART_ClearFlag_RXNE(USART_TypeDef *USARTx) /** * @brief Clear LIN Break Detection Flag - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll SR LBD LL_USART_ClearFlag_LBD * @param USARTx USART Instance @@ -2044,7 +2044,7 @@ __STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx) /** * @brief Clear CTS Interrupt Flag - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll SR CTS LL_USART_ClearFlag_nCTS * @param USARTx USART Instance @@ -2120,7 +2120,7 @@ __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx) /** * @brief Enable LIN Break Detection Interrupt - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LBDIE LL_USART_EnableIT_LBD * @param USARTx USART Instance @@ -2148,7 +2148,7 @@ __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx) /** * @brief Enable CTS Interrupt - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS * @param USARTx USART Instance @@ -2216,7 +2216,7 @@ __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx) /** * @brief Disable LIN Break Detection Interrupt - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LBDIE LL_USART_DisableIT_LBD * @param USARTx USART Instance @@ -2244,7 +2244,7 @@ __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx) /** * @brief Disable CTS Interrupt - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS * @param USARTx USART Instance @@ -2312,7 +2312,7 @@ __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(const USART_TypeDef *USARTx) /** * @brief Check if the USART LIN Break Detection Interrupt is enabled or disabled. - * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not * LIN feature is supported by the USARTx instance. * @rmtoll CR2 LBDIE LL_USART_IsEnabledIT_LBD * @param USARTx USART Instance @@ -2336,7 +2336,7 @@ __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(const USART_TypeDef *USARTx) /** * @brief Check if the USART CTS Interrupt is enabled or disabled. - * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not + * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not * Hardware Flow control feature is supported by the USARTx instance. * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS * @param USARTx USART Instance diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h index c3a548e..f0e13e8 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h @@ -37,6 +37,13 @@ extern "C" { */ /* Exported types ------------------------------------------------------------*/ +#ifndef HAL_USB_TIMEOUT +#define HAL_USB_TIMEOUT 0xF000000U +#endif /* define HAL_USB_TIMEOUT */ + +#ifndef HAL_USB_CURRENT_MODE_MAX_DELAY_MS +#define HAL_USB_CURRENT_MODE_MAX_DELAY_MS 200U +#endif /* define HAL_USB_CURRENT_MODE_MAX_DELAY_MS */ /** * @brief USB Mode definition @@ -85,42 +92,42 @@ typedef enum */ typedef struct { - uint32_t dev_endpoints; /*!< Device Endpoints number. + uint8_t dev_endpoints; /*!< Device Endpoints number. This parameter depends on the used USB core. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ #if defined (USB_OTG_FS) - uint32_t Host_channels; /*!< Host Channels number. + uint8_t Host_channels; /*!< Host Channels number. This parameter Depends on the used USB core. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ +#endif /* defined (USB_OTG_FS) */ - uint32_t dma_enable; /*!< USB DMA state. + uint8_t dma_enable; /*!< USB DMA state. If DMA is not supported this parameter shall be set by default to zero */ -#endif /* defined (USB_OTG_FS) */ - uint32_t speed; /*!< USB Core speed. - This parameter can be any value of @ref PCD_Speed/HCD_Speed - (HCD_SPEED_xxx, HCD_SPEED_xxx) */ + uint8_t speed; /*!< USB Core speed. + This parameter can be any value of @ref PCD_Speed/HCD_Speed + (HCD_SPEED_xxx, HCD_SPEED_xxx) */ - uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */ + uint8_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */ - uint32_t phy_itface; /*!< Select the used PHY interface. - This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module */ + uint8_t phy_itface; /*!< Select the used PHY interface. + This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module */ - uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ + uint8_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ - uint32_t low_power_enable; /*!< Enable or disable the low Power Mode. */ + uint8_t low_power_enable; /*!< Enable or disable the low Power Mode. */ - uint32_t lpm_enable; /*!< Enable or disable Link Power Management. */ + uint8_t lpm_enable; /*!< Enable or disable Link Power Management. */ - uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */ + uint8_t battery_charging_enable; /*!< Enable or disable Battery charging. */ #if defined (USB_OTG_FS) - uint32_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */ + uint8_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */ - uint32_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */ + uint8_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */ - uint32_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */ + uint8_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */ #endif /* defined (USB_OTG_FS) */ } USB_CfgTypeDef; @@ -513,41 +520,41 @@ HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx); HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx); HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed); HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDef mode); -HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed); +HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed); HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx); HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num); -HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep); HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, +HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len); -void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len); -HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); -HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address); -HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx); +void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len); +HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); +HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address); +HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx); HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t *psetup); -uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx); -uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, const uint8_t *psetup); +uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx); +uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx); uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx); -uint32_t USB_ReadChInterrupts(USB_OTG_GlobalTypeDef *USBx, uint8_t chnum); -uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx); -uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum); -uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx); -uint32_t USB_ReadDevInEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum); +uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum); +uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx); +uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum); +uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx); +uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum); void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt); HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg); -HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq); -HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state); +HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq); +HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state); uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx); uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx); HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num, @@ -556,12 +563,12 @@ HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num, HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc); -uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num); -HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num); +uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num); +HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num); HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx); -HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx); +HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx); #endif /* defined (USB_OTG_FS) */ #if defined (USB) diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_utils.h b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_utils.h index d938fa3..69483bd 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_utils.h +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_utils.h @@ -212,7 +212,7 @@ __STATIC_INLINE uint32_t LL_GetFlashSize(void) * @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro) * @note When a RTOS is used, it is recommended to avoid changing the SysTick * configuration by calling this function, for a delay use rather osDelay RTOS service. - * @param Ticks Number of ticks + * @param Ticks Frequency of Ticks (Hz) * @retval None */ __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks) diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c index e66fc22..da80972 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c @@ -57,7 +57,7 @@ */ #define __STM32F1xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */ #define __STM32F1xx_HAL_VERSION_SUB1 (0x01U) /*!< [23:16] sub1 version */ -#define __STM32F1xx_HAL_VERSION_SUB2 (0x09U) /*!< [15:8] sub2 version */ +#define __STM32F1xx_HAL_VERSION_SUB2 (0x0AU) /*!< [15:8] sub2 version */ #define __STM32F1xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */ #define __STM32F1xx_HAL_VERSION ((__STM32F1xx_HAL_VERSION_MAIN << 24)\ |(__STM32F1xx_HAL_VERSION_SUB1 << 16)\ diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c index c6c87c6..9342123 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c @@ -290,6 +290,38 @@ void HAL_MPU_Enable(uint32_t MPU_Control) __ISB(); } +/** + * @brief Enable the MPU Region. + * @retval None + */ +void HAL_MPU_EnableRegion(uint32_t RegionNumber) +{ + /* Check the parameters */ + assert_param(IS_MPU_REGION_NUMBER(RegionNumber)); + + /* Set the Region number */ + MPU->RNR = RegionNumber; + + /* Enable the Region */ + SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk); +} + +/** + * @brief Disable the MPU Region. + * @retval None + */ +void HAL_MPU_DisableRegion(uint32_t RegionNumber) +{ + /* Check the parameters */ + assert_param(IS_MPU_REGION_NUMBER(RegionNumber)); + + /* Set the Region number */ + MPU->RNR = RegionNumber; + + /* Disable the Region */ + CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk); +} + /** * @brief Initializes and configures the Region and the memory to be protected. * @param MPU_Init: Pointer to a MPU_Region_InitTypeDef structure that contains @@ -301,38 +333,32 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init) /* Check the parameters */ assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number)); assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable)); + assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec)); + assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission)); + assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField)); + assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable)); + assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable)); + assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable)); + assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable)); + assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size)); /* Set the Region number */ MPU->RNR = MPU_Init->Number; - if ((MPU_Init->Enable) != RESET) - { - /* Check the parameters */ - assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec)); - assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission)); - assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField)); - assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable)); - assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable)); - assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable)); - assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable)); - assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size)); - - MPU->RBAR = MPU_Init->BaseAddress; - MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) | - ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) | - ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) | - ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) | - ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) | - ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) | - ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) | - ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) | - ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos); - } - else - { - MPU->RBAR = 0x00U; - MPU->RASR = 0x00U; - } + /* Disable the Region */ + CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk); + + /* Apply configuration */ + MPU->RBAR = MPU_Init->BaseAddress; + MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) | + ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) | + ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) | + ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) | + ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) | + ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) | + ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) | + ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) | + ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos); } #endif /* __MPU_PRESENT */ diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c index 6f920ae..fe5e596 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c @@ -265,9 +265,6 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data) { HAL_StatusTypeDef status = HAL_OK; - - /* Process Locked */ - __HAL_LOCK(&pFlash); /* Check the parameters */ assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram)); @@ -587,8 +584,6 @@ void HAL_FLASH_IRQHandler(void) __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR); #endif /* FLASH_BANK2_END */ - /* Process Unlocked */ - __HAL_UNLOCK(&pFlash); } } diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c index e6200c2..33ae03c 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c @@ -318,9 +318,6 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) { HAL_StatusTypeDef status = HAL_OK; - /* Process Locked */ - __HAL_LOCK(&pFlash); - /* If procedure already ongoing, reject the next one */ if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) { diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c index f837c58..9fc5944 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c @@ -505,7 +505,7 @@ void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) * the next reset. * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral * @param GPIO_Pin: specifies the port bit to be locked. -* This parameter can be any combination of GPIO_Pin_x where x can be (0..15). +* This parameter can be any combination of GPIO_PIN_x where x can be (0..15). * @retval None */ HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c index c65b792..1d61feb 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c @@ -120,7 +120,8 @@ The timeout value is multiplied by 1000 to be converted in milliseconds. LSI startup time is also considered here by adding LSI_STARTUP_TIME converted in milliseconds. */ -#define HAL_IWDG_DEFAULT_TIMEOUT (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL)) +#define HAL_IWDG_DEFAULT_TIMEOUT (((6UL * 256UL * 1000UL) / (LSI_VALUE / 128U)) + \ + ((LSI_STARTUP_TIME / 1000UL) + 1UL)) #define IWDG_KERNEL_UPDATE_FLAGS (IWDG_SR_RVU | IWDG_SR_PVU) /** * @} diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c index e01efe5..6a89738 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c @@ -130,9 +130,6 @@ static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep */ HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) { -#if defined (USB_OTG_FS) - USB_OTG_GlobalTypeDef *USBx; -#endif /* defined (USB_OTG_FS) */ uint8_t i; /* Check the PCD handle allocation */ @@ -144,10 +141,6 @@ HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) /* Check the parameters */ assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance)); -#if defined (USB_OTG_FS) - USBx = hpcd->Instance; -#endif /* defined (USB_OTG_FS) */ - if (hpcd->State == HAL_PCD_STATE_RESET) { /* Allocate lock resource and initialize it */ @@ -181,13 +174,8 @@ HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) hpcd->State = HAL_PCD_STATE_BUSY; -#if defined (USB_OTG_FS) /* Disable DMA mode for FS instance */ - if ((USBx->CID & (0x1U << 8)) == 0U) - { - hpcd->Init.dma_enable = 0U; - } -#endif /* defined (USB_OTG_FS) */ + hpcd->Init.dma_enable = 0U; /* Disable the Interrupts */ __HAL_PCD_DISABLE(hpcd); @@ -199,8 +187,12 @@ HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) return HAL_ERROR; } - /* Force Device Mode*/ - (void)USB_SetCurrentMode(hpcd->Instance, USB_DEVICE_MODE); + /* Force Device Mode */ + if (USB_SetCurrentMode(hpcd->Instance, USB_DEVICE_MODE) != HAL_OK) + { + hpcd->State = HAL_PCD_STATE_ERROR; + return HAL_ERROR; + } /* Init endpoints structures */ for (i = 0U; i < hpcd->Init.dev_endpoints; i++) @@ -2115,9 +2107,9 @@ static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t */ static HAL_StatusTypeDef PCD_EP_OutXfrComplete_int(PCD_HandleTypeDef *hpcd, uint32_t epnum) { - USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; + const USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; uint32_t USBx_BASE = (uint32_t)USBx; - uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U); + uint32_t gSNPSiD = *(__IO const uint32_t *)(&USBx->CID + 0x1U); uint32_t DoepintReg = USBx_OUTEP(epnum)->DOEPINT; if (gSNPSiD == USB_OTG_CORE_ID_310A) @@ -2162,9 +2154,9 @@ static HAL_StatusTypeDef PCD_EP_OutXfrComplete_int(PCD_HandleTypeDef *hpcd, uint */ static HAL_StatusTypeDef PCD_EP_OutSetupPacket_int(PCD_HandleTypeDef *hpcd, uint32_t epnum) { - USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; + const USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; uint32_t USBx_BASE = (uint32_t)USBx; - uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U); + uint32_t gSNPSiD = *(__IO const uint32_t *)(&USBx->CID + 0x1U); uint32_t DoepintReg = USBx_OUTEP(epnum)->DOEPINT; if ((gSNPSiD > USB_OTG_CORE_ID_300A) && diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c index 40cee88..c00a9de 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c @@ -3821,13 +3821,16 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Cha */ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) { + uint32_t itsource = htim->Instance->DIER; + uint32_t itflag = htim->Instance->SR; + /* Capture compare 1 event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) + if ((itflag & (TIM_FLAG_CC1)) == (TIM_FLAG_CC1)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET) + if ((itsource & (TIM_IT_CC1)) == (TIM_IT_CC1)) { { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC1); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; /* Input capture event */ @@ -3855,11 +3858,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* Capture compare 2 event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) + if ((itflag & (TIM_FLAG_CC2)) == (TIM_FLAG_CC2)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET) + if ((itsource & (TIM_IT_CC2)) == (TIM_IT_CC2)) { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC2); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; /* Input capture event */ if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) @@ -3885,11 +3888,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* Capture compare 3 event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) + if ((itflag & (TIM_FLAG_CC3)) == (TIM_FLAG_CC3)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET) + if ((itsource & (TIM_IT_CC3)) == (TIM_IT_CC3)) { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC3); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; /* Input capture event */ if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U) @@ -3915,11 +3918,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* Capture compare 4 event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) + if ((itflag & (TIM_FLAG_CC4)) == (TIM_FLAG_CC4)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET) + if ((itsource & (TIM_IT_CC4)) == (TIM_IT_CC4)) { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC4); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; /* Input capture event */ if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U) @@ -3945,11 +3948,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* TIM Update event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) + if ((itflag & (TIM_FLAG_UPDATE)) == (TIM_FLAG_UPDATE)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET) + if ((itsource & (TIM_IT_UPDATE)) == (TIM_IT_UPDATE)) { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_UPDATE); #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->PeriodElapsedCallback(htim); #else @@ -3958,11 +3961,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* TIM Break input event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET) + if ((itflag & (TIM_FLAG_BREAK)) == (TIM_FLAG_BREAK)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET) + if ((itsource & (TIM_IT_BREAK)) == (TIM_IT_BREAK)) { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_BREAK); #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->BreakCallback(htim); #else @@ -3971,11 +3974,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* TIM Trigger detection event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) + if ((itflag & (TIM_FLAG_TRIGGER)) == (TIM_FLAG_TRIGGER)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET) + if ((itsource & (TIM_IT_TRIGGER)) == (TIM_IT_TRIGGER)) { - __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_TRIGGER); #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->TriggerCallback(htim); #else @@ -3984,11 +3987,11 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* TIM commutation event */ - if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET) + if ((itflag & (TIM_FLAG_COM)) == (TIM_FLAG_COM)) { - if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) != RESET) + if ((itsource & (TIM_IT_COM)) == (TIM_IT_COM)) { - __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM); + __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_COM); #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) htim->CommutationCallback(htim); #else @@ -4475,7 +4478,8 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_O * @retval HAL status */ HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, - uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength) + uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, + uint32_t BurstLength) { HAL_StatusTypeDef status; @@ -6809,6 +6813,13 @@ void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure /* Generate an update event to reload the Prescaler and the repetition counter (only for advanced timer) value immediately */ TIMx->EGR = TIM_EGR_UG; + + /* Check if the update flag is set after the Update Generation, if so clear the UIF flag */ + if (HAL_IS_BIT_SET(TIMx->SR, TIM_FLAG_UPDATE)) + { + /* Clear the update flag */ + CLEAR_BIT(TIMx->SR, TIM_FLAG_UPDATE); + } } /** @@ -6933,7 +6944,6 @@ void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config) tmpccer |= (OC_Config->OCNPolarity << 4U); /* Reset the Output N State */ tmpccer &= ~TIM_CCER_CC2NE; - } if (IS_TIM_BREAK_INSTANCE(TIMx)) diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c index ff8c8f5..8a565a6 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c @@ -835,7 +835,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channe /* Disable the TIM Break interrupt (only if no more channel is active) */ tmpccer = htim->Instance->CCER; - if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET) + if ((tmpccer & TIM_CCER_CCxNE_MASK) == (uint32_t)RESET) { __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK); } @@ -1081,17 +1081,6 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Chann (+) Stop the Complementary PWM and disable interrupts. (+) Start the Complementary PWM and enable DMA transfers. (+) Stop the Complementary PWM and disable DMA transfers. - (+) Start the Complementary Input Capture measurement. - (+) Stop the Complementary Input Capture. - (+) Start the Complementary Input Capture and enable interrupts. - (+) Stop the Complementary Input Capture and disable interrupts. - (+) Start the Complementary Input Capture and enable DMA transfers. - (+) Stop the Complementary Input Capture and disable DMA transfers. - (+) Start the Complementary One Pulse generation. - (+) Stop the Complementary One Pulse. - (+) Start the Complementary One Pulse and enable interrupts. - (+) Stop the Complementary One Pulse and disable interrupts. - @endverbatim * @{ */ @@ -1317,7 +1306,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Chann /* Disable the TIM Break interrupt (only if no more channel is active) */ tmpccer = htim->Instance->CCER; - if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET) + if ((tmpccer & TIM_CCER_CCxNE_MASK) == (uint32_t)RESET) { __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK); } @@ -2100,7 +2089,7 @@ HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap) */ /** - * @brief Hall commutation changed callback in non-blocking mode + * @brief Commutation callback in non-blocking mode * @param htim TIM handle * @retval None */ @@ -2114,7 +2103,7 @@ __weak void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim) */ } /** - * @brief Hall commutation changed half complete callback in non-blocking mode + * @brief Commutation half complete callback in non-blocking mode * @param htim TIM handle * @retval None */ @@ -2129,7 +2118,7 @@ __weak void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim) } /** - * @brief Hall Break detection callback in non-blocking mode + * @brief Break detection callback in non-blocking mode * @param htim TIM handle * @retval None */ @@ -2280,15 +2269,6 @@ static void TIM_DMADelayPulseNCplt(DMA_HandleTypeDef *hdma) TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); } } - else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) - { - htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; - - if (hdma->Init.Mode == DMA_NORMAL) - { - TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); - } - } else { /* nothing to do */ @@ -2357,13 +2337,13 @@ static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Cha { uint32_t tmp; - tmp = TIM_CCER_CC1NE << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */ + tmp = TIM_CCER_CC1NE << (Channel & 0xFU); /* 0xFU = 15 bits max shift */ /* Reset the CCxNE Bit */ TIMx->CCER &= ~tmp; /* Set or reset the CCxNE Bit */ - TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */ + TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0xFU)); /* 0xFU = 15 bits max shift */ } /** * @} diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c index db1f087..b7cf66c 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c @@ -1174,6 +1174,8 @@ HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pD { if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { + huart->gState = HAL_UART_STATE_READY; + return HAL_TIMEOUT; } if (pdata8bits == NULL) @@ -1191,6 +1193,8 @@ HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pD if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) { + huart->gState = HAL_UART_STATE_READY; + return HAL_TIMEOUT; } @@ -1258,6 +1262,8 @@ HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, ui { if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) { + huart->RxState = HAL_UART_STATE_READY; + return HAL_TIMEOUT; } if (pdata8bits == NULL) @@ -1786,21 +1792,18 @@ HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_ status = UART_Start_Receive_DMA(huart, pData, Size); /* Check Rx process has been successfully started */ - if (status == HAL_OK) + if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) { - if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) - { - __HAL_UART_CLEAR_IDLEFLAG(huart); - ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); - } - else - { - /* In case of errors already pending when reception is started, - Interrupts may have already been raised and lead to reception abortion. - (Overrun error for instance). - In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */ - status = HAL_ERROR; - } + __HAL_UART_CLEAR_IDLEFLAG(huart); + ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); + } + else + { + /* In case of errors already pending when reception is started, + Interrupts may have already been raised and lead to reception abortion. + (Overrun error for instance). + In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */ + status = HAL_ERROR; } return status; @@ -3188,19 +3191,31 @@ static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, /* Check for the Timeout */ if (Timeout != HAL_MAX_DELAY) { - if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout)) + if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U)) { - /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ - ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE)); - ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); - huart->gState = HAL_UART_STATE_READY; - huart->RxState = HAL_UART_STATE_READY; + return HAL_TIMEOUT; + } - /* Process Unlocked */ - __HAL_UNLOCK(huart); + if ((READ_BIT(huart->Instance->CR1, USART_CR1_RE) != 0U) && (Flag != UART_FLAG_TXE) && (Flag != UART_FLAG_TC)) + { + if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) == SET) + { + /* Clear Overrun Error flag*/ + __HAL_UART_CLEAR_OREFLAG(huart); - return HAL_TIMEOUT; + /* Blocking error : transfer is aborted + Set the UART state ready to be able to start again the process, + Disable Rx Interrupts if ongoing */ + UART_EndRxTransfer(huart); + + huart->ErrorCode = HAL_UART_ERROR_ORE; + + /* Process Unlocked */ + __HAL_UNLOCK(huart); + + return HAL_ERROR; + } } } } diff --git a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c index a25f305..7e481aa 100644 --- a/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c +++ b/fw/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c @@ -221,9 +221,9 @@ HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDe do { - HAL_Delay(1U); - ms++; - } while ((USB_GetMode(USBx) != (uint32_t)USB_HOST_MODE) && (ms < 50U)); + HAL_Delay(10U); + ms += 10U; + } while ((USB_GetMode(USBx) != (uint32_t)USB_HOST_MODE) && (ms < HAL_USB_CURRENT_MODE_MAX_DELAY_MS)); } else if (mode == USB_DEVICE_MODE) { @@ -231,16 +231,16 @@ HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDe do { - HAL_Delay(1U); - ms++; - } while ((USB_GetMode(USBx) != (uint32_t)USB_DEVICE_MODE) && (ms < 50U)); + HAL_Delay(10U); + ms += 10U; + } while ((USB_GetMode(USBx) != (uint32_t)USB_DEVICE_MODE) && (ms < HAL_USB_CURRENT_MODE_MAX_DELAY_MS)); } else { return HAL_ERROR; } - if (ms == 50U) + if (ms == HAL_USB_CURRENT_MODE_MAX_DELAY_MS) { return HAL_ERROR; } @@ -383,7 +383,7 @@ HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num) { count++; - if (count > 200000U) + if (count > HAL_USB_TIMEOUT) { return HAL_TIMEOUT; } @@ -397,7 +397,7 @@ HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num) { count++; - if (count > 200000U) + if (count > HAL_USB_TIMEOUT) { return HAL_TIMEOUT; } @@ -420,7 +420,7 @@ HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx) { count++; - if (count > 200000U) + if (count > HAL_USB_TIMEOUT) { return HAL_TIMEOUT; } @@ -434,7 +434,7 @@ HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx) { count++; - if (count > 200000U) + if (count > HAL_USB_TIMEOUT) { return HAL_TIMEOUT; } @@ -452,7 +452,7 @@ HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx) * @arg USB_OTG_SPEED_FULL: Full speed mode * @retval Hal status */ -HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed) +HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -467,7 +467,7 @@ HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed) * This parameter can be one of these values: * @arg USBD_FS_SPEED: Full speed mode */ -uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx) +uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; uint8_t speed; @@ -492,7 +492,7 @@ uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx) * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t epnum = (uint32_t)ep->num; @@ -530,7 +530,7 @@ HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTy * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t epnum = (uint32_t)ep->num; @@ -569,7 +569,7 @@ HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t epnum = (uint32_t)ep->num; @@ -616,7 +616,7 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EP * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t epnum = (uint32_t)ep->num; @@ -792,7 +792,7 @@ HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) { __IO uint32_t count = 0U; HAL_StatusTypeDef ret = HAL_OK; @@ -852,7 +852,7 @@ HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef * @param len Number of bytes to write * @retval HAL status */ -HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, +HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -880,7 +880,7 @@ HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, * @param len Number of bytes to read * @retval pointer to destination buffer */ -void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len) +void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len) { uint32_t USBx_BASE = (uint32_t)USBx; uint8_t *pDest = dest; @@ -922,7 +922,7 @@ void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len) * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t epnum = (uint32_t)ep->num; @@ -953,7 +953,7 @@ HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef * @param ep pointer to endpoint structure * @retval HAL status */ -HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep) +HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t epnum = (uint32_t)ep->num; @@ -1023,7 +1023,7 @@ HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx) * This parameter can be a value from 0 to 255 * @retval HAL status */ -HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address) +HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1038,7 +1038,7 @@ HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address * @param USBx Selected device * @retval HAL status */ -HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx) +HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1055,7 +1055,7 @@ HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx) * @param USBx Selected device * @retval HAL status */ -HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx) +HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1088,7 +1088,7 @@ uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx) * @param chnum Channel number * @retval USB Channel Interrupt status */ -uint32_t USB_ReadChInterrupts(USB_OTG_GlobalTypeDef *USBx, uint8_t chnum) +uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t tmpreg; @@ -1104,7 +1104,7 @@ uint32_t USB_ReadChInterrupts(USB_OTG_GlobalTypeDef *USBx, uint8_t chnum) * @param USBx Selected device * @retval USB Device OUT EP interrupt status */ -uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx) +uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t tmpreg; @@ -1120,7 +1120,7 @@ uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx) * @param USBx Selected device * @retval USB Device IN EP interrupt status */ -uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx) +uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t tmpreg; @@ -1138,7 +1138,7 @@ uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx) * This parameter can be a value from 0 to 15 * @retval Device OUT EP Interrupt register */ -uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum) +uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t tmpreg; @@ -1156,7 +1156,7 @@ uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum) * This parameter can be a value from 0 to 15 * @retval Device IN EP Interrupt register */ -uint32_t USB_ReadDevInEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum) +uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t tmpreg; @@ -1190,7 +1190,7 @@ void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt) * 0 : Host * 1 : Device */ -uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx) +uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx) { return ((USBx->GINTSTS) & 0x1U); } @@ -1200,7 +1200,7 @@ uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx) * @param USBx Selected device * @retval HAL status */ -HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx) +HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1218,10 +1218,10 @@ HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx) * @param psetup pointer to setup packet * @retval HAL status */ -HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t *psetup) +HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, const uint8_t *psetup) { uint32_t USBx_BASE = (uint32_t)USBx; - uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U); + uint32_t gSNPSiD = *(__IO const uint32_t *)(&USBx->CID + 0x1U); UNUSED(psetup); if (gSNPSiD > USB_OTG_CORE_ID_300A) @@ -1254,7 +1254,7 @@ static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx) { count++; - if (count > 200000U) + if (count > HAL_USB_TIMEOUT) { return HAL_TIMEOUT; } @@ -1268,7 +1268,7 @@ static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx) { count++; - if (count > 200000U) + if (count > HAL_USB_TIMEOUT) { return HAL_TIMEOUT; } @@ -1349,7 +1349,7 @@ HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef c * HCFG_6_MHZ : Low Speed 6 MHz Clock * @retval HAL status */ -HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq) +HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1379,7 +1379,7 @@ HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq) * @note (1)The application must wait at least 10 ms * before clearing the reset bit. */ -HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx) +HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1406,7 +1406,7 @@ HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx) * 1 : Activate VBUS * @retval HAL status */ -HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state) +HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state) { uint32_t USBx_BASE = (uint32_t)USBx; __IO uint32_t hprt0 = 0U; @@ -1704,7 +1704,7 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe * @param USBx Selected device * @retval HAL state */ -uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx) +uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1718,7 +1718,7 @@ uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx) * This parameter can be a value from 1 to 15 * @retval HAL state */ -HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num) +HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t hcnum = (uint32_t)hc_num; @@ -1802,7 +1802,7 @@ HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num) * This parameter can be a value from 1 to 15 * @retval HAL state */ -HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num) +HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num) { uint32_t USBx_BASE = (uint32_t)USBx; uint32_t chnum = (uint32_t)ch_num; @@ -1891,7 +1891,7 @@ HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx) * @param USBx Selected device * @retval HAL status */ -HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx) +HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; @@ -1909,7 +1909,7 @@ HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx) * @param USBx Selected device * @retval HAL status */ -HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx) +HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx) { uint32_t USBx_BASE = (uint32_t)USBx; diff --git a/fw/Makefile b/fw/Makefile index 8227934..fc8ae9b 100644 --- a/fw/Makefile +++ b/fw/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Fri Mar 15 23:06:10 EDT 2024] +# File automatically-generated by tool: [projectgenerator] version: [4.5.0-B34] date: [Wed Oct 09 13:45:14 EDT 2024] ########################################################################################################################## # ------------------------------------------------ @@ -13,7 +13,8 @@ ###################################### # target ###################################### -TARGET = DVM-V24-stm32f103 +TARGET_V1 = DVM-V24-stm32f103 +TARGET_V2 = DVM-V24-V2-stm32f103 ###################################### @@ -79,7 +80,9 @@ v24/src/util.c \ v24/src/vcp.c \ Core/Src/dma.c \ Core/Src/iwdg.c \ -Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c +Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c \ +Core/Src/sysmem.c \ +Core/Src/syscalls.c # ASM sources ASM_SOURCES = \ diff --git a/fw/USB_DEVICE/App/usbd_cdc_if.c b/fw/USB_DEVICE/App/usbd_cdc_if.c index 872280e..652268f 100644 --- a/fw/USB_DEVICE/App/usbd_cdc_if.c +++ b/fw/USB_DEVICE/App/usbd_cdc_if.c @@ -89,10 +89,10 @@ /* Create buffer for reception and transmission */ /* It's up to user to redefine and/or remove those define */ /** Received data over USB are stored in this buffer */ -uint8_t UserRxBufferFS[P25_V24_LDU_FRAME_LENGTH_BYTES * 2]; +uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; /** Data to send over USB CDC are stored in this buffer */ -uint8_t UserTxBufferFS[P25_V24_LDU_FRAME_LENGTH_BYTES * 2]; +uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE BEGIN PRIVATE_VARIABLES */ diff --git a/fw/USB_DEVICE/Target/usbd_conf.c b/fw/USB_DEVICE/Target/usbd_conf.c index 48ef41d..9e158db 100644 --- a/fw/USB_DEVICE/Target/usbd_conf.c +++ b/fw/USB_DEVICE/Target/usbd_conf.c @@ -77,9 +77,9 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) __HAL_RCC_USB_CLK_ENABLE(); /* Peripheral interrupt init */ - HAL_NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, NVIC_PRI_USB, 0); + HAL_NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, 4, 0); HAL_NVIC_EnableIRQ(USB_HP_CAN1_TX_IRQn); - HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, NVIC_PRI_USB, 0); + HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 4, 0); HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); /* USER CODE BEGIN USB_MspInit 1 */ diff --git a/fw/cmake/gcc-arm-none-eabi.cmake b/fw/cmake/gcc-arm-none-eabi.cmake new file mode 100644 index 0000000..897871d --- /dev/null +++ b/fw/cmake/gcc-arm-none-eabi.cmake @@ -0,0 +1,48 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) + +set(CMAKE_C_COMPILER_FORCED TRUE) +set(CMAKE_CXX_COMPILER_FORCED TRUE) +set(CMAKE_C_COMPILER_ID GNU) +set(CMAKE_CXX_COMPILER_ID GNU) + +# Some default GCC settings +# arm-none-eabi- must be part of path environment +set(TOOLCHAIN_PREFIX arm-none-eabi-) + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) +set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +# MCU specific flags +set(TARGET_FLAGS "-mcpu=cortex-m3 ") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections") +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3") +endif() +if(CMAKE_BUILD_TYPE MATCHES Release) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -g0") +endif() + +set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP") +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics") + +set(CMAKE_C_LINK_FLAGS "${TARGET_FLAGS}") +set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -T \"${CMAKE_SOURCE_DIR}/STM32F103C8Tx_FLASH.ld\"") +set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --specs=nano.specs") +set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections") +set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lc -lm -Wl,--end-group") +set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--print-memory-usage") + +set(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group") \ No newline at end of file diff --git a/fw/cmake/stm32cubemx/CMakeLists.txt b/fw/cmake/stm32cubemx/CMakeLists.txt new file mode 100644 index 0000000..8d372c6 --- /dev/null +++ b/fw/cmake/stm32cubemx/CMakeLists.txt @@ -0,0 +1,79 @@ +cmake_minimum_required(VERSION 3.22) + +project(stm32cubemx) +add_library(stm32cubemx INTERFACE) + +# Enable CMake support for ASM and C languages +enable_language(C ASM) + +target_compile_definitions(stm32cubemx INTERFACE + USE_HAL_DRIVER + STM32F103xB + $<$:DEBUG> +) + +target_include_directories(stm32cubemx INTERFACE + ../../Core/Inc + ../../USB_DEVICE/App + ../../USB_DEVICE/Target + ../../Drivers/STM32F1xx_HAL_Driver/Inc + ../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy + ../../Middlewares/ST/STM32_USB_Device_Library/Core/Inc + ../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc + ../../Drivers/CMSIS/Device/ST/STM32F1xx/Include + ../../Drivers/CMSIS/Include +) + +target_sources(stm32cubemx INTERFACE + ../../Core/Src/main.c + ../../Core/Src/gpio.c + ../../Core/Src/dma.c + ../../Core/Src/iwdg.c + ../../Core/Src/tim.c + ../../Core/Src/usart.c + ../../Core/Src/stm32f1xx_it.c + ../../Core/Src/stm32f1xx_hal_msp.c + ../../USB_DEVICE/App/usb_device.c + ../../USB_DEVICE/App/usbd_desc.c + ../../USB_DEVICE/App/usbd_cdc_if.c + ../../USB_DEVICE/Target/usbd_conf.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c + ../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c + ../../Core/Src/system_stm32f1xx.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/CDC/Src/usbd_cdc.c + ../../Core/Src/sysmem.c + ../../Core/Src/syscalls.c + ../../startup_stm32f103xb.s +) + +target_link_directories(stm32cubemx INTERFACE +) + +target_link_libraries(stm32cubemx INTERFACE +) + +# Validate that STM32CubeMX code is compatible with C standard +if(CMAKE_C_STANDARD LESS 11) + message(ERROR "Generated code requires C11 or higher") +endif() + + diff --git a/fw/v24/inc/config.h b/fw/v24/inc/config.h index b95b8da..b677e24 100644 --- a/fw/v24/inc/config.h +++ b/fw/v24/inc/config.h @@ -34,23 +34,31 @@ extern "C" { // Enable periodic status print //#define PERIODIC_STATUS +// Sanity check +#if !defined DVM_V24_V1 && !defined DVM_V24_V2 +#error "Invalid compile-time environment! Missing one of DVM_V24_V1 or DVM_V24_V2" +#endif + // Report buffer space in 16-byte blocks instead of LDUs #define STATUS_SPACE_BLOCKS // STM32 Interrupt Priorities #define NVIC_PRI_TIM2 3U -#define NVIC_PRI_USB 4U +#define NVIC_PRI_USB_USART1 4U #define NVIC_PRI_DMA 5U -#define NVIC_PRI_USART 6U +#define NVIC_PRI_USART2 6U // Time in ms above which critical routines will throw a warning #define FUNC_TIMER_WARN 10U -#ifndef GITHASH -#define GITHASH "00000000" -#endif +#define FW_MAJ "2" +#define FW_MIN "2" -#define VERSION_STRING "DVM-V24 FW V2.1 (" GITHASH ")" +#ifdef DVM_V24_V2 +#define VERSION_STRING "DVM-V24-V2 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" +#else +#define VERSION_STRING "DVM-V24 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" +#endif #define BUILD_DATE_STRING __DATE__ " " __TIME__ #define HARDWARE_STRING VERSION_STRING ", " BUILD_DATE_STRING diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index 2f23ae7..acd9bb8 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -10,7 +10,6 @@ #include "leds.h" #include "stdio.h" -#include "usbd_cdc_if.h" #include "log.h" #include "fifo.h" #include "util.h" @@ -18,6 +17,10 @@ #include "string.h" #include "hdlc.h" +#ifdef DVM_V24_V1 +#include "usbd_cdc_if.h" +#endif + // Indicates if the host has opened the port extern bool USB_VCP_DTR; From 291f10bac6642b09320036792e5baa42204e48a7 Mon Sep 17 00:00:00 2001 From: Patrick W3AXL Date: Wed, 9 Oct 2024 17:31:48 -0400 Subject: [PATCH 02/17] define cleanup --- fw/CMakeLists.txt | 1 - fw/Core/Src/main.c | 6 ++--- fw/DVM-V24-stm32f103.ioc | 24 +++++++++++++++++++- fw/v24/inc/config.h | 11 +++------ fw/v24/inc/leds.h | 4 ++++ fw/v24/inc/vcp.h | 6 +++++ fw/v24/src/vcp.c | 48 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 13 deletions(-) diff --git a/fw/CMakeLists.txt b/fw/CMakeLists.txt index 32dc175..f0213fa 100644 --- a/fw/CMakeLists.txt +++ b/fw/CMakeLists.txt @@ -107,7 +107,6 @@ target_include_directories(${CMAKE_TARGET_V2} PRIVATE ) target_compile_definitions(${CMAKE_TARGET_V2} PRIVATE - DVM_V24_V2 GIT_HASH="${GIT_VER_HASH}" ) diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index ff57396..b83d587 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -133,10 +133,10 @@ int main(void) MX_DMA_Init(); MX_USART2_UART_Init(); MX_TIM2_Init(); - #ifdef DVM_V24_V2 - MX_USART1_UART_Init(); - #else + #ifdef DVM_V24_V1 MX_USB_DEVICE_Init(); + #else + MX_USART1_UART_Init(); #endif MX_IWDG_Init(); /* USER CODE BEGIN 2 */ diff --git a/fw/DVM-V24-stm32f103.ioc b/fw/DVM-V24-stm32f103.ioc index 1e0d35e..34a0354 100644 --- a/fw/DVM-V24-stm32f103.ioc +++ b/fw/DVM-V24-stm32f103.ioc @@ -3,7 +3,27 @@ CAD.formats= CAD.pinconfig= CAD.provider= Dma.Request0=USART2_TX -Dma.RequestsNb=1 +Dma.Request1=USART1_TX +Dma.Request2=USART1_RX +Dma.RequestsNb=3 +Dma.USART1_RX.2.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART1_RX.2.Instance=DMA1_Channel5 +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_MEDIUM +Dma.USART1_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority +Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH +Dma.USART1_TX.1.Instance=DMA1_Channel4 +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_MEDIUM +Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority Dma.USART2_TX.0.Direction=DMA_MEMORY_TO_PERIPH Dma.USART2_TX.0.Instance=DMA1_Channel7 Dma.USART2_TX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE @@ -67,6 +87,8 @@ Mcu.UserName=STM32F103C8Tx MxCube.Version=6.12.1 MxDb.Version=DB.6.0.121 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.DMA1_Channel4_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true NVIC.DMA1_Channel7_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.ForceEnableDMAVector=true diff --git a/fw/v24/inc/config.h b/fw/v24/inc/config.h index b677e24..c93f619 100644 --- a/fw/v24/inc/config.h +++ b/fw/v24/inc/config.h @@ -34,11 +34,6 @@ extern "C" { // Enable periodic status print //#define PERIODIC_STATUS -// Sanity check -#if !defined DVM_V24_V1 && !defined DVM_V24_V2 -#error "Invalid compile-time environment! Missing one of DVM_V24_V1 or DVM_V24_V2" -#endif - // Report buffer space in 16-byte blocks instead of LDUs #define STATUS_SPACE_BLOCKS @@ -54,10 +49,10 @@ extern "C" { #define FW_MAJ "2" #define FW_MIN "2" -#ifdef DVM_V24_V2 -#define VERSION_STRING "DVM-V24-V2 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" +#ifdef DVM_V24_V1 +#define VERSION_STRING "DVM-V24-V1 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" #else -#define VERSION_STRING "DVM-V24 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" +#define VERSION_STRING "DVM-V24-V2 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" #endif #define BUILD_DATE_STRING __DATE__ " " __TIME__ #define HARDWARE_STRING VERSION_STRING ", " BUILD_DATE_STRING diff --git a/fw/v24/inc/leds.h b/fw/v24/inc/leds.h index bf5584b..93eaef2 100644 --- a/fw/v24/inc/leds.h +++ b/fw/v24/inc/leds.h @@ -2,10 +2,14 @@ #define LEDS_H // LED Command Defines +#ifdef DVM_V24_V1 #define LED_HB(state) HAL_GPIO_WritePin(LED_HB_GPIO_Port, LED_HB_Pin, state) #define LED_USB(state) HAL_GPIO_WritePin(LED_USB_GPIO_Port, LED_USB_Pin, state) #define LED_LINK(state) HAL_GPIO_WritePin(LED_LINK_GPIO_Port, LED_LINK_Pin, state) #define LED_ACT(state) HAL_GPIO_WritePin(LED_ACT_GPIO_Port, LED_ACT_Pin, state) +#else + +#endif // Miscellaneous Parameters #define LED_TEST_DURATION 5000 diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index 2f1b073..d506395 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -55,6 +55,12 @@ enum DVM_STATE { STATE_P25 = 2U, //! Project 25 }; +// Vars for V2 serial implementation +#ifndef DVM_V24_V1 +bool usartRx = false; +uint8_t usartRxBuffer[8] = {0}; +#endif + void VCPRxITCallback(uint8_t* buf, uint32_t len); void VCPRxCallback(); diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index acd9bb8..f69aa3b 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -19,6 +19,8 @@ #ifdef DVM_V24_V1 #include "usbd_cdc_if.h" +#else +#include "usart.h" #endif // Indicates if the host has opened the port @@ -84,6 +86,34 @@ void VCPRxITCallback(uint8_t* buf, uint32_t len) #endif } +/** + * @brief Interrupt handler for USART1 RX + * + * @param huart uart to handle (should be usart1) + */ +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) +{ + uint32_t start = HAL_GetTick(); + // Add received bytes to the fifo + for (int i = 0; i < 8; i++) + { + if (FifoPush(&vcpRxFifo, usartRxBuffer[i])) + { + log_error("VCP RX FIFO full! Clearing buffer"); + FifoClear(&vcpRxFifo); + } + } + if (HAL_GetTick() - start > FUNC_TIMER_WARN) + { + log_warn("HAL_UART_RxCpltCallback took %u ms!", HAL_GetTick() - start); + } + #ifdef TRACE_VCP_RX + log_debug("Added 8 bytes to VCP RX FIFO"); + #endif + // Call the interrupt again + HAL_UART_Receive_IT(huart, usartRxBuffer, 8); +} + /** * @brief reset counters and flags related to VCP RX routine */ @@ -106,6 +136,16 @@ void VCPRxCallback() */ + #ifndef DVM_V24_V1 + if (!usartRx) + { + HAL_UART_Receive_IT(&huart1, usartRxBuffer, 8); + usartRx = true; + log_info("Started USART1 callback interrupt"); + } + #endif + + uint32_t start = HAL_GetTick(); if (vcpRxFifo.size > 0) @@ -336,6 +376,8 @@ void VCPTxCallback() return; } + #ifdef DVM_V24_V1 + // Directly write to the VCP bool sent = false; uint8_t attempts = USB_TX_RETRIES; @@ -370,6 +412,12 @@ void VCPTxCallback() { log_error("Failed to write to USB port"); } + #else + + // Write to USART1 + HAL_UART_Transmit(&huart1, txBuffer, txPos, 100); + + #endif } /** From 11ee8712b08503fdb978977869e899b419f203e0 Mon Sep 17 00:00:00 2001 From: Patrick W3AXL Date: Wed, 9 Oct 2024 18:09:36 -0400 Subject: [PATCH 03/17] cleanup to get v1 code working with cmake --- fw/.mxproject | 10 +++---- fw/Core/Inc/stm32f1xx_it.h | 2 ++ fw/Core/Src/dma.c | 6 ++++ fw/Core/Src/main.c | 5 ++++ fw/Core/Src/stm32f1xx_it.c | 30 ++++++++++++++++++++ fw/Core/Src/usart.c | 39 ++++++++++++++++++++++++++ fw/DVM-V24-stm32f103.ioc | 4 +-- fw/USB_DEVICE/App/usbd_cdc_if.c | 4 +++ fw/v24/inc/fifo.h | 2 +- fw/v24/inc/leds.h | 8 ++++-- fw/v24/inc/serial.h | 8 +++--- fw/v24/inc/sync.h | 5 ++-- fw/v24/inc/vcp.h | 10 +++++-- fw/v24/src/log.c | 2 +- fw/v24/src/serial.c | 38 ++++++++++++------------- fw/v24/src/sync.c | 4 +-- fw/v24/src/vcp.c | 49 ++++++++++++++++++++++----------- 17 files changed, 167 insertions(+), 59 deletions(-) diff --git a/fw/.mxproject b/fw/.mxproject index a15ef9c..c2b6842 100644 --- a/fw/.mxproject +++ b/fw/.mxproject @@ -6,6 +6,11 @@ SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\iwdg.c;Core\ HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Middlewares\ST\STM32_USB_Device_Library\Core\Inc;Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Inc;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;USB_DEVICE\App;USB_DEVICE\Target; CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER; +[PreviousUsedCMakes] +SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\iwdg.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_cdc_if.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.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\CDC\Src\usbd_cdc.c; +HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Middlewares\ST\STM32_USB_Device_Library\Core\Inc;Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Inc;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;USB_DEVICE\App;USB_DEVICE\Target; +CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER; + [PreviousGenFiles] AdvancedFolderStructure=true HeaderFileListSize=12 @@ -45,8 +50,3 @@ SourcePath#1=..\USB_DEVICE\App SourcePath#2=..\USB_DEVICE\Target SourceFiles=; -[PreviousUsedCMakes] -SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\iwdg.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_cdc_if.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pcd_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usb.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_iwdg.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.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\CDC\Src\usbd_cdc.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.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\CDC\Src\usbd_cdc.c; -HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Middlewares\ST\STM32_USB_Device_Library\Core\Inc;Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Inc;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;USB_DEVICE\App;USB_DEVICE\Target; -CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER; - diff --git a/fw/Core/Inc/stm32f1xx_it.h b/fw/Core/Inc/stm32f1xx_it.h index 1bcc4c7..e8fbe6a 100644 --- a/fw/Core/Inc/stm32f1xx_it.h +++ b/fw/Core/Inc/stm32f1xx_it.h @@ -55,6 +55,8 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void DMA1_Channel4_IRQHandler(void); +void DMA1_Channel5_IRQHandler(void); void DMA1_Channel7_IRQHandler(void); void USB_HP_CAN1_TX_IRQHandler(void); void USB_LP_CAN1_RX0_IRQHandler(void); diff --git a/fw/Core/Src/dma.c b/fw/Core/Src/dma.c index 04b3b67..5633b7e 100644 --- a/fw/Core/Src/dma.c +++ b/fw/Core/Src/dma.c @@ -43,6 +43,12 @@ void MX_DMA_Init(void) __HAL_RCC_DMA1_CLK_ENABLE(); /* DMA interrupt init */ + /* DMA1_Channel4_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 4, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn); + /* DMA1_Channel5_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 4, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); /* DMA1_Channel7_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index b83d587..d61b17d 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -74,6 +74,8 @@ void SystemClock_Config(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ + +#ifdef DVM_V24_V1 // HB LED is only on DVM-V24 V1 boards void hbLED() { if (HAL_GetTick() - lastHb > 1000) @@ -86,6 +88,7 @@ void hbLED() LED_HB(0); } } +#endif void linkLED() { @@ -177,7 +180,9 @@ int main(void) VCPTxCallback(); SerialCallback(&huart2); // LED callbacks + #ifdef DVM_V24_V1 hbLED(); + #endif linkLED(); // Refresh the IWDG watchdog #ifndef DISABLE_WATCHDOG diff --git a/fw/Core/Src/stm32f1xx_it.c b/fw/Core/Src/stm32f1xx_it.c index f2a8336..baa5232 100644 --- a/fw/Core/Src/stm32f1xx_it.c +++ b/fw/Core/Src/stm32f1xx_it.c @@ -58,6 +58,8 @@ /* External variables --------------------------------------------------------*/ extern PCD_HandleTypeDef hpcd_USB_FS; extern TIM_HandleTypeDef htim2; +extern DMA_HandleTypeDef hdma_usart1_tx; +extern DMA_HandleTypeDef hdma_usart1_rx; extern DMA_HandleTypeDef hdma_usart2_tx; extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; @@ -210,6 +212,34 @@ void SysTick_Handler(void) /* please refer to the startup file (startup_stm32f1xx.s). */ /******************************************************************************/ +/** + * @brief This function handles DMA1 channel4 global interrupt. + */ +void DMA1_Channel4_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel4_IRQn 0 */ + + /* USER CODE END DMA1_Channel4_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_usart1_tx); + /* USER CODE BEGIN DMA1_Channel4_IRQn 1 */ + + /* USER CODE END DMA1_Channel4_IRQn 1 */ +} + +/** + * @brief This function handles DMA1 channel5 global interrupt. + */ +void DMA1_Channel5_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel5_IRQn 0 */ + + /* USER CODE END DMA1_Channel5_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_usart1_rx); + /* USER CODE BEGIN DMA1_Channel5_IRQn 1 */ + + /* USER CODE END DMA1_Channel5_IRQn 1 */ +} + /** * @brief This function handles DMA1 channel7 global interrupt. */ diff --git a/fw/Core/Src/usart.c b/fw/Core/Src/usart.c index c7d7e39..e909502 100644 --- a/fw/Core/Src/usart.c +++ b/fw/Core/Src/usart.c @@ -26,6 +26,8 @@ UART_HandleTypeDef huart1; UART_HandleTypeDef huart2; +DMA_HandleTypeDef hdma_usart1_tx; +DMA_HandleTypeDef hdma_usart1_rx; DMA_HandleTypeDef hdma_usart2_tx; /* USART1 init function */ @@ -114,6 +116,39 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* USART1 DMA Init */ + /* USART1_TX Init */ + hdma_usart1_tx.Instance = DMA1_Channel4; + hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE; + hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_usart1_tx.Init.Mode = DMA_NORMAL; + hdma_usart1_tx.Init.Priority = DMA_PRIORITY_MEDIUM; + if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx); + + /* USART1_RX Init */ + hdma_usart1_rx.Instance = DMA1_Channel5; + hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; + hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_usart1_rx.Init.Mode = DMA_NORMAL; + hdma_usart1_rx.Init.Priority = DMA_PRIORITY_MEDIUM; + if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart1_rx); + /* USART1 interrupt Init */ HAL_NVIC_SetPriority(USART1_IRQn, 4, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); @@ -187,6 +222,10 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); + /* USART1 DMA DeInit */ + HAL_DMA_DeInit(uartHandle->hdmatx); + HAL_DMA_DeInit(uartHandle->hdmarx); + /* USART1 interrupt Deinit */ HAL_NVIC_DisableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspDeInit 1 */ diff --git a/fw/DVM-V24-stm32f103.ioc b/fw/DVM-V24-stm32f103.ioc index 34a0354..ce3aa54 100644 --- a/fw/DVM-V24-stm32f103.ioc +++ b/fw/DVM-V24-stm32f103.ioc @@ -87,8 +87,8 @@ Mcu.UserName=STM32F103C8Tx MxCube.Version=6.12.1 MxDb.Version=DB.6.0.121 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.DMA1_Channel4_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true -NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.DMA1_Channel4_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:true +NVIC.DMA1_Channel5_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:true NVIC.DMA1_Channel7_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.ForceEnableDMAVector=true diff --git a/fw/USB_DEVICE/App/usbd_cdc_if.c b/fw/USB_DEVICE/App/usbd_cdc_if.c index 652268f..7ae622b 100644 --- a/fw/USB_DEVICE/App/usbd_cdc_if.c +++ b/fw/USB_DEVICE/App/usbd_cdc_if.c @@ -268,7 +268,9 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) { /* USER CODE BEGIN 6 */ + #ifdef DVM_V24_V1 VCPRxITCallback(Buf, *Len); + #endif USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); USBD_CDC_ReceivePacket(&hUsbDeviceFS); return (USBD_OK); @@ -290,12 +292,14 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) { uint8_t result = USBD_OK; /* USER CODE BEGIN 7 */ + #ifdef DVM_V24_V1 USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; if (hcdc->TxState != 0){ return USBD_BUSY; } USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + #endif /* USER CODE END 7 */ return result; } diff --git a/fw/v24/inc/fifo.h b/fw/v24/inc/fifo.h index 73485f0..d6bcd78 100644 --- a/fw/v24/inc/fifo.h +++ b/fw/v24/inc/fifo.h @@ -19,7 +19,7 @@ extern "C" { typedef struct { uint8_t * const buffer; - unsigned int size; + int size; int head; int tail; const int maxlen; diff --git a/fw/v24/inc/leds.h b/fw/v24/inc/leds.h index 93eaef2..6a3a42d 100644 --- a/fw/v24/inc/leds.h +++ b/fw/v24/inc/leds.h @@ -2,13 +2,15 @@ #define LEDS_H // LED Command Defines +#define LED_LINK(state) HAL_GPIO_WritePin(LED_LINK_GPIO_Port, LED_LINK_Pin, state) +#define LED_ACT(state) HAL_GPIO_WritePin(LED_ACT_GPIO_Port, LED_ACT_Pin, state) + #ifdef DVM_V24_V1 #define LED_HB(state) HAL_GPIO_WritePin(LED_HB_GPIO_Port, LED_HB_Pin, state) #define LED_USB(state) HAL_GPIO_WritePin(LED_USB_GPIO_Port, LED_USB_Pin, state) -#define LED_LINK(state) HAL_GPIO_WritePin(LED_LINK_GPIO_Port, LED_LINK_Pin, state) -#define LED_ACT(state) HAL_GPIO_WritePin(LED_ACT_GPIO_Port, LED_ACT_Pin, state) #else - +#define LED_USB_TX(state) HAL_GPIO_WritePin(LED_USB_GPIO_Port, LED_USB_Pin, state) +#define LED_USB_RX(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) #endif // Miscellaneous Parameters diff --git a/fw/v24/inc/serial.h b/fw/v24/inc/serial.h index 54884ea..0192f29 100644 --- a/fw/v24/inc/serial.h +++ b/fw/v24/inc/serial.h @@ -32,10 +32,10 @@ extern "C" { // External functions void SerialCallback(UART_HandleTypeDef *huart); -void SerialWrite(UART_HandleTypeDef *huart, const char *data); -void SerialWriteLn(UART_HandleTypeDef *huart, const char *data); -void SerialClear(UART_HandleTypeDef *huart); -void SerialStartup(UART_HandleTypeDef *huart); +void SerialWrite(const char *data); +void SerialWriteLn(const char *data); +void SerialClear(); +void SerialStartup(); #ifdef __cplusplus } diff --git a/fw/v24/inc/sync.h b/fw/v24/inc/sync.h index e2fd0a8..886e21d 100644 --- a/fw/v24/inc/sync.h +++ b/fw/v24/inc/sync.h @@ -46,7 +46,6 @@ extern "C" { extern unsigned long rxValidFrames; extern unsigned long rxTotalFrames; extern unsigned long txTotalFrames; -extern volatile enum RxState SyncRxState; // State machine stuff enum RxState { @@ -55,11 +54,13 @@ enum RxState { SYNCED = 0x02, }; +extern volatile enum RxState SyncRxState; + void SyncStartup(TIM_HandleTypeDef *tim); void SyncReset(); void SyncTimerCallback(void); bool SyncAddTxByte(const uint8_t byte); -bool SyncAddTxBytes(const uint8_t *bytes, int len); +bool SyncAddTxBytes(const uint8_t *bytes, unsigned int len); uint8_t SyncGetTxFree(); void RxMessageCallback(); uint16_t StuffByte(uint8_t byte); diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index d506395..4ea0f83 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -58,12 +58,16 @@ enum DVM_STATE { // Vars for V2 serial implementation #ifndef DVM_V24_V1 bool usartRx = false; -uint8_t usartRxBuffer[8] = {0}; +#define USART_RX_BUF_SIZE 4 +uint8_t usartRxBuffer[USART_RX_BUF_SIZE] = {0}; #endif +#ifdef DVM_V24_V1 +void VCPEnumerate(); void VCPRxITCallback(uint8_t* buf, uint32_t len); -void VCPRxCallback(); +#endif +void VCPRxCallback(); void VCPTxCallback(); bool VCPWrite(uint8_t *data, uint16_t len); @@ -78,7 +82,7 @@ bool VCPWriteDebug2(const char *text, int16_t n1); bool VCPWriteDebug3(const char *text, int16_t n1, int16_t n2); bool VCPWriteDebug4(const char *text, int16_t n1, int16_t n2, int16_t n3); -void VCPEnumerate(); + #ifdef __cplusplus } diff --git a/fw/v24/src/log.c b/fw/v24/src/log.c index 41ff819..efab0c7 100644 --- a/fw/v24/src/log.c +++ b/fw/v24/src/log.c @@ -80,7 +80,7 @@ static void stdout_callback(log_Event *ev) { #endif vsprintf(fullBuf + strlen(fullBuf), ev->fmt, ev->ap); sprintf(fullBuf + strlen(fullBuf), "\x1b[0m\r\n"); - SerialWrite(uart, fullBuf); + SerialWrite(fullBuf); memset(fullBuf, 0, MAX_MSG_LENGTH); } diff --git a/fw/v24/src/serial.c b/fw/v24/src/serial.c index dba1e6b..0962d4d 100644 --- a/fw/v24/src/serial.c +++ b/fw/v24/src/serial.c @@ -74,12 +74,10 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) /** * @brief uart write command, writes bytes directly to terminal - * @param *huart: hardware UART object (pointer) * @param *data: data array (pointer) * @retval none */ -void SerialWrite(UART_HandleTypeDef *huart, const char *data) { - //HAL_UART_Transmit_IT(huart, (uint8_t*)data, strlen(data)); +void SerialWrite(const char *data) { uint16_t len = strlen(data); for (int i=0; i SYNC_TX_BUF_LEN) { log_error("Tried to add more TX bytes than TX buffer supports!"); return false; } - for (int i=0; i 0) { // Turn activity LED on + #ifdef DVM_V24_V1 LED_USB(1); + #else + LED_USB_RX(1); + #endif // Read a byte uint8_t c; @@ -338,7 +358,11 @@ void VCPRxCallback() } // turn activity LED off + #ifdef DVM_V24_V1 LED_USB(0); + #else + LED_USB_RX(0); + #endif } // Check elapsed time @@ -414,8 +438,11 @@ void VCPTxCallback() } #else + // Turn LED on (turned off by TX cplt callback) + LED_USB_TX(1); + // Write to USART1 - HAL_UART_Transmit(&huart1, txBuffer, txPos, 100); + HAL_UART_Transmit_DMA(&huart1, txBuffer, txPos); #endif } @@ -794,14 +821,4 @@ bool VCPWriteDebug4(const char *text, int16_t n1, int16_t n2, int16_t n3) // Return return ret; -} - -/** - * @brief Toggles the 1.5k resistor on D+ to renumerate the USB device -*/ -void VCPEnumerate() -{ - USB_ENUM(0); - HAL_Delay(50); - USB_ENUM(1); } \ No newline at end of file From 75e7bc22088f39bd2c76aecbffcd724f31d57976 Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:09:34 -0400 Subject: [PATCH 04/17] v24 pretty much fully working on v2 hardware --- fw/CMakeLists.txt | 19 +++++++++++++ fw/Core/Src/dma.c | 7 ++--- fw/Core/Src/usart.c | 24 +++------------- fw/v24/inc/config.h | 9 +++--- fw/v24/inc/vcp.h | 12 +++----- fw/v24/src/serial.c | 8 ++++++ fw/v24/src/vcp.c | 69 ++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 107 insertions(+), 41 deletions(-) diff --git a/fw/CMakeLists.txt b/fw/CMakeLists.txt index f0213fa..c719eae 100644 --- a/fw/CMakeLists.txt +++ b/fw/CMakeLists.txt @@ -92,6 +92,12 @@ target_link_libraries(${CMAKE_TARGET_V1} stm32cubemx ) +# Add .bin generation +add_custom_command(TARGET ${CMAKE_TARGET_V1} + POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${CMAKE_TARGET_V1}.bin +) + # # V2 Target Setup # @@ -113,4 +119,17 @@ target_compile_definitions(${CMAKE_TARGET_V2} PRIVATE # Add linked libraries target_link_libraries(${CMAKE_TARGET_V2} stm32cubemx +) + +# Add .bin generation +add_custom_command(TARGET ${CMAKE_TARGET_V2} + POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O binary $ ${CMAKE_TARGET_V2}.bin +) + +# Make sure bins are cleaned +set_property( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + APPEND + PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_TARGET_V1}.bin ${CMAKE_TARGET_V2}.bin ) \ No newline at end of file diff --git a/fw/Core/Src/dma.c b/fw/Core/Src/dma.c index 5633b7e..6a83623 100644 --- a/fw/Core/Src/dma.c +++ b/fw/Core/Src/dma.c @@ -43,14 +43,11 @@ void MX_DMA_Init(void) __HAL_RCC_DMA1_CLK_ENABLE(); /* DMA interrupt init */ - /* DMA1_Channel4_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 4, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn); /* DMA1_Channel5_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 4, 0); + HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_PRI_USART1_RX, 0); HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); /* DMA1_Channel7_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 5, 0); + HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_USART2_DMA, 0); HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); } diff --git a/fw/Core/Src/usart.c b/fw/Core/Src/usart.c index e909502..673bb8c 100644 --- a/fw/Core/Src/usart.c +++ b/fw/Core/Src/usart.c @@ -72,7 +72,7 @@ void MX_USART2_UART_Init(void) /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; - huart2.Init.BaudRate = 256000; + huart2.Init.BaudRate = 576000; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; @@ -117,22 +117,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USART1 DMA Init */ - /* USART1_TX Init */ - hdma_usart1_tx.Instance = DMA1_Channel4; - hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; - hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE; - hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart1_tx.Init.Mode = DMA_NORMAL; - hdma_usart1_tx.Init.Priority = DMA_PRIORITY_MEDIUM; - if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK) - { - Error_Handler(); - } - - __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx); - /* USART1_RX Init */ hdma_usart1_rx.Instance = DMA1_Channel5; hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; @@ -141,7 +125,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_usart1_rx.Init.Mode = DMA_NORMAL; - hdma_usart1_rx.Init.Priority = DMA_PRIORITY_MEDIUM; + hdma_usart1_rx.Init.Priority = DMA_PRIORITY_HIGH; if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK) { Error_Handler(); @@ -150,7 +134,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart1_rx); /* USART1 interrupt Init */ - HAL_NVIC_SetPriority(USART1_IRQn, 4, 0); + HAL_NVIC_SetPriority(USART1_IRQn, NVIC_PRI_USART1_RX, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspInit 1 */ @@ -197,7 +181,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); /* USART2 interrupt Init */ - HAL_NVIC_SetPriority(USART2_IRQn, 6, 0); + HAL_NVIC_SetPriority(USART2_IRQn, NVIC_PRI_USART2_INT, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ diff --git a/fw/v24/inc/config.h b/fw/v24/inc/config.h index c93f619..53b80eb 100644 --- a/fw/v24/inc/config.h +++ b/fw/v24/inc/config.h @@ -38,10 +38,11 @@ extern "C" { #define STATUS_SPACE_BLOCKS // STM32 Interrupt Priorities -#define NVIC_PRI_TIM2 3U -#define NVIC_PRI_USB_USART1 4U -#define NVIC_PRI_DMA 5U -#define NVIC_PRI_USART2 6U +#define NVIC_PRI_TIM2 2U +#define NVIC_PRI_USART1_TX 3U +#define NVIC_PRI_USART1_RX 4U +#define NVIC_PRI_USART2_DMA 5U +#define NVIC_PRI_USART2_INT 6U // Time in ms above which critical routines will throw a warning #define FUNC_TIMER_WARN 10U diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index 4ea0f83..07c4e64 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -22,7 +22,8 @@ extern "C" { #define VCP_RX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 4) #define VCP_TX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 2) -#define VCP_RX_TIMEOUT 100 +#define VCP_RX_TIMEOUT 10 +#define VCP_TX_TIMEOUT 10 #define USB_ENUM(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) @@ -55,16 +56,11 @@ enum DVM_STATE { STATE_P25 = 2U, //! Project 25 }; -// Vars for V2 serial implementation -#ifndef DVM_V24_V1 -bool usartRx = false; -#define USART_RX_BUF_SIZE 4 -uint8_t usartRxBuffer[USART_RX_BUF_SIZE] = {0}; -#endif - #ifdef DVM_V24_V1 void VCPEnumerate(); void VCPRxITCallback(uint8_t* buf, uint32_t len); +#else +void VCPTxComplete(); #endif void VCPRxCallback(); diff --git a/fw/v24/src/serial.c b/fw/v24/src/serial.c index 0962d4d..18f38ec 100644 --- a/fw/v24/src/serial.c +++ b/fw/v24/src/serial.c @@ -12,6 +12,8 @@ #include "stdbool.h" #include "config.h" #include "util.h" +#include "leds.h" +#include "vcp.h" uint8_t serialDMABuffer[SERIAL_BUFFER_SIZE]; @@ -70,6 +72,12 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { serialTxSending = false; } + #ifndef DVM_V24_V1 + if (huart->Instance == USART1) + { + VCPTxComplete(); + } + #endif } /** diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index 609ce66..d23a09c 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -21,6 +21,7 @@ #include "usbd_cdc_if.h" #else #include "usart.h" +#include "stdlib.h" #endif // Indicates if the host has opened the port @@ -53,6 +54,11 @@ FIFO_t vcpRxFifo = { .maxlen = VCP_RX_BUF_LEN }; +// Buffer for tx message +uint8_t txBuffer[VCP_MAX_MSG_LENGTH_BYTES]; +// TX message position/length +uint16_t txPos = 0U; + // VCP RX FIFO uint8_t vcpTxBuf[VCP_TX_BUF_LEN]; FIFO_t vcpTxFifo = { @@ -62,6 +68,15 @@ FIFO_t vcpTxFifo = { .maxlen = VCP_TX_BUF_LEN }; +// Vars for V2 serial implementation +#ifndef DVM_V24_V1 +bool usartRx = false; +bool usartTx = false; +unsigned long usartTxStart = 0; +#define USART_RX_BUF_SIZE 4 +uint8_t usartRxBuffer[USART_RX_BUF_SIZE] = {0}; +#endif + #ifdef DVM_V24_V1 /** @@ -128,6 +143,26 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) HAL_UART_Receive_DMA(huart, usartRxBuffer, USART_RX_BUF_SIZE); } +/** + * @brief Called by the HAL_UART_TxCpltCallback in serial.c + */ +void VCPTxComplete() +{ + // Check for excessive delay + unsigned long txTime = HAL_GetTick() - usartTxStart; + if (txTime > VCP_TX_TIMEOUT) + { + log_error("VCP USART TX routine took %u ms!", txTime); + } + // Reset buffer & position + memset(txBuffer, 0x00U, VCP_MAX_MSG_LENGTH_BYTES); + txPos = 0; + // Reset LED + LED_USB_TX(0); + // Reset flag + usartTx = false; +} + #endif /** @@ -372,11 +407,26 @@ void VCPRxCallback() } } +/** + * @brief VCP TX callback for handling outgoing messages to the host + */ void VCPTxCallback() { - // Buffer for tx message - uint8_t txBuffer[VCP_MAX_MSG_LENGTH_BYTES]; - uint16_t txPos = 0U; + #ifdef DVM_V24_V1 + // On V1, since we use USB, we don't have a CPLT callback and clear these here + if (txPos > 0) + { + memset(txBuffer, 0x00U, VCP_MAX_MSG_LENGTH_BYTES); + txPos = 0; + } + #else + // On V2, everything is cleared by the complete callback so we just check if we're currently transmitting + if (usartTx) + { + return; + } + usartTxStart = HAL_GetTick(); + #endif // Write any bytes in the VCP TX queue while (vcpTxFifo.size > 0) @@ -441,8 +491,17 @@ void VCPTxCallback() // Turn LED on (turned off by TX cplt callback) LED_USB_TX(1); + // Set flag + usartTx = true; + // Write to USART1 - HAL_UART_Transmit_DMA(&huart1, txBuffer, txPos); + //HAL_UART_Transmit_DMA(&huart1, txBuffer, txPos); + HAL_UART_Transmit(&huart1, txBuffer, txPos, VCP_TX_TIMEOUT); + VCPTxComplete(); + + #ifdef DEBUG_VCP_TX + log_debug("Sent %u-byte message to VCP TX DMA", txPos); + #endif #endif } @@ -458,11 +517,13 @@ void VCPTxCallback() bool VCPWrite(uint8_t *data, uint16_t len) { // Return false if the port isn't open + #ifdef DVM_V24_V1 if (!USB_VCP_DTR) { log_warn("USB VCP not open, dropping message"); return false; } + #endif // Add to TX fifo for (int i = 0; i < len; i++) From 6c14e28bbb97b39cbef96e70151bc407a1aca15b Mon Sep 17 00:00:00 2001 From: Patrick W3AXL Date: Wed, 9 Oct 2024 23:10:18 -0400 Subject: [PATCH 05/17] update STM32CubeMX project to match (mostly) --- fw/DVM-V24-stm32f103.ioc | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/fw/DVM-V24-stm32f103.ioc b/fw/DVM-V24-stm32f103.ioc index ce3aa54..8d9d7bd 100644 --- a/fw/DVM-V24-stm32f103.ioc +++ b/fw/DVM-V24-stm32f103.ioc @@ -3,27 +3,17 @@ CAD.formats= CAD.pinconfig= CAD.provider= Dma.Request0=USART2_TX -Dma.Request1=USART1_TX -Dma.Request2=USART1_RX -Dma.RequestsNb=3 -Dma.USART1_RX.2.Direction=DMA_PERIPH_TO_MEMORY -Dma.USART1_RX.2.Instance=DMA1_Channel5 -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_MEDIUM -Dma.USART1_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority -Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH -Dma.USART1_TX.1.Instance=DMA1_Channel4 -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_MEDIUM -Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority +Dma.Request1=USART1_RX +Dma.RequestsNb=2 +Dma.USART1_RX.1.Direction=DMA_PERIPH_TO_MEMORY +Dma.USART1_RX.1.Instance=DMA1_Channel5 +Dma.USART1_RX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.USART1_RX.1.MemInc=DMA_MINC_ENABLE +Dma.USART1_RX.1.Mode=DMA_NORMAL +Dma.USART1_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.USART1_RX.1.PeriphInc=DMA_PINC_DISABLE +Dma.USART1_RX.1.Priority=DMA_PRIORITY_HIGH +Dma.USART1_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority Dma.USART2_TX.0.Direction=DMA_MEMORY_TO_PERIPH Dma.USART2_TX.0.Instance=DMA1_Channel7 Dma.USART2_TX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE @@ -87,7 +77,6 @@ Mcu.UserName=STM32F103C8Tx MxCube.Version=6.12.1 MxDb.Version=DB.6.0.121 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.DMA1_Channel4_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:true NVIC.DMA1_Channel5_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:true NVIC.DMA1_Channel7_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false @@ -235,7 +224,7 @@ TIM2.Period=1875 TIM2.Prescaler=1 USART1.IPParameters=VirtualMode USART1.VirtualMode=VM_ASYNC -USART2.BaudRate=256000 +USART2.BaudRate=576000 USART2.IPParameters=VirtualMode,Mode,BaudRate USART2.Mode=MODE_TX USART2.VirtualMode=VM_ASYNC From a31b3862f045d6d5a022c3e436841cb20e22ad3c Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:07:26 -0400 Subject: [PATCH 06/17] mostly working v2 firmware, now with flashing over UART --- fw/CMakeLists.txt | 4 + fw/Core/Inc/main.h | 2 +- fw/Core/Src/main.c | 293 +++++++++++++++++++++++++++++--------------- fw/v24/inc/config.h | 9 +- fw/v24/inc/vcp.h | 47 ++++++- fw/v24/src/vcp.c | 180 +++++++++++++++++++++++++-- 6 files changed, 418 insertions(+), 117 deletions(-) diff --git a/fw/CMakeLists.txt b/fw/CMakeLists.txt index c719eae..154deb8 100644 --- a/fw/CMakeLists.txt +++ b/fw/CMakeLists.txt @@ -46,6 +46,10 @@ message("Git Hash: " ${GIT_VER_HASH}) project(${CMAKE_PROJECT_NAME}) message("Build type: " ${CMAKE_BUILD_TYPE}) +# Remap __FILE__ directive to display filename only, not full path +message("Remapping ${CMAKE_SOURCE_DIR}/ to /") +add_definitions(-fmacro-prefix-map="${CMAKE_SOURCE_DIR}/=/") + # Create executables add_executable(${CMAKE_TARGET_V1}) add_executable(${CMAKE_TARGET_V2}) diff --git a/fw/Core/Inc/main.h b/fw/Core/Inc/main.h index bc753a3..8b186ed 100644 --- a/fw/Core/Inc/main.h +++ b/fw/Core/Inc/main.h @@ -53,7 +53,7 @@ extern "C" { void Error_Handler(void); /* USER CODE BEGIN EFP */ - +void ResetMCU(); /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index d61b17d..939dff3 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -102,57 +102,128 @@ void linkLED() } } +#ifndef DVM_V24_V1 + +/** + * @brief Jump to the STM32 USART1 system bootloader + * + * Taken from the dvmfirmware-hs function of the same name + */ +void jumpToBootloader() +{ + // De-init RCC + HAL_RCC_DeInit(); + + // De-init TIM2 + //HAL_TIM_Base_DeInit(&htim2); + + // De-init USART1 & 2 (also de-inits DMA) + HAL_UART_MspDeInit(&huart1); + HAL_UART_MspDeInit(&huart2); + + // Disable Systick timer + SysTick->CTRL = 0; + SysTick->LOAD = 0; + SysTick->VAL = 0; + + // Clear Interrupt Enable Register & Interrupt Pending Register + for (uint8_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) + { + NVIC->ICER[i] = 0xFFFFFFFF; + NVIC->ICPR[i] = 0xFFFFFFFF; + } + + volatile uint32_t addr = 0x1FFFF000; + + // Update the NVIC's vector + SCB->VTOR = addr; + + void (*SysMemBootJump)(void); + SysMemBootJump = (void (*)(void))(*((uint32_t *)(addr + 4))); + __ASM volatile("MSR msp, %0" : : "r"(*(uint32_t *)addr) : "sp"); // __set_MSP + SysMemBootJump(); +} + +#endif + /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ + /* USER CODE BEGIN 1 */ +#ifndef DVM_V24_V1 + // Check if we need to jump straight to the system bootloader (borrowed from dvmfirmware-hs main()) + if ((STM32_CNF_PAGE[STM32_CNF_PAGE_24] != 0xFFFFFFFFU) && (STM32_CNF_PAGE[STM32_CNF_PAGE_24] != 0x00U)) + { + // Check if the bootload mode flag is set + uint8_t bootloadMode = (STM32_CNF_PAGE[STM32_CNF_PAGE_24] >> 8) & 0xFFU; + if ((bootloadMode & 0x20U) == 0x20U) + { + // Setup the erase struct + static FLASH_EraseInitTypeDef EraseInitStruct; + // Storage for errors from the erase command + uint32_t sectorError; + // Unlock Flash + HAL_FLASH_Unlock(); + // Clear the config page + EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; + EraseInitStruct.PageAddress = STM32_CNF_PAGE_ADDR; + EraseInitStruct.NbPages = 1; + if (HAL_FLASHEx_Erase(&EraseInitStruct, §orError) != HAL_OK) + { + HAL_FLASH_Lock(); + return HAL_FLASH_GetError(); + } + // Jump + jumpToBootloader(); + } + } +#endif + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_USART2_UART_Init(); - MX_TIM2_Init(); - #ifdef DVM_V24_V1 + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_DMA_Init(); + MX_USART2_UART_Init(); + MX_TIM2_Init(); +#ifdef DVM_V24_V1 MX_USB_DEVICE_Init(); - #else +#else MX_USART1_UART_Init(); - #endif - MX_IWDG_Init(); - /* USER CODE BEGIN 2 */ +#endif + MX_IWDG_Init(); + /* USER CODE BEGIN 2 */ // Init stuff log_set_uart(&huart2); - //SerialClear(&huart2); + // SerialClear(&huart2); SerialStartup(&huart2); - // Enumerate the VCP - //log_info("Enumerating USB VCP"); - #ifdef DVM_V24_V1 +// Enumerate the VCP +// log_info("Enumerating USB VCP"); +#ifdef DVM_V24_V1 VCPEnumerate(); - #endif +#endif // Start sync serial handler log_info("Starting synchronous serial handler"); @@ -162,15 +233,15 @@ int main(void) log_info("Startup complete"); SyncReset(); - // Warn that watchdog is disbaled - #ifdef DISABLE_WATCHDOG +// Warn that watchdog is disbaled +#ifdef DISABLE_WATCHDOG log_warn("System watchdog timers disbaled!"); - #endif +#endif - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { // Processing callbacks @@ -179,67 +250,66 @@ int main(void) VCPRxCallback(); VCPTxCallback(); SerialCallback(&huart2); - // LED callbacks - #ifdef DVM_V24_V1 +// LED callbacks +#ifdef DVM_V24_V1 hbLED(); - #endif +#endif linkLED(); - // Refresh the IWDG watchdog - #ifndef DISABLE_WATCHDOG +// Refresh the IWDG watchdog +#ifndef DISABLE_WATCHDOG HAL_IWDG_Refresh(&hiwdg); - #endif - /* USER CODE END WHILE */ +#endif + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.LSIState = RCC_LSI_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) - { - Error_Handler(); - } - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; - PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - Error_Handler(); - } + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.LSIState = RCC_LSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) + { + Error_Handler(); + } + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -250,36 +320,57 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) SyncTimerCallback(); } +/** + * @brief Reset the STM32 + * + */ +void ResetMCU() +{ + log_warn("MCU is resetting!"); + HAL_Delay(250); + LED_ACT(0); + LED_LINK(0); +#ifdef DVM_V24_V1 + LED_HB(0); + LED_USB(0); +#else + LED_USB_RX(0); + LED_USB_TX(0); +#endif + HAL_Delay(250); + HAL_NVIC_SystemReset(); +} + /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/fw/v24/inc/config.h b/fw/v24/inc/config.h index 53b80eb..27148f1 100644 --- a/fw/v24/inc/config.h +++ b/fw/v24/inc/config.h @@ -27,8 +27,8 @@ extern "C" { //#define TRACE_HDLC // Virtual Com Port (VCP) logging -//#define DEBUG_VCP_RX -//#define DEBUG_VCP_TX +#define DEBUG_VCP_RX +#define DEBUG_VCP_TX //#define TRACE_VCP // Enable periodic status print @@ -44,6 +44,11 @@ extern "C" { #define NVIC_PRI_USART2_DMA 5U #define NVIC_PRI_USART2_INT 6U +// Flash Areas (shamelessly stolen from dvmfirmware-hs) +#define STM32_CNF_PAGE_ADDR (uint32_t)0x0800FC00 +#define STM32_CNF_PAGE ((uint32_t *)0x0800FC00) +#define STM32_CNF_PAGE_24 24U + // Time in ms above which critical routines will throw a warning #define FUNC_TIMER_WARN 10U diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index 07c4e64..08a2e2c 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -22,10 +22,10 @@ extern "C" { #define VCP_RX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 4) #define VCP_TX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 2) -#define VCP_RX_TIMEOUT 10 -#define VCP_TX_TIMEOUT 10 +#define VCP_RX_TIMEOUT 50 +#define VCP_TX_TIMEOUT 50 -#define USB_ENUM(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) +#define USB_ENUM(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) #define USB_TX_RETRIES 3 @@ -33,13 +33,18 @@ extern "C" { enum DVM_COMMANDS { CMD_GET_VERSION = 0x00, CMD_GET_STATUS = 0x01, + CMD_SET_CONFIG = 0x02, CMD_SET_MODE = 0x03, + CMD_SET_RFPARAMS = 0x06, CMD_CAL_DATA = 0x08, CMD_P25_DATA = 0x31, CMD_P25_LOST = 0x32, CMD_P25_CLEAR = 0x33, CMD_ACK = 0x70, CMD_NAK = 0x7F, + CMD_FLASH_READ = 0xE0, + CMD_FLASH_WRITE = 0xE1, + CMD_RESET_MCU = 0xEA, CMD_DEBUG1 = 0xF1, CMD_DEBUG2 = 0xF2, CMD_DEBUG3 = 0xF3, @@ -50,6 +55,37 @@ enum DVM_COMMANDS { DVM_SHORT_FRAME_START = 0xFE, }; +// DVM response reason codes +enum DVM_REASONS { + RSN_OK = 0U, //! OK + RSN_NAK = 1U, //! Negative Acknowledge + + RSN_ILLEGAL_LENGTH = 2U, //! Illegal Length + RSN_INVALID_REQUEST = 4U, //! Invalid Request + RSN_RINGBUFF_FULL = 8U, //! Ring Buffer Full + + RSN_INVALID_FDMA_PREAMBLE = 10U, //! Invalid FDMA Preamble Length + RSN_INVALID_MODE = 11U, //! Invalid Mode + + RSN_INVALID_DMR_CC = 12U, //! Invalid DMR CC + RSN_INVALID_DMR_SLOT = 13U, //! Invalid DMR Slot + RSN_INVALID_DMR_START = 14U, //! Invaild DMR Start Transmit + RSN_INVALID_DMR_RX_DELAY = 15U, //! Invalid DMR Rx Delay + + RSN_INVALID_P25_CORR_COUNT = 16U, //! Invalid P25 Correlation Count + + RSN_NO_INTERNAL_FLASH = 20U, //! No Internal Flash + RSN_FAILED_ERASE_FLASH = 21U, //! Failed to erase flash partition + RSN_FAILED_WRITE_FLASH = 22U, //! Failed to write flash partition + RSN_FLASH_WRITE_TOO_BIG = 23U, //! Data to large for flash partition + + RSN_HS_NO_DUAL_MODE = 32U, //! (Hotspot) No Dual Mode Operation + + RSN_DMR_DISABLED = 63U, //! DMR Disabled + RSN_P25_DISABLED = 64U, //! Project 25 Disabled + RSN_NXDN_DISABLED = 65U //! NXDN Disabled +}; + // DVM status states enum DVM_STATE { STATE_IDLE = 0U, //! Idle @@ -68,10 +104,15 @@ void VCPTxCallback(); bool VCPWrite(uint8_t *data, uint16_t len); bool VCPWriteAck(uint8_t cmd); +bool VCPWriteNak(uint8_t cmd, uint8_t err); bool VCPWriteP25Frame(const uint8_t *data, uint16_t len); void sendVersion(); void sendStatus(); +#ifndef DVM_V24_V1 +void flashRead(); +uint8_t flashWrite(const uint8_t* data, uint8_t length); +#endif bool VCPWriteDebug1(const char *text); bool VCPWriteDebug2(const char *text, int16_t n1); diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index d23a09c..c0e5c74 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -16,6 +16,7 @@ #include "config.h" #include "string.h" #include "hdlc.h" +#include "main.h" #ifdef DVM_V24_V1 #include "usbd_cdc_if.h" @@ -73,7 +74,7 @@ FIFO_t vcpTxFifo = { bool usartRx = false; bool usartTx = false; unsigned long usartTxStart = 0; -#define USART_RX_BUF_SIZE 4 +#define USART_RX_BUF_SIZE 1 uint8_t usartRxBuffer[USART_RX_BUF_SIZE] = {0}; #endif @@ -201,7 +202,7 @@ void VCPRxCallback() if (vcpRxFifo.size > 0) { - #ifdef DEBUG_VCP_RX + #ifdef TRACE_VCP_RX log_debug("VCP RX FIFO size: %d/%d", vcpRxFifo.size, vcpRxFifo.maxlen); #endif } @@ -330,6 +331,7 @@ void VCPRxCallback() { // Send P25 data as a UI frame case CMD_P25_DATA: + { // Process the UI frame #ifdef DEBUG_VCP_RX log_debug("Sending UI frame of length %d via HDLC", vcpRxMsgLength - offset - 2U); @@ -341,6 +343,7 @@ void VCPRxCallback() #endif // Send the UI, ignoring the first 0x00 byte HDLCSendUI(vcpRxMsg + offset + 2, vcpRxMsgLength - offset - 2); + } break; // Reply to version request case CMD_GET_VERSION: @@ -350,12 +353,26 @@ void VCPRxCallback() case CMD_GET_STATUS: sendStatus(); break; + // Ignore config set command + case CMD_SET_CONFIG: + #ifdef DEBUG_VCP_RX + log_debug("Ignoring CMD_SET_CONFIG, no config to set"); + #endif + VCPWriteAck(CMD_SET_CONFIG); + break; // Ignore mode set command case CMD_SET_MODE: #ifdef DEBUG_VCP_RX log_debug("Ignoring CMD_SET_MODE, always in P25 mode"); #endif break; + // Ignore RF params config + case CMD_SET_RFPARAMS: + #ifdef DEBUG_VCP_RX + log_debug("Ignoring CMD_SET_RFPARAMS, no RF params to set"); + #endif + VCPWriteAck(CMD_SET_RFPARAMS); + break; case CMD_P25_CLEAR: #ifdef DEBUG_VCP_RX log_debug("Ignoring CMD_P25_CLEAR, not implemented yet"); @@ -370,9 +387,43 @@ void VCPRxCallback() #endif VCPWriteAck(CMD_CAL_DATA); break; + + // Flash read/write is only supported on DVM-V24-V2 + #ifndef DVM_V24_V1 + // Flash Read + case CMD_FLASH_READ: + #ifdef DEBUG_VCP_RX + log_debug("Reading flash to serial port"); + #endif + flashRead(); + break; + // Flash Write + case CMD_FLASH_WRITE: + { + #ifdef DEBUG_VCP_RX + log_debug("Writing data to flash from serial port"); + #endif + uint8_t err = flashWrite(vcpRxMsg + 3U, vcpRxMsgLength - 3U); + if (err == RSN_OK) + { + VCPWriteAck(CMD_FLASH_WRITE); + } + else + { + log_error("Invalid flash data write: %u", err); + VCPWriteNak(CMD_FLASH_WRITE, err); + } + } + break; + #endif + + case CMD_RESET_MCU: + ResetMCU(); + break; // Default handler default: log_warn("VCP RX: Unhandled DVM command %02X", vcpRxMsg[offset]); + VCPWriteNak(vcpRxMsg[offset], RSN_NAK); break; } @@ -400,6 +451,13 @@ void VCPRxCallback() #endif } + // Timeout and reset if we haven't received a full message + if ((vcpRxMsgPosition > 0) && (HAL_GetTick() - vcpRxLastByte > VCP_RX_TIMEOUT)) + { + log_error("Timed out waiting for full VCP message, resetting"); + vcpRxReset(); + } + // Check elapsed time if (HAL_GetTick() - start > FUNC_TIMER_WARN) { @@ -497,12 +555,13 @@ void VCPTxCallback() // Write to USART1 //HAL_UART_Transmit_DMA(&huart1, txBuffer, txPos); HAL_UART_Transmit(&huart1, txBuffer, txPos, VCP_TX_TIMEOUT); - VCPTxComplete(); #ifdef DEBUG_VCP_TX log_debug("Sent %u-byte message to VCP TX DMA", txPos); #endif + VCPTxComplete(); + #endif } @@ -556,6 +615,27 @@ bool VCPWriteAck(uint8_t cmd) return VCPWrite(buffer, 4U); } +/** + * @brief Send a NACK back + * + * @param cmd + * @param err + * @return true + * @return false + */ +bool VCPWriteNak(uint8_t cmd, uint8_t err) +{ + uint8_t buffer[5U]; + + buffer[0U] = DVM_SHORT_FRAME_START; + buffer[1U] = 5U; + buffer[2U] = CMD_NAK; + buffer[3U] = cmd; + buffer[4U] = err; + + return VCPWrite(buffer, 5U); +} + /** * @brief Write a P25 frame to the USB port, using the DVMHost modem format * @@ -637,16 +717,14 @@ void sendStatus() // Mode (always P25 mode) reply[3U] = 0x08U; - // Report P25 mode only if HDLC peer is connected + // Report if V24 peer is connected or not if (HDLCPeerConnected) { - reply[4U] = STATE_P25; + reply[3U] |= 0x40U; } - else - { - reply[4U] = STATE_IDLE; - } - + + // Report P25 mode always + reply[4U] = STATE_P25; // Calculate free space in the VCP RX FIFO #ifdef STATUS_SPACE_BLOCKS @@ -680,6 +758,88 @@ void sendStatus() #endif*/ } +#ifndef DVM_V24_V1 + +/** + * @brief Read out the STM32 config flash page and send to the serial port + * + * @return uint8_t + */ +void flashRead() +{ + uint8_t reply[249U]; + reply[0U] = DVM_SHORT_FRAME_START; + reply[1U] = 249U; + reply[2U] = CMD_FLASH_READ; + + memcpy(reply + 3U, (void*)STM32_CNF_PAGE, 246U); + + VCPWrite(reply, 249U); +} + +/** + * @brief Write to STM32 config flash page + * + * @param data data to write + * @param length length of data to write + * @return uint8_t return reason + */ +uint8_t flashWrite(const uint8_t* data, uint8_t length) +{ + if (length > 249U) + { + log_error("Flash write too big! %u > %u", length, 249U); + return RSN_FLASH_WRITE_TOO_BIG; + } + + // Unlock flash + HAL_FLASH_Unlock(); + + // Erase + static FLASH_EraseInitTypeDef EraseInitStruct; + uint32_t sectorError; + EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; + EraseInitStruct.PageAddress = STM32_CNF_PAGE_ADDR; + EraseInitStruct.NbPages = 1; + HAL_StatusTypeDef status; + status = HAL_FLASHEx_Erase(&EraseInitStruct, §orError); + if (status != HAL_OK) + { + HAL_FLASH_Lock(); + log_error("HAL_FLASHEx_Erase failed with code %u", status); + return RSN_FAILED_ERASE_FLASH; + } + + // Compile bytes into words + uint32_t address = STM32_CNF_PAGE_ADDR; + uint8_t i = 0; + while (i < length) + { + uint32_t word = + (uint32_t)(data[i + 3] << 24) + + (uint32_t)(data[i + 2] << 16) + + (uint32_t)(data[i + 1] << 8) + + (uint32_t)(data); + + status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, word); + if (status != HAL_OK) + { + HAL_FLASH_Lock(); + log_error("HAL_FLASH_Program failed to write address %08X with code %u", address, status); + return RSN_FAILED_WRITE_FLASH; + } + else + { + address += 4; + i += 4; + } + } + HAL_FLASH_Lock(); + return RSN_OK; +} + +#endif + /** * @brief Write a debug message to the USB port, using the DVMHost modem format * From 26a73724608dc05dafefabc8c5ca92f842b9d681 Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:55:26 -0400 Subject: [PATCH 07/17] disabled extra debug prints and updated NAK reason for unhandled commands --- fw/v24/inc/config.h | 4 ++-- fw/v24/src/vcp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fw/v24/inc/config.h b/fw/v24/inc/config.h index 27148f1..37b9263 100644 --- a/fw/v24/inc/config.h +++ b/fw/v24/inc/config.h @@ -27,8 +27,8 @@ extern "C" { //#define TRACE_HDLC // Virtual Com Port (VCP) logging -#define DEBUG_VCP_RX -#define DEBUG_VCP_TX +//#define DEBUG_VCP_RX +//#define DEBUG_VCP_TX //#define TRACE_VCP // Enable periodic status print diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index c0e5c74..9f6053c 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -416,14 +416,14 @@ void VCPRxCallback() } break; #endif - + // Reset MCU case CMD_RESET_MCU: ResetMCU(); break; // Default handler default: log_warn("VCP RX: Unhandled DVM command %02X", vcpRxMsg[offset]); - VCPWriteNak(vcpRxMsg[offset], RSN_NAK); + VCPWriteNak(vcpRxMsg[offset], RSN_INVALID_REQUEST); break; } From 16d3bc305acbbbb8bddc510f5de71789666d33d0 Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:45:59 -0400 Subject: [PATCH 08/17] removed rx msg timeout check, not needed anymore --- fw/v24/src/vcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index 9f6053c..fe120dd 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -452,11 +452,11 @@ void VCPRxCallback() } // Timeout and reset if we haven't received a full message - if ((vcpRxMsgPosition > 0) && (HAL_GetTick() - vcpRxLastByte > VCP_RX_TIMEOUT)) + /*if ((vcpRxMsgPosition > 0) && (HAL_GetTick() - vcpRxLastByte > VCP_RX_TIMEOUT)) { log_error("Timed out waiting for full VCP message, resetting"); vcpRxReset(); - } + }*/ // Check elapsed time if (HAL_GetTick() - start > FUNC_TIMER_WARN) From a7f749318c1b124418211accd37e7c027b8045bf Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Sun, 20 Oct 2024 15:40:44 -0400 Subject: [PATCH 09/17] brought back the RX timeout and made it work, the USART is still being weird but this temp fix should work for now --- fw/v24/inc/vcp.h | 4 ++-- fw/v24/src/vcp.c | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index 08a2e2c..f9f87ef 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -22,8 +22,8 @@ extern "C" { #define VCP_RX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 4) #define VCP_TX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 2) -#define VCP_RX_TIMEOUT 50 -#define VCP_TX_TIMEOUT 50 +#define VCP_RX_TIMEOUT 100 +#define VCP_TX_TIMEOUT 100 #define USB_ENUM(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index fe120dd..26005de 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -166,6 +166,23 @@ void VCPTxComplete() #endif +/** + * @brief Clear the RX buffers related to the VCP RX routines + * + */ +void vcpRxClearBuffer() +{ + // Clear FIFO + FifoClear(&vcpRxFifo); + #ifndef DVM_V24_V1 + // Clear USART + for (int i = 0; i < USART_RX_BUF_SIZE; i++) + { + usartRxBuffer[i] = 0x00U; + } + #endif +} + /** * @brief reset counters and flags related to VCP RX routine */ @@ -452,11 +469,12 @@ void VCPRxCallback() } // Timeout and reset if we haven't received a full message - /*if ((vcpRxMsgPosition > 0) && (HAL_GetTick() - vcpRxLastByte > VCP_RX_TIMEOUT)) + if ((vcpRxMsgPosition > 0) && (HAL_GetTick() - vcpRxLastByte > VCP_RX_TIMEOUT)) { log_error("Timed out waiting for full VCP message, resetting"); vcpRxReset(); - }*/ + vcpRxClearBuffer(); + } // Check elapsed time if (HAL_GetTick() - start > FUNC_TIMER_WARN) From cfbb886599bb657ddd044d760724d3120c07608f Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Sun, 20 Oct 2024 17:21:35 -0400 Subject: [PATCH 10/17] increased RX timeout slightly, added additional log prints on startup --- fw/Core/Src/main.c | 5 +++-- fw/v24/inc/vcp.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index 939dff3..4cf6c2e 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -231,6 +231,7 @@ int main(void) // Done! log_info("Startup complete"); + VCPWriteDebug1("Startup complete"); SyncReset(); // Warn that watchdog is disbaled @@ -326,8 +327,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) */ void ResetMCU() { - log_warn("MCU is resetting!"); - HAL_Delay(250); + //log_warn("MCU is resetting!"); + //HAL_Delay(250); LED_ACT(0); LED_LINK(0); #ifdef DVM_V24_V1 diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index f9f87ef..1f28904 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -22,8 +22,8 @@ extern "C" { #define VCP_RX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 4) #define VCP_TX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 2) -#define VCP_RX_TIMEOUT 100 -#define VCP_TX_TIMEOUT 100 +#define VCP_RX_TIMEOUT 150 +#define VCP_TX_TIMEOUT 150 #define USB_ENUM(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) From 98327562c2dfe42a26eb747f469acf796425750c Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:14:51 -0400 Subject: [PATCH 11/17] updated readme for v2 info --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf5b490..bf9a57f 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ DVM-V24 boards are available from the [W3AXL Online Store](https://store.w3axl.c Schematics for the board are also included in the `hw` directory to build your own adapters. +### Hardware Revisions + +There are two hardware revisions, the original "V1" boards, and the newer "V2" boards. The V2 boards offload the USB->serial functionality to a dedicated CP2102 chip which alleviates some lockup/freezing issues that were encountered with the original V1 hardware. + +The two hardware revisions require different firmware binaries, but both can be built from the same repository and commands. + ### The `CLKSEL` Jumper This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. In the future, the board will support external clocking, but for now the firmware only supports generating clocks for both TX & RX. @@ -19,7 +25,58 @@ Firmware is availble in this repo, under the `fw` directory. It's written in bar ### Building the latest firmware We recommend building the firmware for the DVM-V24 on a linux-based machine, since it's much easier to set up a working ARM toolchain. -Once you have the ARM toolchain installed, simply running `make` will create binary & elf files in a `./build/` directory. These can then be flashed using the STLink using the `make flash` command. +On debian machines, you will need to install the following packages to build the fw: + +```bash +sudo apt install gcc-arm-none-eabi cmake +``` + +Once you have the everything installed, perform the following steps to prepare the build environment: + +```bash +mkdir build +cd build +cmake .. +``` + +Finally, you can build firmware individually for the v1 or v2 boards, or build both binaries: + +```bash +make dvm-v24-v1 +make dvm-v24-v2 +make # make with no options will build both v1 and v2 binaries +``` + +### Flashing the firmware + +#### Using STLink programmer + +You may use the SWD headers on the board to load firmware via an STLink programmer. This is required for the V1 boards, and on the V2 boards if the firmware becomes corrupted and USB loading no longer works. + +First make sure the stlink-tools are installed on your system: + +```bash +sudo apt install stlink-tools +``` + +Then you can flash the board by using the following command +```bash +st-flash --reset write dvm-v24-xxx.bin 0x8000000 +``` + +#### Using USB flashing + +DVMV24-V2 boards can be loaded using the ST serial bootloader, in the same way that DVM modems can. First, you must put the board into bootloader mode using `dvmhost` in calibration mode: + +```bash +./dvmhost -c --cal +``` + +Then, enter bootloader mode using the `!` command. DVMHost will exit, and at this point you can use the stm32flash command: + +```bash +stm32flash -v -w ./dvm-v24-v2.bin -R /dev/ttyUSBx +``` ## Quick Start From 8adf1c954df2e163f1538872fc9f29b57e2496eb Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:25:31 -0500 Subject: [PATCH 12/17] some improvements to v2 serial handling --- fw/Core/Src/dma.c | 5 ++- fw/v24/inc/config.h | 5 ++- fw/v24/inc/vcp.h | 5 ++- fw/v24/src/serial.c | 19 +++++---- fw/v24/src/vcp.c | 98 ++++++++++++++++++++++++--------------------- 5 files changed, 72 insertions(+), 60 deletions(-) diff --git a/fw/Core/Src/dma.c b/fw/Core/Src/dma.c index 6a83623..a70e62e 100644 --- a/fw/Core/Src/dma.c +++ b/fw/Core/Src/dma.c @@ -44,8 +44,9 @@ void MX_DMA_Init(void) /* DMA interrupt init */ /* DMA1_Channel5_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_PRI_USART1_RX, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); + // Disabling this for now since we're using IT mode instead of DMA mode for USARt 1 */ + //HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_PRI_USART1_RX, 0); + //HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); /* DMA1_Channel7_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_USART2_DMA, 0); HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); diff --git a/fw/v24/inc/config.h b/fw/v24/inc/config.h index 37b9263..0720c2f 100644 --- a/fw/v24/inc/config.h +++ b/fw/v24/inc/config.h @@ -54,11 +54,12 @@ extern "C" { #define FW_MAJ "2" #define FW_MIN "2" +#define FW_REV "0" #ifdef DVM_V24_V1 -#define VERSION_STRING "DVM-V24-V1 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" +#define VERSION_STRING "DVM-V24-V1 FW V" FW_MAJ "." FW_MIN "." FW_REV " (" GIT_HASH ")" #else -#define VERSION_STRING "DVM-V24-V2 FW V" FW_MAJ "." FW_MIN " (" GIT_HASH ")" +#define VERSION_STRING "DVM-V24-V2 FW V" FW_MAJ "." FW_MIN "." FW_REV " (" GIT_HASH ")" #endif #define BUILD_DATE_STRING __DATE__ " " __TIME__ #define HARDWARE_STRING VERSION_STRING ", " BUILD_DATE_STRING diff --git a/fw/v24/inc/vcp.h b/fw/v24/inc/vcp.h index 1f28904..e00da86 100644 --- a/fw/v24/inc/vcp.h +++ b/fw/v24/inc/vcp.h @@ -22,8 +22,9 @@ extern "C" { #define VCP_RX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 4) #define VCP_TX_BUF_LEN (P25_V24_LDU_FRAME_LENGTH_BYTES * 2) -#define VCP_RX_TIMEOUT 150 -#define VCP_TX_TIMEOUT 150 +// a 255-byte RS232 mesasge should take around 25ms ideally, but it seems to sometimes take much longer for a full message to make its way through +#define VCP_RX_TIMEOUT 100 +#define VCP_TX_TIMEOUT 100 #define USB_ENUM(state) HAL_GPIO_WritePin(USB_ENUM_GPIO_Port, USB_ENUM_Pin, state) diff --git a/fw/v24/src/serial.c b/fw/v24/src/serial.c index 18f38ec..a356c42 100644 --- a/fw/v24/src/serial.c +++ b/fw/v24/src/serial.c @@ -63,17 +63,20 @@ void SerialCallback(UART_HandleTypeDef *huart) */ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { - uint16_t bytes = SerialFillDMA(); - if (bytes > 0) + if (huart->Instance == USART2) { - HAL_UART_Transmit_DMA(huart, serialDMABuffer, bytes); - } - else - { - serialTxSending = false; + uint16_t bytes = SerialFillDMA(); + if (bytes > 0) + { + HAL_UART_Transmit_DMA(huart, serialDMABuffer, bytes); + } + else + { + serialTxSending = false; + } } #ifndef DVM_V24_V1 - if (huart->Instance == USART1) + else if (huart->Instance == USART1) { VCPTxComplete(); } diff --git a/fw/v24/src/vcp.c b/fw/v24/src/vcp.c index 26005de..e765c8e 100644 --- a/fw/v24/src/vcp.c +++ b/fw/v24/src/vcp.c @@ -74,10 +74,33 @@ FIFO_t vcpTxFifo = { bool usartRx = false; bool usartTx = false; unsigned long usartTxStart = 0; -#define USART_RX_BUF_SIZE 1 -uint8_t usartRxBuffer[USART_RX_BUF_SIZE] = {0}; +uint8_t usartRxBuffer = 0; #endif +/** + * @brief Clear the RX buffers related to the VCP RX routines + * + */ +void vcpRxClearBuffer() +{ + // Clear FIFO + FifoClear(&vcpRxFifo); + #ifndef DVM_V24_V1 + usartRxBuffer = 0x00U; + #endif +} + +/** + * @brief reset counters and flags related to VCP RX routine +*/ +void vcpRxReset() +{ + vcpRxMsgInProgress = false; + vcpRxDoubleLength = false; + vcpRxMsgLength = 0U; + vcpRxMsgPosition = 0U; +} + #ifdef DVM_V24_V1 /** @@ -92,7 +115,7 @@ void VCPRxITCallback(uint8_t* buf, uint32_t len) { log_error("VCP RX FIFO full! Clearing buffer"); // Clear - FifoClear(&vcpRxFifo); + vcpRxClearBuffer(); } } if (HAL_GetTick() - start > FUNC_TIMER_WARN) @@ -124,24 +147,32 @@ void VCPEnumerate() void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { uint32_t start = HAL_GetTick(); - // Add received bytes to the fifo - for (int i = 0; i < USART_RX_BUF_SIZE; i++) + // Add received byte to the fifo + if (FifoPush(&vcpRxFifo, usartRxBuffer)) { - if (FifoPush(&vcpRxFifo, usartRxBuffer[i])) - { - log_error("VCP RX FIFO full! Clearing buffer"); - FifoClear(&vcpRxFifo); - } + log_error("VCP RX FIFO full! Clearing buffer"); + FifoClear(&vcpRxFifo); } + // Check how long this took if (HAL_GetTick() - start > FUNC_TIMER_WARN) { log_warn("HAL_UART_RxCpltCallback took %u ms!", HAL_GetTick() - start); } - #ifdef TRACE_VCP_RX - log_debug("Added %u bytes to VCP RX FIFO", USART_RX_BUF_SIZE); - #endif // Call the interrupt again - HAL_UART_Receive_DMA(huart, usartRxBuffer, USART_RX_BUF_SIZE); + HAL_UART_Receive_IT(huart, &usartRxBuffer, 1); +} + +/** + * @brief Handle errors during UART operation + * + * @param huart + */ +void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) +{ + log_error("Got UART error: %02X", huart->ErrorCode); + VCPWriteDebug2("Got HAL UART error code ", huart->ErrorCode); + vcpRxReset(); + vcpRxClearBuffer(); } /** @@ -154,6 +185,7 @@ void VCPTxComplete() if (txTime > VCP_TX_TIMEOUT) { log_error("VCP USART TX routine took %u ms!", txTime); + VCPWriteDebug1("VCP USART TX routine took > " STR(VCP_TX_TIMEOUT) "ms"); } // Reset buffer & position memset(txBuffer, 0x00U, VCP_MAX_MSG_LENGTH_BYTES); @@ -166,34 +198,6 @@ void VCPTxComplete() #endif -/** - * @brief Clear the RX buffers related to the VCP RX routines - * - */ -void vcpRxClearBuffer() -{ - // Clear FIFO - FifoClear(&vcpRxFifo); - #ifndef DVM_V24_V1 - // Clear USART - for (int i = 0; i < USART_RX_BUF_SIZE; i++) - { - usartRxBuffer[i] = 0x00U; - } - #endif -} - -/** - * @brief reset counters and flags related to VCP RX routine -*/ -void vcpRxReset() -{ - vcpRxMsgInProgress = false; - vcpRxDoubleLength = false; - vcpRxMsgLength = 0U; - vcpRxMsgPosition = 0U; -} - /** * @brief Called during main loop to handle any data received from USB */ @@ -208,9 +212,9 @@ void VCPRxCallback() #ifndef DVM_V24_V1 if (!usartRx) { - HAL_UART_Receive_DMA(&huart1, usartRxBuffer, USART_RX_BUF_SIZE); + HAL_UART_Receive_IT(&huart1, &usartRxBuffer, 1); usartRx = true; - log_info("Started USART1 RX DMA transfer"); + log_info("Started USART1 RX IT transfer"); } #endif @@ -472,6 +476,7 @@ void VCPRxCallback() if ((vcpRxMsgPosition > 0) && (HAL_GetTick() - vcpRxLastByte > VCP_RX_TIMEOUT)) { log_error("Timed out waiting for full VCP message, resetting"); + VCPWriteDebug1("Timed out waiting for full VCP message, resetting"); vcpRxReset(); vcpRxClearBuffer(); } @@ -572,13 +577,14 @@ void VCPTxCallback() // Write to USART1 //HAL_UART_Transmit_DMA(&huart1, txBuffer, txPos); - HAL_UART_Transmit(&huart1, txBuffer, txPos, VCP_TX_TIMEOUT); + //HAL_UART_Transmit(&huart1, txBuffer, txPos, VCP_TX_TIMEOUT); + HAL_UART_Transmit_IT(&huart1, txBuffer, txPos); #ifdef DEBUG_VCP_TX log_debug("Sent %u-byte message to VCP TX DMA", txPos); #endif - VCPTxComplete(); + //VCPTxComplete(); #endif } From 2603083d102387d8d83e95d6a279502bec94b4f8 Mon Sep 17 00:00:00 2001 From: Patrick W3AXL Date: Mon, 2 Dec 2024 19:15:56 -0500 Subject: [PATCH 13/17] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf9a57f..5022cd6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,11 @@ The two hardware revisions require different firmware binaries, but both can be ### The `CLKSEL` Jumper -This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. In the future, the board will support external clocking, but for now the firmware only supports generating clocks for both TX & RX. +This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. Version 1 boards require a jumper to be in place, while version 2 boards have the solder jumper shorted by default. In the future, the boards may support external clocking, but for now the firmware only supports generating clocks for both TX & RX. + +### `UBT0` and `URST` Jumpers + +These jumpers are specific to the version 2 boards and enable the RTS and DTR signals of the serial chip to force the board into UART bootloader mode. This will allow for programming using `stm32flash` even without access to the software boot command in `dvmhost`. By default these jumpers are **not** connected and must be bridged with solder to enable RTS/DTR boot control. ## Firmware Firmware is availble in this repo, under the `fw` directory. It's written in bare C, generated from STM32CubeMX. You will need an STLink programmer in order to flash the boards with the latest version of software. @@ -78,6 +82,12 @@ Then, enter bootloader mode using the `!` command. DVMHost will exit, and at thi stm32flash -v -w ./dvm-v24-v2.bin -R /dev/ttyUSBx ``` +If you have the `UBT0` and `URST` jumpers shorted, you can also flash the board using DTR & RTS in a single command as follows: + +```bash +stm32flash -v -w ./dvm-v24-v2.bin -i 'rts&-dtr:-rts&dtr' -R /dev/ttyUSBx +``` + ## Quick Start ### Quantar V24 Connection From cb4dfe75015d2a300c16abf753d3326b9cc0fd70 Mon Sep 17 00:00:00 2001 From: Patrick W3AXL Date: Mon, 2 Dec 2024 19:17:22 -0500 Subject: [PATCH 14/17] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5022cd6..65caeb3 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,12 @@ cmake .. Finally, you can build firmware individually for the v1 or v2 boards, or build both binaries: ```bash +# To build for V1 only: make dvm-v24-v1 +# or to build for V2: make dvm-v24-v2 -make # make with no options will build both v1 and v2 binaries +# make with no options will build both v1 and v2 binaries +make ``` ### Flashing the firmware From 1060458eb3d46de0fb9218bfd0747fde7fe9e3c9 Mon Sep 17 00:00:00 2001 From: W3AXL Date: Mon, 2 Dec 2024 19:29:26 -0500 Subject: [PATCH 15/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 65caeb3..f7908ae 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ stm32flash -v -w ./dvm-v24-v2.bin -R /dev/ttyUSBx If you have the `UBT0` and `URST` jumpers shorted, you can also flash the board using DTR & RTS in a single command as follows: ```bash -stm32flash -v -w ./dvm-v24-v2.bin -i 'rts&-dtr:-rts&dtr' -R /dev/ttyUSBx +stm32flash -v -w ./dvm-v24-v2.bin -i 'rts&-dtr:-rts&dtr' /dev/ttyUSBx ``` ## Quick Start From 58ab32668154f731c818e745633b767189615f34 Mon Sep 17 00:00:00 2001 From: W3AXL Date: Mon, 2 Dec 2024 20:05:20 -0500 Subject: [PATCH 16/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7908ae..c731847 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This jumper connects the serial clock line to the `RXCLK` pin. Currently this ju ### `UBT0` and `URST` Jumpers -These jumpers are specific to the version 2 boards and enable the RTS and DTR signals of the serial chip to force the board into UART bootloader mode. This will allow for programming using `stm32flash` even without access to the software boot command in `dvmhost`. By default these jumpers are **not** connected and must be bridged with solder to enable RTS/DTR boot control. +These jumpers are specific to the version 2 boards and enable the RTS and DTR signals of the serial chip to force the board into UART bootloader mode. This will allow for programming using `stm32flash` even without access to the software boot command in `dvmhost`. By default these jumpers are **not** connected and must be bridged with solder to enable RTS/DTR boot control. Note that with these jumpers shorted, the V24 board will reset when `dvmhost` connects. ## Firmware Firmware is availble in this repo, under the `fw` directory. It's written in bare C, generated from STM32CubeMX. You will need an STLink programmer in order to flash the boards with the latest version of software. From fe2184966f14bae6f600fa96599e1c66875d5f8b Mon Sep 17 00:00:00 2001 From: W3AXL Date: Mon, 2 Dec 2024 20:53:35 -0500 Subject: [PATCH 17/17] Update firmware-build.yml --- .github/workflows/firmware-build.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/firmware-build.yml b/.github/workflows/firmware-build.yml index 0d6f866..e494c27 100644 --- a/.github/workflows/firmware-build.yml +++ b/.github/workflows/firmware-build.yml @@ -16,9 +16,10 @@ jobs: uses: actions/checkout@v4 - name: Install ARM GCC uses: carlosperate/arm-none-eabi-gcc-action@v1 - - name: Run make - run: make - working-directory: ./fw + - name: Run cmake + uses: threeal/cmake-action@v2.0.0 + with: + source-dir: ./fw - name: Upload artifacts uses: actions/upload-artifact@v4 with: