From 0809e47e0b2cfeecb1cbe4cbd951a150a3f1bbd8 Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Fri, 24 May 2024 04:29:12 -0400 Subject: [PATCH] add adcs and can id conversion --- .mxproject | 7 +- Core/Inc/FreeRTOSConfig.h | 3 +- Core/Inc/can_handler.h | 6 +- Core/Inc/controller.h | 10 ++ Core/Inc/main.h | 3 +- Core/Inc/monitor.h | 12 +- Core/Inc/msb.h | 21 +-- Core/Inc/msb_conf.h | 12 +- Core/Inc/serial_monitor.h | 4 +- Core/Inc/stm32f4xx_hal_conf.h | 2 +- Core/Inc/stm32f4xx_it.h | 2 +- Core/Src/can_handler.c | 21 +-- Core/Src/controller.c | 42 ++++++ Core/Src/main.c | 201 ++++++++++++++++---------- Core/Src/monitor.c | 147 ++++++++++++++++--- Core/Src/msb.c | 26 +++- Core/Src/serial_monitor.c | 26 ++-- Core/Src/stm32f4xx_hal_msp.c | 4 +- Core/Src/stm32f4xx_hal_timebase_tim.c | 137 ++++++++++++++++++ Core/Src/stm32f4xx_it.c | 40 ++--- MSB-FW.ioc | 13 +- Makefile | 6 +- 22 files changed, 566 insertions(+), 179 deletions(-) create mode 100644 Core/Inc/controller.h create mode 100644 Core/Src/controller.c create mode 100644 Core/Src/stm32f4xx_hal_timebase_tim.c diff --git a/.mxproject b/.mxproject index 22e1152..7578a09 100644 --- a/.mxproject +++ b/.mxproject @@ -2,7 +2,7 @@ LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_can.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_iwdg.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_iwdg.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_spi.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Middlewares/Third_Party/FreeRTOS/Source/include/croutine.h;Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h;Middlewares/Third_Party/FreeRTOS/Source/include/event_groups.h;Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h;Middlewares/Third_Party/FreeRTOS/Source/include/list.h;Middlewares/Third_Party/FreeRTOS/Source/include/message_buffer.h;Middlewares/Third_Party/FreeRTOS/Source/include/mpu_prototypes.h;Middlewares/Third_Party/FreeRTOS/Source/include/mpu_wrappers.h;Middlewares/Third_Party/FreeRTOS/Source/include/portable.h;Middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h;Middlewares/Third_Party/FreeRTOS/Source/include/queue.h;Middlewares/Third_Party/FreeRTOS/Source/include/semphr.h;Middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h;Middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h;Middlewares/Third_Party/FreeRTOS/Source/include/stream_buffer.h;Middlewares/Third_Party/FreeRTOS/Source/include/task.h;Middlewares/Third_Party/FreeRTOS/Source/include/timers.h;Middlewares/Third_Party/FreeRTOS/Source/include/atomic.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_mpool.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_os2.h;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_can.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_iwdg.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_iwdg.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_spi.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Middlewares/Third_Party/FreeRTOS/Source/include/croutine.h;Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h;Middlewares/Third_Party/FreeRTOS/Source/include/event_groups.h;Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h;Middlewares/Third_Party/FreeRTOS/Source/include/list.h;Middlewares/Third_Party/FreeRTOS/Source/include/message_buffer.h;Middlewares/Third_Party/FreeRTOS/Source/include/mpu_prototypes.h;Middlewares/Third_Party/FreeRTOS/Source/include/mpu_wrappers.h;Middlewares/Third_Party/FreeRTOS/Source/include/portable.h;Middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h;Middlewares/Third_Party/FreeRTOS/Source/include/queue.h;Middlewares/Third_Party/FreeRTOS/Source/include/semphr.h;Middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h;Middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h;Middlewares/Third_Party/FreeRTOS/Source/include/stream_buffer.h;Middlewares/Third_Party/FreeRTOS/Source/include/task.h;Middlewares/Third_Party/FreeRTOS/Source/include/timers.h;Middlewares/Third_Party/FreeRTOS/Source/include/atomic.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_mpool.h;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_os2.h;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f405xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_starmc1.h;Drivers/CMSIS/Include/core_cm55.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/pac_armv81.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/pmu_armv8.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/cachel1_armv7.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cm85.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/cmsis_iccarm.h; [PreviousUsedMakefileFiles] -SourceFiles=Core/Src/main.c;Core/Src/freertos.c;Core/Src/stm32f4xx_it.c;Core/Src/stm32f4xx_hal_msp.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;;;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c; +SourceFiles=Core/Src/main.c;Core/Src/freertos.c;Core/Src/stm32f4xx_it.c;Core/Src/stm32f4xx_hal_msp.c;Core/Src/stm32f4xx_hal_timebase_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;;;Middlewares/Third_Party/FreeRTOS/Source/croutine.c;Middlewares/Third_Party/FreeRTOS/Source/event_groups.c;Middlewares/Third_Party/FreeRTOS/Source/list.c;Middlewares/Third_Party/FreeRTOS/Source/queue.c;Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c;Middlewares/Third_Party/FreeRTOS/Source/tasks.c;Middlewares/Third_Party/FreeRTOS/Source/timers.c;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c;Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c; HeaderPath=Drivers/STM32F4xx_HAL_Driver/Inc;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;Middlewares/Third_Party/FreeRTOS/Source/include;Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F;Drivers/CMSIS/Device/ST/STM32F4xx/Include;Drivers/CMSIS/Include;Core/Inc; CDefines=USE_HAL_DRIVER;STM32F405xx;USE_HAL_DRIVER;USE_HAL_DRIVER; @@ -16,11 +16,12 @@ HeaderFiles#3=../Core/Inc/main.h HeaderFolderListSize=1 HeaderPath#0=../Core/Inc HeaderFiles=; -SourceFileListSize=4 +SourceFileListSize=5 SourceFiles#0=../Core/Src/freertos.c SourceFiles#1=../Core/Src/stm32f4xx_it.c SourceFiles#2=../Core/Src/stm32f4xx_hal_msp.c -SourceFiles#3=../Core/Src/main.c +SourceFiles#3=../Core/Src/stm32f4xx_hal_timebase_tim.c +SourceFiles#4=../Core/Src/main.c SourceFolderListSize=1 SourcePath#0=../Core/Src SourceFiles=; diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index b863c35..5331016 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -51,7 +51,6 @@ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include extern uint32_t SystemCoreClock; - void xPortSysTickHandler(void); #endif #ifndef CMSIS_device_header #define CMSIS_device_header "stm32f4xx.h" @@ -162,7 +161,7 @@ standard names. */ /* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */ -#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1 +#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0 /* USER CODE BEGIN Defines */ /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index e419f17..6990b20 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -17,13 +17,13 @@ #include "can.h" #include "cmsis_os.h" -void can1_callback(CAN_HandleTypeDef* hcan); +void can1_callback(CAN_HandleTypeDef *hcan); -void vCanDispatch(void* pv_params); +void vCanDispatch(void *pv_params); extern osThreadId_t can_dispatch_handle; extern const osThreadAttr_t can_dispatch_attributes; int8_t queue_can_msg(can_msg_t msg); -void init_can1(CAN_HandleTypeDef* hcan); +void init_can1(CAN_HandleTypeDef *hcan); #endif diff --git a/Core/Inc/controller.h b/Core/Inc/controller.h new file mode 100644 index 0000000..0a41ba2 --- /dev/null +++ b/Core/Inc/controller.h @@ -0,0 +1,10 @@ +#ifndef CONTROL_MSB +#define CONTROL_MSB + +#include "cmsis_os.h" + +void vLedController(void *pv_params); +extern osThreadId_t led_controller_handle; +extern const osThreadAttr_t led_controller_attributes; + +#endif \ No newline at end of file diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 9b083d6..9874dfa 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -53,12 +53,13 @@ extern "C" { void Error_Handler(void); /* USER CODE BEGIN EFP */ - /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ #define VCC5_En_Pin GPIO_PIN_2 #define VCC5_En_GPIO_Port GPIOC +#define Shockpot_Pin GPIO_PIN_0 +#define Shockpot_GPIO_Port GPIOA #define Strain1_Pin GPIO_PIN_5 #define Strain1_GPIO_Port GPIOA #define Strain2_Pin GPIO_PIN_6 diff --git a/Core/Inc/monitor.h b/Core/Inc/monitor.h index d5259ba..263ff2e 100644 --- a/Core/Inc/monitor.h +++ b/Core/Inc/monitor.h @@ -5,13 +5,21 @@ #include "stm32f4xx_hal.h" /* Defining Temperature Monitor Task */ -void vTempMonitor(void* pv_params); +void vTempMonitor(void *pv_params); extern osThreadId_t temp_monitor_handle; extern const osThreadAttr_t temp_monitor_attributes; /* Task for Monitoring the IMU */ -void vIMUMonitor(void* pv_params); +void vIMUMonitor(void *pv_params); extern osThreadId_t imu_monitor_handle; extern const osThreadAttr_t imu_monitor_attributes; +void vShockpotMonitor(void *pv_params); +extern osThreadId_t shockpot_monitor_handle; +extern const osThreadAttr_t shockpot_monitor_attributes; + +void vStrainMonitor(void *pv_params); +extern osThreadId_t strain_monitor_handle; +extern const osThreadAttr_t strain_monitor_attributes; + #endif \ No newline at end of file diff --git a/Core/Inc/msb.h b/Core/Inc/msb.h index 37c6b6c..ce72873 100644 --- a/Core/Inc/msb.h +++ b/Core/Inc/msb.h @@ -21,25 +21,17 @@ typedef struct sht30_t *temp_sensor; lsm6dso_t *imu; ADC_HandleTypeDef *adc1; + uint32_t adc1_buf[3]; GPIO_TypeDef *debug_led1_gpio; uint16_t *debug_led1_pin; GPIO_TypeDef *debug_led2_gpio; uint16_t *debug_led2_pin; device_loc_t *device_loc; - osMutexId_t *adc_mutex; osMutexId_t *i2c_mutex; } msb_t; -typedef struct -{ - int8_t channel_0; - int8_t channel_1; - int8_t channel_2; - int8_t channel_3; -} adc_channels; - -msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef *debug_led1_gpio, -uint16_t *debug_led1_pin, GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin, +msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef *debug_led1_gpio, + uint16_t *debug_led1_pin, GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin, device_loc_t *device_loc); int8_t measure_central_temp(msb_t *msb, uint16_t *temp, uint16_t *humidity); @@ -48,9 +40,12 @@ int8_t read_accel(msb_t *msb, uint16_t accel[3]); int8_t read_gyro(msb_t *msb, uint16_t gyro[3]); -int8_t write_debug1(msb_t* msb, bool status); +int8_t write_debug1(msb_t *msb, bool status); -int8_t write_debug2(msb_t* msb, bool status); +int8_t write_debug2(msb_t *msb, bool status); +void read_shockpot(msb_t *msb, uint32_t shockpot_sense); +void read_strain1(msb_t *msb, uint32_t strain1); +void read_strain2(msb_t *msb, uint32_t strain2); #endif diff --git a/Core/Inc/msb_conf.h b/Core/Inc/msb_conf.h index af4aea1..d707261 100644 --- a/Core/Inc/msb_conf.h +++ b/Core/Inc/msb_conf.h @@ -4,10 +4,18 @@ #define DELAY_CAN_DISPATCH 5 #define DELAY_TEMP_SENSOR_REFRESH 500 #define DELAY_IMU_REFRESH 500 +#define DELAY_SHOCKPOT_REFRESH 500 +#define DELAY_STRAIN_REFRESH 500 +#define DELAY_TOF_REFRESH 500 +#define DELAY_WHEEL_TEMP_REFRESH 500 + +#define DELAY_DEBUG_LED_REFRESH 250 // CAN IDS #define CANID_TEMP_SENSOR 0x602 #define CANID_IMU_ACCEL 0x603 #define CANID_IMU_GYRO 0x604 - - +#define CANID_STRAIN_SENSE 0x605 +#define CANID_SHOCK_SENSE 0x606 +#define CANID_TOF 0x607 +#define CANID_WHEEL_TEMP 0x608 diff --git a/Core/Inc/serial_monitor.h b/Core/Inc/serial_monitor.h index ac48dd5..31cb392 100644 --- a/Core/Inc/serial_monitor.h +++ b/Core/Inc/serial_monitor.h @@ -4,10 +4,10 @@ #include "cmsis_os.h" /* Function to queue a message to be sent on the UART stream */ -int serial_print(const char* format, ...); +int serial_print(const char *format, ...); /* Defining Temperature Monitor Task */ -void vSerialMonitor(void* pv_params); +void vSerialMonitor(void *pv_params); extern osThreadId_t serial_monitor_handle; extern const osThreadAttr_t serial_monitor_attributes; diff --git a/Core/Inc/stm32f4xx_hal_conf.h b/Core/Inc/stm32f4xx_hal_conf.h index d5a9b06..b98e556 100644 --- a/Core/Inc/stm32f4xx_hal_conf.h +++ b/Core/Inc/stm32f4xx_hal_conf.h @@ -63,7 +63,7 @@ /* #define HAL_SD_MODULE_ENABLED */ /* #define HAL_MMC_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 9068113..53e0c55 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -52,8 +52,8 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); -void SysTick_Handler(void); void CAN1_RX0_IRQHandler(void); +void TIM5_IRQHandler(void); void DMA2_Stream0_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index b1640d9..3482a61 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -24,14 +24,14 @@ static osMessageQueueId_t can_outbound_queue; can_t *can1; -void init_can1(CAN_HandleTypeDef* hcan) +void init_can1(CAN_HandleTypeDef *hcan) { assert(hcan); can1 = malloc(sizeof(can_t)); assert(can1); - can1->hcan = hcan; + can1->hcan = hcan; assert(!can_init(can1)); @@ -40,19 +40,21 @@ void init_can1(CAN_HandleTypeDef* hcan) osThreadId_t can_dispatch_handle; const osThreadAttr_t can_dispatch_attributes = { - .name = "CanDispatch", + .name = "CanDispatch", .stack_size = 128 * 8, - .priority = (osPriority_t)osPriorityRealtime5, + .priority = (osPriority_t)osPriorityRealtime5, }; -void vCanDispatch(void* pv_params) +void vCanDispatch(void *pv_params) { can_msg_t msg_from_queue; HAL_StatusTypeDef msg_status; - for (;;) { + for (;;) + { /* Send CAN message */ - if (osOK == osMessageQueueGet(can_outbound_queue, &msg_from_queue, NULL, osWaitForever)) { + if (osOK == osMessageQueueGet(can_outbound_queue, &msg_from_queue, NULL, osWaitForever)) + { msg_status = can_send_msg(can1, &msg_from_queue); if (msg_status == HAL_ERROR) { @@ -62,12 +64,12 @@ void vCanDispatch(void* pv_params) { serial_print("Outbound mailbox full!"); } - #ifdef LOG_VERBOSE +#ifdef LOG_VERBOSE else { printf("Message sent: %lX\r\n", msg_from_queue.id); } - #endif +#endif } osDelay(DELAY_CAN_DISPATCH); @@ -82,4 +84,3 @@ int8_t queue_can_msg(can_msg_t msg) osMessageQueuePut(can_outbound_queue, &msg, 0U, 0U); return 0; } - diff --git a/Core/Src/controller.c b/Core/Src/controller.c new file mode 100644 index 0000000..21c94cf --- /dev/null +++ b/Core/Src/controller.c @@ -0,0 +1,42 @@ +#include "controller.h" +#include "msb_conf.h" +#include "msb.h" + +osThreadId_t led_controller_handle; +const osThreadAttr_t led_controller_attributes = { + .name = "LedController", + .stack_size = 32 * 8, + .priority = (osPriority_t)osPriorityBelowNormal1, +}; + +void vLedController(void *pv_params) +{ + + msb_t *msb = (msb_t *)pv_params; + + switch (*msb->device_loc) + { + case DEVICE_FRONT_LEFT: + write_debug1(msb, true); + write_debug2(msb, true); + break; + case DEVICE_FRONT_RIGHT: + write_debug1(msb, true); + write_debug2(msb, false); + break; + case DEVICE_BACK_LEFT: + write_debug1(msb, false); + write_debug2(msb, true); + break; + case DEVICE_BACK_RIGHT: + write_debug1(msb, false); + write_debug2(msb, false); + break; + } + + for (;;) + { + + osDelay(DELAY_DEBUG_LED_REFRESH); + } +} \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 3d0e513..c05bda7 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -23,6 +23,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "can_handler.h" +#include "controller.h" #include "serial_monitor.h" #include "monitor.h" #include "msb.h" @@ -61,9 +62,9 @@ UART_HandleTypeDef huart2; /* Definitions for defaultTask */ osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { - .name = "defaultTask", - .stack_size = 128 * 4, - .priority = (osPriority_t) osPriorityNormal, + .name = "defaultTask", + .stack_size = 128 * 4, + .priority = (osPriority_t)osPriorityNormal, }; /* USER CODE BEGIN PV */ @@ -91,9 +92,9 @@ void StartDefaultTask(void *argument); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { @@ -127,6 +128,32 @@ int main(void) MX_SPI2_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ + // determine MSB location + bool loc1 = HAL_GPIO_ReadPin(Addr0_GPIO_Port, Addr0_Pin); + bool loc2 = HAL_GPIO_ReadPin(Addr1_GPIO_Port, Addr1_Pin); + bool loc3 = HAL_GPIO_ReadPin(Addr2_GPIO_Port, Addr2_Pin); + + device_loc_t loc; + if (loc1 && loc2) + { + loc = DEVICE_FRONT_LEFT; + } + else if (loc1 && !loc2) + { + loc = DEVICE_FRONT_RIGHT; + } + else if (!loc1 && loc2) + { + loc = DEVICE_BACK_LEFT; + } + else if (!loc1 && !loc3) + { + loc = DEVICE_BACK_RIGHT; + } + else + { + loc = DEVICE_FRONT_LEFT; + } /* USER CODE END 2 */ @@ -138,7 +165,7 @@ int main(void) // determine the configuration of the device - msb_t *msb = init_msb(&hi2c3, &hadc1, Debug_LED_1_GPIO_Port,(uint16_t *) Debug_LED_1_Pin , Debug_LED_2_GPIO_Port, (uint16_t *) Debug_LED_2_Pin, (device_loc_t *) DEVICE_BACK_RIGHT); + msb_t *msb = init_msb(&hi2c3, &hadc1, Debug_LED_1_GPIO_Port, (uint16_t *)Debug_LED_1_Pin, Debug_LED_2_GPIO_Port, (uint16_t *)Debug_LED_2_Pin, &loc); /* USER CODE END RTOS_MUTEX */ @@ -168,6 +195,14 @@ int main(void) assert(temp_monitor_handle); imu_monitor_handle = osThreadNew(vIMUMonitor, msb, &imu_monitor_attributes); assert(imu_monitor_handle); + shockpot_monitor_handle = osThreadNew(vIMUMonitor, msb, &shockpot_monitor_attributes); + assert(shockpot_monitor_handle); + strain_monitor_handle = osThreadNew(vIMUMonitor, msb, &strain_monitor_attributes); + assert(strain_monitor_handle); + + led_controller_handle = osThreadNew(vLedController, msb, &led_controller_attributes); + assert(led_controller_handle); + /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ @@ -191,23 +226,23 @@ int main(void) } /** - * @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}; /** Configure the main internal regulator output voltage - */ + */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI; + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.LSIState = RCC_LSI_ON; @@ -218,9 +253,8 @@ void SystemClock_Config(void) } /** 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.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; @@ -233,10 +267,10 @@ void SystemClock_Config(void) } /** - * @brief ADC1 Initialization Function - * @param None - * @retval None - */ + * @brief ADC1 Initialization Function + * @param None + * @retval None + */ static void MX_ADC1_Init(void) { @@ -251,7 +285,7 @@ static void MX_ADC1_Init(void) /* USER CODE END ADC1_Init 1 */ /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) - */ + */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; hadc1.Init.Resolution = ADC_RESOLUTION_12B; @@ -270,7 +304,7 @@ static void MX_ADC1_Init(void) } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. - */ + */ sConfig.Channel = ADC_CHANNEL_5; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; @@ -280,7 +314,7 @@ static void MX_ADC1_Init(void) } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. - */ + */ sConfig.Rank = 2; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { @@ -288,7 +322,7 @@ static void MX_ADC1_Init(void) } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. - */ + */ sConfig.Rank = 3; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { @@ -296,7 +330,7 @@ static void MX_ADC1_Init(void) } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. - */ + */ sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 4; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) @@ -306,14 +340,13 @@ static void MX_ADC1_Init(void) /* USER CODE BEGIN ADC1_Init 2 */ /* USER CODE END ADC1_Init 2 */ - } /** - * @brief CAN1 Initialization Function - * @param None - * @retval None - */ + * @brief CAN1 Initialization Function + * @param None + * @retval None + */ static void MX_CAN1_Init(void) { @@ -344,14 +377,13 @@ static void MX_CAN1_Init(void) init_can1(&hcan1); /* USER CODE END CAN1_Init 2 */ - } /** - * @brief I2C3 Initialization Function - * @param None - * @retval None - */ + * @brief I2C3 Initialization Function + * @param None + * @retval None + */ static void MX_I2C3_Init(void) { @@ -378,14 +410,13 @@ static void MX_I2C3_Init(void) /* USER CODE BEGIN I2C3_Init 2 */ /* USER CODE END I2C3_Init 2 */ - } /** - * @brief IWDG Initialization Function - * @param None - * @retval None - */ + * @brief IWDG Initialization Function + * @param None + * @retval None + */ static void MX_IWDG_Init(void) { @@ -406,14 +437,13 @@ static void MX_IWDG_Init(void) /* USER CODE BEGIN IWDG_Init 2 */ /* USER CODE END IWDG_Init 2 */ - } /** - * @brief SPI2 Initialization Function - * @param None - * @retval None - */ + * @brief SPI2 Initialization Function + * @param None + * @retval None + */ static void MX_SPI2_Init(void) { @@ -444,14 +474,13 @@ static void MX_SPI2_Init(void) /* USER CODE BEGIN SPI2_Init 2 */ /* USER CODE END SPI2_Init 2 */ - } /** - * @brief USART2 Initialization Function - * @param None - * @retval None - */ + * @brief USART2 Initialization Function + * @param None + * @retval None + */ static void MX_USART2_UART_Init(void) { @@ -477,12 +506,11 @@ static void MX_USART2_UART_Init(void) /* USER CODE BEGIN USART2_Init 2 */ /* USER CODE END USART2_Init 2 */ - } /** - * Enable DMA controller clock - */ + * Enable DMA controller clock + */ static void MX_DMA_Init(void) { @@ -493,19 +521,18 @@ static void MX_DMA_Init(void) /* DMA2_Stream0_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn); - } /** - * @brief GPIO Initialization Function - * @param None - * @retval None - */ + * @brief GPIO Initialization Function + * @param None + * @retval None + */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; -/* USER CODE BEGIN MX_GPIO_Init_1 */ -/* USER CODE END MX_GPIO_Init_1 */ + /* USER CODE BEGIN MX_GPIO_Init_1 */ + /* USER CODE END MX_GPIO_Init_1 */ /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOH_CLK_ENABLE(); @@ -514,23 +541,23 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, VCC5_En_Pin|Debug_LED_1_Pin|Debug_LED_2_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOC, VCC5_En_Pin | Debug_LED_1_Pin | Debug_LED_2_Pin, GPIO_PIN_RESET); /*Configure GPIO pins : VCC5_En_Pin Debug_LED_1_Pin Debug_LED_2_Pin */ - GPIO_InitStruct.Pin = VCC5_En_Pin|Debug_LED_1_Pin|Debug_LED_2_Pin; + GPIO_InitStruct.Pin = VCC5_En_Pin | Debug_LED_1_Pin | Debug_LED_2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pins : Addr0_Pin Addr1_Pin Addr2_Pin */ - GPIO_InitStruct.Pin = Addr0_Pin|Addr1_Pin|Addr2_Pin; + GPIO_InitStruct.Pin = Addr0_Pin | Addr1_Pin | Addr2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); -/* USER CODE BEGIN MX_GPIO_Init_2 */ -/* USER CODE END MX_GPIO_Init_2 */ + /* USER CODE BEGIN MX_GPIO_Init_2 */ + /* USER CODE END MX_GPIO_Init_2 */ } /* USER CODE BEGIN 4 */ @@ -558,9 +585,31 @@ void StartDefaultTask(void *argument) } /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief Period elapsed callback in non blocking mode + * @note This function is called when TIM5 interrupt took place, inside + * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment + * a global variable "uwTick" used as application time base. + * @param htim : TIM handle + * @retval None + */ +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + /* USER CODE BEGIN Callback 0 */ + + /* USER CODE END Callback 0 */ + if (htim->Instance == TIM5) + { + HAL_IncTick(); + } + /* USER CODE BEGIN Callback 1 */ + + /* USER CODE END Callback 1 */ +} + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ @@ -572,14 +621,14 @@ void Error_Handler(void) /* 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 */ diff --git a/Core/Src/monitor.c b/Core/Src/monitor.c index a4778a7..a001f04 100644 --- a/Core/Src/monitor.c +++ b/Core/Src/monitor.c @@ -11,32 +11,51 @@ #include #include - #include "monitor.h" +uint16_t convert_can(uint16_t original_value, device_loc_t *mode) +{ + switch (*mode) + { + case DEVICE_FRONT_LEFT: + return original_value; + case DEVICE_FRONT_RIGHT: + return original_value + 0x20; + case DEVICE_BACK_LEFT: + return original_value + 0x40; + case DEVICE_BACK_RIGHT: + return original_value + 0x60; + default: + return original_value; + } +} + osThreadId_t temp_monitor_handle; const osThreadAttr_t temp_monitor_attributes = { - .name = "TempMonitor", - .stack_size = 32 * 8, - .priority = (osPriority_t)osPriorityHigh1, + .name = "TempMonitor", + .stack_size = 32 * 8, + .priority = (osPriority_t)osPriorityHigh1, }; void vTempMonitor(void *pv_params) { - can_msg_t temp_sensor_msg = {.id = CANID_TEMP_SENSOR, .len = 4, .data = {0}}; msb_t *msb = (msb_t *)pv_params; + can_msg_t temp_sensor_msg = {.id = convert_can(CANID_TEMP_SENSOR, msb->device_loc), .len = 4, .data = {0}}; + struct __attribute__((__packed__)) { uint16_t temp; uint16_t humidity; } temp_sensor_data; + uint16_t temp_dat = 0; + uint16_t humidity_dat = 0; + for (;;) - { - uint16_t temp_dat; - uint16_t humidity_dat; + { + if (measure_central_temp(msb, &temp_dat, &humidity_dat)) { printf("Failed to get temp"); @@ -67,19 +86,19 @@ void vTempMonitor(void *pv_params) osThreadId_t imu_monitor_handle; const osThreadAttr_t imu_monitor_attributes = { - .name = "IMUMonitor", - .stack_size = 32 * 8, - .priority = (osPriority_t)osPriorityHigh, + .name = "IMUMonitor", + .stack_size = 32 * 8, + .priority = (osPriority_t)osPriorityHigh, }; void vIMUMonitor(void *pv_params) { - const uint8_t num_samples = 10; - can_msg_t imu_accel_msg = {.id = CANID_IMU_ACCEL, .len = 6, .data = {0}}; - can_msg_t imu_gyro_msg = {.id = CANID_IMU_GYRO, .len = 6, .data = {0}}; - msb_t *msb = (msb_t *)pv_params; + const uint8_t num_samples = 10; + can_msg_t imu_accel_msg = {.id = convert_can(CANID_IMU_ACCEL, msb->device_loc), .len = 6, .data = {0}}; + can_msg_t imu_gyro_msg = {.id = convert_can(CANID_IMU_GYRO, msb->device_loc), .len = 6, .data = {0}}; + struct __attribute__((__packed__)) { uint16_t accel_x; @@ -94,11 +113,13 @@ void vIMUMonitor(void *pv_params) uint16_t gyro_z; } gyro_data; + uint16_t accel_data_temp[3] = {0}; + uint16_t gyro_data_temp[3] = {0}; + for (;;) { /* Take measurement */ - uint16_t accel_data_temp[3] = {0}; - uint16_t gyro_data_temp[3] = {0}; + if (read_accel(msb, accel_data_temp)) { serial_print("Failed to get IMU acceleration"); @@ -117,6 +138,11 @@ void vIMUMonitor(void *pv_params) gyro_data.gyro_y = (gyro_data.gyro_y + gyro_data_temp[1]) / num_samples; gyro_data.gyro_z = (gyro_data.gyro_z + gyro_data_temp[2]) / num_samples; +#ifdef LOG_VERBOSE + serial_print("IMU Accel x: %d y: %d z: %d \r\n", accel_data.accel_x, accel_data.accel_y, accel_data.accel_z); + serial_print("IMU Gyro x: %d y: %d z: %d \r\n", gyro_data.gyro_x, gyro_data.gyro_y, gyro_data.gyro_z); +#endif + /* convert to big endian */ endian_swap(&accel_data.accel_x, sizeof(accel_data.accel_x)); endian_swap(&accel_data.accel_y, sizeof(accel_data.accel_y)); @@ -141,4 +167,91 @@ void vIMUMonitor(void *pv_params) /* Yield to other tasks */ osDelay(DELAY_IMU_REFRESH); } +} + +osThreadId_t shockpot_monitor_handle; +const osThreadAttr_t shockpot_monitor_attributes = { + .name = "ShockpotMonitor", + .stack_size = 32 * 8, + .priority = (osPriority_t)osPriorityHigh1, +}; + +void vShockpotMonitor(void *pv_params) +{ + + msb_t *msb = (msb_t *)pv_params; + + can_msg_t shockpot_msg = {.id = convert_can(CANID_SHOCK_SENSE, msb->device_loc), .len = 4, .data = {0}}; + + uint32_t shock_value = 0; + + for (;;) + { + read_shockpot(msb, shock_value); + +#ifdef LOG_VERBOSE + serial_print("Shock value:\t%d\r\n", shock_value); +#endif + + endian_swap(&shock_value, sizeof(shock_value)); + + memcpy(shockpot_msg.data, &shock_value, shockpot_msg.len); + /* Send CAN message */ + if (queue_can_msg(shockpot_msg)) + { + serial_print("Failed to send CAN message"); + } + + /* Yield to other tasks */ + osDelay(DELAY_SHOCKPOT_REFRESH); + } +} + +osThreadId_t strain_monitor_handle; +const osThreadAttr_t strain_monitor_attributes = { + .name = "StrainMonitor", + .stack_size = 32 * 8, + .priority = (osPriority_t)osPriorityHigh1, +}; + +void vStrainMonitor(void *pv_params) +{ + + msb_t *msb = (msb_t *)pv_params; + + can_msg_t strain_msg = {.id = convert_can(CANID_STRAIN_SENSE, msb->device_loc), .len = 8, .data = {0}}; + + struct __attribute__((__packed__)) + { + uint32_t strain1; + uint32_t strain2; + } strain_data; + + uint32_t strain1_dat = 0; + uint32_t strain2_dat = 0; + for (;;) + { + read_strain1(msb, strain1_dat); + read_strain2(msb, strain2_dat); + +#ifdef LOG_VERBOSE + serial_print("Strain 1: %d 2: %d \r\n", strain1_dat, strain2_dat); +#endif + + strain_data.strain1 = strain1_dat; + strain_data.strain2 = strain2_dat; + + endian_swap(&strain_data.strain1, sizeof(strain_data.strain1)); + endian_swap(&strain_data.strain2, sizeof(strain_data.strain2)); + + memcpy(strain_msg.data, &strain_data, strain_msg.len); + /* Send CAN message */ + if (queue_can_msg(strain_msg)) + { + serial_print("Failed to send CAN message"); + } + + /* Yield to other tasks */ + osDelay(DELAY_SHOCKPOT_REFRESH); + } } \ No newline at end of file diff --git a/Core/Src/msb.c b/Core/Src/msb.c index f382a86..75d8581 100644 --- a/Core/Src/msb.c +++ b/Core/Src/msb.c @@ -5,7 +5,6 @@ #include "lsm6dso.h" static osMutexAttr_t msb_i2c_mutex_attr; -static osMutexAttr_t msb_adc_mutex_attr; msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef *debug_led1_gpio, uint16_t *debug_led1_pin, GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin, @@ -39,13 +38,12 @@ msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef * assert(msb->imu); assert(!lsm6dso_init(msb->imu, msb->hi2c)); /* This is always connected */ + assert(!HAL_ADC_Start_DMA(msb->adc1, msb->adc1_buf, sizeof(msb->adc1_buf) / sizeof(uint32_t))); + /* Create Mutexes */ msb->i2c_mutex = osMutexNew(&msb_i2c_mutex_attr); assert(msb->i2c_mutex); - msb->adc_mutex = osMutexNew(&msb_adc_mutex_attr); - assert(msb->adc_mutex); - return msb; } @@ -73,6 +71,26 @@ int8_t measure_central_temp(msb_t *msb, uint16_t *temp, uint16_t *humidity) return 0; } +void read_adc1(msb_t *msb, uint32_t adc1_buf[3]) +{ + memcpy(adc1_buf, msb->adc1_buf, sizeof(msb->adc1_buf)); +} + +void read_shockpot(msb_t *msb, uint32_t shockpot_sense) +{ + memcpy((uint32_t *)shockpot_sense, msb->adc1_buf, sizeof(shockpot_sense)); +} + +void read_strain1(msb_t *msb, uint32_t strain1) +{ + memcpy((uint32_t *)strain1, msb->adc1_buf + 1, sizeof(strain1)); +} + +void read_strain2(msb_t *msb, uint32_t strain2) +{ + memcpy((uint32_t *)strain2, msb->adc1_buf + 2, sizeof(strain2)); +} + int8_t read_accel(msb_t *msb, uint16_t accel[3]) { if (!msb) diff --git a/Core/Src/serial_monitor.c b/Core/Src/serial_monitor.c index 1dc1ff4..a0e2f15 100644 --- a/Core/Src/serial_monitor.c +++ b/Core/Src/serial_monitor.c @@ -15,10 +15,10 @@ const osThreadAttr_t serial_monitor_attributes; * Referenced https://github.com/esp8266/Arduino/blob/master/cores/esp8266/Print.cpp * Preformat string then put into a buffer */ -int serial_print(const char* format, ...) +int serial_print(const char *format, ...) { va_list arg; - char* buffer = malloc(sizeof(char) * PRINTF_BUFFER_LEN); + char *buffer = malloc(sizeof(char) * PRINTF_BUFFER_LEN); if (buffer == NULL) return -1; @@ -28,14 +28,16 @@ int serial_print(const char* format, ...) va_end(arg); /* Check to make sure we don't overflow buffer */ - if (len > PRINTF_BUFFER_LEN - 1) { + if (len > PRINTF_BUFFER_LEN - 1) + { free(buffer); return -2; } /* If string can't be queued */ osStatus_t stat = osMessageQueuePut(printf_queue, &buffer, 0U, 0U); - if (stat) { + if (stat) + { free(buffer); return -3; } @@ -43,19 +45,23 @@ int serial_print(const char* format, ...) return 0; } -void vSerialMonitor(void* pv_params) +void vSerialMonitor(void *pv_params) { - char* message; + char *message; osStatus_t status; - printf_queue = osMessageQueueNew(PRINTF_QUEUE_SIZE, sizeof(char*), NULL); + printf_queue = osMessageQueueNew(PRINTF_QUEUE_SIZE, sizeof(char *), NULL); - for (;;) { + for (;;) + { /* Wait until new printf message comes into queue */ status = osMessageQueueGet(printf_queue, &message, NULL, osWaitForever); - if (status != osOK) { + if (status != osOK) + { // TODO: Trigger fault ? - } else { + } + else + { printf(message); free(message); } diff --git a/Core/Src/stm32f4xx_hal_msp.c b/Core/Src/stm32f4xx_hal_msp.c index 147b714..682805d 100644 --- a/Core/Src/stm32f4xx_hal_msp.c +++ b/Core/Src/stm32f4xx_hal_msp.c @@ -103,7 +103,7 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) PA5 ------> ADC1_IN5 PA6 ------> ADC1_IN6 */ - GPIO_InitStruct.Pin = GPIO_PIN_0|Strain1_Pin|Strain2_Pin; + GPIO_InitStruct.Pin = Shockpot_Pin|Strain1_Pin|Strain2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); @@ -155,7 +155,7 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) PA5 ------> ADC1_IN5 PA6 ------> ADC1_IN6 */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|Strain1_Pin|Strain2_Pin); + HAL_GPIO_DeInit(GPIOA, Shockpot_Pin|Strain1_Pin|Strain2_Pin); /* ADC1 DMA DeInit */ HAL_DMA_DeInit(hadc->DMA_Handle); diff --git a/Core/Src/stm32f4xx_hal_timebase_tim.c b/Core/Src/stm32f4xx_hal_timebase_tim.c new file mode 100644 index 0000000..b55af1b --- /dev/null +++ b/Core/Src/stm32f4xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_hal_timebase_tim.c + * @brief HAL time base based on the hardware TIM. + ****************************************************************************** + * @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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_tim.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +TIM_HandleTypeDef htim5; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief This function configures the TIM5 as a time base source. + * The time source is configured to have 1ms time base with a dedicated + * Tick interrupt priority. + * @note This function is called automatically at the beginning of program after + * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). + * @param TickPriority: Tick interrupt priority. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) +{ + RCC_ClkInitTypeDef clkconfig; + uint32_t uwTimclock, uwAPB1Prescaler = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* Enable TIM5 clock */ + __HAL_RCC_TIM5_CLK_ENABLE(); + + /* Get clock configuration */ + HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); + + /* Get APB1 prescaler */ + uwAPB1Prescaler = clkconfig.APB1CLKDivider; + /* Compute TIM5 clock */ + if (uwAPB1Prescaler == RCC_HCLK_DIV1) + { + uwTimclock = HAL_RCC_GetPCLK1Freq(); + } + else + { + uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); + } + + /* Compute the prescaler value to have TIM5 counter clock equal to 1MHz */ + uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); + + /* Initialize TIM5 */ + htim5.Instance = TIM5; + + /* Initialize TIMx peripheral as follow: + + + Period = [(TIM5CLK/1000) - 1]. to have a (1/1000) s time base. + + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. + + ClockDivision = 0 + + Counter direction = Up + */ + htim5.Init.Period = (1000000U / 1000U) - 1U; + htim5.Init.Prescaler = uwPrescalerValue; + htim5.Init.ClockDivision = 0; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim5); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim5); + if (status == HAL_OK) + { + /* Enable the TIM5 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM5_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @brief Suspend Tick increment. + * @note Disable the tick increment by disabling TIM5 update interrupt. + * @param None + * @retval None + */ +void HAL_SuspendTick(void) +{ + /* Disable TIM5 update Interrupt */ + __HAL_TIM_DISABLE_IT(&htim5, TIM_IT_UPDATE); +} + +/** + * @brief Resume Tick increment. + * @note Enable the tick increment by Enabling TIM5 update interrupt. + * @param None + * @retval None + */ +void HAL_ResumeTick(void) +{ + /* Enable TIM5 Update interrupt */ + __HAL_TIM_ENABLE_IT(&htim5, TIM_IT_UPDATE); +} + diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 3de1b18..55a2bd2 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -20,8 +20,6 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f4xx_it.h" -#include "FreeRTOS.h" -#include "task.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -59,6 +57,8 @@ /* External variables --------------------------------------------------------*/ extern DMA_HandleTypeDef hdma_adc1; extern CAN_HandleTypeDef hcan1; +extern TIM_HandleTypeDef htim5; + /* USER CODE BEGIN EV */ /* USER CODE END EV */ @@ -154,28 +154,6 @@ void DebugMon_Handler(void) /* USER CODE END DebugMonitor_IRQn 1 */ } -/** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ - HAL_IncTick(); -#if (INCLUDE_xTaskGetSchedulerState == 1 ) - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) - { -#endif /* INCLUDE_xTaskGetSchedulerState */ - xPortSysTickHandler(); -#if (INCLUDE_xTaskGetSchedulerState == 1 ) - } -#endif /* INCLUDE_xTaskGetSchedulerState */ - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ -} - /******************************************************************************/ /* STM32F4xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ @@ -197,6 +175,20 @@ void CAN1_RX0_IRQHandler(void) /* USER CODE END CAN1_RX0_IRQn 1 */ } +/** + * @brief This function handles TIM5 global interrupt. + */ +void TIM5_IRQHandler(void) +{ + /* USER CODE BEGIN TIM5_IRQn 0 */ + + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ + + /* USER CODE END TIM5_IRQn 1 */ +} + /** * @brief This function handles DMA2 stream0 global interrupt. */ diff --git a/MSB-FW.ioc b/MSB-FW.ioc index 2782abb..8e93673 100644 --- a/MSB-FW.ioc +++ b/MSB-FW.ioc @@ -84,7 +84,7 @@ Mcu.Pin22=PC12 Mcu.Pin23=PB3 Mcu.Pin24=VP_FREERTOS_VS_CMSIS_V2 Mcu.Pin25=VP_IWDG_VS_IWDG -Mcu.Pin26=VP_SYS_VS_Systick +Mcu.Pin26=VP_SYS_VS_tim5 Mcu.Pin3=PA0-WKUP Mcu.Pin4=PA2 Mcu.Pin5=PA3 @@ -112,8 +112,13 @@ NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false NVIC.SavedPendsvIrqHandlerGenerated=true NVIC.SavedSvcallIrqHandlerGenerated=true NVIC.SavedSystickIrqHandlerGenerated=true -NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:true\:false\:true\:false +NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false +NVIC.TIM5_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true +NVIC.TimeBase=TIM5_IRQn +NVIC.TimeBaseIP=TIM5 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +PA0-WKUP.GPIOParameters=GPIO_Label +PA0-WKUP.GPIO_Label=Shockpot PA0-WKUP.Locked=true PA0-WKUP.Signal=ADCx_IN0 PA11.Locked=true @@ -261,7 +266,7 @@ VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2 VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2 VP_IWDG_VS_IWDG.Mode=IWDG_Activate VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim5.Mode=TIM5 +VP_SYS_VS_tim5.Signal=SYS_VS_tim5 board=custom rtos.0.ip=FREERTOS diff --git a/Makefile b/Makefile index 19f47f2..eda2195 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Fri May 24 06:14:07 GMT 2024] +# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Fri May 24 08:00:53 GMT 2024] ########################################################################################################################## # ------------------------------------------------ @@ -38,6 +38,7 @@ BUILD_DIR = build C_SOURCES = \ Core/Src/main.c \ Core/Src/can_handler.c \ +Core/Src/controller.c \ Core/Src/serial_monitor.c \ Core/Src/monitor.c \ Core/Src/msb.c \ @@ -84,7 +85,8 @@ Middlewares/Third_Party/FreeRTOS/Source/tasks.c \ Middlewares/Third_Party/FreeRTOS/Source/timers.c \ Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ -Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c +Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ +Core/Src/stm32f4xx_hal_timebase_tim.c # ASM sources ASM_SOURCES = \