diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-29 23:10:32 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-29 23:10:32 +0200 |
commit | 89d464c7f38b902e332f082f99df075dee080978 (patch) | |
tree | 603750026d3fa12b2db7fa19abb8cdc079c5d3be | |
parent | 4c159924abc0ad027166fe8853d062ed0a46481e (diff) | |
download | radio-controller-89d464c7f38b902e332f082f99df075dee080978.tar.gz radio-controller-89d464c7f38b902e332f082f99df075dee080978.tar.bz2 radio-controller-89d464c7f38b902e332f082f99df075dee080978.tar.xz radio-controller-89d464c7f38b902e332f082f99df075dee080978.zip |
o Setting up for TIM1/Channel 1 as input capture. Enabling IWDG.
-rw-r--r-- | .gdbinit | 26 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | openocd.cfg | 25 | ||||
-rw-r--r-- | src/radio-controller.cpp | 16 | ||||
-rw-r--r-- | stm32cubemx/Inc/main.h | 11 | ||||
-rw-r--r-- | stm32cubemx/Inc/stm32f1xx_hal_conf.h | 4 | ||||
-rw-r--r-- | stm32cubemx/Inc/stm32f1xx_it.h | 1 | ||||
-rw-r--r-- | stm32cubemx/Src/main.c | 26 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_hal_msp.c | 22 | ||||
-rw-r--r-- | stm32cubemx/Src/stm32f1xx_it.c | 15 | ||||
-rw-r--r-- | stm32cubemx/stm32cubemx.gpdsc | 4 | ||||
-rw-r--r-- | stm32cubemx/stm32cubemx.ioc | 36 | ||||
m--------- | thirdparty/mcu.cmake | 0 | ||||
m--------- | thirdparty/mcucpp | 0 |
15 files changed, 180 insertions, 21 deletions
diff --git a/.gdbinit b/.gdbinit new file mode 100644 index 0000000..e2ea19a --- /dev/null +++ b/.gdbinit @@ -0,0 +1,26 @@ +define target hookpost-remote + monitor arm semihosting enable + monitor reset halt + set remotetimeout 10 +end + +define target hookpost-extended-remote + monitor arm semihosting enable + monitor reset halt + set remotetimeout 10 +end + +define run_firmware + make -C build firmware + + monitor reset halt + + set confirm off + file build/firmware + set confirm on + + load + continue +end + +target extended-remote :3333 @@ -1 +1,3 @@ build +cmake-build-* +.idea diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ed8461..2ffe0f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.6) set(MCU_CHIP stm32f103C6) set(MCU_USE_STM32CUBEMX TRUE) +set(MCU_LTO_MODE OFF) include(thirdparty/mcu.cmake/mcu.cmake) project(radio-controller C CXX ASM) @@ -16,9 +17,14 @@ target_include_directories(firmware PUBLIC thirdparty/mcu.cmake/stm32f103/include ) target_sources(firmware PUBLIC - thirdparty/mcu.cmake/stm32f103/src/default_handler.cpp +# thirdparty/mcu.cmake/stm32f103/src/default_handler.cpp thirdparty/mcu.cmake/stm32f103/src/init_high.cpp - thirdparty/mcu.cmake/stm32f103/src/init_low.s +# thirdparty/mcu.cmake/stm32f103/src/init_low.s + thirdparty/mcu.cmake/stm32f103/src/init_stm32f103_ld.cpp + thirdparty/mcu.cmake/stm32f103/src/init_low_halt.s + thirdparty/mcu.cmake/stm32f103/src/init_low_Reset_Handler.s + thirdparty/mcu.cmake/stm32f103/src/breakpoint.s + $ENV{HOME}/opt/STM32CubeMX/Repository/STM32Cube_FW_F1_V1.4.0/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s ) # mcucpp sources @@ -39,6 +45,9 @@ target_sources(firmware PUBLIC mcu_include_directories_from_sources( SOURCE_DIR stm32cubemx EXCLUDE Templates + EXCLUDE _template.c + EXCLUDE Examples + EXCLUDE DSP_Lib EXCLUDE stm32f1xx_it.c SOURCES_VAR STM32_CUBEMX_SOURCES HEADERS_VAR STM32_CUBEMX_HEADERS diff --git a/openocd.cfg b/openocd.cfg new file mode 100644 index 0000000..15a42d4 --- /dev/null +++ b/openocd.cfg @@ -0,0 +1,25 @@ +source [find interface/stlink-v2.cfg] +source [find target/stm32f1x.cfg] + +telnet_port disabled +tcl_port disabled + +if { [info exists HLA_SERIAL] } { + # If set with -c use that by default +} elseif { [info exists env(HLA_SERIAL)] } { + eval "set HLA_SERIAL $env(HLA_SERIAL)" +} + +if { [info exists HLA_SERIAL] } { + hla_serial $HLA_SERIAL +} + +if { [info exists GDB_PORT] } { + # If set with -c use that by default +} elseif { [info exists env(GDB_PORT)] } { + set GDB_PORT $env(GDB_PORT) +} else { + set GDB_PORT 3333 +} + +gdb_port $GDB_PORT diff --git a/src/radio-controller.cpp b/src/radio-controller.cpp index e69de29..53f6ef0 100644 --- a/src/radio-controller.cpp +++ b/src/radio-controller.cpp @@ -0,0 +1,16 @@ +#include "main.h" +#include "stm32f1xx_hal.h" +#include <cstdio> +#include "mcu/arm/semihosting.h" + +void main_pre_init() { + SystemInit(); +} + +void main_post_init() { + semihosting::enable(); +} + +void main_loop() { + printf("hello world!"); +} diff --git a/stm32cubemx/Inc/main.h b/stm32cubemx/Inc/main.h index 6b905ce..6e20349 100644 --- a/stm32cubemx/Inc/main.h +++ b/stm32cubemx/Inc/main.h @@ -40,9 +40,20 @@ /* USER CODE END Includes */ /* Private define ------------------------------------------------------------*/ +#define RX_TIMER_PRESCALER 72000000 / 2000 /* USER CODE BEGIN Private defines */ +#ifdef __cplusplus +extern "C" { +#endif +void main_pre_init(); +void main_post_init(); +void main_loop(); + +#ifdef __cplusplus +} +#endif /* USER CODE END Private defines */ /** diff --git a/stm32cubemx/Inc/stm32f1xx_hal_conf.h b/stm32cubemx/Inc/stm32f1xx_hal_conf.h index a652ace..463c8ba 100644 --- a/stm32cubemx/Inc/stm32f1xx_hal_conf.h +++ b/stm32cubemx/Inc/stm32f1xx_hal_conf.h @@ -57,7 +57,7 @@ /*#define HAL_CORTEX_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ /*#define HAL_DAC_MODULE_ENABLED */ -/*#define HAL_DMA_MODULE_ENABLED */ +#define HAL_DMA_MODULE_ENABLED /*#define HAL_ETH_MODULE_ENABLED */ /*#define HAL_FLASH_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED @@ -142,7 +142,7 @@ * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ -/* #define USE_FULL_ASSERT 1 */ + #define USE_FULL_ASSERT 1 /* ################## Ethernet peripheral configuration ##################### */ diff --git a/stm32cubemx/Inc/stm32f1xx_it.h b/stm32cubemx/Inc/stm32f1xx_it.h index b04b2cf..73ada16 100644 --- a/stm32cubemx/Inc/stm32f1xx_it.h +++ b/stm32cubemx/Inc/stm32f1xx_it.h @@ -54,6 +54,7 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void DMA1_Channel2_IRQHandler(void); void TIM1_TRG_COM_IRQHandler(void); #ifdef __cplusplus diff --git a/stm32cubemx/Src/main.c b/stm32cubemx/Src/main.c index b69bf4f..e9fdb8e 100644 --- a/stm32cubemx/Src/main.c +++ b/stm32cubemx/Src/main.c @@ -42,6 +42,7 @@ IWDG_HandleTypeDef hiwdg; TIM_HandleTypeDef htim1; +DMA_HandleTypeDef hdma_tim1_ch1; /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ @@ -52,6 +53,7 @@ TIM_HandleTypeDef htim1; void SystemClock_Config(void); void Error_Handler(void); static void MX_GPIO_Init(void); +static void MX_DMA_Init(void); static void MX_TIM1_Init(void); static void MX_IWDG_Init(void); static void MX_NVIC_Init(void); @@ -69,7 +71,7 @@ int main(void) { /* USER CODE BEGIN 1 */ - + main_pre_init(); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ @@ -82,6 +84,7 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); + MX_DMA_Init(); MX_TIM1_Init(); MX_IWDG_Init(); @@ -89,7 +92,7 @@ int main(void) MX_NVIC_Init(); /* USER CODE BEGIN 2 */ - + main_post_init(); /* USER CODE END 2 */ /* Infinite loop */ @@ -99,7 +102,7 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - + main_loop(); } /* USER CODE END 3 */ @@ -185,7 +188,7 @@ static void MX_TIM1_Init(void) TIM_IC_InitTypeDef sConfigIC; htim1.Instance = TIM1; - htim1.Init.Prescaler = 0; + htim1.Init.Prescaler = RX_TIMER_PRESCALER; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 0; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; @@ -213,6 +216,21 @@ static void MX_TIM1_Init(void) } +/** + * Enable DMA controller clock + */ +static void MX_DMA_Init(void) +{ + /* DMA controller clock enable */ + __HAL_RCC_DMA1_CLK_ENABLE(); + + /* DMA interrupt init */ + /* DMA1_Channel2_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); + +} + /** Configure pins as * Analog * Input diff --git a/stm32cubemx/Src/stm32f1xx_hal_msp.c b/stm32cubemx/Src/stm32f1xx_hal_msp.c index 696dd5d..be02361 100644 --- a/stm32cubemx/Src/stm32f1xx_hal_msp.c +++ b/stm32cubemx/Src/stm32f1xx_hal_msp.c @@ -34,6 +34,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_hal.h" +extern DMA_HandleTypeDef hdma_tim1_ch1; + extern void Error_Handler(void); /* USER CODE BEGIN 0 */ @@ -96,6 +98,23 @@ void HAL_TIM_IC_MspInit(TIM_HandleTypeDef* htim_ic) GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* Peripheral DMA init*/ + + hdma_tim1_ch1.Instance = DMA1_Channel2; + hdma_tim1_ch1.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_tim1_ch1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_tim1_ch1.Init.MemInc = DMA_MINC_ENABLE; + hdma_tim1_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_tim1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + hdma_tim1_ch1.Init.Mode = DMA_NORMAL; + hdma_tim1_ch1.Init.Priority = DMA_PRIORITY_LOW; + if (HAL_DMA_Init(&hdma_tim1_ch1) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(htim_ic,hdma[TIM_DMA_ID_CC1],hdma_tim1_ch1); + /* USER CODE BEGIN TIM1_MspInit 1 */ /* USER CODE END TIM1_MspInit 1 */ @@ -119,6 +138,9 @@ void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef* htim_ic) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8); + /* Peripheral DMA DeInit*/ + HAL_DMA_DeInit(htim_ic->hdma[TIM_DMA_ID_CC1]); + /* Peripheral interrupt DeInit*/ HAL_NVIC_DisableIRQ(TIM1_TRG_COM_IRQn); diff --git a/stm32cubemx/Src/stm32f1xx_it.c b/stm32cubemx/Src/stm32f1xx_it.c index 40c5612..473a07a 100644 --- a/stm32cubemx/Src/stm32f1xx_it.c +++ b/stm32cubemx/Src/stm32f1xx_it.c @@ -40,6 +40,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern DMA_HandleTypeDef hdma_tim1_ch1; extern TIM_HandleTypeDef htim1; /******************************************************************************/ @@ -185,6 +186,20 @@ void SysTick_Handler(void) /******************************************************************************/ /** +* @brief This function handles DMA1 channel2 global interrupt. +*/ +void DMA1_Channel2_IRQHandler(void) +{ + /* USER CODE BEGIN DMA1_Channel2_IRQn 0 */ + + /* USER CODE END DMA1_Channel2_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_tim1_ch1); + /* USER CODE BEGIN DMA1_Channel2_IRQn 1 */ + + /* USER CODE END DMA1_Channel2_IRQn 1 */ +} + +/** * @brief This function handles TIM1 trigger and commutation interrupts. */ void TIM1_TRG_COM_IRQHandler(void) diff --git a/stm32cubemx/stm32cubemx.gpdsc b/stm32cubemx/stm32cubemx.gpdsc index 973f795..c42a5f0 100644 --- a/stm32cubemx/stm32cubemx.gpdsc +++ b/stm32cubemx/stm32cubemx.gpdsc @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- ****************************************************************************** * File Name : stm32cubemx.gpdsc - * Date : 22/04/2017 11:30:22 + * Date : 29/04/2017 23:09:40 * Description : Generator PDSC File generated by STM32CubeMX (DO NOT EDIT!) ****************************************************************************** --> @@ -12,7 +12,7 @@ <url>/home/trygvis/dev/io.trygvis/2017/04/433-controller/stm32cubemx</url> <releases> <release version="1.0.0"> - - Generated: 22/04/2017 11:30:22 + - Generated: 29/04/2017 23:09:40 </release> </releases> <requirements> diff --git a/stm32cubemx/stm32cubemx.ioc b/stm32cubemx/stm32cubemx.ioc index 6a34db8..461d8af 100644 --- a/stm32cubemx/stm32cubemx.ioc +++ b/stm32cubemx/stm32cubemx.ioc @@ -1,13 +1,25 @@ #MicroXplorer Configuration settings - do not modify +Dma.Request0=TIM1_CH1 +Dma.RequestsNb=1 +Dma.TIM1_CH1.0.Direction=DMA_PERIPH_TO_MEMORY +Dma.TIM1_CH1.0.Instance=DMA1_Channel2 +Dma.TIM1_CH1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +Dma.TIM1_CH1.0.MemInc=DMA_MINC_ENABLE +Dma.TIM1_CH1.0.Mode=DMA_NORMAL +Dma.TIM1_CH1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD +Dma.TIM1_CH1.0.PeriphInc=DMA_PINC_DISABLE +Dma.TIM1_CH1.0.Priority=DMA_PRIORITY_LOW +Dma.TIM1_CH1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority File.Version=6 KeepUserPlacement=false Mcu.Family=STM32F1 -Mcu.IP0=IWDG -Mcu.IP1=NVIC -Mcu.IP2=RCC -Mcu.IP3=SYS -Mcu.IP4=TIM1 -Mcu.IPNb=5 +Mcu.IP0=DMA +Mcu.IP1=IWDG +Mcu.IP2=NVIC +Mcu.IP3=RCC +Mcu.IP4=SYS +Mcu.IP5=TIM1 +Mcu.IPNb=6 Mcu.Name=STM32F103C(4-6)Tx Mcu.Package=LQFP48 Mcu.Pin0=PC14-OSC32_IN @@ -20,11 +32,12 @@ Mcu.Pin6=PA14 Mcu.Pin7=VP_IWDG_VS_IWDG Mcu.Pin8=VP_SYS_VS_Systick Mcu.PinsNb=9 -Mcu.UserConstants= +Mcu.UserConstants=RX_TIMER_PRESCALER,72000000 / 2000 Mcu.UserName=STM32F103C6Tx MxCube.Version=4.20.1 MxDb.Version=DB.4.0.200 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true +NVIC.DMA1_Channel2_IRQn=true\:0\:0\:false\:false\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true @@ -62,13 +75,13 @@ ProjectManager.BackupPrevious=false ProjectManager.CompilerOptimize=2 ProjectManager.ComputerToolchain=false ProjectManager.CoupleFile=false -ProjectManager.CustomerFirmwarePackage= +ProjectManager.CustomerFirmwarePackage=/home/trygvis/opt/STM32CubeMX/Repository/STM32Cube_FW_F1_V1.4.0 ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32F103C6Tx ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.4.0 ProjectManager.FreePins=false -ProjectManager.HalAssertFull=false +ProjectManager.HalAssertFull=true ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true ProjectManager.LastFirmware=true @@ -81,7 +94,7 @@ ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=Other Toolchains (GPDSC) ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL,2-SystemClock_Config-RCC-false-HAL,3-MX_TIM1_Init-TIM1-false-HAL,4-MX_IWDG_Init-IWDG-false-HAL +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL,2-MX_DMA_Init-DMA-false-HAL,3-SystemClock_Config-RCC-false-HAL,4-MX_TIM1_Init-TIM1-false-HAL,5-MX_IWDG_Init-IWDG-false-HAL RCC.ADCFreqValue=36000000 RCC.AHBFreq_Value=72000000 RCC.APB1CLKDivider=RCC_HCLK_DIV2 @@ -106,7 +119,8 @@ RCC.VCOOutput2Freq_Value=8000000 SH.S_TIM1_CH1.0=TIM1_CH1,Input_Capture1_from_TI1 SH.S_TIM1_CH1.ConfNb=1 TIM1.Channel-Input_Capture1_from_TI1=TIM_CHANNEL_1 -TIM1.IPParameters=Channel-Input_Capture1_from_TI1 +TIM1.IPParameters=Channel-Input_Capture1_from_TI1,Prescaler +TIM1.Prescaler=RX_TIMER_PRESCALER VP_IWDG_VS_IWDG.Mode=IWDG_Activate VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG VP_SYS_VS_Systick.Mode=SysTick diff --git a/thirdparty/mcu.cmake b/thirdparty/mcu.cmake -Subproject 1d49a93190aff3ccf21838d78ffca0a69673eb8 +Subproject f21e17eee960a18cc1c4eb7712e1c19104d1ba4 diff --git a/thirdparty/mcucpp b/thirdparty/mcucpp -Subproject 4b449c0a39fc29031537862f0b339175d7cf6df +Subproject 8eb287e155802b96941627d257b086926255bd4 |