Skip to content

Commit a35f0d9

Browse files
authored
Merge pull request #2 from DVMProject/v24-v2-dev
Switch to cmake for build, version 2 firmware updates
2 parents b3f11ce + fe21849 commit a35f0d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1977
-564
lines changed

.github/workflows/firmware-build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ jobs:
1616
uses: actions/checkout@v4
1717
- name: Install ARM GCC
1818
uses: carlosperate/arm-none-eabi-gcc-action@v1
19-
- name: Run make
20-
run: make
21-
working-directory: ./fw
19+
- name: Run cmake
20+
uses: threeal/[email protected]
21+
with:
22+
source-dir: ./fw
2223
- name: Upload artifacts
2324
uses: actions/upload-artifact@v4
2425
with:

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,87 @@ DVM-V24 boards are available from the [W3AXL Online Store](https://store.w3axl.c
99

1010
Schematics for the board are also included in the `hw` directory to build your own adapters.
1111

12+
### Hardware Revisions
13+
14+
There are two hardware revisions, the original "V1" boards, and the newer "V2" boards. The V2 boards offload the USB->serial functionality to a dedicated CP2102 chip which alleviates some lockup/freezing issues that were encountered with the original V1 hardware.
15+
16+
The two hardware revisions require different firmware binaries, but both can be built from the same repository and commands.
17+
1218
### The `CLKSEL` Jumper
1319

14-
This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. In the future, the board will support external clocking, but for now the firmware only supports generating clocks for both TX & RX.
20+
This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. Version 1 boards require a jumper to be in place, while version 2 boards have the solder jumper shorted by default. In the future, the boards may support external clocking, but for now the firmware only supports generating clocks for both TX & RX.
21+
22+
### `UBT0` and `URST` Jumpers
23+
24+
These jumpers are specific to the version 2 boards and enable the RTS and DTR signals of the serial chip to force the board into UART bootloader mode. This will allow for programming using `stm32flash` even without access to the software boot command in `dvmhost`. By default these jumpers are **not** connected and must be bridged with solder to enable RTS/DTR boot control. Note that with these jumpers shorted, the V24 board will reset when `dvmhost` connects.
1525

1626
## Firmware
1727
Firmware is availble in this repo, under the `fw` directory. It's written in bare C, generated from STM32CubeMX. You will need an STLink programmer in order to flash the boards with the latest version of software.
1828

1929
### Building the latest firmware
2030
We recommend building the firmware for the DVM-V24 on a linux-based machine, since it's much easier to set up a working ARM toolchain.
2131

22-
Once you have the ARM toolchain installed, simply running `make` will create binary & elf files in a `./build/` directory. These can then be flashed using the STLink using the `make flash` command.
32+
On debian machines, you will need to install the following packages to build the fw:
33+
34+
```bash
35+
sudo apt install gcc-arm-none-eabi cmake
36+
```
37+
38+
Once you have the everything installed, perform the following steps to prepare the build environment:
39+
40+
```bash
41+
mkdir build
42+
cd build
43+
cmake ..
44+
```
45+
46+
Finally, you can build firmware individually for the v1 or v2 boards, or build both binaries:
47+
48+
```bash
49+
# To build for V1 only:
50+
make dvm-v24-v1
51+
# or to build for V2:
52+
make dvm-v24-v2
53+
# make with no options will build both v1 and v2 binaries
54+
make
55+
```
56+
57+
### Flashing the firmware
58+
59+
#### Using STLink programmer
60+
61+
You may use the SWD headers on the board to load firmware via an STLink programmer. This is required for the V1 boards, and on the V2 boards if the firmware becomes corrupted and USB loading no longer works.
62+
63+
First make sure the stlink-tools are installed on your system:
64+
65+
```bash
66+
sudo apt install stlink-tools
67+
```
68+
69+
Then you can flash the board by using the following command
70+
```bash
71+
st-flash --reset write dvm-v24-xxx.bin 0x8000000
72+
```
73+
74+
#### Using USB flashing
75+
76+
DVMV24-V2 boards can be loaded using the ST serial bootloader, in the same way that DVM modems can. First, you must put the board into bootloader mode using `dvmhost` in calibration mode:
77+
78+
```bash
79+
./dvmhost -c <config file.yml> --cal
80+
```
81+
82+
Then, enter bootloader mode using the `!` command. DVMHost will exit, and at this point you can use the stm32flash command:
83+
84+
```bash
85+
stm32flash -v -w ./dvm-v24-v2.bin -R /dev/ttyUSBx
86+
```
87+
88+
If you have the `UBT0` and `URST` jumpers shorted, you can also flash the board using DTR & RTS in a single command as follows:
89+
90+
```bash
91+
stm32flash -v -w ./dvm-v24-v2.bin -i 'rts&-dtr:-rts&dtr' /dev/ttyUSBx
92+
```
2393

2494
## Quick Start
2595

fw/.mxproject

Lines changed: 6 additions & 1 deletion
Large diffs are not rendered by default.

fw/CMakeLists.txt

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
#
4+
# This file is generated only once,
5+
# and is not re-generated if converter is called multiple times.
6+
#
7+
# User is free to modify the file as much as necessary
8+
#
9+
10+
# Setup compiler settings
11+
set(CMAKE_C_STANDARD 11)
12+
set(CMAKE_C_STANDARD_REQUIRED ON)
13+
set(CMAKE_C_EXTENSIONS ON)
14+
15+
16+
# Define the build type
17+
if(NOT CMAKE_BUILD_TYPE)
18+
set(CMAKE_BUILD_TYPE "Debug")
19+
endif()
20+
21+
# Set the project name
22+
set(CMAKE_PROJECT_NAME DVM-V24)
23+
set(CMAKE_TARGET_V1 dvm-v24-v1)
24+
set(CMAKE_TARGET_V2 dvm-v24-v2)
25+
26+
# Include toolchain file
27+
include("cmake/gcc-arm-none-eabi.cmake")
28+
29+
# Enable compile command to ease indexing with e.g. clangd
30+
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
31+
32+
# Enable CMake support for ASM and C languages
33+
enable_language(C ASM)
34+
35+
#
36+
# Set GIT_VER compiler directive
37+
#
38+
set(GIT_VER "")
39+
set(GIT_VER_HASH "UNKNOWN")
40+
execute_process(COMMAND git describe --abbrev=8 --dirty --always WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_VER OUTPUT_STRIP_TRAILING_WHITESPACE)
41+
execute_process(COMMAND git describe --abbrev=8 --always WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_VER_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
42+
message("Git Version: " ${GIT_VER})
43+
message("Git Hash: " ${GIT_VER_HASH})
44+
45+
# Core project settings
46+
project(${CMAKE_PROJECT_NAME})
47+
message("Build type: " ${CMAKE_BUILD_TYPE})
48+
49+
# Remap __FILE__ directive to display filename only, not full path
50+
message("Remapping ${CMAKE_SOURCE_DIR}/ to /")
51+
add_definitions(-fmacro-prefix-map="${CMAKE_SOURCE_DIR}/=/")
52+
53+
# Create executables
54+
add_executable(${CMAKE_TARGET_V1})
55+
add_executable(${CMAKE_TARGET_V2})
56+
57+
# Add STM32CubeMX generated sources
58+
add_subdirectory(cmake/stm32cubemx)
59+
60+
# Common source files
61+
set(V24_SOURCES
62+
v24/src/fault.c
63+
v24/src/fifo.c
64+
v24/src/hdlc.c
65+
v24/src/log.c
66+
v24/src/serial.c
67+
v24/src/sync.c
68+
v24/src/util.c
69+
v24/src/vcp.c
70+
)
71+
72+
# Common includes
73+
set(V24_INCLUDE v24/inc)
74+
75+
#
76+
# V1 Target Setup
77+
#
78+
target_link_directories(${CMAKE_TARGET_V1} PRIVATE
79+
)
80+
81+
target_sources(${CMAKE_TARGET_V1} PRIVATE
82+
${V24_SOURCES}
83+
)
84+
85+
target_include_directories(${CMAKE_TARGET_V1} PRIVATE
86+
${V24_INCLUDE}
87+
)
88+
89+
target_compile_definitions(${CMAKE_TARGET_V1} PRIVATE
90+
DVM_V24_V1
91+
GIT_HASH="${GIT_VER_HASH}"
92+
)
93+
94+
# Add linked libraries
95+
target_link_libraries(${CMAKE_TARGET_V1}
96+
stm32cubemx
97+
)
98+
99+
# Add .bin generation
100+
add_custom_command(TARGET ${CMAKE_TARGET_V1}
101+
POST_BUILD
102+
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_TARGET_V1}> ${CMAKE_TARGET_V1}.bin
103+
)
104+
105+
#
106+
# V2 Target Setup
107+
#
108+
target_link_directories(${CMAKE_TARGET_V2} PRIVATE
109+
)
110+
111+
target_sources(${CMAKE_TARGET_V2} PRIVATE
112+
${V24_SOURCES}
113+
)
114+
115+
target_include_directories(${CMAKE_TARGET_V2} PRIVATE
116+
${V24_INCLUDE}
117+
)
118+
119+
target_compile_definitions(${CMAKE_TARGET_V2} PRIVATE
120+
GIT_HASH="${GIT_VER_HASH}"
121+
)
122+
123+
# Add linked libraries
124+
target_link_libraries(${CMAKE_TARGET_V2}
125+
stm32cubemx
126+
)
127+
128+
# Add .bin generation
129+
add_custom_command(TARGET ${CMAKE_TARGET_V2}
130+
POST_BUILD
131+
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_TARGET_V2}> ${CMAKE_TARGET_V2}.bin
132+
)
133+
134+
# Make sure bins are cleaned
135+
set_property(
136+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
137+
APPEND
138+
PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_TARGET_V1}.bin ${CMAKE_TARGET_V2}.bin
139+
)

fw/CMakePresets.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"version": 3,
3+
"configurePresets": [
4+
{
5+
"name": "default",
6+
"hidden": true,
7+
"generator": "Ninja",
8+
"binaryDir": "${sourceDir}/build/${presetName}",
9+
"toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",
10+
"cacheVariables": {
11+
}
12+
},
13+
{
14+
"name": "Debug",
15+
"inherits": "default",
16+
"cacheVariables": {
17+
"CMAKE_BUILD_TYPE": "Debug"
18+
}
19+
},
20+
{
21+
"name": "RelWithDebInfo",
22+
"inherits": "default",
23+
"cacheVariables": {
24+
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
25+
}
26+
},
27+
{
28+
"name": "Release",
29+
"inherits": "default",
30+
"cacheVariables": {
31+
"CMAKE_BUILD_TYPE": "Release"
32+
}
33+
},
34+
{
35+
"name": "MinSizeRel",
36+
"inherits": "default",
37+
"cacheVariables": {
38+
"CMAKE_BUILD_TYPE": "MinSizeRel"
39+
}
40+
}
41+
],
42+
"buildPresets": [
43+
{
44+
"name": "Debug",
45+
"configurePreset": "Debug"
46+
},
47+
{
48+
"name": "RelWithDebInfo",
49+
"configurePreset": "RelWithDebInfo"
50+
},
51+
{
52+
"name": "Release",
53+
"configurePreset": "Release"
54+
},
55+
{
56+
"name": "MinSizeRel",
57+
"configurePreset": "MinSizeRel"
58+
}
59+
]
60+
}

fw/Core/Inc/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353
void Error_Handler(void);
5454

5555
/* USER CODE BEGIN EFP */
56-
56+
void ResetMCU();
5757
/* USER CODE END EFP */
5858

5959
/* Private defines -----------------------------------------------------------*/

fw/Core/Inc/stm32f1xx_it.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ void SVC_Handler(void);
5555
void DebugMon_Handler(void);
5656
void PendSV_Handler(void);
5757
void SysTick_Handler(void);
58+
void DMA1_Channel4_IRQHandler(void);
59+
void DMA1_Channel5_IRQHandler(void);
5860
void DMA1_Channel7_IRQHandler(void);
5961
void USB_HP_CAN1_TX_IRQHandler(void);
6062
void USB_LP_CAN1_RX0_IRQHandler(void);
6163
void TIM2_IRQHandler(void);
64+
void USART1_IRQHandler(void);
6265
void USART2_IRQHandler(void);
6366
/* USER CODE BEGIN EFP */
6467

fw/Core/Inc/usart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ extern "C" {
3232

3333
/* USER CODE END Includes */
3434

35+
extern UART_HandleTypeDef huart1;
36+
3537
extern UART_HandleTypeDef huart2;
3638

3739
/* USER CODE BEGIN Private defines */
3840

3941
/* USER CODE END Private defines */
4042

43+
void MX_USART1_UART_Init(void);
4144
void MX_USART2_UART_Init(void);
4245

4346
/* USER CODE BEGIN Prototypes */

fw/Core/Src/dma.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ void MX_DMA_Init(void)
4343
__HAL_RCC_DMA1_CLK_ENABLE();
4444

4545
/* DMA interrupt init */
46+
/* DMA1_Channel5_IRQn interrupt configuration */
47+
// Disabling this for now since we're using IT mode instead of DMA mode for USARt 1 */
48+
//HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_PRI_USART1_RX, 0);
49+
//HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
4650
/* DMA1_Channel7_IRQn interrupt configuration */
47-
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_DMA, 0);
51+
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_USART2_DMA, 0);
4852
HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
4953

5054
}

0 commit comments

Comments
 (0)