From 8665bdbf682bdff02576a6f4393f09bc56572043 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 11 May 2017 11:36:52 +0200 Subject: wip --- .gdbinit | 2 ++ CMakeLists.txt | 5 +++-- include/radio-controller.h | 15 +++++++++++++++ launch-openocd | 16 ++++++++++++++++ openocd.cfg | 18 ++++++++++++++++-- src/radio-controller.cpp | 20 ++++++++++++++++---- stm32cubemx/Inc/main.h | 8 -------- stm32cubemx/Src/main.c | 2 +- stm32cubemx/Src/stm32f1xx_it.c | 4 ++-- thirdparty/mcu.cmake | 2 +- thirdparty/mcucpp | 2 +- 11 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 include/radio-controller.h create mode 100755 launch-openocd diff --git a/.gdbinit b/.gdbinit index 3edbdf0..2d3042d 100644 --- a/.gdbinit +++ b/.gdbinit @@ -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 +#include #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 /* 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 index f21e17e..d645452 160000 --- a/thirdparty/mcu.cmake +++ b/thirdparty/mcu.cmake @@ -1 +1 @@ -Subproject commit f21e17eee960a18cc1c4eb7712e1c19104d1ba42 +Subproject commit d6454522261d34a0c7460189194a6d5716751c69 diff --git a/thirdparty/mcucpp b/thirdparty/mcucpp index 8eb287e..2ff0cbc 160000 --- a/thirdparty/mcucpp +++ b/thirdparty/mcucpp @@ -1 +1 @@ -Subproject commit 8eb287e155802b96941627d257b086926255bd48 +Subproject commit 2ff0cbc23628d5712773ed820bc291f420119090 -- cgit v1.2.3