diff options
-rw-r--r-- | .gdbinit | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | include/radio-controller.h | 15 | ||||
-rwxr-xr-x | launch-openocd | 16 | ||||
-rw-r--r-- | openocd.cfg | 18 | ||||
-rw-r--r-- | src/radio-controller.cpp | 20 | ||||
-rw-r--r-- | stm32cubemx/Inc/main.h | 8 | ||||
-rw-r--r-- | stm32cubemx/Src/main.c | 2 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_it.c | 4 | ||||
m--------- | thirdparty/mcu.cmake | 0 | ||||
m--------- | thirdparty/mcucpp | 0 |
11 files changed, 71 insertions, 19 deletions
@@ -23,6 +23,8 @@ define run_firmware continue end +set print pretty + target extended-remote :3333 set confirm off file build/firmware diff --git a/CMakeLists.txt b/CMakeLists.txt index 4097d5a..2826974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,9 @@ project(radio-controller C CXX ASM) set(CMAKE_CXX_STANDARD 14) -add_executable(firmware src/radio-controller.cpp) +add_executable(firmware src/radio-controller.cpp include/radio-controller.h) target_compile_definitions(firmware PUBLIC MCUCMAKE_USING_STM32CUBEMX=1) +target_include_directories(firmware PUBLIC include) target_link_libraries(firmware PUBLIC gcc) mcu_add_executable(TARGET firmware) @@ -34,7 +35,7 @@ target_include_directories(firmware PUBLIC ) target_sources(firmware PUBLIC thirdparty/mcucpp/src/arm/semihosting.cpp - thirdparty/mcucpp/src/arm/semihosting-putc.cpp + thirdparty/mcucpp/src/arm/semihosting-puts.cpp thirdparty/mcucpp/src/arm/semihosting-putchar.cpp thirdparty/mcucpp/src/generic/tinyprintf-printf.cpp thirdparty/mcucpp/src/generic/tinyprintf-snprintf.cpp diff --git a/include/radio-controller.h b/include/radio-controller.h new file mode 100644 index 0000000..58f2594 --- /dev/null +++ b/include/radio-controller.h @@ -0,0 +1,15 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void main_pre_init(); +void main_post_init(); +void main_loop(); + +void it_tim1(); + +#ifdef __cplusplus +} +#endif diff --git a/launch-openocd b/launch-openocd new file mode 100755 index 0000000..18b30b2 --- /dev/null +++ b/launch-openocd @@ -0,0 +1,16 @@ +#!/bin/sh + +stlinkv2=$(lsusb -d 0483:374b | wc -l) +olimex=$(lsusb -d 15ba:002a | wc -l) + +DEVICE= +if [ $stlinkv2 -gt 0 ] +then + DEVICE=stlinkv2 +elif [ $olimex -gt 0 ] +then + DEVICE=olimex-arm-usb-tiny-h +fi + +export DEVICE +exec openocd -f openocd.cfg diff --git a/openocd.cfg b/openocd.cfg index 15a42d4..48d7292 100644 --- a/openocd.cfg +++ b/openocd.cfg @@ -1,5 +1,19 @@ -source [find interface/stlink-v2.cfg] -source [find target/stm32f1x.cfg] +if { [info exists env(DEVICE)] } { + set device $env(DEVICE) +} else { + set device "stlink-v2" +} + +switch $device { + "stlink-v2" { + source [find interface/stlink-v2.cfg] + } + "olimex-arm-usb-tiny-h" { + source [find interface/ftdi/olimex-arm-usb-tiny-h.cfg] + source [find interface/ftdi/olimex-arm-jtag-swd.cfg] + source [find target/stm32f1x.cfg] + } +} telnet_port disabled tcl_port disabled diff --git a/src/radio-controller.cpp b/src/radio-controller.cpp index 132f581..c71aaa5 100644 --- a/src/radio-controller.cpp +++ b/src/radio-controller.cpp @@ -1,28 +1,40 @@ -#include "main.h" +#include "radio-controller.h" #include "stm32f1xx_hal.h" -#include <cstdio> +#include <cstring> #include "mcu/arm/semihosting.h" #ifdef HAL_IWDG_MODULE_ENABLED extern IWDG_HandleTypeDef hiwdg; #endif +extern TIM_HandleTypeDef htim1; + void main_pre_init() { -// SystemInit(); } void main_post_init() { semihosting::enable(); + + HAL_TIM_Base_Start(&htim1); } +static uint32_t tick_next = 0; + void main_loop() { // printf("hello world!"); + auto now = HAL_GetTick(); + + if (now >= tick_next) { + uint32_t cnt = __HAL_TIM_GET_COUNTER(&htim1); + printf("cnt=%lu, now=%lu\n", cnt, now); + tick_next += 1000; + } #ifdef HAL_IWDG_MODULE_ENABLED HAL_IWDG_Refresh(&hiwdg); #endif } -void it_tim1(TIM_HandleTypeDef *htim1) { +void it_tim1() { ; } diff --git a/stm32cubemx/Inc/main.h b/stm32cubemx/Inc/main.h index 951e332..3078082 100644 --- a/stm32cubemx/Inc/main.h +++ b/stm32cubemx/Inc/main.h @@ -46,8 +46,6 @@ /* Includes ------------------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "stm32f1xx_hal_dma.h" -#include "stm32f1xx_hal_tim.h" /* USER CODE END Includes */ /* Private define ------------------------------------------------------------*/ @@ -58,12 +56,6 @@ extern "C" { #endif -void main_pre_init(); -void main_post_init(); -void main_loop(); - -void it_tim1(TIM_HandleTypeDef *htim1); - #ifdef __cplusplus } #endif diff --git a/stm32cubemx/Src/main.c b/stm32cubemx/Src/main.c index 0afb615..e0e60be 100644 --- a/stm32cubemx/Src/main.c +++ b/stm32cubemx/Src/main.c @@ -47,7 +47,7 @@ #include "usb_device.h" /* USER CODE BEGIN Includes */ - +#include "radio-controller.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ diff --git a/stm32cubemx/Src/stm32f1xx_it.c b/stm32cubemx/Src/stm32f1xx_it.c index a71b015..02f62b2 100644 --- a/stm32cubemx/Src/stm32f1xx_it.c +++ b/stm32cubemx/Src/stm32f1xx_it.c @@ -36,7 +36,7 @@ #include "stm32f1xx_it.h" /* USER CODE BEGIN 0 */ -#include "main.h" +#include <radio-controller.h> /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ @@ -234,7 +234,7 @@ void USB_LP_CAN1_RX0_IRQHandler(void) void TIM1_TRG_COM_IRQHandler(void) { /* USER CODE BEGIN TIM1_TRG_COM_IRQn 0 */ - it_tim1(&htim1); + it_tim1(); /* USER CODE END TIM1_TRG_COM_IRQn 0 */ HAL_TIM_IRQHandler(&htim1); /* USER CODE BEGIN TIM1_TRG_COM_IRQn 1 */ diff --git a/thirdparty/mcu.cmake b/thirdparty/mcu.cmake -Subproject f21e17eee960a18cc1c4eb7712e1c19104d1ba4 +Subproject d6454522261d34a0c7460189194a6d5716751c6 diff --git a/thirdparty/mcucpp b/thirdparty/mcucpp -Subproject 8eb287e155802b96941627d257b086926255bd4 +Subproject 2ff0cbc23628d5712773ed820bc291f42011909 |