From cd1e4d2a923747dfea77de1f6663b4aad31e6fa7 Mon Sep 17 00:00:00 2001 From: Scott A <89099102+Sabramz@users.noreply.github.com> Date: Fri, 24 Jan 2025 21:21:09 -0500 Subject: [PATCH] ADBMS Integration (#138) Co-authored-by: Jack Rubacha --- .github/workflows/build-check.yml | 1 + .github/workflows/format-check.yml | 1 + .gitmodules | 3 + .mxproject | 9 +- Core/Inc/FreeRTOSConfig.h | 3 +- Core/Inc/adi_interaction.h | 238 ++++ Core/Inc/analyzer.h | 25 +- Core/Inc/bmsConfig.h | 17 +- Core/Inc/can_handler.h | 41 +- Core/Inc/compute.h | 93 +- Core/Inc/datastructs.h | 30 +- Core/Inc/segment.h | 78 +- Core/Inc/shep_tasks.h | 9 + Core/Inc/stm32f4xx_hal_conf.h | 2 +- Core/Inc/stm32f4xx_it.h | 2 +- Core/Src/adi_interaction.c | 382 +++++++ Core/Src/analyzer.c | 415 +++---- Core/Src/compute.c | 225 +++- Core/Src/main.c | 266 ++++- Core/Src/segment.c | 1017 ++++++----------- Core/Src/shep_tasks.c | 135 ++- Core/Src/stateMachine.c | 76 +- Core/Src/stm32f4xx_hal_msp.c | 27 +- Core/Src/stm32f4xx_hal_timebase_tim.c | 138 +++ Core/Src/stm32f4xx_it.c | 40 +- Core/Src/syscalls.c | 176 +++ Core/Src/sysmem.c | 79 ++ Drivers/Embedded-Base | 2 +- Drivers/adbms | 1 + Makefile | 17 +- shepherd2.ioc | 43 +- ...405RGTx_FLASH.ld => stm32f405rgtx_flash.ld | 1 - 32 files changed, 2455 insertions(+), 1137 deletions(-) create mode 100644 Core/Inc/adi_interaction.h create mode 100644 Core/Src/adi_interaction.c create mode 100644 Core/Src/stm32f4xx_hal_timebase_tim.c create mode 100644 Core/Src/syscalls.c create mode 100644 Core/Src/sysmem.c create mode 160000 Drivers/adbms rename STM32F405RGTx_FLASH.ld => stm32f405rgtx_flash.ld (96%) diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 2390778a..de82e429 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -9,6 +9,7 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive + token: ${{ secrets.PAT_TOKEN }} fetch-depth: 0 - name: Execute Make run: | diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml index 80a40900..e1a21c4f 100644 --- a/.github/workflows/format-check.yml +++ b/.github/workflows/format-check.yml @@ -10,6 +10,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive + token: ${{ secrets.PAT_TOKEN }} - name: Run clang-format style check for C/C++ sources uses: Northeastern-Electric-Racing/clang-format-action@main with: diff --git a/.gitmodules b/.gitmodules index e2548a27..da1c65f3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "Drivers/Embedded-Base"] path = Drivers/Embedded-Base url = https://github.com/Northeastern-Electric-Racing/Embedded-Base.git +[submodule "Drivers/adbms"] + path = Drivers/adbms + url = git@github.com:Northeastern-Electric-Racing/adbms.git diff --git a/.mxproject b/.mxproject index b3e9d9cb..b96dd2c9 100644 --- a/.mxproject +++ b/.mxproject @@ -1,8 +1,8 @@ [PreviousLibFiles] -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_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h;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;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;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_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h;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/cmsis_armclang.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/cachel1_armv7.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/pac_armv81.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm55.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/pmu_armv8.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_starmc1.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h;Drivers/CMSIS/Include/core_cm85.h; +LibFiles=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_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_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h;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_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.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_uart.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;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_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;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_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h;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/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/pmu_armv8.h;Drivers/CMSIS/Include/cachel1_armv7.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_cm55.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_starmc1.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/core_cm85.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/pac_armv81.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;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;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;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;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_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.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_uart.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;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_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.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_uart.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c;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; @@ -19,11 +19,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 c1e8e9b6..41e0046f 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" @@ -164,7 +163,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/adi_interaction.h b/Core/Inc/adi_interaction.h new file mode 100644 index 00000000..da04d7dd --- /dev/null +++ b/Core/Inc/adi_interaction.h @@ -0,0 +1,238 @@ +#include "adBms6830Data.h" +#include "bmsConfig.h" + +// --- BEGIN SET HELPERS --- + +/** + * @brief Set the status of the REFON bit. + * + * @param chip Pointer to the chip to modify. + * @param state New state of the REFON bit. + */ +void set_REFON(cell_asic *chip, REFON state); + +/** + * @brief Set the C-ADC vs. S-ADC comparison voltage threshold + * + * @param chip Pointer to the chip to modify. + * @param threshold Threshold to set. + */ +void set_volt_adc_comp_thresh(cell_asic *chip, CTH threshold); + +void set_diagnostic_flags(cell_asic *chip, FLAG_D config); + +/** + * @brief Set the discharge state of a cell. + * + * @param chip Pointer to chip with cell to modify. + * @param cell ID of cell to modify. Cell indexes start are from 1-16 (NOT ZERO INDEXED). + * @param discharge Cell discharge state. true to discharge, false to disable discharge. + */ +void set_cell_discharge(cell_asic *chip, uint8_t cell, bool discharge); + +/** + * @brief Set the state of the SOAKON bit to either enable or disable soak times. + * + * @param chip Pointer to chip to configure + * @param state Enable or disable SOAKON + */ +void set_soak_on(cell_asic *chip, SOAKON state); + +/** + * @brief Set the soak time range. + * + * @param chip Pointer to chip to configure + * @param range The range of time over which to soak for aux and aux2 + */ +void set_aux_soak_range(cell_asic *chip, OWRNG range); + +/** + * @brief Set the open wire soak time. See data sheet for formula. + * + * @param chip Pointer to chip configuration + * @param time The amount of time to soak for. Higher OWA is a higher soak time. + */ +void set_open_wire_soak_time(cell_asic *chip, OWA time); + +/** + * @brief Set the pull of a GPIO pin on an ADBMS8630. + * + * @param chip ADBMS6830 chip + * @param gpio Number of the GPIO pin to change (1-10) + * @param input True is no pull down, False is pull down. + */ +void set_gpio_pull(cell_asic *chip, uint8_t gpio, bool input); + +/** + * @brief Set the corner frequency of the IIR filter. + * + * @param chip Pointer to chip config + * @param freq Corner frequency (see IIR_FPA enum for frequencies) + */ +void set_iir_corner_freq(cell_asic *chip, IIR_FPA freq); + +/** + * @brief Configure a chip as a break in the isoSPI daisy chain. + * + * @param chip Pointer to chip config + * @param is_break True if chip is break, false if chip is not break + */ +void set_comm_break(cell_asic *chip, bool is_break); + +/** + * @brief Enable/disable discharging through the mute discharge bit. + * + * @param chip Pointer to chip config + * @param disable_discharge True to disable discharge, false to enable discharge. + */ +void set_mute_state(cell_asic *chip, bool disable_discharge); + +/** + * @brief Set whether or not this chip is taking a snapshot. The chip will not begin reading new values unless the snapshot bit is cleared. + * + * @param chip Pointer to chip config + * @param take_snapshot True to take a snapshot, false to end the snapshot + */ +void set_snapshot(cell_asic *chip, bool take_snapshot); + +/** + * @brief Enable/disable the discharge timer monitor. + * + * @param chip Pointer to chip config + * @param enabled True if discharge timer monitor is enabled, false if otherwise + */ +void set_discharge_timer_monitor(cell_asic *chip, bool enabled); + +/** + * @brief Configure the discharge timer range, which affects the resolution. + * + * @param chip Pointer to chip config + * @param large True for large range, False for small range + */ +void set_discharge_timer_range(cell_asic *chip, bool large); + +/** + * @brief Set the discharge monitor timeout, which is dependent on the discharge timer range. + * + * @param chip Pointer to chip config + * @param timeout Base for timeout multiplicaiton. Must be below six bits. + */ +void set_discharge_timeout(cell_asic *chip, uint8_t timeout); + +// --- END SET HELPERS --- + +// --- BEGIN WRITE COMMANDS --- + +/** + * @brief Soft reset all chips, then re-wake them + * + * @param chips + */ +void soft_reset_chips(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Write config registers. Wakes chips before writing. + * + * @param chips Array of chips to write config registers of. + */ +void write_config_regs(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Clears all status regster C flags except the CS FLT + * + * @param chips + */ +void write_clear_flags(cell_asic chips[NUM_CHIPS]); + +// --- END WRITE COMMANDS --- + +// --- BEGIN READ COMMANDS --- + +/** + * @brief Read all filtered voltage results. IIR must be on and ADC must be continous + * + * @param chips The chips to read voltages from + */ +void read_filtered_voltage_registers(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Read every register connected to the AUX ADC. + * + * @param chips Array of chips to get voltage readings of. + */ +void adc_and_read_aux_registers(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Read voltages in every register connected to AUX2 ADC. + * + * @param chips Array of chips to get voltages of. + */ +void adc_and_read_aux2_registers(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Read status registers. + * + * @param chips Array of chips to read. + */ +void read_status_registers(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Read status and aux registers in one command. + * + * @param chips Array of chips to read. + */ +void read_status_aux_registers(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Read the serial ID of the chip. + * + * @param chips Array of chips to read. + */ +void read_serial_id(cell_asic chips[NUM_CHIPS]); + +// --- END READ COMMANDS --- + +// --- BEGIN ADC POLL --- + +/** + * @brief Get voltage readings from the C-ADCs. Takes a single shot measurement. + * + * @param chips Array of chips to get voltage readings from. + */ +void get_c_adc_voltages(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Get voltages from the S-ADCs. Makes a single shot measurement. + * + * @param chip Array of chips to get voltage readings from. + */ +void get_s_adc_voltages(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Get the avgeraged cell voltages. + * + * @param chip Array of chips to get voltage readings of. + */ +void get_avgd_cell_voltages(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Get the filtered cell volrages. + * + * @param chip Array of chips to get voltage readings of. + */ +void get_filtered_cell_voltages(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Get the c and s adc voltages. Does this with RDCSALL command. + * + * @param chips Array of chips to get voltage readings of. + */ +void get_c_and_s_adc_voltages(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Starts a continous c ADC conversion with S redundancy + * + */ +void start_c_adc_conv(); + +// --- END ADC POLL --- diff --git a/Core/Inc/analyzer.h b/Core/Inc/analyzer.h index 0e9b0759..d89a1bbe 100644 --- a/Core/Inc/analyzer.h +++ b/Core/Inc/analyzer.h @@ -11,23 +11,6 @@ extern uint8_t THERM_DISABLE[NUM_CHIPS][NUM_THERMS_PER_CHIP]; extern const uint8_t NO_THERM; extern const uint8_t MUX_OFFSET; - -/** - * @brief Mapping the Relevant Thermistors for each cell based on cell # - * @note 0xFF indicates the end of the relevant therms - * @note Low side - */ -extern const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP] - [NUM_RELEVANT_THERMS]; - -/** - * @brief Mapping the Relevant Thermistors for each cell based on cell # - * @note 0xFF indicates the end of the relevant therms - * @note High side - */ -extern const uint8_t RELEVANT_THERM_MAP_H[NUM_CELLS_PER_CHIP] - [NUM_RELEVANT_THERMS]; - /* * List of therms that we actually read from, NOT reordered by cell */ @@ -44,6 +27,14 @@ extern const uint8_t POPULATED_THERM_LIST_H[NUM_THERMS_PER_CHIP]; //#define MAX_SIZE_OF_HIST_QUEUE 300000U //bytes +/** + * @brief Get the number of cells on a chip. + * + * @param chip_data Pointer to struct containing chip data. + * @return uint8_t The number of cells in the chip. + */ +uint8_t get_num_cells(chipdata_t *chip_data); + /** * @brief Calculate thermistor values and cell temps using thermistors. * diff --git a/Core/Inc/bmsConfig.h b/Core/Inc/bmsConfig.h index fa9049c3..96e8e425 100644 --- a/Core/Inc/bmsConfig.h +++ b/Core/Inc/bmsConfig.h @@ -1,12 +1,19 @@ #ifndef BMS_CONFIG_H #define BMS_CONFIG_H +#define DEBUG_MODE_ENABLED true +#define DEBUG_STATS + // Hardware definition -#define NUM_SEGMENTS 6 -#define NUM_CHIPS NUM_SEGMENTS * 2 -#define NUM_CELLS_PER_CHIP 10 -#define NUM_THERMS_PER_CHIP 32 -#define NUM_RELEVANT_THERMS 3 +#define NUM_SEGMENTS 1 +#define NUM_CHIPS 1 //NUM_SEGMENTS * 2 +#define NUM_CELLS_ALPHA 14 +#define NUM_CELLS_BETA 11 +#define NUM_CELLS_SEG NUM_CELLS_ALPHA + NUM_CELLS_BETA +#define NUM_CELLS \ + ((NUM_CELLS_ALPHA * (NUM_CHIPS / 2.0)) + \ + (NUM_CELLS_BETA * (NUM_CHIPS / 2.0))) +#define NUM_THERMS_PER_CHIP 14 // Firmware limits #define MAX_TEMP 65 //degrees C diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index fd679ab2..d197992c 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -39,9 +39,44 @@ #define NOISE_CANID 0x88 #define NOISE_SIZE 6 #define DEBUG_CANID 0x702 -#define DEBUG_SIZE 8 -#define FAULT_TIMER_CANID 0x6FF -#define FAULT_TIMER_SIZE 4 + +#define ALPHA_CELL_CANID 0x6FA +#define BETA_CELL_CANID 0x6FB +#define CELL_MSG_SIZE 7 +#define BETA_STAT_A_CANID 0x6FD +#define BETA_STAT_A_SIZE 8 +#define BETA_STAT_B_CANID 0x6FE +#define BETA_STAT_B_SIZE 8 +#define ALPHA_STAT_A_CANID 0x6FC +#define ALPHA_STAT_A_SIZE 7 +#define ALPHA_STAT_B_CANID 0x6FF +#define ALPHA_STAT_B_SIZE 7 + +typedef struct { + uint32_t prev_tick; + uint32_t msg_rate; /* in milliseconds */ +} rl_data_t; + +typedef enum { + CHARGE, + DISCHARGE, + ACC_STATUS, + BMS_STATUS, + SHUTDOWN_CTRL, + CELL_DATA, + CELL_VOLTAGE, + CURRENT, + CELL_TEMP, + SEGMENT_TEMP, + FAULT, + NOISE, + DEBUG, + RL_MSG_COUNT +} rate_lim_t; + +#define DEBUG_SIZE 8 +#define FAULT_TIMER_CANID 0x6FF +#define FAULT_TIMER_SIZE 4 void can_receive_callback(CAN_HandleTypeDef *hcan); diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index b0fee329..9620af90 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -149,22 +149,7 @@ void compute_send_shutdown_ctrl_message(uint8_t mpe_state); * * @return Returns a fault if we are not able to send */ -void compute_send_cell_data_message(acc_data_t *bmsdata); - -/** - * @brief sends cell voltage message - * - * @param cell_id - * @param instant_volt - * @param internal_res - * @param shunted - * @param open_voltage - * - * @return Returns a fault if we are not able to send - */ -void compute_send_cell_voltage_message(uint8_t cell_id, uint16_t instant_volt, - uint16_t internal_res, uint8_t shunted, - uint16_t open_voltage); +void compute_send_cell_voltage_message(acc_data_t *bmsdata); /** * @brief sends out the calculated values of currents @@ -215,4 +200,80 @@ void compute_send_debug_message(uint8_t debug0, uint8_t debug1, uint16_t debug2, */ void compute_send_voltage_noise_message(acc_data_t *bmsdata); +/** + * @brief Send a message containing cell data. + * + * @param alpha If this message contains alpha cell data. False sends a beta cell message. + * @param temperature Temperature in Celsius. Has a maximum value of 80 degrees celsius. + * @param voltage_a The voltage of cell A. + * @param voltage_b The voltage of cell B. + * @param chip_ID The chip ID. + * @param cell_a The number of cell A. + * @param cell_b The number of cell B. + * @param discharging_a The state of cell A while balancing. + * @param discharging_b The state of cell B while balancing. + */ +void compute_send_cell_data_message(bool alpha, uint16_t temperature, + uint16_t voltage_a, uint16_t voltage_b, + uint8_t chip_ID, uint8_t cell_a, + uint8_t cell_b, bool discharging_a, + bool discharging_b); + +/** + * @brief Send cell message containing Beta cell 10, the Beta onboard therm, the temperature of the ADBMS6830 die, and the voltage from V+ to V-. + * + * @param cell_temperature Temperature of Beta cell 10. + * @param voltage Voltage of Beta cell 10. + * @param discharging Whether or not the cell is discharging. + * @param chip The ID of the chip. + * @param segment_temperature The output of the onboard therm. + * @param die_temperature The temperature of the ADBMS6830 die. + * @param vpv The voltage from V+ to V-. + */ +void compute_send_beta_status_a_message(uint16_t cell_temperature, + uint16_t voltage, bool discharging, + uint8_t chip, + uint16_t segment_temperature, + uint16_t die_temperature, uint16_t vpv); + +/** + * @brief Send message containing ADBMS6830 diagnostic data. + * + * @param vref2 Second reference voltage for ADBMS6830. + * @param v_analog Analog power supply voltage. + * @param v_digital Digital power supply voltage. + * @param chip ID of the chip. + * @param v_res VREF2 across a resistor for open wire detection. + * @param vmv Voltage between S1N and V-. + */ +void compute_send_beta_status_b_message(uint16_t vref2, uint16_t v_analog, + uint16_t v_digital, uint8_t chip, + uint16_t v_res, uint16_t vmv); + +/** + * @brief Send message containing ADBMS6830 diagnostic data and onboard therm data. + * + * @param segment_temp Temperature reading from on-board therm. + * @param chip ID of the chip. + * @param die_temperature Temperature of the ADBOS6830 die. + * @param vpv The voltage from V+ to V-. + * @param vmv Voltage between S1N and V-. + */ +void compute_send_alpha_status_a_message(uint16_t segment_temp, uint8_t chip, + uint16_t die_temperature, uint16_t vpv, + uint16_t vmv); + +/** + * @brief Send message containing ADBMS6830 diagnostic data. + * + * @param v_res VREF2 across a resistor for open wire detection. + * @param chip ID of the chip. + * @param vref2 Second reference voltage for ADBMS6830. + * @param v_analog Analog power supply voltage. + * @param v_digital Digital power supply voltage. + */ +void compute_send_alpha_status_b_message(uint16_t v_res, uint8_t chip, + uint16_t vref2, uint16_t v_analog, + uint16_t v_digital); + #endif // COMPUTE_H diff --git a/Core/Inc/datastructs.h b/Core/Inc/datastructs.h index ed7869c1..781ab1de 100644 --- a/Core/Inc/datastructs.h +++ b/Core/Inc/datastructs.h @@ -6,29 +6,32 @@ #include "bmsConfig.h" #include "timer.h" #include "cmsis_os2.h" +#include "adBms6830Data.h" /** * @brief Individual chip data * @note stores thermistor values, voltage readings, and the discharge status */ typedef struct { - /* These are retrieved from the initial LTC comms */ - uint16_t voltage - [NUM_CELLS_PER_CHIP]; /* store voltage readings from each chip */ - int8_t thermistor_reading - [NUM_THERMS_PER_CHIP]; /* store all therm readings from each chip */ - int8_t thermistor_value[NUM_THERMS_PER_CHIP]; int error_reading; /* These are calculated during the analysis of data */ - int8_t cell_temp[NUM_CELLS_PER_CHIP]; - float cell_resistance[NUM_CELLS_PER_CHIP]; - uint16_t open_cell_voltage[NUM_CELLS_PER_CHIP]; + + /* Cell temperature in celsius */ + int8_t cell_temp[NUM_CELLS_ALPHA]; + float cell_resistance[NUM_CELLS_ALPHA]; + uint16_t open_cell_voltage[NUM_CELLS_ALPHA]; uint8_t noise_reading - [NUM_CELLS_PER_CHIP]; /* bool representing noise ignored read */ + [NUM_CELLS_ALPHA]; /* bool representing noise ignored read */ uint8_t consecutive_noise - [NUM_CELLS_PER_CHIP]; /* count representing consecutive noisy reads */ + [NUM_CELLS_ALPHA]; /* count representing consecutive noisy reads */ + + /* True if chip is alpha, False if Chip is Beta */ + bool alpha; + + /* For temperatures of on-board therms. Length 1 if Alpha, length 2 if Beta. */ + int8_t on_board_temp; } chipdata_t; /** @@ -82,9 +85,14 @@ typedef struct { #define ACCUMULATOR_FRAME_SIZE sizeof(acc_data_t); typedef struct { + /* chip_data and chips are parallel arrays. */ + /* Array of data from all chips in the system */ chipdata_t chip_data[NUM_CHIPS]; + /* Array of structs containing raw data from and configurations for the ADBMS6830 chips */ + cell_asic chips[NUM_CHIPS]; + int fault_status; // FIXME: this field is unused int16_t pack_current; /* this value is multiplied by 10 to account for decimal precision */ diff --git a/Core/Inc/segment.h b/Core/Inc/segment.h index 607259d5..5f899a74 100644 --- a/Core/Inc/segment.h +++ b/Core/Inc/segment.h @@ -1,63 +1,81 @@ #ifndef SEGMENT_H #define SEGMENT_H -#include "ltc68041.h" #include "bmsConfig.h" #include "datastructs.h" /** * @brief Initializes the segments */ -void segment_init(); +void segment_init(acc_data_t *bmsdata); /** * @brief Pulls all cell data from the segments and returns all cell data * - * @todo make sure that retrieving cell data doesn't block code too much */ -void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]); +void segment_retrieve_data(acc_data_t *bmsdata); /** - * @brief Enables/disables balancing for all cells - * - * @param balance_enable + * @brief Fetch extra data for segment + * */ -void segment_enable_balancing(bool balance_enable); +void segment_retrieve_debug_data(acc_data_t *bmsdata); /** - * @brief Enables/disables balancing for a specific cell + * @brief Disables balancing for all cells. * - * @param chip_num - * @param cell_num - * @param balance_enable + * @param chips Array of ADBMS6830 data structs. */ -void cell_enable_balancing(uint8_t chip_num, uint8_t cell_num, - bool balance_enable); +void segment_disable_balancing(acc_data_t *bmsdata); /** - * @brief Sets each cell to whatever state is passed in the boolean config area - * - * @param discharge_config + * @brief Configure which cells should discharge, and send configuration to ICs. + * + * @param bmsdata Pointer to acc data struct. + * @param discharge_config Array containing the discharge configuration. true = discharge, false = do not discharge. */ void segment_configure_balancing( - bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP]); + acc_data_t *bmsdata, bool discharge_config[NUM_CHIPS][NUM_CELLS_ALPHA]); /** - * @brief Returns if a specific cell is balancing - * - * @param chip_num - * @return true - * @return false + * @brief Returns if any cells are balancing. + * + * @param chips Array of ADBMS6830 chips. + * @return true + * @return false */ -bool cell_is_balancing(uint8_t chip_num, uint8_t cell_num); +bool segment_is_balancing(cell_asic chips[NUM_CHIPS]); /** - * @brief Returns if any cells are balancing - * @todo This should just be a state variable -Scott - * - * @return true - * @return false + * @brief Reset, then wake, then re-configure all chips + * + * @param bmsdata + */ +void segment_restart(acc_data_t *bmsdata); + +/** + * @brief Do a single shot, redundant C-ADC measurement and read + * the contents of Status Register Group C, which contains the + * CSxFLT bits indicating whether the difference between the + * C and S ADC measurements was above the CTH[2:0] set in config + * register A. + * + * @param chips Pointer to accumulator data struct. + */ +void get_adc_comparison(acc_data_t *bmsdata); + +/** + * @brief Read the serial ID of the chip. + * + * @param chips Array of chips to read. + */ +void read_serial_id(cell_asic chips[NUM_CHIPS]); + +/** + * @brief Read voltages in every register connected to AUX2 ADC. + * + * @param chips Array of chips to get voltages of. */ -bool segment_is_balancing(); +void adc_and_read_aux2_registers(cell_asic chips[NUM_CHIPS]); #endif \ No newline at end of file diff --git a/Core/Inc/shep_tasks.h b/Core/Inc/shep_tasks.h index 6b9510be..da18dccd 100644 --- a/Core/Inc/shep_tasks.h +++ b/Core/Inc/shep_tasks.h @@ -49,4 +49,13 @@ void vStateMachine(void *pv_params); extern osThreadId_t state_machine_thread; extern const osThreadAttr_t state_machine_attrs; +/** + * @brief Task that handles all BMS debug mode functionalities. + * + * @param pv_params Pointer to accumulator data struct. + */ +void vDebugMode(void *pv_params); +extern osThreadId_t debug_mode_thread; +extern const osThreadAttr_t debug_mode_attrs; + #endif diff --git a/Core/Inc/stm32f4xx_hal_conf.h b/Core/Inc/stm32f4xx_hal_conf.h index e28f8b19..caa25296 100644 --- a/Core/Inc/stm32f4xx_hal_conf.h +++ b/Core/Inc/stm32f4xx_hal_conf.h @@ -214,7 +214,7 @@ #define MAC_ADDR5 0U /* Definition of the Ethernet driver buffers size and count */ -#define ETH_RX_BUF_SIZE /* buffer size for receive */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ #define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ #define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 086b3951..4f9096b1 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -52,9 +52,9 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); -void SysTick_Handler(void); void DMA1_Stream4_IRQHandler(void); void CAN1_RX0_IRQHandler(void); +void TIM3_IRQHandler(void); void UART4_IRQHandler(void); void DMA2_Stream0_IRQHandler(void); void DMA2_Stream2_IRQHandler(void); diff --git a/Core/Src/adi_interaction.c b/Core/Src/adi_interaction.c new file mode 100644 index 00000000..e7b321a1 --- /dev/null +++ b/Core/Src/adi_interaction.c @@ -0,0 +1,382 @@ +#include "adi_interaction.h" +#include "adBms6830CmdList.h" +#include "adBms6830GenericType.h" +#include "mcuWrapper.h" + +/** + * @brief Set a bit in a uint16 + * + * @param number uint16 to change. + * @param n Nth bit to change. + * @param x true sets, false clears. + * @return uint16_t New uint16. + */ +inline uint16_t set_uint16_bit(uint16_t number, uint16_t n, bool x) +{ + return (number & ~((uint16_t)1 << n)) | ((uint16_t)x << n); +} + +// --- BEGIN SET HELPERS --- + +void set_REFON(cell_asic *chip, REFON state) +{ + chip->tx_cfga.refon = state; +} + +void set_volt_adc_comp_thresh(cell_asic *chip, CTH threshold) +{ + chip->tx_cfga.cth = threshold; +} + +void set_diagnostic_flags(cell_asic *chip, FLAG_D config) +{ + chip->tx_cfga.flag_d = + (uint8_t)set_uint16_bit(chip->tx_cfga.flag_d, config, true); +} + +void set_cell_discharge(cell_asic *chip, uint8_t cell, bool discharge) +{ + chip->tx_cfgb.dcc = set_uint16_bit(chip->tx_cfgb.dcc, cell, discharge); +} + +void set_soak_on(cell_asic *chip, SOAKON state) +{ + chip->tx_cfga.soakon = state; +} + +void set_aux_soak_range(cell_asic *chip, OWRNG range) +{ + chip->tx_cfga.owrng = range; +} + +void set_open_wire_soak_time(cell_asic *chip, OWA time) +{ + chip->tx_cfga.owa = time; +} + +void set_gpio_pull(cell_asic *chip, uint8_t gpio, bool input) +{ + if (gpio > 10 || gpio < 1) { + printf("ERROR: Invalid GPIO pin %d\n", gpio); + return; + } + chip->tx_cfga.gpo = set_uint16_bit(chip->tx_cfga.gpo, gpio - 1, input); +} + +void set_iir_corner_freq(cell_asic *chip, IIR_FPA freq) +{ + chip->tx_cfga.fc = freq; +} + +void set_comm_break(cell_asic *chip, bool is_break) +{ + chip->tx_cfga.comm_bk = is_break; +} + +void set_mute_state(cell_asic *chip, bool disable_discharge) +{ + chip->tx_cfga.mute_st = disable_discharge; +} + +void set_snapshot(cell_asic *chip, bool take_snapshot) +{ + chip->tx_cfga.snap = take_snapshot; +} + +void set_discharge_timer_monitor(cell_asic *chip, bool enabled) +{ + chip->tx_cfgb.dtmen = enabled; +} + +void set_discharge_timer_range(cell_asic *chip, bool large) +{ + chip->tx_cfgb.dtrng = large; +} + +void set_discharge_timeout(cell_asic *chip, uint8_t timeout) +{ + if (timeout >> 6 > 0) { + printf("Invalid discharge time\n"); + return; + // TODO: Non-critical fault + } + chip->tx_cfgb.dcto = timeout; +} + +// --- END SET HELPERS --- + +// void start_cell_voltages_adc(cell_asic chips[NUM_CHIPS]) +// { +// adbms_wake_isospi(); +// adBms6830_Adcv(RD_ON, CONTINUOUS, DCP_OFF, RSTF_OFF, OW_OFF_ALL_CH); +// adBmsPollAdc(PLCADC); +// } + +// --- BEGIN RW --- + +extern TIM_HandleTypeDef htim2; + +/** + * @brief Delays a certain number of microseconds + * + * Approximately +50% error as seen in logic analyzer + * + * @param us the number of us to delay + */ +inline void delay_us(uint16_t us) +{ + uint16_t tickstart = __HAL_TIM_GET_COUNTER(&htim2); + uint16_t wait = us; + + while ((__HAL_TIM_GET_COUNTER(&htim2) - tickstart) < wait) { + } +} + +/** + * @brief Wake the isoSPI of every ADBMS6830 IC in the daisy chain. Blocking wait for around 30us * NUM_CHIPS. + * + */ +void adbms_wake_isospi() +{ + for (uint8_t ic = 0; ic < NUM_CHIPS; ic++) { + adBmsCsLow(); + adBmsCsHigh(); + delay_us(20); + } +} + +/** + * @brief Wake the chip of every ADBMS6830 IC. Blocking wait about 1ms * NUM_CHIPS + * + */ +void adbms_wake_core() +{ + for (uint8_t ic = 0; ic < NUM_CHIPS; ic++) { + adBmsCsLow(); + adBmsCsHigh(); + delay_us(1000); + } +} + +/** + * @brief Write data to all chips. + * + * @param chip Array of chips to write data to. + * @param command Command to issue to the chip. + * @param type Register type to write to. + * @param group Group of registers to write to. + */ +void write_adbms_data(cell_asic chips[NUM_CHIPS], uint8_t command[2], TYPE type, + GRP group) +{ + adbms_wake_isospi(); + + for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { + adBmsWriteData(NUM_CHIPS, &chips[chip], command, type, group); + } +} + +/** + * @brief Read data from all chips. + * + * @param chips Array of chips to read data to. + * @param command Command to issue to the chip. + * @param type Register type to write to. + * @param group Group of registers to write to. + */ +void read_adbms_data(cell_asic chips[NUM_CHIPS], uint8_t command[2], TYPE type, + GRP group) +{ + adbms_wake_isospi(); + + for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { + adBmsReadData(NUM_CHIPS, &chips[chip], command, type, group); + } + + // Count PEC errors + uint32_t pec_error_count = 0; + for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { + // Yes, they did separate every PEC as if that mattered. + pec_error_count += + chips[chip].cccrc.cfgr_pec + chips[chip].cccrc.sid_pec + + chips[chip].cccrc.cell_pec + + chips[chip].cccrc.acell_pec + + chips[chip].cccrc.scell_pec + + chips[chip].cccrc.fcell_pec + + chips[chip].cccrc.aux_pec + chips[chip].cccrc.raux_pec + + chips[chip].cccrc.stat_pec + + chips[chip].cccrc.comm_pec + chips[chip].cccrc.pwm_pec; + + if (pec_error_count > 0) { + printf("PEC COUNT: %ld | Chip: %d | CMD: %d\n", + pec_error_count, chip, type); + } + + chips[chip].cccrc.cfgr_pec = 0; + chips[chip].cccrc.sid_pec = 0; + chips[chip].cccrc.cell_pec = 0; + chips[chip].cccrc.acell_pec = 0; + chips[chip].cccrc.scell_pec = 0; + chips[chip].cccrc.fcell_pec = 0; + chips[chip].cccrc.aux_pec = 0; + chips[chip].cccrc.raux_pec = 0; + chips[chip].cccrc.stat_pec = 0; + chips[chip].cccrc.comm_pec = 0; + chips[chip].cccrc.pwm_pec = 0; + } + pec_error_count = 0; +} + +// --- BEGIN WRITE COMMANDS --- + +void soft_reset_chips(cell_asic chips[NUM_CHIPS]) +{ + write_adbms_data(chips, SRST, Comm, NONE); + adbms_wake_core(); +} + +void write_config_regs(cell_asic chips[NUM_CHIPS]) +{ + write_adbms_data(chips, WRCFGA, Config, A); + write_adbms_data(chips, WRCFGB, Config, B); +} + +void write_clear_flags(cell_asic chips[NUM_CHIPS]) +{ + for (int chip = 0; chip < NUM_CHIPS; chip++) { + chips[chip].clflag.cl_sleep = 1; + chips[chip].clflag.cl_smed = 1; + chips[chip].clflag.cl_sed = 1; + chips[chip].clflag.cl_cmed = 1; + chips[chip].clflag.cl_ced = 1; + chips[chip].clflag.cl_vduv = 1; + chips[chip].clflag.cl_vdov = 1; + chips[chip].clflag.cl_vauv = 1; + chips[chip].clflag.cl_vaov = 1; + chips[chip].clflag.cl_oscchk = 1; + chips[chip].clflag.cl_tmode = 1; + chips[chip].clflag.cl_thsd = 1; + chips[chip].clflag.cl_sleep = 1; + chips[chip].clflag.cl_spiflt = 1; + chips[chip].clflag.cl_vdel = 1; + chips[chip].clflag.cl_vde = 1; + } + write_adbms_data(chips, CLRFLAG, Clrflag, NONE); +} + +// --- END WRITE COMMANDS + +// --- BEGIN READ COMMANDS --- + +void read_filtered_voltage_registers(cell_asic chips[NUM_CHIPS]) +{ + read_adbms_data(chips, RDFCALL, Rdfcall, ALL_GRP); +} + +void adc_and_read_aux_registers(cell_asic chips[NUM_CHIPS]) +{ + // TODO only poll correct GPIOs + adbms_wake_isospi(); + adBms6830_Adax(AUX_OW_OFF, PUP_DOWN, AUX_ALL); + adBmsPollAdc(PLAUX2); + + read_adbms_data(chips, RDAUXA, Aux, A); + read_adbms_data(chips, RDAUXB, Aux, B); + read_adbms_data(chips, RDAUXC, Aux, C); + read_adbms_data(chips, RDAUXD, Aux, D); +} + +void adc_and_read_aux2_registers(cell_asic chips[NUM_CHIPS]) +{ + adbms_wake_isospi(); + adBms6830_Adax2(AUX_ALL); + adBmsPollAdc(PLAUX2); + + read_adbms_data(chips, RDRAXA, RAux, A); + read_adbms_data(chips, RDRAXB, RAux, B); + read_adbms_data(chips, RDRAXC, RAux, C); + read_adbms_data(chips, RDRAXD, RAux, D); +} + +void read_status_registers(cell_asic chips[NUM_CHIPS]) +{ + read_adbms_data(chips, RDSTATA, Status, A); + read_adbms_data(chips, RDSTATB, Status, B); + read_adbms_data(chips, RDSTATC, Status, C); + read_adbms_data(chips, RDSTATD, Status, D); + read_adbms_data(chips, RDSTATE, Status, E); +} + +void read_status_aux_registers(cell_asic chips[NUM_CHIPS]) +{ + read_adbms_data(chips, RDASALL, Rdasall, ALL_GRP); +} + +void read_serial_id(cell_asic chips[NUM_CHIPS]) +{ + read_adbms_data(chips, RDSID, Sid, NONE); +} + +// --- END READ COMMANDS --- + +// --- BEGIN ADC POLL --- + +void get_c_adc_voltages(cell_asic chips[NUM_CHIPS]) +{ + adbms_wake_isospi(); + // Take single shot measurement + adBms6830_Adcv(RD_OFF, SINGLE, DCP_OFF, RSTF_OFF, OW_OFF_ALL_CH); + adBmsPollAdc(PLCADC); + read_adbms_data(chips, RDCVALL, Rdcvall, ALL_GRP); +} + +void get_s_adc_voltages(cell_asic chips[NUM_CHIPS]) +{ + write_config_regs(chips); + adbms_wake_isospi(); + adBms6830_Adsv(SINGLE, DCP_OFF, OW_OFF_ALL_CH); + adBmsPollAdc(PLSADC); + + adbms_wake_isospi(); + read_adbms_data(chips, RDSALL, Rdsall, ALL_GRP); + // read_adbms_data(chip, RDSVA, S_volt, A); + // read_adbms_data(chip, RDSVB, S_volt, B); + // read_adbms_data(chip, RDSVC, S_volt, C); + // read_adbms_data(chip, RDSVD, S_volt, D); + // read_adbms_data(chip, RDSVE, S_volt, E); + // read_adbms_data(chip, RDSVF, S_volt, F); +} + +void get_avgd_cell_voltages(cell_asic chips[NUM_CHIPS]) +{ + adbms_wake_isospi(); + adBms6830_Adcv(RD_ON, CONTINUOUS, DCP_OFF, RSTF_OFF, OW_OFF_ALL_CH); + adBmsPollAdc(PLCADC); + + adbms_wake_isospi(); + read_adbms_data(chips, RDACALL, Rdacall, ALL_GRP); +} + +void get_filtered_cell_voltages(cell_asic chips[NUM_CHIPS]) +{ + adbms_wake_isospi(); + read_adbms_data(chips, RDFCALL, Rdfcall, ALL_GRP); +} + +void get_c_and_s_adc_voltages(cell_asic chips[NUM_CHIPS]) +{ + adbms_wake_isospi(); + adBms6830_Adcv(RD_ON, CONTINUOUS, DCP_OFF, RSTF_OFF, OW_OFF_ALL_CH); + adBmsPollAdc(PLCADC); + + adbms_wake_isospi(); + read_adbms_data(chips, RDCSALL, Rdcsall, ALL_GRP); +} + +void start_c_adc_conv() +{ + adbms_wake_isospi(); + adBms6830_Adcv(RD_ON, CONTINUOUS, DCP_OFF, RSTF_ON, OW_OFF_ALL_CH); +} + +// --- END ADC POLL --- diff --git a/Core/Src/analyzer.c b/Core/Src/analyzer.c index c0509b42..4ef2bc46 100644 --- a/Core/Src/analyzer.c +++ b/Core/Src/analyzer.c @@ -2,10 +2,37 @@ #include #include +#include #include "compute.h" +#include "serialPrintResult.h" + +#define GPIO1 0 +#define GPIO2 1 +#define GPIO3 2 +#define GPIO4 3 +#define GPIO5 4 +#define GPIO6 5 +#define GPIO7 6 +#define GPIO8 7 +#define GPIO9 8 +#define GPIO10 9 + +typedef enum { + THERM1 = 0, + THERM2, + THERM3, + THERM4, + THERM5, + THERM6, + THERM7 +} THERM; + // clang-format off + +//TODO: CHANGE ALL FOR NEW CELLS + /** * @brief Mapping Cell temperature to the cell resistance based on the * nominal cell resistance curve profile of the Samsung 186500 INR in the @@ -66,6 +93,8 @@ const uint8_t STATE_OF_CHARGE_CURVE[18] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 24, 56, 74, 85, 95, 98, 100 }; +// END TODO + /** * @brief Mapping desired fan speed PWM to the cell temperature * @@ -83,109 +112,93 @@ const uint8_t NO_THERM = 0xFF; const uint8_t MUX_OFFSET = 16; /** - * @brief Mapping the Relevant Thermistors for each cell based on cell # - * @note 0xFF indicates the end of the relevant therms - * @note High side + * @brief Map cells to therms. + * */ -const uint8_t RELEVANT_THERM_MAP_H[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS] = +const THERM THERM_MAP[NUM_CELLS_ALPHA] = { - {5, 3, NO_THERM}, - {12 + MUX_OFFSET, 14 + MUX_OFFSET, NO_THERM}, - {2, 0, 1}, - {9 + MUX_OFFSET, 11 + MUX_OFFSET, NO_THERM}, - {8, 6, NO_THERM}, - {0 + MUX_OFFSET, 2 + MUX_OFFSET, NO_THERM}, - {12, 14, 13}, - {3 + MUX_OFFSET, 5 + MUX_OFFSET, NO_THERM}, - {11, 9, NO_THERM}, - {6 + MUX_OFFSET, 8 + MUX_OFFSET, NO_THERM}, + THERM1, + THERM1, + THERM2, + THERM2, + THERM3, + THERM3, + THERM4, + THERM4, + THERM5, + THERM5, + THERM6, + THERM6, + THERM7, + THERM7 }; -/** - * @brief Mapping the Relevant Thermistors for each cell based on cell # - * @note 0xFF indicates the end of the relevant therms - * @note Low side - */ -const uint8_t RELEVANT_THERM_MAP_L[NUM_CELLS_PER_CHIP][NUM_RELEVANT_THERMS] = -{ - {5, 3, 4}, - {12 + MUX_OFFSET, 14 + MUX_OFFSET, NO_THERM}, - {2, 0, NO_THERM}, - {11 + MUX_OFFSET, 9 + MUX_OFFSET, NO_THERM}, - {6, 7, 8}, - {0 + MUX_OFFSET, 2 + MUX_OFFSET, NO_THERM}, - {14, 12, NO_THERM}, - {5 + MUX_OFFSET, 3 + MUX_OFFSET, NO_THERM}, - {9, 10, 11}, - {6 + MUX_OFFSET, 8 + MUX_OFFSET, NO_THERM}, -}; +// clang-format on + +nertimer_t analysisTimer; +nertimer_t ocvTimer; -uint8_t THERM_DISABLE[NUM_CHIPS][NUM_THERMS_PER_CHIP] = +bool is_first_reading_ = true; + +uint8_t get_num_cells(chipdata_t *chip_data) { - {1,0,1,0,0,1,0,1,1,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,1,0 }, - {1,0,1,0,0,1,0,0,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1 }, - {1,0,1,0,0,1,0,0,1,0,0,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0 }, - {1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,0,0,0,1,1,1,0,1,0,0,1,0,0,0,0 }, - {1,0,1,0,0,1,0,1,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1 }, - {1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0 }, - {1,0,1,0,0,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,0,0,0,0,0,1,0 }, - {1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,1,1,1,1,1 }, - {1,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0 }, - {1,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0 }, - {1,1,1,0,0,1,0,0,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0 }, - {1,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0 } -}; + if (chip_data->alpha) { + return NUM_CELLS_ALPHA; + } else { + return NUM_CELLS_BETA; + } +} -/* - * List of therms that we actually read from, NOT reordered by cell +/** + * @brief Calculate a cell temperature based on the thermistor reading. + * + * @param x The thremistor reading. + * @return int8_t Temperature in celsius. */ -const uint8_t POPULATED_THERM_LIST_H[NUM_THERMS_PER_CHIP] = +int8_t calc_cell_temp(uint16_t x) { - true, false, true, - true, true, true, - true, true, true, - true, true, true, - true, false, true, false, - true, false, true, - true, false, true, - true, false, true, - true, false, true, - true, false, true, false -}; + /* Polynomial fit of temperatures -7 -> 65 celsius vs. thermistor voltage. */ + return 0.6984 * pow(x, 4) + 4.4933 * pow(x, 3) - 10.278 * pow(x, 2) + + 34.184 * x + 2.7608; +} -const uint8_t POPULATED_THERM_LIST_L[NUM_THERMS_PER_CHIP] = +void calc_cell_temps(acc_data_t *bmsdata) { - true, true, true, - true, false, true, - true, false, true, - true, false, true, - true, true, true, false, - true, false, true, - true, false, true, - true, false, true, - true, false, true, - true, false, true, false -}; + for (int chip = 0; chip < NUM_CHIPS; chip++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[chip]); -/** - * @brief Selecting thermistors to ignore - * - * @note True / 1 will disable the thermistor - * @note disabling both unpopulaed (see above) and populated but bad cells ( not great permanent solution) - */ + for (int cell = 0; cell < num_cells; cell++) { + int16_t x = bmsdata->chips[chip] + .raux.ra_codes[THERM_MAP[cell]]; -// clang-format on + bmsdata->chip_data[chip].cell_temp[cell] = + calc_cell_temp(x); + } -nertimer_t analysisTimer; -nertimer_t ocvTimer; + // Calculate onboard therm temps + + if (!bmsdata->chip_data[chip].alpha) { + // Take average of both onboard therms + bmsdata->chip_data[chip].on_board_temp = + (calc_cell_temp((bmsdata->chips[chip] + .raux.ra_codes[6])) + + calc_cell_temp(bmsdata->chips[chip] + .raux.ra_codes[7])) / + 2; + } else { + bmsdata->chip_data[chip].on_board_temp = calc_cell_temp( + bmsdata->chips[chip].raux.ra_codes[7]); + } + } -bool is_first_reading_ = true; + /* + -/* we are not corrctly mapping each therm reading to the correct cell. So, we are taking the average of all good readings (not disabled) for a given chip, - and assigning that to be the cell val for every cell in the chip*/ + 22A CODE FOR REFERENCE + + //we are not corrctly mapping each therm reading to the correct cell. So, we are taking the average of all good readings (not disabled) for a given chip, + //and assigning that to be the cell val for every cell in the chip -void calc_cell_temps(acc_data_t *bmsdata) -{ for (uint8_t c = 0; c < NUM_CHIPS; c++) { for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { const uint8_t(*therm_map)[NUM_RELEVANT_THERMS] = @@ -206,12 +219,12 @@ void calc_cell_temps(acc_data_t *bmsdata) } } //printf("\r\n"); - /* Takes the average temperature of all the relevant thermistors */ - bmsdata->chip_data[c].cell_temp[cell] = - temp_sum / therm_count; + + // Takes the average temperature of all the relevant thermistors + bmsdata->chip_data[c].cell_temp[cell] = temp_sum / therm_count; therm_count = 0; - } } + */ } void calc_pack_temps(acc_data_t *bmsdata) @@ -223,44 +236,14 @@ void calc_pack_temps(acc_data_t *bmsdata) bmsdata->min_temp.val = MAX_TEMP; bmsdata->min_temp.cellNum = 0; bmsdata->min_temp.chipIndex = 0; + int total_temp = 0; int total_seg_temp = 0; - int total_accepted = 0; - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) { - /* finds out the maximum cell temp and location */ - - //if (THERM_DISABLE[c][therm]) continue; - total_accepted++; - //if (bmsdata->chip_data[c].thermistor_value[therm] > bmsdata->max_temp.val) { - // bmsdata->max_temp.val = bmsdata->chip_data[c].thermistor_value[therm]; - // bmsdata->max_temp.cellNum = c; - // bmsdata->max_temp.chipIndex = therm; - //} - - /* finds out the minimum cell temp and location */ - //if (bmsdata->chip_data[c].thermistor_value[therm] < bmsdata->min_temp.val) { - // bmsdata->min_temp.val = bmsdata->chip_data[c].thermistor_value[therm]; - // bmsdata->min_temp.cellNum = c; - // bmsdata->min_temp.chipIndex = therm; - //} - - total_temp += - bmsdata->chip_data[c].thermistor_value[therm]; - total_seg_temp += - bmsdata->chip_data[c].thermistor_value[therm]; - } - - /* only for NERO */ - if (c % 2 == 0) { - bmsdata->segment_average_temps[c / 2] = - total_seg_temp / 22; - total_seg_temp = 0; - } - } for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[c]); + + for (uint8_t cell = 0; cell < num_cells; cell++) { if (bmsdata->chip_data[c].cell_temp[cell] > bmsdata->max_temp.val) { bmsdata->max_temp.val = @@ -277,11 +260,21 @@ void calc_pack_temps(acc_data_t *bmsdata) bmsdata->min_temp.cellNum = cell; bmsdata->min_temp.chipIndex = c; } + + total_temp += bmsdata->chip_data[c].cell_temp[cell]; + total_seg_temp += bmsdata->chip_data[c].cell_temp[cell]; + } + /* only for NERO */ + if (c % 2 == 0) { + bmsdata->segment_average_temps[c / 2] = + total_seg_temp / + (NUM_CELLS_ALPHA + NUM_CELLS_BETA); + total_seg_temp = 0; } } - /* takes the average of all the cell temperatures */ - bmsdata->avg_temp = total_temp / (total_accepted); + /* Takes the average of all the cell temperatures. */ + bmsdata->avg_temp = total_temp / NUM_CELLS; compute_send_cell_temp_message(bmsdata); } @@ -304,16 +297,21 @@ void calc_pack_voltage_stats(acc_data_t *bmsdata) bmsdata->min_ocv.cellNum = 0; bmsdata->min_ocv.chipIndex = 0; - uint32_t total_volt = 0; - uint32_t total_ocv = 0; + float total_volt = 0; + float total_ocv = 0; for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[c]); + for (uint8_t cell = 0; cell < num_cells; cell++) { /* fings out the maximum cell voltage and location */ - if (bmsdata->chip_data[c].voltage[cell] > + if (getVoltage(bmsdata->chips[c].fcell.fc_codes[cell]) * + 10000 > bmsdata->max_voltage.val) { bmsdata->max_voltage.val = - bmsdata->chip_data[c].voltage[cell]; + getVoltage( + bmsdata->chips[c] + .fcell.fc_codes[cell]) * + 10000; bmsdata->max_voltage.chipIndex = c; bmsdata->max_voltage.cellNum = cell; } @@ -328,10 +326,14 @@ void calc_pack_voltage_stats(acc_data_t *bmsdata) } /* finds out the minimum cell voltage and location */ - if (bmsdata->chip_data[c].voltage[cell] < + if (getVoltage(bmsdata->chips[c].fcell.fc_codes[cell]) * + 10000 < bmsdata->min_voltage.val) { bmsdata->min_voltage.val = - bmsdata->chip_data[c].voltage[cell]; + getVoltage( + bmsdata->chips[c] + .fcell.fc_codes[cell]) * + 10000; bmsdata->min_voltage.chipIndex = c; bmsdata->min_voltage.cellNum = cell; } @@ -345,30 +347,36 @@ void calc_pack_voltage_stats(acc_data_t *bmsdata) bmsdata->min_ocv.cellNum = cell; } - total_volt += bmsdata->chip_data[c].voltage[cell]; + total_volt += getVoltage( + bmsdata->chips[c].fcell.fc_codes[cell]); total_ocv += bmsdata->chip_data[c].open_cell_voltage[cell]; } } /* calculate some voltage stats */ - bmsdata->avg_voltage = total_volt / (NUM_CELLS_PER_CHIP * NUM_CHIPS); - bmsdata->pack_voltage = total_volt / 1000; /* convert to voltage * 10 */ + // TODO: Make this based on total cells when actual segment is here + bmsdata->avg_voltage = (total_volt * 10000) / 16; + + bmsdata->pack_voltage = total_volt * 10; /* convert to voltage * 10 */ + bmsdata->delt_voltage = bmsdata->max_voltage.val - bmsdata->min_voltage.val; - bmsdata->avg_ocv = total_ocv / (NUM_CELLS_PER_CHIP * NUM_CHIPS); + bmsdata->avg_ocv = total_ocv / NUM_CELLS; bmsdata->pack_ocv = total_ocv / 1000; /* convert to voltage * 10 */ bmsdata->delt_ocv = bmsdata->max_ocv.val - bmsdata->min_ocv.val; compute_send_acc_status_message(bmsdata); - compute_send_cell_data_message(bmsdata); + compute_send_cell_voltage_message(bmsdata); } void calc_cell_resistances(acc_data_t *bmsdata) { for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[c]); + + for (uint8_t cell = 0; cell < num_cells; cell++) { uint8_t cell_temp = bmsdata->chip_data[c].cell_temp[cell]; @@ -392,6 +400,7 @@ void calc_cell_resistances(acc_data_t *bmsdata) } } +// TODO: Change to match P45Bs. void calc_dcl(acc_data_t *bmsdata) { static nertimer_t dcl_timer; @@ -401,7 +410,8 @@ void calc_dcl(acc_data_t *bmsdata) int16_t current_limit = 0x7FFF; for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[c]); + for (uint8_t cell = 0; cell < num_cells; cell++) { /* Apply equation */ /* Multiplying resistance by 10 to convert from mOhm to Ohm and then to Ohm * 10000 to * account for the voltage units */ @@ -463,6 +473,7 @@ void calc_dcl(acc_data_t *bmsdata) compute_send_current_message(bmsdata); } +//TODO: Fix for new cells and BMS void calc_cont_dcl(acc_data_t *bmsdata) { uint8_t min_res_index = @@ -477,12 +488,14 @@ void calc_cont_dcl(acc_data_t *bmsdata) } } +//TODO: Change for P45B electrical characteristics. void calcCCL(acc_data_t *bmsdata) { int16_t currentLimit = 0x7FFF; for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[c]); + for (uint8_t cell = 0; cell < num_cells; cell++) { /* Apply equation */ uint16_t tmpCCL = ((MAX_VOLT * 10000) - @@ -510,6 +523,7 @@ void calcCCL(acc_data_t *bmsdata) compute_send_current_message(bmsdata); } +//TODO: Change for P45B electrical characteristics. void calc_cont_ccl(acc_data_t *bmsdata) { uint8_t min_res_index = @@ -528,6 +542,8 @@ void calc_cont_ccl(acc_data_t *bmsdata) } } +//TODO: Make it actually calc OCVs. Revise algorithm and stuff. +//TODO: Change for new cells (probs not needed). void calc_open_cell_voltage(acc_data_t *bmsdata) { static chipdata_t prev_chipdata[12]; @@ -535,13 +551,16 @@ void calc_open_cell_voltage(acc_data_t *bmsdata) /* if there is no previous data point, set inital open cell voltage to current reading */ if (is_first_reading_) { for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; - cell++) { + uint8_t num_cells = + get_num_cells(&bmsdata->chip_data[chip]); + for (uint8_t cell = 0; cell < num_cells; cell++) { bmsdata->chip_data[chip] .open_cell_voltage[cell] = - bmsdata->chip_data[chip].voltage[cell]; + bmsdata->chips[chip] + .fcell.fc_codes[cell]; prev_chipdata[chip].open_cell_voltage[cell] = - bmsdata->chip_data[chip].voltage[cell]; + bmsdata->chips[chip] + .fcell.fc_codes[cell]; } } return; @@ -552,21 +571,24 @@ void calc_open_cell_voltage(acc_data_t *bmsdata) if (is_timer_expired(&ocvTimer) || !is_timer_active(&ocvTimer)) { for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { - for (uint8_t cell = 0; - cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells( + &bmsdata->chip_data[chip]); + for (uint8_t cell = 0; cell < num_cells; + cell++) { /* Sets open cell voltage to a moving average of OCV_AVG values */ bmsdata->chip_data[chip] .open_cell_voltage[cell] = - ((uint32_t)(bmsdata->chip_data[chip] - .voltage[cell]) + + ((uint32_t)(bmsdata->chips[chip] + .fcell + .fc_codes[cell]) + ((uint32_t)(prev_chipdata[chip].open_cell_voltage [cell]) * (OCV_AVG - 1))) / OCV_AVG; bmsdata->chip_data[chip] .open_cell_voltage[cell] = - bmsdata->chip_data[chip] - .voltage[cell]; + bmsdata->chips[chip] + .fcell.fc_codes[cell]; if (bmsdata->chip_data[chip] .open_cell_voltage[cell] > @@ -594,7 +616,8 @@ void calc_open_cell_voltage(acc_data_t *bmsdata) start_timer(&ocvTimer, 1000); } for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[chip]); + for (uint8_t cell = 0; cell < num_cells; cell++) { /* Set OCV to the previous/existing OCV */ bmsdata->chip_data[chip].open_cell_voltage[cell] = prev_chipdata[chip].open_cell_voltage[cell]; @@ -602,6 +625,7 @@ void calc_open_cell_voltage(acc_data_t *bmsdata) } } +//TODO: Change for new fans and cell temps uint8_t analyzer_calc_fan_pwm(acc_data_t *bmsdata) { /* Resistance LUT increments by 5C for each index, plus we account for negative minimum */ @@ -618,30 +642,33 @@ uint8_t analyzer_calc_fan_pwm(acc_data_t *bmsdata) (2 * 5); } -void disable_therms(acc_data_t *bmsdata) -{ - int8_t tmp_temp = - 25; /* Iniitalize to room temp (necessary to stabilize when the BMS first boots up/has null values) */ - if (!is_first_reading_) - tmp_temp = - bmsdata->avg_temp; /* Set to actual average temp of the pack */ - - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) { - /* If 2D LUT shows therm should be disable */ - if (THERM_DISABLE[c][therm]) { - /* Nullify thermistor by setting to pack average */ - bmsdata->chip_data[c].thermistor_value[therm] = - tmp_temp; - } else { - bmsdata->chip_data[c].thermistor_value[therm] = - bmsdata->chip_data[c] - .thermistor_reading[therm]; - } - } - } -} +// void disable_therms(acc_data_t *bmsdata) +// { +// int8_t tmp_temp = +// 25; /* Iniitalize to room temp (necessary to stabilize when the BMS first boots up/has null values) */ +// if (!is_first_reading_) +// tmp_temp = +// bmsdata->avg_temp; /* Set to actual average temp of the pack */ + +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 0; therm < NUM_THERMS_PER_CHIP; therm++) { +// /* If 2D LUT shows therm should be disable */ +// if (THERM_DISABLE[c][therm]) { +// /* Nullify thermistor by setting to pack average */ +// bmsdata->chip_data[c].thermistor_value[therm] = +// tmp_temp; +// } else { +// bmsdata->chip_data[c].thermistor_value[therm] = +// bmsdata->chip_data[c] +// .thermistor_reading[therm]; +// } +// } +// } +// } +//TODO: Change for P45B electrical characteristics. +//TODO: Add coulomb couting. +// FUTURE: State of power calcs. void calc_state_of_charge(acc_data_t *bmsdata) { /* Spltting the delta voltage into 18 increments */ @@ -672,25 +699,27 @@ void calc_state_of_charge(acc_data_t *bmsdata) compute_send_acc_status_message(bmsdata); } -void calc_noise_volt_percent(acc_data_t *bmsdata) -{ - int i = 0; - for (uint8_t seg = 0; seg < NUM_SEGMENTS; seg++) { - uint8_t count = 0; - /* merge results from each of the two chips on a given segment */ - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { - count = bmsdata->chip_data[seg + i].noise_reading[cell]; - count += bmsdata->chip_data[seg + i + 1] - .noise_reading[cell]; - } - i++; +// NOTE: This function is broken or something. +// void calc_noise_volt_percent(acc_data_t *bmsdata) +// { +// int i = 0; +// for (uint8_t seg = 0; seg < NUM_SEGMENTS; seg++) { +// uint8_t count = 0; + +// /* merge results from each of the two chips on a given segment */ +// for (uint8_t cell = 0; cell < NUM_CELLS_SEG; cell++) { +// count = bmsdata->chip_data[seg + i].noise_reading[cell]; +// count += bmsdata->chip_data[seg + i + 1] +// .noise_reading[cell]; +// } +// i++; - /* turn into percentage */ - //printf("count: %d\r\n", count); - bmsdata->segment_noise_percentage[seg] = - (uint8_t)(100 * (count) / (NUM_CELLS_PER_CHIP * 2.0f)); - } -} +// /* turn into percentage */ +// //printf("count: %d\r\n", count); +// bmsdata->segment_noise_percentage[seg] = +// (uint8_t)(100 * (count) / (NUM_CELLS_SEG * 2.0f)); +// } +// } // void high_curr_therm_check() // { diff --git a/Core/Src/compute.c b/Core/Src/compute.c index c42421ac..e7de1add 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -163,7 +163,6 @@ uint8_t compute_set_fan_speed(TIM_HandleTypeDef *pwmhandle, void compute_set_fault(int fault_state) { - // TODO work with charger fw on this HAL_GPIO_WritePin(GPIOA, Fault_Output_Pin, !fault_state); // if (true) digitalWrite(CHARGE_SAFETY_RELAY, 1); } @@ -371,8 +370,7 @@ void compute_send_bms_status_message(acc_data_t *bmsdata, int bms_state, bms_status_msg_data.temp_avg = (int8_t)(bmsdata->avg_temp); bms_status_msg_data.state = (uint8_t)(bms_state); bms_status_msg_data.temp_internal = (uint8_t)(0); - bms_status_msg_data.balance = - (uint8_t)(balance); // segment_is_balancing() + bms_status_msg_data.balance = (uint8_t)(balance); can_msg_t msg; msg.id = BMS_STATUS_CANID; @@ -401,7 +399,7 @@ void compute_send_shutdown_ctrl_message(uint8_t mpe_state) queue_can_msg(msg); } -void compute_send_cell_data_message(acc_data_t *bmsdata) +void compute_send_cell_voltage_message(acc_data_t *bmsdata) { struct __attribute__((__packed__)) { uint16_t high_cell_voltage; @@ -437,42 +435,6 @@ void compute_send_cell_data_message(acc_data_t *bmsdata) queue_can_msg(msg); } -void compute_send_cell_voltage_message(uint8_t cell_id, - uint16_t instant_voltage, - uint16_t internal_Res, uint8_t shunted, - uint16_t open_voltage) -{ - struct __attribute__((__packed__)) { - uint8_t cellID; - uint16_t instantVoltage; - uint16_t internalResistance; - uint8_t shunted; - uint16_t openVoltage; - } cell_voltage_msg_data; - - cell_voltage_msg_data.cellID = cell_id; - cell_voltage_msg_data.instantVoltage = instant_voltage; - cell_voltage_msg_data.internalResistance = internal_Res; - cell_voltage_msg_data.shunted = shunted; - cell_voltage_msg_data.openVoltage = open_voltage; - - /* convert to big endian */ - endian_swap(&cell_voltage_msg_data.instantVoltage, - sizeof(cell_voltage_msg_data.instantVoltage)); - endian_swap(&cell_voltage_msg_data.internalResistance, - sizeof(cell_voltage_msg_data.internalResistance)); - endian_swap(&cell_voltage_msg_data.openVoltage, - sizeof(cell_voltage_msg_data.openVoltage)); - - can_msg_t msg; - msg.id = CELL_VOLTAGE_CANID; - msg.len = CELL_VOLTAGE_SIZE; - - memcpy(msg.data, &cell_voltage_msg_data, sizeof(cell_voltage_msg_data)); - - queue_can_msg(msg); -} - void compute_send_current_message(acc_data_t *bmsdata) { struct __attribute__((__packed__)) { @@ -685,6 +647,187 @@ void compute_send_debug_message(uint8_t debug0, uint8_t debug1, uint16_t debug2, queue_can_msg(msg); } +void compute_send_cell_data_message(bool alpha, uint16_t temperature, + uint16_t voltage_a, uint16_t voltage_b, + uint8_t chip_ID, uint8_t cell_a, + uint8_t cell_b, bool discharging_a, + bool discharging_b) +{ + endian_swap(&temperature, sizeof(temperature)); + endian_swap(&voltage_a, sizeof(voltage_a)); + endian_swap(&voltage_b, sizeof(voltage_b)); + + struct __attribute__((__packed__)) { + uint16_t temperature : 10; + uint16_t voltage_a : 13; + uint16_t voltage_b : 13; + uint8_t chip_ID : 4; + uint8_t cell_a : 4; + uint8_t cell_b : 4; + uint8_t discharging_a : 1; + uint8_t discharging_b : 1; + } cell_data_msg_data; + + cell_data_msg_data.temperature = temperature; + cell_data_msg_data.voltage_a = voltage_a; + cell_data_msg_data.voltage_b = voltage_b; + cell_data_msg_data.chip_ID = chip_ID; + cell_data_msg_data.cell_a = cell_a; + cell_data_msg_data.cell_b = cell_b; + cell_data_msg_data.discharging_a = discharging_a; + cell_data_msg_data.discharging_b = discharging_b; + + can_msg_t msg; + if (alpha) { + msg.id = ALPHA_CELL_CANID; + } else { + msg.id = BETA_CELL_CANID; + } + msg.len = CELL_MSG_SIZE; + + memcpy(msg.data, &cell_data_msg_data, CELL_MSG_SIZE); + + queue_can_msg(msg); +} + +void compute_send_beta_status_a_message(uint16_t cell_temperature, + uint16_t voltage, bool discharging, + uint8_t chip, + uint16_t segment_temperature, + uint16_t die_temperature, uint16_t vpv) +{ + endian_swap(&cell_temperature, sizeof(cell_temperature)); + endian_swap(&voltage, sizeof(voltage)); + endian_swap(&segment_temperature, sizeof(segment_temperature)); + endian_swap(&die_temperature, sizeof(die_temperature)); + endian_swap(&vpv, sizeof(vpv)); + + struct __attribute__((__packed__)) { + uint16_t cell_temperature : 10; + uint16_t voltage : 13; + uint8_t discharging : 1; + uint8_t chip : 4; + uint16_t segment_temperature : 10; + uint16_t die_temperature : 13; + uint16_t vpv : 13; + } beta_status_a_data; + + beta_status_a_data.cell_temperature = cell_temperature; + beta_status_a_data.voltage = voltage; + beta_status_a_data.discharging = discharging; + beta_status_a_data.chip = chip; + beta_status_a_data.segment_temperature = segment_temperature; + beta_status_a_data.die_temperature = die_temperature; + beta_status_a_data.vpv = vpv; + + can_msg_t msg; + msg.id = BETA_STAT_A_CANID; + msg.len = BETA_STAT_A_SIZE; + + memcpy(msg.data, &beta_status_a_data, BETA_STAT_A_SIZE); + + queue_can_msg(msg); +} + +void compute_send_beta_status_b_message(uint16_t vref2, uint16_t v_analog, + uint16_t v_digital, uint8_t chip, + uint16_t v_res, uint16_t vmv) +{ + endian_swap(&vref2, sizeof(vref2)); + endian_swap(&v_analog, sizeof(v_analog)); + endian_swap(&v_digital, sizeof(v_digital)); + endian_swap(&v_res, sizeof(v_res)); + endian_swap(&vmv, sizeof(vmv)); + + struct __attribute__((__packed__)) { + uint16_t vref2 : 13; + uint16_t v_analog : 10; + uint16_t v_digital : 10; + uint8_t chip : 4; + uint16_t v_res : 13; + uint16_t vmv : 13; + } beta_status_b_data; + + beta_status_b_data.vref2 = vref2; + beta_status_b_data.v_analog = v_analog; + beta_status_b_data.v_digital = v_digital; + beta_status_b_data.chip = chip; + beta_status_b_data.v_res = v_res; + beta_status_b_data.vmv = vmv; + + can_msg_t msg; + msg.id = BETA_STAT_B_CANID; + msg.len = BETA_STAT_B_SIZE; + + memcpy(msg.data, &beta_status_b_data, BETA_STAT_B_SIZE); + + queue_can_msg(msg); +} + +void compute_send_alpha_status_a_message(uint16_t segment_temp, uint8_t chip, + uint16_t die_temperature, uint16_t vpv, + uint16_t vmv) +{ + endian_swap(&segment_temp, sizeof(segment_temp)); + endian_swap(&die_temperature, sizeof(die_temperature)); + endian_swap(&vpv, sizeof(vpv)); + endian_swap(&vmv, sizeof(vmv)); + + struct __attribute__((__packed__)) { + uint16_t segment_temp : 10; + uint8_t chip : 4; + uint16_t die_temperature : 13; + uint16_t vpv : 13; + uint16_t vmv : 13; + } alpha_status_a_data; + + alpha_status_a_data.segment_temp = segment_temp; + alpha_status_a_data.chip = chip; + alpha_status_a_data.die_temperature = die_temperature; + alpha_status_a_data.vpv = vpv; + alpha_status_a_data.vmv = vmv; + + can_msg_t msg; + msg.id = ALPHA_STAT_A_CANID; + msg.len = ALPHA_STAT_A_SIZE; + + memcpy(msg.data, &alpha_status_a_data, ALPHA_STAT_A_SIZE); + + queue_can_msg(msg); +} + +void compute_send_alpha_status_b_message(uint16_t v_res, uint8_t chip, + uint16_t vref2, uint16_t v_analog, + uint16_t v_digital) +{ + endian_swap(&v_res, sizeof(v_res)); + endian_swap(&vref2, sizeof(vref2)); + endian_swap(&v_analog, sizeof(v_analog)); + endian_swap(&v_digital, sizeof(v_digital)); + + struct __attribute__((__packed__)) { + uint16_t v_res : 13; + uint8_t chip : 4; + uint16_t vref2 : 13; + uint16_t v_analog : 13; + uint16_t v_digital : 13; + } alpha_status_b_data; + + alpha_status_b_data.v_res = v_res; + alpha_status_b_data.chip = chip; + alpha_status_b_data.vref2 = vref2; + alpha_status_b_data.v_analog = v_analog; + alpha_status_b_data.v_digital = v_digital; + + can_msg_t msg; + msg.id = ALPHA_STAT_B_CANID; + msg.len = ALPHA_STAT_B_SIZE; + + memcpy(msg.data, &alpha_status_b_data, ALPHA_STAT_B_SIZE); + + queue_can_msg(msg); +} + void change_adc1_channel(uint8_t channel) { ADC_ChannelConfTypeDef sConfig = { 0 }; @@ -699,4 +842,4 @@ void change_adc1_channel(uint8_t channel) if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } -} +} \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index 199bb058..28df1f08 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -27,6 +27,8 @@ #include "assert.h" #include "string.h" +#include "serialPrintResult.h" + /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -40,6 +42,12 @@ //#ifdef DEBUG_EVERYTHING //#define DEBUG_CHARGING // #define DEBUG_STATS +#define DEBUG_VOLTAGES +// #define DEBUG_RAW_VOLTAGES +#define DEBUG_RAW_VOLTAGES_FORMATTED +// #define DEBUG_OCV +// #define DEUBG_THERMS +// #define DEBUG_OTHER // etc etc //#endif /* USER CODE END PD */ @@ -68,6 +76,7 @@ SPI_HandleTypeDef hspi3; TIM_HandleTypeDef htim1; TIM_HandleTypeDef htim2; +TIM_HandleTypeDef htim5; TIM_HandleTypeDef htim8; UART_HandleTypeDef huart4; @@ -79,7 +88,7 @@ PCD_HandleTypeDef hpcd_USB_OTG_FS; osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { .name = "defaultTask", - .stack_size = 128 * 4, + .stack_size = 256 * 4, .priority = (osPriority_t) osPriorityNormal, }; /* USER CODE BEGIN PV */ @@ -104,6 +113,7 @@ static void MX_TIM8_Init(void); static void MX_ADC1_Init(void); static void MX_ADC2_Init(void); static void MX_IWDG_Init(void); +static void MX_TIM5_Init(void); void StartDefaultTask(void *argument); /* USER CODE BEGIN PFP */ @@ -117,9 +127,25 @@ void StartDefaultTask(void *argument); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +/* the following reroutes printf to uart */ +#ifdef __GNUC__ +#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) +#else +#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) +#endif + +PUTCHAR_PROTOTYPE +{ + HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, HAL_MAX_DELAY); + return ch; +} + int _write(int file, char* ptr, int len) { - HAL_UART_Transmit_DMA(&huart4, (uint8_t *)ptr, len); - + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) { + __io_putchar( *ptr++ ); + } return len; } @@ -128,94 +154,134 @@ int _write(int file, char* ptr, int len) { const void print_bms_stats(acc_data_t *acc_data) { static nertimer_t debug_stat_timer; - static const uint16_t PRINT_STAT_WAIT = 500; //ms + static const uint16_t PRINT_STAT_WAIT = 1000; //ms if(!is_timer_expired(&debug_stat_timer) && debug_stat_timer.active) return; + #ifdef DEBUG_OTHER //TODO get this from eeprom once implemented // question - should we read from eeprom here, or do that on loop and store locally? // printf("Prev Fault: %#x", previousFault); - printf("CAN Error:\t%ld\r\n", HAL_CAN_GetError(&hcan1)); - printf("Current * 10: %d\r\n", (acc_data->pack_current)); - printf("Min, Max, Avg Temps: %ld, %ld, %d\r\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp); - printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\r\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage); - printf("DCL: %d\r\n", acc_data->discharge_limit); - printf("CCL: %d\r\n", acc_data->charge_limit); - printf("Cont CCL %d\r\n", acc_data->cont_CCL); - printf("SoC: %d\r\n", acc_data->soc); - printf("Is Balancing?: %d\r\n", segment_is_balancing()); + + printf("CAN Error:\t%ld\n", HAL_CAN_GetError(&hcan1)); + printf("Current * 10: %d\n", (acc_data->pack_current)); + printf("Min, Max, Avg Temps: %ld, %ld, %d\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp); + #endif + + #ifdef DEBUG_VOLTAGES + printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage); + printf("Min, Max, Avg, Delta Voltages: %f, %f, %f, %f\n", acc_data->min_voltage.val / 10000.0, acc_data->max_voltage.val / 10000.0, acc_data->avg_voltage / 10000.0, acc_data->delt_voltage / 10000.0); + #endif + + #ifdef DEBUG_OTHER + printf("DCL: %d\n", acc_data->discharge_limit); + printf("CCL: %d\n", acc_data->charge_limit); + printf("Cont CCL %d\n", acc_data->cont_CCL); + printf("SoC: %d\n", acc_data->soc); + printf("Is Balancing?: %d\n", segment_is_balancing(acc_data->chips)); printf("State: "); - if (current_state == 0) printf("BOOT\r\n"); - else if (current_state == 1) printf("READY\r\n"); - else if (current_state == 2) printf("CHARGING\r\n"); - else if (current_state == 3) printf("FAULTED: %lX\r\n", acc_data->fault_code); - - printf("Voltage Noise Percent:\r\n"); - printf("Seg 1: %d\r\n", acc_data->segment_noise_percentage[0]); - printf("Seg 2: %d\r\n", acc_data->segment_noise_percentage[1]); - printf("Seg 3: %d\r\n", acc_data->segment_noise_percentage[2]); - printf("Seg 4: %d\r\n", acc_data->segment_noise_percentage[3]); - printf("Seg 5: %d\r\n", acc_data->segment_noise_percentage[4]); - printf("Seg 6: %d\r\n", acc_data->segment_noise_percentage[5]); - - printf("Raw Cell Voltage:\r\n"); + if (current_state == 0) printf("BOOT\n"); + else if (current_state == 1) printf("READY\n"); + else if (current_state == 2) printf("CHARGING\n"); + else if (current_state == 3) printf("FAULTED: %lX\n", acc_data->fault_code); + + printf("Voltage Noise Percent:\n"); + printf("Seg 1: %d\n", acc_data->segment_noise_percentage[0]); + printf("Seg 2: %d\n", acc_data->segment_noise_percentage[1]); + printf("Seg 3: %d\n", acc_data->segment_noise_percentage[2]); + printf("Seg 4: %d\n", acc_data->segment_noise_percentage[3]); + printf("Seg 5: %d\n", acc_data->segment_noise_percentage[4]); + printf("Seg 6: %d\n", acc_data->segment_noise_percentage[5]); + #endif + + #ifdef DEBUG_RAW_VOLTAGES + printf("Raw Cell Voltage:\n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { - for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) + uint8_t num_cells = get_num_cells(&acc_data->chip_data[c]); + for(uint8_t cell = 0; cell < num_cells; cell++) { - printf("%d\t", acc_data->chip_data[c].voltage[cell]); + printf("%d\t", acc_data->chips[c].cell.c_codes[cell]); } - printf("\r\n"); + printf("\n"); } + #endif - printf("Open Cell Voltage:\r\n"); + #ifdef DEBUG_RAW_VOLTAGES_FORMATTED + for(uint8_t c = 0; c < NUM_CHIPS; c++) + { + uint8_t num_cells = get_num_cells(&acc_data->chip_data[c]); + for(uint8_t cell = 0; cell < num_cells; cell++) + { + printf("%.3f\t", getVoltage(acc_data->chips[c].fcell.fc_codes[cell])); + } + printf("\n"); + } + #endif + + #ifdef DEBUG_OCV + printf("Open Cell Voltage:\n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { - for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) + uint8_t num_cells = get_num_cells(&acc_data->chip_data[c]); + for(uint8_t cell = 0; cell < num_cells; cell++) { printf("%d\t", acc_data->chip_data[c].open_cell_voltage[cell]); } - printf("\r\n"); + printf("\n"); } + #endif - printf("Thermistors with Disabling:\r\n"); +#define DEBUG_THERM_VOLTS + #ifdef DEBUG_THERM_VOLTS + printf("THERM VOLTS: \n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { - printf("Chip %d: ", c); - - for (uint8_t cell = 0; cell < NUM_THERMS_PER_CHIP; cell++) { - - //if (THERM_DISABLE[c][cell]) continue; - printf("%d ", acc_data->chip_data[c].thermistor_value[cell]); - } - - printf("\r\n"); + for(uint8_t gpio = 0; gpio < 10; gpio++) + { + printf("%f\t", getVoltage(acc_data->chips[c].raux.ra_codes[gpio])); + } + printf("\n"); } - - printf("UnFiltered Thermistor Temps:\r\n"); + #endif + + #ifdef DEBUG_OTHER + + printf("UnFiltered Thermistor Temps:\n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { printf("Chip %d: ", c); - for (uint8_t cell = 0; cell < NUM_THERMS_PER_CHIP; cell++) { + uint8_t num_therms; + if (acc_data->chip_data->alpha) { + num_therms = 7; + } else { + num_therms = 6; + } - printf("%d ", acc_data->chip_data[c].thermistor_reading[cell]); + for (uint8_t therm = 0; therm < num_therms; therm++) { + + printf("%d ", acc_data->chips[c].aux.a_codes[therm]); } - printf("\r\n"); + printf("\n"); } - printf("Cell Temps:\r\n"); + #endif + + #ifdef DEUBG_THERMS + printf("Cell Temps:\n"); for(uint8_t c = 0; c < NUM_CHIPS; c++) { printf("Chip %d: ", c); - - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&acc_data->chip_data[c]); + for (uint8_t cell = 0; cell < num_cells; cell++) { printf("%d ", acc_data->chip_data[c].cell_temp[cell]); } - printf("\r\n"); + printf("\n"); } + #endif start_timer(&debug_stat_timer, PRINT_STAT_WAIT); } @@ -241,6 +307,7 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *phuart) */ int main(void) { + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ @@ -284,6 +351,7 @@ int main(void) MX_ADC1_Init(); MX_ADC2_Init(); MX_IWDG_Init(); + MX_TIM5_Init(); /* USER CODE BEGIN 2 */ //for (int i = 0; i < 58; i++) //{ @@ -299,9 +367,9 @@ int main(void) HAL_Delay(500); init_both_can(&hcan1, &hcan2); - segment_init(); + segment_init(acc_data); compute_init(); - printf("Init passed\r\n"); + printf("Init passed\n"); /* USER CODE END 2 */ /* Init scheduler */ @@ -325,13 +393,14 @@ int main(void) /* Create the thread(s) */ /* creation of defaultTask */ - defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); + defaultTaskHandle = osThreadNew(StartDefaultTask, (void*) acc_data, &defaultTask_attributes); /* USER CODE BEGIN RTOS_THREADS */ /* Messaging */ can_dispatch_handle = osThreadNew(vCanDispatch, &hcan1, &can_dispatch_attributes); assert(can_dispatch_handle); + can_receive_thread = osThreadNew(vCanReceive, NULL, &can_receive_attributes); assert(can_receive_thread); @@ -347,6 +416,11 @@ int main(void) state_machine_thread = osThreadNew(vStateMachine, acc_data, &state_machine_attrs); assert(state_machine_thread); + if (DEBUG_MODE_ENABLED) { + debug_mode_thread = osThreadNew(vDebugMode, acc_data, &debug_mode_attrs); + assert(debug_mode_thread); + } + /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ @@ -357,6 +431,7 @@ int main(void) osKernelStart(); /* We should never get here as control is now taken by the scheduler */ + /* Infinite loop */ /* USER CODE BEGIN WHILE */ for(;;) { @@ -766,7 +841,7 @@ static void MX_SPI3_Init(void) hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; hspi3.Init.NSS = SPI_NSS_SOFT; - hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi3.Init.TIMode = SPI_TIMODE_DISABLE; hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; @@ -879,7 +954,7 @@ static void MX_TIM2_Init(void) /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; - htim2.Init.Prescaler = 0; + htim2.Init.Prescaler = 16; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 4294967295; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; @@ -900,11 +975,56 @@ static void MX_TIM2_Init(void) Error_Handler(); } /* USER CODE BEGIN TIM2_Init 2 */ - + HAL_TIM_Base_Start(&htim2); /* USER CODE END TIM2_Init 2 */ } +/** + * @brief TIM5 Initialization Function + * @param None + * @retval None + */ +static void MX_TIM5_Init(void) +{ + + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 0; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 4294967295; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ + + /* USER CODE END TIM5_Init 2 */ + +} + /** * @brief TIM8 Initialization Function * @param None @@ -1229,7 +1349,7 @@ void send_git_version_message() { void StartDefaultTask(void *argument) { /* USER CODE BEGIN 5 */ - acc_data_t *bmsdata = (acc_data_t *)argument; + acc_data_t* bmsdata = (acc_data_t*) argument; bool alt = true; @@ -1241,20 +1361,19 @@ void StartDefaultTask(void *argument) #endif if (alt) { - printf(".\r\n"); + printf(".\n"); } else { - printf("..\r\n"); + printf("..\n"); } alt = !alt; compute_send_bms_status_message(bmsdata, current_state, - segment_is_balancing()); + segment_is_balancing(bmsdata->chips)); compute_send_fault_status_message(bmsdata); send_git_version_message(); - HAL_IWDG_Refresh(&hiwdg); osDelay(1000); @@ -1262,6 +1381,27 @@ void StartDefaultTask(void *argument) /* USER CODE END 5 */ } +/** + * @brief Period elapsed callback in non blocking mode + * @note This function is called when TIM3 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 == TIM3) { + HAL_IncTick(); + } + /* USER CODE BEGIN Callback 1 */ + + /* USER CODE END Callback 1 */ +} + /** * @brief This function is executed in case of error occurrence. * @retval None diff --git a/Core/Src/segment.c b/Core/Src/segment.c index 7faf3140..8370deff 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -1,736 +1,425 @@ #include "segment.h" -#include "main.h" #include -#include -#include -#include - -#define THERM_WAIT_TIME 500 /* ms */ -#define VOLTAGE_WAIT_TIME 100 /* ms */ -#define THERM_AVG 15 /* Number of values to average */ -#define MAX_VOLT_DELTA 2500 -#define MAX_CONSEC_NOISE 10 -#define GPIO_EXPANDER_ADDR 0x40 -#define GPIO_REGISTER_ADDR 0x09 - -// TODO ensure spi 1 is correct for talking to segs -extern SPI_HandleTypeDef hspi1; -ltc_config *ltc68041; - -uint8_t local_config[NUM_CHIPS][6] = {}; -uint8_t therm_avg_counter = 0; +#include "analyzer.h" +#include "c_utils.h" -chipdata_t *segment_data = NULL; -chipdata_t previous_data[NUM_CHIPS] = {}; -uint16_t discharge_commands[NUM_CHIPS] = {}; +#include "serialPrintResult.h" +#include "adBms6830ParseCreate.h" +#include "adi_interaction.h" -nertimer_t therm_timer; -nertimer_t voltage_reading_timer; -nertimer_t variance_timer; +#define T_READY 10 /* microseconds*/ +#define T_IDLE 4.3 /* milliseconds, minimum. typ is 5.5, max is 6.7 */ +#define T_WAKE 200 /* microseconds */ +#define T_SLEEP 1.8 /* seconds minimum, typ is 2, max is 2.2 */ +#define T_REFUP 2.7 /* milliseconds minimum, typ is 3.5, max is 4.4 */ -int voltage_error = 0; // not faulted -int therm_error = 0; // not faulted -uint16_t crc_error_check = 0; - -/* our segments are mapped backwards and in pairs, so they are read in 1,0 then - * 3,2, etc*/ -const int mapping_correction[12] = { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10 }; - -uint16_t therm_settle_time_ = 0; - -const uint32_t VOLT_TEMP_CONV[106] = { - 157300, 148800, 140300, 131800, 123300, 114800, 108772, 102744, 96716, - 90688, 84660, 80328, 75996, 71664, 67332, 63000, 59860, 56720, - 53580, 50440, 47300, 45004, 42708, 40412, 38116, 35820, 34124, - 32428, 30732, 29036, 27340, 26076, 24812, 23548, 22284, 21020, - 20074, 19128, 18182, 17236, 16290, 15576, 14862, 14148, 13434, - 12720, 12176, 11632, 11088, 10544, 10000, 9584, 9168, 8753, - 8337, 7921, 7600, 7279, 6957, 6636, 6315, 6065, 5816, - 5566, 5317, 5067, 4872, 4676, 4481, 4285, 4090, 3936, - 3782, 3627, 3473, 3319, 3197, 3075, 2953, 2831, 2709, - 2612, 2514, 2417, 2319, 2222, 2144, 2066, 1988, 1910, - 1832, 1769, 1706, 1644, 1581, 1518, 1467, 1416, 1366, - 1315, 1264, 1223, 1181, 1140, 1098, 1057 -}; - -const int32_t VOLT_TEMP_CALIB_OFFSET = 0; +#define THERM_WAIT_TIME 500 /* ms */ +#define VOLTAGE_WAIT_TIME 500 /* ms */ +#define THERM_AVG 15 /* Number of values to average */ +#define MAX_VOLT_DELTA 2500 +#define MAX_CONSEC_NOISE 10 -/* private function prototypes */ -void serialize_i2c_msg(uint8_t data_to_write[][3], uint8_t comm_output[][6]); -int8_t steinhart_est(uint16_t V); -void variance_therm_check(void); -void discard_neutrals(void); -void pull_chip_configuration(void); -int16_t calc_average(void); -int8_t calc_therm_standard_dev(int16_t avg_temp); - -void push_chip_configuration() -{ - LTC6804_wrcfg(ltc68041, NUM_CHIPS, local_config); -} +extern TIM_HandleTypeDef htim2; -void segment_init() -{ - printf("Initializing Segments..."); +uint8_t therm_avg_counter = 0; - ltc68041 = malloc(sizeof(ltc_config)); - LTC6804_initialize(ltc68041, &hspi1, GPIOA, SPI_1_CS_Pin); +nertimer_t variance_timer; - pull_chip_configuration(); +/* private function prototypes */ +// void variance_therm_check(void); +// void discard_neutrals(chipdata_t segment_data[NUM_CHIPS]); +// void pull_chip_configuration(void); +// int16_t calc_average(chipdata_t segment_data[NUM_CHIPS]); +// int8_t calc_therm_standard_dev(int16_t avg_temp); +void init_chip(cell_asic *chip); +void write_config_regs(cell_asic chip[NUM_CHIPS]); +void set_cell_discharge(cell_asic *chip, uint8_t cell, bool discharge); + +/** + * @brief Initialize a chip with our default values. + * + * @param chip Pointer to chip to initialize. + */ +void init_chip(cell_asic *chip) +{ + set_REFON(chip, PWR_UP); + // WARNING, THE ENUM IS WRONG, CHECK TABLE 102 + set_volt_adc_comp_thresh(chip, CVT_135mV); + chip->tx_cfga.flag_d = 0; - for (int c = 0; c < NUM_CHIPS; c++) { - local_config[c][0] = 0xF8; - local_config[c][1] = 0x19; /* VUV = 0x619 = 1561 -> 2.4992V */ - local_config[c][2] = 0x06; /* VOV = 0xA60 = 2656 -> 4.2496V */ - local_config[c][3] = 0xA6; - local_config[c][4] = 0x00; - local_config[c][5] = 0x00; - } - push_chip_configuration(); + // Short soak on ADAX + set_soak_on(chip, SOAKON_SET); + set_aux_soak_range(chip, SHORT); - start_timer(&voltage_reading_timer, VOLTAGE_WAIT_TIME); - start_timer(&therm_timer, THERM_WAIT_TIME); + // No open wire detect soak + set_open_wire_soak_time(chip, OWA0); - uint8_t i2c_write_data[NUM_CHIPS][3]; + // Set therm GPIOs + set_gpio_pull(chip, 1, true); + set_gpio_pull(chip, 2, true); + set_gpio_pull(chip, 3, true); + set_gpio_pull(chip, 4, true); + set_gpio_pull(chip, 5, true); + set_gpio_pull(chip, 6, true); + set_gpio_pull(chip, 7, true); // this is a on board therm for beta only + set_gpio_pull(chip, 8, true); // this is a on board therm - // Set GPIO expander to output - for (int chip = 0; chip < NUM_CHIPS; chip++) { - i2c_write_data[chip][0] = 0x40; // GPIO expander addr - i2c_write_data[chip][1] = 0x00; // GPIO direction addr - i2c_write_data[chip][2] = 0x00; // Set all to output - } - uint8_t comm_reg_data[NUM_CHIPS][6]; + // set outputs, 9=iso led 10=bal LED + set_gpio_pull(chip, 9, false); + set_gpio_pull(chip, 10, false); - serialize_i2c_msg(i2c_write_data, comm_reg_data); - LTC6804_wrcomm(ltc68041, NUM_CHIPS, comm_reg_data); - LTC6804_stcomm(ltc68041, 24); -} + // Registers are unfrozen + set_snapshot(chip, SNAP_OFF); -void select_therm(uint8_t therm) -{ - /* Exit if out of range values */ - if (therm < 1 || therm > 16) { - return; - } + // Charging is deactivated + set_mute_state(chip, true); - uint8_t i2c_write_data[NUM_CHIPS][3]; - uint8_t comm_reg_data[NUM_CHIPS][6]; + // Not an endpoint in the daisy chain + set_comm_break(chip, false); - // select 0-16 on GPIO expander - for (int chip = 0; chip < NUM_CHIPS; chip++) { - i2c_write_data[chip][0] = GPIO_EXPANDER_ADDR; - i2c_write_data[chip][1] = GPIO_REGISTER_ADDR; - i2c_write_data[chip][2] = - (therm - - 1); // 0-15, will change multiplexer to select thermistor - } - serialize_i2c_msg(i2c_write_data, comm_reg_data); - push_chip_configuration(); - LTC6804_wrcomm(ltc68041, NUM_CHIPS, comm_reg_data); - LTC6804_stcomm(ltc68041, 24); -} + // IIR filter disabled + set_iir_corner_freq(chip, IIR_FPA16); -int pull_voltages() -{ - /** - * If we haven't waited long enough between pulling voltage data - * just copy over the contents of the last good reading and the fault status - * from the most recent attempt - */ - - // int test_v[12] = {800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, - // 800}; - if (!is_timer_expired(&voltage_reading_timer) && - voltage_reading_timer.active) { - for (uint8_t i = 0; i < NUM_CHIPS; i++) { - memcpy(segment_data[i].voltage, - previous_data[i].voltage, - sizeof(segment_data[i].voltage)); - } - return voltage_error; - } + // Init config B - uint16_t raw_voltages[NUM_CHIPS][12]; + // If the corresponding fault bits are sent high, it does not affect the IC + chip->tx_cfgb.vov = SetOverVoltageThreshold(4.2); + chip->tx_cfgb.vuv = SetUnderVoltageThreshold(3.0); - push_chip_configuration(); - LTC6804_adcv(ltc68041); + // Discharge timer monitor off + set_discharge_timer_monitor(chip, false); - /** - * If we received an incorrect PEC indicating a bad read - * copy over the data from the last good read and indicate an error - */ - if (LTC6804_rdcv(ltc68041, 0, NUM_CHIPS, raw_voltages) == -1) { - for (uint8_t i = 0; i < NUM_CHIPS; i++) { - memcpy(segment_data[i].voltage, - previous_data[i].voltage, - sizeof(segment_data[i].voltage)); + // Set discharge timer range to 0 to 63 minutes with 1 minute increments + set_discharge_timer_range(chip, RANG_0_TO_63_MIN); - crc_error_check++; - printf("Bad voltage read\n"); - } - return 1; - } + // Disable discharge for all cells + chip->tx_cfgb.dcc = 0; +} - /* If the read was successful, copy the voltage data */ - for (uint8_t i = 0; i < NUM_CHIPS; i++) { - int corrected_index = mapping_correction[i]; - - /* correction to account for missing index, see more info below */ - int dest_index = 0; - - for (uint8_t j = 0; j < NUM_CELLS_PER_CHIP + 1; j++) { - /* cell 6 on every chip is not a real reading, we need to have the array - * skip this, and shift the remaining readings up one index*/ - if (j == 5) - continue; - - segment_data[corrected_index].noise_reading[dest_index] = - 0; - - if (raw_voltages[i][j] > - (int)(10000 * (MAX_VOLT + 0.5)) || - raw_voltages[i][j] < - (int)(10000 * (MIN_VOLT - 0.5))) { - // if (previous_data[corrected_index].voltage[dest_index] > 45000 || - // previous_data[corrected_index].voltage[dest_index] < 20000) - // printf("poop\r\n"); - segment_data[corrected_index] - .voltage[dest_index] = - previous_data[corrected_index] - .voltage[dest_index]; - segment_data[corrected_index] - .noise_reading[dest_index] = 1; - segment_data[corrected_index] - .consecutive_noise[dest_index]++; - // printf("New data: %d\r\n", - // segment_data[corrected_index].voltage[dest_index]); - // if (segment_data[corrected_index].consecutive_noise[dest_index] > - // MAX_CONSEC_NOISE) { - // segment_data[corrected_index].noise_reading[dest_index] = 0; - // segment_data[corrected_index].consecutive_noise[dest_index] = 0; - // segment_data[corrected_index].voltage[dest_index] = - // raw_voltages[i][j]; - // } - } else { - // printf("previous: %d\r\n", - // previous_data[corrected_index].voltage[dest_index]); if - // (previous_data[corrected_index].voltage[dest_index] > 45000 || - // previous_data[corrected_index].voltage[dest_index] < 20000) - // printf("pee\r\n"); else printf("wiping\r\n"); - segment_data[corrected_index] - .consecutive_noise[dest_index] = 0; - segment_data[corrected_index] - .voltage[dest_index] = - raw_voltages[i][j]; - - if (raw_voltages[i][j] < 45000 && - raw_voltages[i][j] > 24000) { - previous_data[corrected_index] - .voltage[dest_index] = - raw_voltages[i][j]; - // printf("previous: %d\r\n", - // previous_data[corrected_index].voltage[dest_index]); printf("raw: - // %d\r\n", segment_data[corrected_index].voltage[dest_index]); - } - } - dest_index++; - } +/** + * @brief Initialize chips with default values. + * + */ +void segment_init(acc_data_t *bmsdata) +{ + printf("Initializing Segments..."); + for (int chip = 0; chip < NUM_CHIPS; chip++) { + init_chip(&bmsdata->chips[chip]); + // TODO: Make sure this is accurate + bmsdata->chip_data[chip].alpha = chip % 2 == 0; } + write_config_regs(bmsdata->chips); - /* Start the timer between readings if successful */ - start_timer(&voltage_reading_timer, VOLTAGE_WAIT_TIME); - - return 0; + start_c_adc_conv(); } -int pull_thermistors() +void segment_adc_comparison(acc_data_t *bmsdata) { - /* If polled too soon, just copy existing values from memory */ - if (!is_timer_expired(&therm_timer)) { - for (uint8_t i = 0; i < NUM_CHIPS; i++) { - memcpy(segment_data[i].thermistor_reading, - previous_data[i].thermistor_reading, - sizeof(segment_data[i].thermistor_reading)); - memcpy(segment_data[i].thermistor_value, - previous_data[i].thermistor_value, - sizeof(segment_data[i].thermistor_value)); - } - return voltage_error; - } + // TODO: S-ADC measurements are all over the place. - uint16_t raw_temp_voltages[NUM_CHIPS][6]; + // Take single shot measurement + // adBms6830_Adcv(RD_ON, SINGLE, DCP_OFF, RSTF_OFF, OW_OFF_ALL_CH); + // adBmsPollAdc(PLCADC); + // read_adbms_data(bmsdata->chips, RDCVALL, Rdcvall, ALL_GRP); - static uint8_t current_therm = 1; - if (current_therm > 16) { - current_therm = 1; - } + // Result of C-ADC and S-ADC comparison is stored in status register group C + read_status_registers(bmsdata->chips); - /* Sets multiplexors to select thermistors */ - select_therm(current_therm); - HAL_Delay(200); - // push_chip_configuration(); - LTC6804_clraux(ltc68041); - LTC6804_adax(ltc68041); /* Run ADC for AUX (GPIOs and refs) */ - HAL_Delay(3); - LTC6804_rdaux(ltc68041, 0, NUM_CHIPS, raw_temp_voltages); - /* Rotate through all thermistor pairs (we can poll two at once) */ - for (uint8_t therm = 1; therm <= (NUM_THERMS_PER_CHIP / 2); therm++) { - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - int corrected_index = mapping_correction[c]; - /* - * Get current temperature LUT. Voltage is adjusted to account for 5V reg - * fluctuations (index 2 is a reading of the ADC 5V ref) - */ - if (therm == current_therm) { - /* see "thermister decoding" in confluence in shepherd software 22A */ - uint16_t steinhart_input_low = - 10000 * - (float)(((float)raw_temp_voltages[c][2]) / - (raw_temp_voltages[c] - [0]) - - 1); - uint16_t steinhart_input_high = - 10000 * - (float)(((float)raw_temp_voltages[c][2]) / - (raw_temp_voltages[c] - [1]) - - 1); - - segment_data[corrected_index] - .thermistor_reading[therm - 1] = - steinhart_est(steinhart_input_low); - segment_data[corrected_index] - .thermistor_reading[therm + 15] = - steinhart_est(steinhart_input_high); - - /* Directly update for a set time from start up due to therm voltages - * needing to settle */ - segment_data[corrected_index] - .thermistor_value[therm - 1] = - segment_data[corrected_index] - .thermistor_reading[therm - 1]; - segment_data[corrected_index] - .thermistor_value[therm + 15] = - segment_data[corrected_index] - .thermistor_reading[therm + 15]; - - if (raw_temp_voltages[c][0] == LTC_BAD_READ || - raw_temp_voltages[c][1] == LTC_BAD_READ || - segment_data[corrected_index] - .thermistor_value[therm - 1] > - (MAX_CELL_TEMP + 5) || - segment_data[corrected_index] - .thermistor_value[therm + - 15] > - (MAX_CELL_TEMP + 5) || - segment_data[corrected_index] - .thermistor_value[therm - 1] < - (MIN_CELL_TEMP - 5) || - segment_data[corrected_index] - .thermistor_value[therm + - 15] < - (MIN_CELL_TEMP - 5)) { - memcpy(segment_data[corrected_index] - .thermistor_reading, - previous_data[c] - .thermistor_reading, - sizeof(segment_data[corrected_index] - .thermistor_reading)); - memcpy(segment_data[corrected_index] - .thermistor_value, - previous_data[c].thermistor_value, - sizeof(segment_data[corrected_index] - .thermistor_value)); - } - } else { - segment_data[corrected_index] - .thermistor_reading[therm - 1] = - previous_data[corrected_index] - .thermistor_reading[therm - 1]; - segment_data[corrected_index] - .thermistor_reading[therm + 15] = - previous_data[corrected_index] - .thermistor_reading[therm + 15]; - - segment_data[corrected_index] - .thermistor_value[therm - 1] = - segment_data[corrected_index] - .thermistor_reading[therm - 1]; - segment_data[corrected_index] - .thermistor_value[therm + 15] = - segment_data[corrected_index] - .thermistor_reading[therm + 15]; + for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { + uint8_t cells = get_num_cells(&bmsdata->chip_data[chip]); + for (uint8_t cell = 0; cell < cells; cell++) { + if (NER_GET_BIT(bmsdata->chips[chip].statc.cs_flt, + cell)) { + printf("ADC VOLTAGE DISCREPANCY ERROR\nChip %d, Cell %d\nC-ADC: %f, S-ADC: %f\n", + chip + 1, cell + 1, + getVoltage( + bmsdata->chips[chip] + .fcell.fc_codes[cell]), + getVoltage( + bmsdata->chips[chip] + .scell.sc_codes[cell])); } } } - current_therm++; - start_timer(&therm_timer, - 100 /*THERM_WAIT_TIME*/); /* Start timer for next reading */ - - /* the following algorithms were used to eliminate noise on Car 17D - keep - * them off if possible */ - // variance_therm_check(); - // standard_dev_therm_check(); - // averaging_therm_check(); - // discard_neutrals(); - - return 0; /* Read successfully */ -} - -void segment_retrieve_data(chipdata_t databuf[NUM_CHIPS]) -{ - segment_data = databuf; - - /* Pull voltages and thermistors and indiacate if there was a problem during - * retrieval */ - voltage_error = pull_voltages(); - therm_error = pull_thermistors(); - - /* Save the contents of the reading so that we can use it to fill in missing - * data */ - memcpy(previous_data, segment_data, sizeof(chipdata_t) * NUM_CHIPS); - - segment_data = NULL; -} - -void configure_discharge(uint8_t chip, uint16_t cells) -{ - /* - * chipConfigurations[chip][4] == chipConfigurations[Literally what chip you - * want][register] 4 and 5 are registers to discharge chips - */ - local_config[chip][4] = (uint8_t)(cells & 0x00FF); - - /* - * Register 5 is split in half, so we maintain the upper half and add in the - * bottom half to discharge cells - */ - local_config[chip][5] = - (local_config[chip][5] & 0xF0) + (uint8_t)(cells >> 8); } -void segment_enable_balancing(bool balance_enable) +void segment_monitor_flts(cell_asic chips[NUM_CHIPS]) { - /* - * Discharging all cells in series - * Making the discharge command all 1's for all cells per chip - */ - static const uint16_t DICHARGE_ALL_COMMAND = 0xFFFF >> - (16 - NUM_CELLS_PER_CHIP); - - if (balance_enable) { - for (int c = 0; c < NUM_CHIPS; c++) { - configure_discharge(c, DICHARGE_ALL_COMMAND); - discharge_commands[c] = DICHARGE_ALL_COMMAND; + read_status_registers(chips); + for (int chip = 0; chip < NUM_CHIPS; chip++) { + if (chips[chip].statc.va_ov) { + printf("A OV FLT\n"); } - push_chip_configuration(); - } else { - for (int c = 0; c < NUM_CHIPS; c++) { - configure_discharge(c, 0); - discharge_commands[c] = 0; + if (chips[chip].statc.va_uv) { + printf("A UV FLT\n"); } - push_chip_configuration(); - } -} - -// @todo Revisit after testing -void cell_enable_balancing(uint8_t chip_num, uint8_t cell_num, - bool balance_enable) -{ - pull_chip_configuration(); - - if (balance_enable) - discharge_commands[chip_num] |= (1 << cell_num); - else - discharge_commands[chip_num] &= ~(1 << cell_num); - - configure_discharge(chip_num, discharge_commands[chip_num]); - - push_chip_configuration(); -} - -void segment_configure_balancing( - bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP]) -{ - for (int c = 0; c < NUM_CHIPS; c++) { - for (int cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { - if (discharge_config[mapping_correction[c]][cell]) - discharge_commands[mapping_correction[c]] |= - 1 << cell; - else - discharge_commands[mapping_correction[c]] &= - ~(1 << cell); + if (chips[chip].statc.vd_ov) { + printf("D OV FLT\n"); } - - configure_discharge(c, discharge_commands[c]); - } - push_chip_configuration(); -} - -bool cell_is_balancing(uint8_t chip_num, uint8_t cell_num) -{ - /* If the cell is one of the first 8, check the 4th register */ - if (cell_num < 8) { - return local_config[chip_num][4] & (1 << cell_num); - } - /* If the cell number is greater than 8, check the 5th register */ - else { - return local_config[chip_num][5] & (1 << (cell_num - 8)); - } - - return false; /* default case */ -} - -bool segment_is_balancing() -{ - for (int c = 0; c < NUM_CHIPS; c++) { - /* Reading from the 4th config register */ - for (int cell = 0; cell < 8; cell++) { - if (local_config[c][4] & (1 << cell)) - return true; + if (chips[chip].statc.vd_uv) { + printf("D OV FLT\n"); } - - /* Reading from the 5th config register */ - for (int cell = 0; cell < 4; cell++) { - if (local_config[c][5] & (1 << (cell))) - return true; + if (chips[chip].statc.vde) { + printf("VDE FLT\n"); } - } - - return false; -} - -void pull_chip_configuration() -{ - uint8_t remote_config[NUM_CHIPS][8]; - LTC6804_rdcfg(ltc68041, NUM_CHIPS, remote_config); - - for (int chip = 0; chip < NUM_CHIPS; chip++) { - for (int index = 0; index < 6; index++) { - local_config[chip][index] = remote_config[chip][index]; + if (chips[chip].statc.vdel) { + printf("VDEL FLT\n"); + } + if (chips[chip].statc.spiflt) { + printf("SPI SLV FLT\n"); + } + if (chips[chip].statc.sleep) { + printf("SLEEP OCCURED\n"); + } + if (chips[chip].statc.thsd) { + printf("THERMAL FLT\n"); + } + if (chips[chip].statc.oscchk) { + printf("OSC FLT\n"); + } + if (chips[chip].statc.otp1_med) { + printf("CMED? FLT\n"); + } + if (chips[chip].statc.otp2_med) { + printf("SMED? FLT\n"); } } + // clear them + write_clear_flags(chips); } -int8_t steinhart_est(uint16_t V) +// ensure stuff used is in the correctfunction +void segment_retrieve_data(acc_data_t *bmsdata) { - /* min temp - max temp with buffer on both */ - for (int i = -25; i < 80; i++) { - if (V > VOLT_TEMP_CONV[i + 25]) { - return i; - } - } + // read from ADC convs + read_filtered_voltage_registers(bmsdata->chips); + + // check our fault flags + segment_monitor_flts(bmsdata->chips); - return 80; + // read all therms using AUX 2 + adc_and_read_aux2_registers(bmsdata->chips); } -void disable_gpio_pulldowns() +void segment_retrieve_debug_data(acc_data_t *bmsdata) { - HAL_Delay(1000); - /* Turn OFF GPIO 1 & 2 pull downs */ - pull_chip_configuration(); - for (int c = 0; c < NUM_CHIPS; c++) { - local_config[c][0] |= 0x18; - } - push_chip_configuration(); - - pull_chip_configuration(); - printf("Chip CFG:\n"); - for (int c = 0; c < NUM_CHIPS; c++) { - for (int byte = 0; byte < 6; byte++) { - printf("%x", local_config[c][byte]); - printf("\t"); - } - printf("\n"); - } - printf("Done\n"); -} + // poll stuff like vref, etc. + adc_and_read_aux_registers(bmsdata->chips); -void serialize_i2c_msg(uint8_t data_to_write[][3], uint8_t comm_output[][6]) -{ - for (int chip = 0; chip < NUM_CHIPS; chip++) { - comm_output[chip][0] = 0x60 | (data_to_write[chip][0] >> - 4); /* START + high side of B0 */ - comm_output[chip][1] = (data_to_write[chip][0] << 4) | - 0x00; /* low side of B0 + ACK */ - comm_output[chip][2] = 0x00 | (data_to_write[chip][1] >> - 4); /* BLANK + high side of B1 */ - comm_output[chip][3] = (data_to_write[chip][1] << 4) | - 0x00; /* low side of B1 + ACK */ - comm_output[chip][4] = 0x00 | (data_to_write[chip][2] >> - 4); /* BLANK + high side of B2 */ - comm_output[chip][5] = (data_to_write[chip][2] << 4) | - 0x09; /* low side of B2 + STOP & NACK */ - } -} + // read the above into status registers + read_status_registers(bmsdata->chips); -void averaging_therm_check() -{ - for (int therm = 1; therm <= 16; therm++) { - for (int c = 0; c < NUM_CHIPS; c++) { - /* Directly update for a set time from start up due to therm voltages - * needing to settle */ - if (therm_avg_counter < THERM_AVG * 10) { - segment_data[c].thermistor_value[therm - 1] = - segment_data[c] - .thermistor_reading[therm - 1]; - segment_data[c].thermistor_value[therm + 15] = - segment_data[c] - .thermistor_reading[therm + 15]; - therm_avg_counter++; - } else { - /* We need to investigate this. Very sloppy */ - /* Discard if reading is 33C */ - if (segment_data[c] - .thermistor_reading[therm - 1] != - 33) { - /* If measured value is larger than current "averaged" value, - * increment value */ - if (segment_data[c] - .thermistor_reading[therm - - 1] > - segment_data[c] - .thermistor_value[therm - - 1]) { - segment_data[c] - .thermistor_value[therm - - 1]++; - /* If measured value is smaller than current "averaged" value, - * decrement value */ - } else if (segment_data[c] - .thermistor_reading - [therm - 1] < - segment_data[c] - .thermistor_value - [therm - 1]) { - segment_data[c] - .thermistor_value[therm - - 1]--; - } - } - - /* See comments above. Identical but for the upper 16 therms */ - if (segment_data[c] - .thermistor_reading[therm + 15] != - 33) { - if (segment_data[c] - .thermistor_reading[therm + - 15] > - segment_data[c] - .thermistor_value[therm + - 15]) { - segment_data[c] - .thermistor_value[therm + - 15]++; - } else if (segment_data[c] - .thermistor_reading - [therm + 15] < - segment_data[c].thermistor_value - [therm + 15]) { - segment_data[c] - .thermistor_value[therm + - 15]--; - } - } - } - } - } + //segment_adc_comparison(bmsdata); } -void standard_dev_therm_check() +void segment_restart(acc_data_t *bmsdata) { - if (previous_data == NULL) - return; - int16_t avg_temp = calc_average(); - uint8_t standard_dev = calc_therm_standard_dev(avg_temp); - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 17; therm < 28; therm++) { - /* - * If difference between thermistor and average is more than - * MAX_STANDARD_DEV set the therm to pack average - */ - if (abs(segment_data[c].thermistor_value[therm] - - avg_temp) > (MAX_STANDARD_DEV * standard_dev)) { - /* Nullify thermistor by setting to pack average */ - segment_data[c].thermistor_value[therm] = - previous_data[c].thermistor_value[therm]; - } - } - } + soft_reset_chips(bmsdata->chips); + segment_init(bmsdata); } -int8_t calc_therm_standard_dev(int16_t avg_temp) +bool segment_is_balancing(cell_asic chips[NUM_CHIPS]) { - uint16_t sum_diff_sqrd = 0; - for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { - for (uint8_t therm = 17; therm < 28; therm++) { - uint16_t sum_diff = - abs(segment_data[chip].thermistor_value[therm] - - avg_temp); - sum_diff_sqrd += sum_diff * sum_diff; + for (int chip = 0; chip < NUM_CHIPS; chip++) { + if (chips[chip].tx_cfgb.dcc > 0) { + return true; } } - - uint8_t standard_dev = sqrt(sum_diff_sqrd / 88); - if (standard_dev < 8) { - standard_dev = 8; - } - return standard_dev; + return false; } -int16_t calc_average() +void segment_disable_balancing(acc_data_t *bmsdata) { - int16_t avg = 0; + // Initializes all array elements to zero + bool discharge_config[NUM_CHIPS][NUM_CELLS_ALPHA] = { 0 }; for (int chip = 0; chip < NUM_CHIPS; chip++) { - for (int therm = 17; therm < 28; therm++) { - avg += segment_data[chip].thermistor_value[therm]; - } + set_mute_state(&bmsdata->chips[chip], true); } - - avg = avg / (NUM_CHIPS * 11); - return avg; + segment_configure_balancing(bmsdata, discharge_config); } -void variance_therm_check() +void segment_configure_balancing( + acc_data_t *bmsdata, bool discharge_config[NUM_CHIPS][NUM_CELLS_ALPHA]) { - if (previous_data == NULL) { - start_timer(&variance_timer, 1000); - return; - } - - if (is_timer_expired(&variance_timer)) { - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 17; therm < 28; therm++) { - if (abs(segment_data[c] - .thermistor_reading[therm] - - previous_data[c] - .thermistor_reading[therm]) > - 5 && - (segment_data[c].thermistor_reading[therm] < - 10 || - segment_data[c].thermistor_reading[therm] > - 30)) { - segment_data[c] - .thermistor_reading[therm] = - previous_data[c] - .thermistor_reading - [therm]; - segment_data[c].thermistor_value[therm] = - previous_data[c] - .thermistor_value[therm]; - } - } + // TODO: Test + for (int chip = 0; chip < NUM_CHIPS; chip++) { + uint8_t num_cells = get_num_cells(bmsdata->chip_data); + for (int cell = 0; cell < num_cells; cell++) { + set_cell_discharge(&bmsdata->chips[chip], cell + 1, + discharge_config[chip][cell]); + set_mute_state(&bmsdata->chips[chip], false); } } + // write_config_regs(bmsdata->chips); } -void discard_neutrals() -{ - for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t therm = 17; therm < 28; therm++) { - if (segment_data[c].thermistor_reading[therm] == 33) { - segment_data[c].thermistor_reading[therm] = 25; - segment_data[c].thermistor_value[therm] = 25; - } - } - } -} +// void averaging_therm_check(chipdata_t segment_data[NUM_CHIPS]) +// { +// for (int therm = 1; therm <= 16; therm++) { +// for (int c = 0; c < NUM_CHIPS; c++) { +// /* Directly update for a set time from start up due to therm voltages +// * needing to settle */ +// if (therm_avg_counter < THERM_AVG * 10) { +// segment_data[c].thermistor_value[therm - 1] = +// segment_data[c] +// .thermistor_reading[therm - 1]; +// segment_data[c].thermistor_value[therm + 15] = +// segment_data[c] +// .thermistor_reading[therm + 15]; +// therm_avg_counter++; +// } else { +// /* We need to investigate this. Very sloppy */ +// /* Discard if reading is 33C */ +// if (segment_data[c] +// .thermistor_reading[therm - 1] != +// 33) { +// /* If measured value is larger than current "averaged" value, +// * increment value */ +// if (segment_data[c] +// .thermistor_reading[therm - +// 1] > +// segment_data[c] +// .thermistor_value[therm - +// 1]) { +// segment_data[c] +// .thermistor_value[therm - +// 1]++; +// /* If measured value is smaller than current "averaged" value, +// * decrement value */ +// } else if (segment_data[c] +// .thermistor_reading +// [therm - 1] < +// segment_data[c] +// .thermistor_value +// [therm - 1]) { +// segment_data[c] +// .thermistor_value[therm - +// 1]--; +// } +// } + +// /* See comments above. Identical but for the upper 16 therms */ +// if (segment_data[c] +// .thermistor_reading[therm + 15] != +// 33) { +// if (segment_data[c] +// .thermistor_reading[therm + +// 15] > +// segment_data[c] +// .thermistor_value[therm + +// 15]) { +// segment_data[c] +// .thermistor_value[therm + +// 15]++; +// } else if (segment_data[c] +// .thermistor_reading +// [therm + 15] < +// segment_data[c].thermistor_value +// [therm + 15]) { +// segment_data[c] +// .thermistor_value[therm + +// 15]--; +// } +// } +// } +// } +// } +// } + +// void standard_dev_therm_check(chipdata_t segment_data[NUM_CHIPS]) +// { +// if (previous_data == NULL) +// return; +// int16_t avg_temp = calc_average(segment_data); +// uint8_t standard_dev = calc_therm_standard_dev(avg_temp); +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// /* +// * If difference between thermistor and average is more than +// * MAX_STANDARD_DEV set the therm to pack average +// */ +// if (abs(segment_data[c].thermistor_value[therm] - +// avg_temp) > (MAX_STANDARD_DEV * standard_dev)) { +// /* Nullify thermistor by setting to pack average */ +// segment_data[c].thermistor_value[therm] = +// previous_data[c].thermistor_value[therm]; +// } +// } +// } +// } + +// int8_t calc_therm_standard_dev(chipdata_t segment_data[NUM_CHIPS], int16_t avg_temp) +// { +// uint16_t sum_diff_sqrd = 0; +// for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// uint16_t sum_diff = +// abs(segment_data[chip].thermistor_value[therm] - +// avg_temp); +// sum_diff_sqrd += sum_diff * sum_diff; +// } +// } + +// uint8_t standard_dev = sqrt(sum_diff_sqrd / 88); +// if (standard_dev < 8) { +// standard_dev = 8; +// } +// return standard_dev; +// } + +// int16_t calc_average(chipdata_t segment_data[NUM_CHIPS]) +// { +// int16_t avg = 0; +// for (int chip = 0; chip < NUM_CHIPS; chip++) { +// for (int therm = 17; therm < 28; therm++) { +// avg += segment_data[chip].thermistor_value[therm]; +// } +// } + +// avg = avg / (NUM_CHIPS * 11); +// return avg; +// } + +// void variance_therm_check() +// { +// if (previous_data == NULL) { +// start_timer(&variance_timer, 1000); +// return; +// } + +// if (is_timer_expired(&variance_timer)) { +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// if (abs(segment_data[c] +// .thermistor_reading[therm] - +// previous_data[c] +// .thermistor_reading[therm]) > +// 5 && +// (segment_data[c].thermistor_reading[therm] < +// 10 || +// segment_data[c].thermistor_reading[therm] > +// 30)) { +// segment_data[c] +// .thermistor_reading[therm] = +// previous_data[c] +// .thermistor_reading +// [therm]; +// segment_data[c].thermistor_value[therm] = +// previous_data[c] +// .thermistor_value[therm]; +// } +// } +// } +// } +// } + +// void discard_neutrals(chipdata_t segment_data[NUM_CHIPS]) +// { +// for (uint8_t c = 0; c < NUM_CHIPS; c++) { +// for (uint8_t therm = 17; therm < 28; therm++) { +// if (segment_data[c].thermistor_reading[therm] == 33) { +// segment_data[c].thermistor_reading[therm] = 25; +// segment_data[c].thermistor_value[therm] = 25; +// } +// } +// } +// } diff --git a/Core/Src/shep_tasks.c b/Core/Src/shep_tasks.c index 2e04369c..89ebd856 100644 --- a/Core/Src/shep_tasks.c +++ b/Core/Src/shep_tasks.c @@ -15,6 +15,7 @@ #include "analyzer.h" #include "compute.h" #include +#include "serialPrintResult.h" #define STATE_MACHINE_FLAG 1 @@ -28,8 +29,21 @@ const osThreadAttr_t get_segment_data_attrs = { .name = "Get Segment Data", void vGetSegmentData(void *pv_params) { acc_data_t *bmsdata = (acc_data_t *)pv_params; + + int i = 0; for (;;) { - segment_retrieve_data(bmsdata->chip_data); + // printf("Get segment data\n"); + segment_retrieve_data(bmsdata); + + if (DEBUG_MODE_ENABLED) { + segment_retrieve_debug_data(bmsdata); + } + + if (++i % (45 * SAMPLE_RATE) == 0) { + printf(" *********** REBOOTING SEGMENT\n\n"); + segment_restart(bmsdata); + } + osThreadFlagsSet(analyzer_thread, ANALYZER_FLAG); osDelay(1000 / SAMPLE_RATE); } @@ -47,7 +61,7 @@ void vAnalyzer(void *pv_params) osThreadFlagsWait(ANALYZER_FLAG, osFlagsWaitAny, osWaitForever); osMutexAcquire(bmsdata->mutex, osWaitForever); - disable_therms(bmsdata); + // disable_therms(bmsdata); calc_cell_temps(bmsdata); calc_pack_temps(bmsdata); @@ -65,7 +79,7 @@ void vAnalyzer(void *pv_params) // temporary end calc_state_of_charge(bmsdata); - calc_noise_volt_percent(bmsdata); + // calc_noise_volt_percent(bmsdata); osMutexRelease(bmsdata->mutex); } @@ -99,3 +113,118 @@ void vStateMachine(void *pv_params) osDelay(10); } } + +osThreadId_t debug_mode_thread; +const osThreadAttr_t debug_mode_attrs = { .name = "Debug Mode Thread", + .stack_size = 2048, + .priority = osPriorityNormal }; +void vDebugMode(void *pv_params) +{ + acc_data_t *bmsdata = (acc_data_t *)pv_params; + + while (69 < 420) { + for (int chip = 0; chip < NUM_CHIPS; chip++) { + uint8_t num_cells = + get_num_cells(&bmsdata->chip_data[chip]); + for (int cell = 0; cell < num_cells; cell += 2) { + compute_send_cell_data_message( + bmsdata->chip_data[chip].alpha, + + bmsdata->chip_data[chip].cell_temp[cell], + + 10000 * getVoltage( + bmsdata->chips[chip] + .cell + .c_codes[cell]), + + 10000 * getVoltage( + bmsdata->chips[chip] + .cell + .c_codes[cell + + 1]), + + chip, + + cell, + + cell + 1, + + (bmsdata->chips[chip].tx_cfgb.dcc >> + cell) & 1, + + (bmsdata->chips[chip].tx_cfgb.dcc >> + (cell + 1)) & + 1); + osDelay(1000 / NUM_CHIPS); + } + + // Send chip status messages + if (!bmsdata->chip_data[chip].alpha) { + compute_send_beta_status_a_message( + 10000 * getVoltage( + bmsdata->chip_data[chip] + .cell_temp[10]), + 10000 * getVoltage( + bmsdata->chips[chip] + .cell + .c_codes[10]), + NER_GET_BIT( + bmsdata->chips[chip].tx_cfgb.dcc, + 10), + chip, + bmsdata->chip_data[chip].on_board_temp, + (getVoltage(bmsdata->chips[chip] + .stata.itmp) / + 0.0075) - + 273, + 10000 * 20 * + getVoltage( // VPV is ra_code 11 w/ different scale + bmsdata->chips[chip] + .raux + .ra_codes[11])); + compute_send_beta_status_b_message( + 10000 * getVoltage( + bmsdata->chips[chip] + .stata.vref2), + 10000 * getVoltage(bmsdata->chips[chip] + .statb.va), + 10000 * getVoltage(bmsdata->chips[chip] + .statb.vd), + chip, + 10000 * getVoltage(bmsdata->chips[chip] + .statb.vr4k), + 10000 * 20 * + getVoltage( // VMV is ra_code 10 + bmsdata->chips[chip] + .raux + .ra_codes[10])); + } else { + compute_send_alpha_status_a_message( + bmsdata->chip_data->on_board_temp, chip, + (getVoltage(bmsdata->chips[chip] + .stata.itmp) / + 0.0075) - + 273, + 10000 * getVoltage( + bmsdata->chips[chip] + .raux + .ra_codes[9]), + 10000 * getVoltage( + bmsdata->chips[chip] + .raux + .ra_codes[8])); + compute_send_alpha_status_b_message( + 10000 * getVoltage(bmsdata->chips[chip] + .statb.vr4k), + chip, + 10000 * getVoltage( + bmsdata->chips[chip] + .stata.vref2), + 10000 * getVoltage(bmsdata->chips[chip] + .statb.va), + 10000 * getVoltage(bmsdata->chips[chip] + .statb.vd)); + } + } + } +} \ No newline at end of file diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index 7fc19f01..6c719ad0 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -44,18 +44,18 @@ typedef union _bms_fault_t { } bms_fault_t; /* private function prototypes */ -void init_boot(void); -void init_ready(void); -void init_charging(void); -void init_faulted(void); +void init_boot(acc_data_t *bmsdata); +void init_ready(acc_data_t *bmsdata); +void init_charging(acc_data_t *bmsdata); +void init_faulted(acc_data_t *bmsdata); void handle_boot(acc_data_t *bmsdata); void handle_ready(acc_data_t *bmsdata); void handle_charging(acc_data_t *bmsdata); void handle_faulted(acc_data_t *bmsdata); -void request_transition(BMSState_t next_state); +void request_transition(acc_data_t *bmsdata, BMSState_t next_state); typedef void (*HandlerFunction_t)(acc_data_t *bmsdata); -typedef void (*InitFunction_t)(); +typedef void (*InitFunction_t)(acc_data_t *bmsdata); const InitFunction_t init_LUT[NUM_STATES] = { &init_boot, &init_ready, &init_charging, &init_faulted }; @@ -64,7 +64,7 @@ const HandlerFunction_t handler_LUT[NUM_STATES] = { &handle_boot, &handle_ready, &handle_charging, &handle_faulted }; -void init_boot() +void init_boot(acc_data_t *bmsdata) { return; } @@ -72,7 +72,7 @@ void init_boot() void handle_boot(acc_data_t *bmsdata) { prevAccData = NULL; - segment_enable_balancing(false); + segment_disable_balancing(bmsdata); compute_enable_charging(false); start_timer(&bootup_timer, 10000); printf("Bootup timer started\r\n"); @@ -80,13 +80,13 @@ void handle_boot(acc_data_t *bmsdata) compute_set_fault(1); // bmsdata->fault_code = FAULTS_CLEAR; - request_transition(READY_STATE); + request_transition(bmsdata, READY_STATE); return; } -void init_ready() +void init_ready(acc_data_t *bmsdata) { - segment_enable_balancing(false); + segment_disable_balancing(bmsdata); compute_enable_charging(false); return; } @@ -96,23 +96,24 @@ void handle_ready(acc_data_t *bmsdata) /* check for charger connection */ if (compute_charger_connected() && is_timer_expired(&bootup_timer)) { // TODO Fix once charger works - request_transition(READY_STATE); + request_transition(bmsdata, READY_STATE); } else { sm_broadcast_current_limit(bmsdata); return; } } -void init_charging() +void init_charging(acc_data_t *bmsdata) { cancel_timer(&charger_settle_countup); return; } +// TODO: Improve algorithm. Change for new cells. Make more configurable. void handle_charging(acc_data_t *bmsdata) { if (!compute_charger_connected()) { - request_transition(READY_STATE); + request_transition(bmsdata, READY_STATE); return; } else { @@ -128,24 +129,25 @@ void handle_charging(acc_data_t *bmsdata) if (sm_balancing_check(bmsdata)) sm_balance_cells(bmsdata); else - segment_enable_balancing(false); + segment_disable_balancing(bmsdata); /* Send CAN message, but not too often */ if (is_timer_expired(&charger_message_timer) || !is_timer_active(&charger_message_timer)) { - compute_send_charging_message((MAX_CHARGE_VOLT * - NUM_CELLS_PER_CHIP * - NUM_CHIPS), - 5, bmsdata); + compute_send_charging_message( + (MAX_CHARGE_VOLT * + (NUM_CELLS_ALPHA + NUM_CELLS_BETA) * + NUM_CHIPS), + 5, bmsdata); start_timer(&charger_message_timer, CHARGE_MESSAGE_WAIT); } } } -void init_faulted() +void init_faulted(acc_data_t *bmsdata) { - segment_enable_balancing(false); + segment_disable_balancing(bmsdata); compute_enable_charging(false); entered_faulted = true; return; @@ -163,15 +165,12 @@ void handle_faulted(acc_data_t *bmsdata) if (bmsdata->fault_code_crit == FAULTS_CLEAR) { compute_set_fault(1); - request_transition(BOOT_STATE); + request_transition(bmsdata, BOOT_STATE); return; } else { compute_set_fault(0); - - // TODO update to HAL - // digitalWrite(CHARGE_SAFETY_RELAY, 0); } return; } @@ -188,7 +187,7 @@ void sm_handle_state(acc_data_t *bmsdata) if (bmsdata->fault_code_crit != FAULTS_CLEAR) { bmsdata->discharge_limit = 0; - request_transition(FAULTED_STATE); + request_transition(bmsdata, FAULTED_STATE); } handler_LUT[current_state](bmsdata); @@ -198,14 +197,14 @@ void sm_handle_state(acc_data_t *bmsdata) sm_broadcast_current_limit(bmsdata); } -void request_transition(BMSState_t next_state) +void request_transition(acc_data_t *bmsdata, BMSState_t next_state) { if (current_state == next_state) return; if (!valid_transition_from_to[current_state][next_state]) return; - init_LUT[next_state](); + init_LUT[next_state](bmsdata); current_state = next_state; } @@ -424,6 +423,7 @@ bool sm_charging_check(acc_data_t *bmsdata) } } +// TODO: Improve algorithm. bool sm_balancing_check(acc_data_t *bmsdata) { if (!compute_charger_connected()) @@ -481,17 +481,20 @@ void sm_broadcast_current_limit(acc_data_t *bmsdata) } } -void sm_balance_cells(acc_data_t *bms_data) +//TODO: Improve algorithm +void sm_balance_cells(acc_data_t *bmsdata) { - bool balanceConfig[NUM_CHIPS][NUM_CELLS_PER_CHIP]; + bool balanceConfig[NUM_CHIPS][NUM_CELLS_ALPHA]; /* For all cells of all the chips, figure out if we need to balance by * comparing the difference in voltages */ for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(&bmsdata->chip_data[chip]); + + for (uint8_t cell = 0; cell < num_cells; cell++) { uint16_t delta = - bms_data->chip_data[chip].voltage[cell] - - (uint16_t)bms_data->min_voltage.val; + bmsdata->chips[chip].fcell.fc_codes[cell] - + (uint16_t)bmsdata->min_voltage.val; if (delta > MAX_DELTA_V * 10000) balanceConfig[chip][cell] = true; else @@ -502,7 +505,8 @@ void sm_balance_cells(acc_data_t *bms_data) #ifdef DEBUG_CHARGING printf("Cell Balancing:"); for (uint8_t c = 0; c < NUM_CHIPS; c++) { - for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { + uint8_t num_cells = get_num_cells(bmsdata->chip_data[c]); + for (uint8_t cell = 0; cell < num_cells; cell++) { printf(balanceConfig[c][cell]); printf("\t"); } @@ -510,12 +514,12 @@ void sm_balance_cells(acc_data_t *bms_data) } #endif - segment_configure_balancing(balanceConfig); + segment_configure_balancing(bmsdata, balanceConfig); } void calculate_pwm(acc_data_t *bmsdata) { - // todo actually implement algorithm + // TODO: actually implement algorithm // this should include: // 1. set PWM based on temp of "nearby" cells // 2. automate seleciton of htim rather than hardcode diff --git a/Core/Src/stm32f4xx_hal_msp.c b/Core/Src/stm32f4xx_hal_msp.c index 4cc36bff..eed59f5f 100644 --- a/Core/Src/stm32f4xx_hal_msp.c +++ b/Core/Src/stm32f4xx_hal_msp.c @@ -20,7 +20,6 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" - /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -70,6 +69,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); */ void HAL_MspInit(void) { + /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ @@ -405,6 +405,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) /* USER CODE BEGIN I2C1_MspInit 1 */ /* USER CODE END I2C1_MspInit 1 */ + } } @@ -635,6 +636,17 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) /* USER CODE END TIM2_MspInit 1 */ } + else if(htim_base->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ + + /* USER CODE END TIM5_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE BEGIN TIM5_MspInit 1 */ + + /* USER CODE END TIM5_MspInit 1 */ + } else if(htim_base->Instance==TIM8) { /* USER CODE BEGIN TIM8_MspInit 0 */ @@ -729,6 +741,17 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) /* USER CODE END TIM2_MspDeInit 1 */ } + else if(htim_base->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ + + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ + + /* USER CODE END TIM5_MspDeInit 1 */ + } else if(htim_base->Instance==TIM8) { /* USER CODE BEGIN TIM8_MspDeInit 0 */ @@ -797,6 +820,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) /* USER CODE BEGIN UART4_MspInit 1 */ /* USER CODE END UART4_MspInit 1 */ + } } @@ -873,6 +897,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ /* USER CODE END USB_OTG_FS_MspInit 1 */ + } } diff --git a/Core/Src/stm32f4xx_hal_timebase_tim.c b/Core/Src/stm32f4xx_hal_timebase_tim.c new file mode 100644 index 00000000..2e90dc2d --- /dev/null +++ b/Core/Src/stm32f4xx_hal_timebase_tim.c @@ -0,0 +1,138 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_hal_timebase_tim.c + * @brief HAL time base based on the hardware TIM. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_tim.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +TIM_HandleTypeDef htim3; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief This function configures the TIM3 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 TIM3 clock */ + __HAL_RCC_TIM3_CLK_ENABLE(); + +/* Get clock configuration */ + HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); + + /* Get APB1 prescaler */ + uwAPB1Prescaler = clkconfig.APB1CLKDivider; + /* Compute TIM3 clock */ + if (uwAPB1Prescaler == RCC_HCLK_DIV1) + { + uwTimclock = HAL_RCC_GetPCLK1Freq(); + } + else + { + uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); + } + + /* Compute the prescaler value to have TIM3 counter clock equal to 1MHz */ + uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); + + /* Initialize TIM3 */ + htim3.Instance = TIM3; + + /* Initialize TIMx peripheral as follow: + + + Period = [(TIM3CLK/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 + */ + htim3.Init.Period = (1000000U / 1000U) - 1U; + htim3.Init.Prescaler = uwPrescalerValue; + htim3.Init.ClockDivision = 0; + htim3.Init.CounterMode = TIM_COUNTERMODE_UP; + htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim3); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim3); + if (status == HAL_OK) + { + /* Enable the TIM3 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM3_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM3_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 TIM3 update interrupt. + * @param None + * @retval None + */ +void HAL_SuspendTick(void) +{ + /* Disable TIM3 update Interrupt */ + __HAL_TIM_DISABLE_IT(&htim3, TIM_IT_UPDATE); +} + +/** + * @brief Resume Tick increment. + * @note Enable the tick increment by Enabling TIM3 update interrupt. + * @param None + * @retval None + */ +void HAL_ResumeTick(void) +{ + /* Enable TIM3 Update interrupt */ + __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE); +} + diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index cebdb281..af740ab4 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 */ #include "can_handler.h" @@ -64,6 +62,8 @@ extern CAN_HandleTypeDef hcan1; extern CAN_HandleTypeDef hcan2; extern DMA_HandleTypeDef hdma_uart4_tx; extern UART_HandleTypeDef huart4; +extern TIM_HandleTypeDef htim3; + /* USER CODE BEGIN EV */ /* USER CODE END EV */ @@ -159,28 +159,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. */ @@ -216,6 +194,20 @@ void CAN1_RX0_IRQHandler(void) /* USER CODE END CAN1_RX0_IRQn 1 */ } +/** + * @brief This function handles TIM3 global interrupt. + */ +void TIM3_IRQHandler(void) +{ + /* USER CODE BEGIN TIM3_IRQn 0 */ + + /* USER CODE END TIM3_IRQn 0 */ + HAL_TIM_IRQHandler(&htim3); + /* USER CODE BEGIN TIM3_IRQn 1 */ + + /* USER CODE END TIM3_IRQn 1 */ +} + /** * @brief This function handles UART4 global interrupt. */ diff --git a/Core/Src/syscalls.c b/Core/Src/syscalls.c new file mode 100644 index 00000000..e33a8492 --- /dev/null +++ b/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/Core/Src/sysmem.c b/Core/Src/sysmem.c new file mode 100644 index 00000000..246470ee --- /dev/null +++ b/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/Drivers/Embedded-Base b/Drivers/Embedded-Base index 83258635..4f5c2501 160000 --- a/Drivers/Embedded-Base +++ b/Drivers/Embedded-Base @@ -1 +1 @@ -Subproject commit 83258635fc749ac72adb4b52e61f4f1a42e1842f +Subproject commit 4f5c25018ede00b10343a099f715e19bd1f95837 diff --git a/Drivers/adbms b/Drivers/adbms new file mode 160000 index 00000000..c0e54fe0 --- /dev/null +++ b/Drivers/adbms @@ -0,0 +1 @@ +Subproject commit c0e54fe0f2280b90ea6176444d1e3cdbfbc2164e diff --git a/Makefile b/Makefile index bf8eede5..c7878836 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Sun Nov 24 16:29:33 EST 2024] +# File automatically-generated by tool: [projectgenerator] version: [4.5.0-RC5] date: [Thu Jan 23 18:47:54 EST 2025] ########################################################################################################################## # ------------------------------------------------ @@ -67,6 +67,7 @@ Core/Src/analyzer.c \ Core/Src/compute.c \ Core/Src/eepromdirectory.c \ Core/Src/segment.c \ +Core/Src/adi_interaction.c \ Core/Src/stateMachine.c \ Core/Src/can_handler.c \ Core/Src/shep_tasks.c \ @@ -74,11 +75,14 @@ Core/Src/stm32f4xx_it.c \ Core/Src/stm32f4xx_hal_msp.c \ Drivers/Embedded-Base/platforms/stm32f405/src/can.c \ Drivers/Embedded-Base/general/src/m24c32.c \ -Drivers/Embedded-Base/general/src/ltc68041.c \ Drivers/Embedded-Base/general/src/sht30.c \ Drivers/Embedded-Base/middleware/src/timer.c \ Drivers/Embedded-Base/middleware/src/ringbuffer.c \ Drivers/Embedded-Base/middleware/src/c_utils.c \ +Drivers/adbms/lib/src/adBms6830GenericType.c \ +Drivers/adbms/lib/src/adBms6830ParseCreate.c \ +Drivers/adbms/program/src/serialPrintResult.c \ +Drivers/adbms/program/src/mcuWrapper.c \ Core/Src/freertos.c \ Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c \ Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c \ @@ -117,7 +121,10 @@ 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/sysmem.c \ +Core/Src/syscalls.c \ +Core/Src/stm32f4xx_hal_timebase_tim.c # ASM sources ASM_SOURCES = \ @@ -182,6 +189,8 @@ C_INCLUDES = \ -IDrivers/Embedded-Base/general/include \ -IDrivers/Embedded-Base/platforms/stm32f405/include \ -IDrivers/Embedded-Base/middleware/include \ +-IDrivers/adbms/program/inc \ +-IDrivers/adbms/lib/inc \ -IMiddlewares/Third_Party/FreeRTOS/Source/include \ -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F @@ -205,7 +214,7 @@ CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" # LDFLAGS ####################################### # link script -LDSCRIPT = STM32F405RGTx_FLASH.ld +LDSCRIPT = stm32f405rgtx_flash.ld # libraries LIBS = -lc -lm -lnosys diff --git a/shepherd2.ioc b/shepherd2.ioc index f6c5a662..f4626d26 100644 --- a/shepherd2.ioc +++ b/shepherd2.ioc @@ -82,8 +82,9 @@ Dma.UART4_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE Dma.UART4_TX.1.PeriphInc=DMA_PINC_DISABLE Dma.UART4_TX.1.Priority=DMA_PRIORITY_LOW Dma.UART4_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -FREERTOS.IPParameters=Tasks01,configUSE_PREEMPTION,configUSE_MALLOC_FAILED_HOOK,configCHECK_FOR_STACK_OVERFLOW,configTOTAL_HEAP_SIZE -FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL +FREERTOS.FootprintOK=true +FREERTOS.IPParameters=Tasks01,configUSE_PREEMPTION,configUSE_MALLOC_FAILED_HOOK,configCHECK_FOR_STACK_OVERFLOW,configTOTAL_HEAP_SIZE,FootprintOK +FREERTOS.Tasks01=defaultTask,24,256,StartDefaultTask,Default,acc_data,Dynamic,NULL,NULL FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2 FREERTOS.configTOTAL_HEAP_SIZE=30000 FREERTOS.configUSE_MALLOC_FAILED_HOOK=1 @@ -103,9 +104,10 @@ Mcu.IP12=SPI3 Mcu.IP13=SYS Mcu.IP14=TIM1 Mcu.IP15=TIM2 -Mcu.IP16=TIM8 -Mcu.IP17=UART4 -Mcu.IP18=USB_OTG_FS +Mcu.IP16=TIM5 +Mcu.IP17=TIM8 +Mcu.IP18=UART4 +Mcu.IP19=USB_OTG_FS Mcu.IP2=CAN1 Mcu.IP3=CAN2 Mcu.IP4=DMA @@ -114,7 +116,7 @@ Mcu.IP6=I2C1 Mcu.IP7=IWDG Mcu.IP8=NVIC Mcu.IP9=RCC -Mcu.IPNb=19 +Mcu.IPNb=20 Mcu.Name=STM32F405RGTx Mcu.Package=LQFP64 Mcu.Pin0=PC13-ANTI_TAMP @@ -165,20 +167,21 @@ Mcu.Pin49=PB9 Mcu.Pin5=PC0 Mcu.Pin50=VP_FREERTOS_VS_CMSIS_V2 Mcu.Pin51=VP_IWDG_VS_IWDG -Mcu.Pin52=VP_SYS_VS_Systick +Mcu.Pin52=VP_SYS_VS_tim3 Mcu.Pin53=VP_TIM1_VS_ClockSourceINT Mcu.Pin54=VP_TIM2_VS_ClockSourceINT -Mcu.Pin55=VP_TIM8_VS_ClockSourceINT +Mcu.Pin55=VP_TIM5_VS_ClockSourceINT +Mcu.Pin56=VP_TIM8_VS_ClockSourceINT Mcu.Pin6=PC1 Mcu.Pin7=PC2 Mcu.Pin8=PC3 Mcu.Pin9=PA0-WKUP -Mcu.PinsNb=56 +Mcu.PinsNb=57 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F405RGTx -MxCube.Version=6.10.0 -MxDb.Version=DB.6.0.100 +MxCube.Version=6.13.0 +MxDb.Version=DB.6.0.130 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.CAN1_RX0_IRQn=true\:5\:0\:true\:false\:true\:true\:true\:true\:true NVIC.CAN2_RX0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true @@ -197,7 +200,10 @@ 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.TIM3_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true +NVIC.TimeBase=TIM3_IRQn +NVIC.TimeBaseIP=TIM3 NVIC.UART4_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false PA0-WKUP.Mode=Asynchronous @@ -452,11 +458,11 @@ SPI2.Mode=SPI_MODE_MASTER SPI2.NSS=SPI_NSS_SOFT SPI2.TIMode=SPI_TIMODE_DISABLE SPI2.VirtualType=VM_MASTER -SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2 +SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8 SPI3.CLKPhase=SPI_PHASE_1EDGE SPI3.CLKPolarity=SPI_POLARITY_LOW SPI3.CRCCalculation=SPI_CRCCALCULATION_DISABLE -SPI3.CalculateBaudRate=8.0 MBits/s +SPI3.CalculateBaudRate=2.0 MBits/s SPI3.DataSize=SPI_DATASIZE_8BIT SPI3.Direction=SPI_DIRECTION_2LINES SPI3.FirstBit=SPI_FIRSTBIT_MSB @@ -468,6 +474,9 @@ SPI3.VirtualType=VM_MASTER TIM1.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 TIM1.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 TIM1.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation3 CH3 +TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_DISABLE +TIM2.IPParameters=Prescaler,AutoReloadPreload +TIM2.Prescaler=16 TIM8.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 TIM8.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2 TIM8.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 @@ -491,12 +500,14 @@ 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_tim3.Mode=TIM3 +VP_SYS_VS_tim3.Signal=SYS_VS_tim3 VP_TIM1_VS_ClockSourceINT.Mode=Internal VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT VP_TIM2_VS_ClockSourceINT.Mode=Internal VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT +VP_TIM5_VS_ClockSourceINT.Mode=Internal +VP_TIM5_VS_ClockSourceINT.Signal=TIM5_VS_ClockSourceINT VP_TIM8_VS_ClockSourceINT.Mode=Internal VP_TIM8_VS_ClockSourceINT.Signal=TIM8_VS_ClockSourceINT board=custom diff --git a/STM32F405RGTx_FLASH.ld b/stm32f405rgtx_flash.ld similarity index 96% rename from STM32F405RGTx_FLASH.ld rename to stm32f405rgtx_flash.ld index 6f1d7fe7..4dcf56f0 100644 --- a/STM32F405RGTx_FLASH.ld +++ b/stm32f405rgtx_flash.ld @@ -203,7 +203,6 @@ SECTIONS libgcc.a ( * ) } - .ARM.attributes 0 : { *(.ARM.attributes) } }