Skip to content

Commit

Permalink
Add support for STM32H733xx (#1057)
Browse files Browse the repository at this point in the history
### Summary
<!-- Quick summary of changes, optional -->

Support binaries for STMH733xx microcontrollers, and add a project for
the H7 dev board.

### Changelist 
<!-- Give a list of the changes covered in this PR. This will help both
you and the reviewer keep this PR within scope. -->

- Support ARM Cortex-M7
- Support STM33H7xx microcontrollers with SEGGER SystemView, FreeRTOS,
and H7 HAL drivers
- Add project for H7 dev board

Note: CAN is not supported on H7 yet, since it ST's FD CAN HAL driver
rather than ST's CAN HAL driver (which we use on the rest of our
microcontrollers).

### Testing Done
<!-- Outline the testing that was done to demonstrate the changes are
solid. This could be unit tests, integration tests, testing on the car,
etc. Include relevant code snippets, screenshots, etc as needed. -->

- None

### Resolved Issues
<!-- Link any issues that this PR resolved like so: `Resolves #1, #2,
and #5` (Note: Using this format, Github will automatically close the
issue(s) when this PR is merged in). -->

### Checklist
*Please change `[ ]` to `[x]` when you are ready.*
- [x] I have read and followed the code conventions detailed in
[README.md](../README.md) (*This will save time for both you and the
reviewer!*).
- [x] If this pull request is longer then **500** lines, I have provided
*explicit* justification in the summary above explaining why I *cannot*
break this up into multiple pull requests (*Small PR's are faster and
less painful for everyone involved!*).
  • Loading branch information
gtaharaedmonds authored Nov 16, 2023
1 parent 73c12c6 commit 4188410
Show file tree
Hide file tree
Showing 24 changed files with 2,817 additions and 55 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@
"showDevDebugOutput": "none",
"preLaunchTask": "Build: DIM.elf"
},
{
"name": "Debug Embedded: h7dev",
"cwd": "${workspaceRoot}",
"executable": "build_fw_deploy/firmware/dev/h7dev/h7dev.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": [
"tools/openocd/stm32h7x.cfg"
],
"showDevDebugOutput": "none",
"preLaunchTask": "Build: h7dev.elf",
"postLaunchCommands": [
"help"
]
},
{
"name": "Debug Tests: BMS",
"type": "cppdbg",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
],
"cmake.buildDirectory": "${workspaceFolder}/${env:BUILD_DIR}",
"cmake.configureOnEdit": false,
"cmake.configureOnOpen": true
"cmake.configureOnOpen": true,
"cortex-debug.variableUseNaturalFormat": false
}
11 changes: 10 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
"cwd": "${workspaceFolder}/build_fw_deploy"
}
},
{
"label": "Build: h7dev.elf",
"type": "shell",
"command": "make -j`nproc` h7dev.elf",
"group": "build",
"options": {
"cwd": "${workspaceFolder}/build_fw_deploy"
}
},
{
"label": "Build: BMS_test",
"type": "shell",
Expand Down Expand Up @@ -166,7 +175,7 @@
{
"label": "Launch: STM32CubeMX",
"type": "shell",
"command": "java -jar STM32CubeMX",
"command": "./STM32CubeMX",
"group": "build",
"linux": {
"options": {
Expand Down
9 changes: 8 additions & 1 deletion firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ if("${TARGET}" STREQUAL "deploy")
CPMAddPackage(
NAME STM32CUBEF4
GITHUB_REPOSITORY UBCFormulaElectric/STM32CubeF4
GIT_TAG 3e907f8
GIT_TAG 3e907f83929363b6909ae1d9a3b7305866a67b82
)

# STM32H7Cube firmware package: Contains STM32 HAL drivers and FreeRTOS with the CMSIS-RTOS v2 API.
CPMAddPackage(
NAME STM32CUBEH7
GITHUB_REPOSITORY UBCFormulaElectric/STM32CubeH7
GIT_TAG 1e1def98759f14a4977ef6234c90dc10cbf43a48
)

# littlefs: Filesystem for microcontrollers
Expand Down
85 changes: 85 additions & 0 deletions firmware/cmake/embedded.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ set(CM4_FPU_FLAGS
-mfpu=fpv4-sp-d16
)

set(CM7_DEFINES
-DARM_MATH_CM7
)
set(CM7_FPU_FLAGS
-mcpu=cortex-m4
-mfloat-abi=hard
-mfpu=fpv5-d16
)

function(embedded_library
LIB_NAME
LIB_SRCS
Expand Down Expand Up @@ -96,6 +105,10 @@ function(embedded_library
list(APPEND COMPILER_DEFINES ${CM4_DEFINES})
list(APPEND COMPILER_FLAGS ${CM4_FPU_FLAGS})
list(APPEND LINKER_FLAGS ${CM4_FPU_FLAGS})
elseif("${ARM_CORE}" STREQUAL "cm7")
list(APPEND COMPILER_DEFINES ${CM7_DEFINES})
list(APPEND COMPILER_FLAGS ${CM7_FPU_FLAGS})
list(APPEND LINKER_FLAGS ${CM7_FPU_FLAGS})
endif()

target_compile_definitions(${LIB_NAME}
Expand Down Expand Up @@ -135,6 +148,10 @@ function(embedded_binary
list(APPEND COMPILER_DEFINES ${CM4_DEFINES})
list(APPEND COMPILER_FLAGS ${CM4_FPU_FLAGS})
list(APPEND LINKER_FLAGS ${CM4_FPU_FLAGS})
elseif("${ARM_CORE}" STREQUAL "cm7")
list(APPEND COMPILER_DEFINES ${CM7_DEFINES})
list(APPEND COMPILER_FLAGS ${CM7_FPU_FLAGS})
list(APPEND LINKER_FLAGS ${CM7_FPU_FLAGS})
endif()

target_compile_definitions(${BIN_NAME}
Expand Down Expand Up @@ -281,3 +298,71 @@ function(stm32f412rx_cube_library
)
endfunction()

function(stm32h733xx_cube_library
HAL_LIB_NAME
HAL_CONF_DIR
HAL_SRCS
SYSCALLS
IOC_CHECKSUM
)
set(DRIVERS_DIR "${STM32CUBEH7_SOURCE_DIR}/Drivers")
set(FREERTOS_DIR "${STM32CUBEH7_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source")

# Set include directories for STM32Cube library.
set(STM32CUBE_INCLUDE_DIRS
"${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Inc"
"${DRIVERS_DIR}/CMSIS/Include"
"${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Inc/Legacy"
"${DRIVERS_DIR}/CMSIS/Device/ST/STM32H7xx/Include"
"${FREERTOS_DIR}/include"
"${FREERTOS_DIR}/CMSIS_RTOS_V2"
"${FREERTOS_DIR}/portable/GCC/ARM_CM4F"
"${HAL_CONF_DIR}"
"${SYSTEMVIEW_DIR}/SEGGER"
"${SYSTEMVIEW_DIR}/Config"
"${SYSTEMVIEW_DIR}/Sample/FreeRTOSV10"
)
# HAL sources.
set(STM32_HAL_SRCS)
foreach(HAL_SRC ${HAL_SRCS})
list(APPEND STM32_HAL_SRCS "${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Src/${HAL_SRC}")
endforeach()

# FreeRTOS sources.
file(GLOB RTOS_SRCS
"${FREERTOS_DIR}/*.c"
"${FREERTOS_DIR}/CMSIS_RTOS_V2/*.c"
"${FREERTOS_DIR}/portable/GCC/ARM_CM4F/*.c"
)

# SEGGER SystemView sources.
file(GLOB SYSTEMVIEW_SRCS
"${SYSTEMVIEW_DIR}/SEGGER/*.c"
"${SYSTEMVIEW_DIR}/SEGGER/*.S"
)
# We use ARM's embedded GCC compiler, so append the GCC-specific SysCalls.
list(APPEND SYSTEMVIEW_SRCS "${SYSTEMVIEW_DIR}/SEGGER/Syscalls/SEGGER_RTT_Syscalls_GCC.c")
# Append the FreeRTOS patch to get SystemView to work with FreeRTOS. All of our boards use FreeRTOS 10.3.1.
file(GLOB_RECURSE SYSTEMVIEW_FREERTOS_SRCS "${SYSTEMVIEW_DIR}/Sample/FreeRTOSV10/*.c")
list(APPEND SYSTEMVIEW_SRCS ${SYSTEMVIEW_FREERTOS_SRCS})

# newlib_freertos_patch adds thread-safe malloc so we can use the heap and FreeRTOS.
file(GLOB_RECURSE NEWLIB_SRCS "${NEWLIB_DIR}/*.c")

# Startup assembly script.
set(STARTUP_SRC "${DRIVERS_DIR}/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h733xx.s")

set(STM32CUBE_SRCS ${STM32_HAL_SRCS} ${RTOS_SRCS} ${SYSTEMVIEW_SRCS} ${SYSCALLS} ${NEWLIB_SRCS} ${IOC_CHECKSUM} ${STARTUP_SRC})
embedded_library(
"${HAL_LIB_NAME}"
"${STM32CUBE_SRCS}"
"${STM32CUBE_INCLUDE_DIRS}"
"cm7"
TRUE
)
target_compile_definitions(${HAL_LIB_NAME}
PUBLIC
-DSTM32H733xx
)
endfunction()

3 changes: 2 additions & 1 deletion firmware/dev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(f4dev)
add_subdirectory(f4dev)
add_subdirectory(h7dev)
75 changes: 75 additions & 0 deletions firmware/dev/h7dev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
set(ARM_CORE "cm7")
set(IOC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/h7dev.ioc")
set(LINKER_SCRIPT "${THIRD_PARTY_DIR}/linker/STM32H733VGTX_FLASH.ld")

file(GLOB_RECURSE APP_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/app/*.c")
list(APPEND APP_SRCS "${SHARED_APP_SRCS}")
list(REMOVE_ITEM APP_SRCS "${SHARED_EMBEDDED_DIR}/app/App_SharedSetPeriodicCanSignals.c")
list(REMOVE_ITEM APP_SRCS "${SHARED_EMBEDDED_DIR}/app/App_SharedSignal.c")
list(REMOVE_ITEM APP_SRCS "${SHARED_EMBEDDED_DIR}/app/App_SharedHeartbeatMonitor.c")
list(REMOVE_ITEM APP_SRCS "${SHARED_EMBEDDED_DIR}/app/App_SharedStateMachine.c")
list(REMOVE_ITEM APP_SRCS "${SHARED_EMBEDDED_DIR}/app/App_SharedWaitSignal.c")
set(APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/app" "${SHARED_APP_INCLUDE_DIR}")

file(GLOB_RECURSE IO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/io/*.c")
list(APPEND IO_SRCS "${SHARED_IO_SRCS}")
list(REMOVE_ITEM IO_SRCS "${SHARED_IO_INCLUDE_DIR}/Io_SharedAdc.c")
list(REMOVE_ITEM IO_SRCS "${SHARED_IO_INCLUDE_DIR}/Io_SharedSpi.c")
list(REMOVE_ITEM IO_SRCS "${SHARED_EMBEDDED_DIR}/io/Io_SharedCan.c")
set(IO_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/io" "${SHARED_IO_INCLUDE_DIR}")

file(GLOB_RECURSE HW_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/src/hw/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/Src/*.c"
)
list(APPEND HW_SRCS "${SHARED_HW_SRCS}")
list(REMOVE_ITEM HW_SRCS "${SHARED_EMBEDDED_DIR}/hw/hw_sd.c")
set(HW_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/hw" "${SHARED_HW_INCLUDE_DIR}")


if("${TARGET}" STREQUAL "deploy")
generate_stm32cube_code(
"h7dev"
"${IOC_PATH}"
)

set(STM32_HAL_SRCS
"stm32h7xx_hal_adc_ex.c"
"stm32h7xx_hal_adc.c"
"stm32h7xx_hal_cortex.c"
"stm32h7xx_hal_dma_ex.c"
"stm32h7xx_hal_dma.c"
"stm32h7xx_hal_exti.c"
"stm32h7xx_hal_gpio.c"
"stm32h7xx_hal_iwdg.c"
"stm32h7xx_hal_pwr_ex.c"
"stm32h7xx_hal_rcc_ex.c"
"stm32h7xx_hal_rcc.c"
"stm32h7xx_hal_tim_ex.c"
"stm32h7xx_hal_tim.c"
"stm32h7xx_hal_uart_ex.c"
"stm32h7xx_hal_uart.c"
"stm32h7xx_hal.c"
)

# Pass syscalls to the cube library so we can build without warnings.
set(SYSCALLS "${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/Src/syscalls.c")
stm32h733xx_cube_library(
"h7dev_stm32cube"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/Inc"
"${STM32_HAL_SRCS}"
"${SYSCALLS}"
"${IOC_PATH}.md5"
)

set(SRCS ${APP_SRCS} ${IO_SRCS} ${HW_SRCS})
set(INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${IO_INCLUDE_DIRS} ${HW_INCLUDE_DIRS})
embedded_binary(
"h7dev.elf"
"${SRCS}"
"${INCLUDE_DIRS}"
"${LINKER_SCRIPT}"
"${ARM_CORE}"
)
target_link_libraries("h7dev.elf" "h7dev_stm32cube")
endif()
Loading

0 comments on commit 4188410

Please sign in to comment.