Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/firmware-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ jobs:
uses: actions/checkout@v4
- name: Install ARM GCC
uses: carlosperate/arm-none-eabi-gcc-action@v1
- name: Run make
run: make
working-directory: ./fw
- name: Run cmake
uses: threeal/cmake-action@v2.0.0
with:
source-dir: ./fw
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,87 @@ DVM-V24 boards are available from the [W3AXL Online Store](https://store.w3axl.c

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

### Hardware Revisions

There are two hardware revisions, the original "V1" boards, and the newer "V2" boards. The V2 boards offload the USB->serial functionality to a dedicated CP2102 chip which alleviates some lockup/freezing issues that were encountered with the original V1 hardware.

The two hardware revisions require different firmware binaries, but both can be built from the same repository and commands.

### The `CLKSEL` Jumper

This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. In the future, the board will support external clocking, but for now the firmware only supports generating clocks for both TX & RX.
This jumper connects the serial clock line to the `RXCLK` pin. Currently this jumper must be in place for the V24 adapter to work properly. Version 1 boards require a jumper to be in place, while version 2 boards have the solder jumper shorted by default. In the future, the boards may support external clocking, but for now the firmware only supports generating clocks for both TX & RX.

### `UBT0` and `URST` Jumpers

These jumpers are specific to the version 2 boards and enable the RTS and DTR signals of the serial chip to force the board into UART bootloader mode. This will allow for programming using `stm32flash` even without access to the software boot command in `dvmhost`. By default these jumpers are **not** connected and must be bridged with solder to enable RTS/DTR boot control. Note that with these jumpers shorted, the V24 board will reset when `dvmhost` connects.

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

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

Once you have the ARM toolchain installed, simply running `make` will create binary & elf files in a `./build/` directory. These can then be flashed using the STLink using the `make flash` command.
On debian machines, you will need to install the following packages to build the fw:

```bash
sudo apt install gcc-arm-none-eabi cmake
```

Once you have the everything installed, perform the following steps to prepare the build environment:

```bash
mkdir build
cd build
cmake ..
```

Finally, you can build firmware individually for the v1 or v2 boards, or build both binaries:

```bash
# To build for V1 only:
make dvm-v24-v1
# or to build for V2:
make dvm-v24-v2
# make with no options will build both v1 and v2 binaries
make
```

### Flashing the firmware

#### Using STLink programmer

You may use the SWD headers on the board to load firmware via an STLink programmer. This is required for the V1 boards, and on the V2 boards if the firmware becomes corrupted and USB loading no longer works.

First make sure the stlink-tools are installed on your system:

```bash
sudo apt install stlink-tools
```

Then you can flash the board by using the following command
```bash
st-flash --reset write dvm-v24-xxx.bin 0x8000000
```

#### Using USB flashing

DVMV24-V2 boards can be loaded using the ST serial bootloader, in the same way that DVM modems can. First, you must put the board into bootloader mode using `dvmhost` in calibration mode:

```bash
./dvmhost -c <config file.yml> --cal
```

Then, enter bootloader mode using the `!` command. DVMHost will exit, and at this point you can use the stm32flash command:

```bash
stm32flash -v -w ./dvm-v24-v2.bin -R /dev/ttyUSBx
```

If you have the `UBT0` and `URST` jumpers shorted, you can also flash the board using DTR & RTS in a single command as follows:

```bash
stm32flash -v -w ./dvm-v24-v2.bin -i 'rts&-dtr:-rts&dtr' /dev/ttyUSBx
```

## Quick Start

Expand Down
7 changes: 6 additions & 1 deletion fw/.mxproject

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions fw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
cmake_minimum_required(VERSION 3.22)

#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#

# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)


# Define the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

# Set the project name
set(CMAKE_PROJECT_NAME DVM-V24)
set(CMAKE_TARGET_V1 dvm-v24-v1)
set(CMAKE_TARGET_V2 dvm-v24-v2)

# Include toolchain file
include("cmake/gcc-arm-none-eabi.cmake")

# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# Enable CMake support for ASM and C languages
enable_language(C ASM)

#
# Set GIT_VER compiler directive
#
set(GIT_VER "")
set(GIT_VER_HASH "UNKNOWN")
execute_process(COMMAND git describe --abbrev=8 --dirty --always WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_VER OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git describe --abbrev=8 --always WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_VER_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
message("Git Version: " ${GIT_VER})
message("Git Hash: " ${GIT_VER_HASH})

# Core project settings
project(${CMAKE_PROJECT_NAME})
message("Build type: " ${CMAKE_BUILD_TYPE})

# Remap __FILE__ directive to display filename only, not full path
message("Remapping ${CMAKE_SOURCE_DIR}/ to /")
add_definitions(-fmacro-prefix-map="${CMAKE_SOURCE_DIR}/=/")

# Create executables
add_executable(${CMAKE_TARGET_V1})
add_executable(${CMAKE_TARGET_V2})

# Add STM32CubeMX generated sources
add_subdirectory(cmake/stm32cubemx)

# Common source files
set(V24_SOURCES
v24/src/fault.c
v24/src/fifo.c
v24/src/hdlc.c
v24/src/log.c
v24/src/serial.c
v24/src/sync.c
v24/src/util.c
v24/src/vcp.c
)

# Common includes
set(V24_INCLUDE v24/inc)

#
# V1 Target Setup
#
target_link_directories(${CMAKE_TARGET_V1} PRIVATE
)

target_sources(${CMAKE_TARGET_V1} PRIVATE
${V24_SOURCES}
)

target_include_directories(${CMAKE_TARGET_V1} PRIVATE
${V24_INCLUDE}
)

target_compile_definitions(${CMAKE_TARGET_V1} PRIVATE
DVM_V24_V1
GIT_HASH="${GIT_VER_HASH}"
)

# Add linked libraries
target_link_libraries(${CMAKE_TARGET_V1}
stm32cubemx
)

# Add .bin generation
add_custom_command(TARGET ${CMAKE_TARGET_V1}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_TARGET_V1}> ${CMAKE_TARGET_V1}.bin
)

#
# V2 Target Setup
#
target_link_directories(${CMAKE_TARGET_V2} PRIVATE
)

target_sources(${CMAKE_TARGET_V2} PRIVATE
${V24_SOURCES}
)

target_include_directories(${CMAKE_TARGET_V2} PRIVATE
${V24_INCLUDE}
)

target_compile_definitions(${CMAKE_TARGET_V2} PRIVATE
GIT_HASH="${GIT_VER_HASH}"
)

# Add linked libraries
target_link_libraries(${CMAKE_TARGET_V2}
stm32cubemx
)

# Add .bin generation
add_custom_command(TARGET ${CMAKE_TARGET_V2}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_TARGET_V2}> ${CMAKE_TARGET_V2}.bin
)

# Make sure bins are cleaned
set_property(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
APPEND
PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_TARGET_V1}.bin ${CMAKE_TARGET_V2}.bin
)
60 changes: 60 additions & 0 deletions fw/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"version": 3,
"configurePresets": [
{
"name": "default",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",
"cacheVariables": {
}
},
{
"name": "Debug",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "RelWithDebInfo",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "Release",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "MinSizeRel",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "MinSizeRel"
}
}
],
"buildPresets": [
{
"name": "Debug",
"configurePreset": "Debug"
},
{
"name": "RelWithDebInfo",
"configurePreset": "RelWithDebInfo"
},
{
"name": "Release",
"configurePreset": "Release"
},
{
"name": "MinSizeRel",
"configurePreset": "MinSizeRel"
}
]
}
2 changes: 1 addition & 1 deletion fw/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
void Error_Handler(void);

/* USER CODE BEGIN EFP */

void ResetMCU();
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
Expand Down
3 changes: 3 additions & 0 deletions fw/Core/Inc/stm32f1xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel4_IRQHandler(void);
void DMA1_Channel5_IRQHandler(void);
void DMA1_Channel7_IRQHandler(void);
void USB_HP_CAN1_TX_IRQHandler(void);
void USB_LP_CAN1_RX0_IRQHandler(void);
void TIM2_IRQHandler(void);
void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
/* USER CODE BEGIN EFP */

Expand Down
3 changes: 3 additions & 0 deletions fw/Core/Inc/usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ extern "C" {

/* USER CODE END Includes */

extern UART_HandleTypeDef huart1;

extern UART_HandleTypeDef huart2;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_USART1_UART_Init(void);
void MX_USART2_UART_Init(void);

/* USER CODE BEGIN Prototypes */
Expand Down
6 changes: 5 additions & 1 deletion fw/Core/Src/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ void MX_DMA_Init(void)
__HAL_RCC_DMA1_CLK_ENABLE();

/* DMA interrupt init */
/* DMA1_Channel5_IRQn interrupt configuration */
// Disabling this for now since we're using IT mode instead of DMA mode for USARt 1 */
//HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_PRI_USART1_RX, 0);
//HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
/* DMA1_Channel7_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_DMA, 0);
HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, NVIC_PRI_USART2_DMA, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);

}
Expand Down
Loading
Loading