diff --git a/.clang-format b/.clang-format index 2e7f699..233409f 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,7 @@ UseTab: Never IndentWidth: 2 TabWidth: 2 BreakBeforeBraces: Custom -AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: false AllowShortLambdasOnASingleLine: true AllowAllArgumentsOnNextLine: true diff --git a/.gitignore b/.gitignore index bb8f116..da88945 100755 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ cmake_install.cmake compile_commands.json .clangd - # eclipse .*project.bak /.settings/* diff --git a/.mxproject b/.mxproject index 451cc75..e1485ea 100644 --- a/.mxproject +++ b/.mxproject @@ -7,13 +7,29 @@ HeaderPath=Drivers/STM32F1xx_HAL_Driver/Inc;Drivers/CMSIS/Device/ST/STM32F1xx/In CDefines=USE_FULL_LL_DRIVER;HSE_VALUE:8000000;HSE_STARTUP_TIMEOUT:100;LSE_STARTUP_TIMEOUT:5000;LSE_VALUE:32768;HSI_VALUE:8000000;LSI_VALUE:40000;VDD_VALUE:3300;PREFETCH_ENABLE:1;STM32F103xB;USE_FULL_LL_DRIVER;HSE_VALUE:8000000;HSE_STARTUP_TIMEOUT:100;LSE_STARTUP_TIMEOUT:5000;LSE_VALUE:32768;HSI_VALUE:8000000;LSI_VALUE:40000;VDD_VALUE:3300;PREFETCH_ENABLE:1; [PreviousUsedCMakes] -SourceFiles=Src/main.c;Src/gpio.c;Src/dma.c;Src/usart.c;Src/stm32f1xx_it.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usart.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_utils.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Src/system_stm32f1xx.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usart.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_utils.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Src/system_stm32f1xx.c;;; -HeaderPath=Drivers/STM32F1xx_HAL_Driver/Inc;Drivers/CMSIS/Device/ST/STM32F1xx/Include;Drivers/CMSIS/Include;Inc; +SourceFiles=Core/Src/main.c;Core/Src/gpio.c;Core/Src/dma.c;Core/Src/usart.c;Core/Src/stm32f1xx_it.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usart.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_utils.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Core/Src/system_stm32f1xx.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usart.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_utils.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Core/Src/system_stm32f1xx.c;;; +HeaderPath=Drivers/STM32F1xx_HAL_Driver/Inc;Drivers/CMSIS/Device/ST/STM32F1xx/Include;Drivers/CMSIS/Include;Core/Inc; CDefines=USE_FULL_LL_DRIVER;HSE_VALUE:8000000;HSE_STARTUP_TIMEOUT:100;LSE_STARTUP_TIMEOUT:5000;LSE_VALUE:32768;HSI_VALUE:8000000;LSI_VALUE:40000;VDD_VALUE:3300;PREFETCH_ENABLE:1;STM32F103xB;USE_FULL_LL_DRIVER;HSE_VALUE:8000000;HSE_STARTUP_TIMEOUT:100;LSE_STARTUP_TIMEOUT:5000;LSE_VALUE:32768;HSI_VALUE:8000000;LSI_VALUE:40000;VDD_VALUE:3300;PREFETCH_ENABLE:1; [PreviousGenFiles] -HeaderPath=../Inc -HeaderFiles=gpio.h;dma.h;usart.h;stm32f1xx_it.h;stm32_assert.h;main.h; -SourcePath=../Src -SourceFiles=gpio.c;dma.c;usart.c;stm32f1xx_it.c;main.c; +AdvancedFolderStructure=true +HeaderFileListSize=6 +HeaderFiles#0=../Core/Inc/gpio.h +HeaderFiles#1=../Core/Inc/dma.h +HeaderFiles#2=../Core/Inc/usart.h +HeaderFiles#3=../Core/Inc/stm32f1xx_it.h +HeaderFiles#4=../Core/Inc/stm32_assert.h +HeaderFiles#5=../Core/Inc/main.h +HeaderFolderListSize=1 +HeaderPath#0=../Core/Inc +HeaderFiles=; +SourceFileListSize=5 +SourceFiles#0=../Core/Src/gpio.c +SourceFiles#1=../Core/Src/dma.c +SourceFiles#2=../Core/Src/usart.c +SourceFiles#3=../Core/Src/stm32f1xx_it.c +SourceFiles#4=../Core/Src/main.c +SourceFolderListSize=1 +SourcePath#0=../Core/Src +SourceFiles=; diff --git a/CMakeLists.txt b/CMakeLists.txt index 66bb860..b1df894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,9 +41,9 @@ add_executable(${CMAKE_PROJECT_NAME}) # Add STM32CubeMX generated sources add_subdirectory(cmake/stm32cubemx) -add_subdirectory(platform) -add_subdirectory(app) -add_subdirectory(f1ll) +add_subdirectory(components/platform) +add_subdirectory(components/app) +add_subdirectory(components/f1ll) target_link_libraries(stm32cubemx INTERFACE app diff --git a/Inc/dma.h b/Core/Inc/dma.h similarity index 100% rename from Inc/dma.h rename to Core/Inc/dma.h diff --git a/Inc/gpio.h b/Core/Inc/gpio.h similarity index 100% rename from Inc/gpio.h rename to Core/Inc/gpio.h diff --git a/Inc/main.h b/Core/Inc/main.h similarity index 100% rename from Inc/main.h rename to Core/Inc/main.h diff --git a/Inc/stm32_assert.h b/Core/Inc/stm32_assert.h similarity index 100% rename from Inc/stm32_assert.h rename to Core/Inc/stm32_assert.h diff --git a/Inc/stm32f1xx_it.h b/Core/Inc/stm32f1xx_it.h similarity index 100% rename from Inc/stm32f1xx_it.h rename to Core/Inc/stm32f1xx_it.h diff --git a/Inc/usart.h b/Core/Inc/usart.h similarity index 100% rename from Inc/usart.h rename to Core/Inc/usart.h diff --git a/Src/dma.c b/Core/Src/dma.c similarity index 100% rename from Src/dma.c rename to Core/Src/dma.c diff --git a/Src/gpio.c b/Core/Src/gpio.c similarity index 100% rename from Src/gpio.c rename to Core/Src/gpio.c diff --git a/Src/main.c b/Core/Src/main.c similarity index 94% rename from Src/main.c rename to Core/Src/main.c index 37fd826..e644704 100644 --- a/Src/main.c +++ b/Core/Src/main.c @@ -80,10 +80,6 @@ int main(void) /* System interrupt init*/ NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); - /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled - */ - LL_GPIO_AF_Remap_SWJ_NOJTAG(); - /* USER CODE BEGIN Init */ /* USER CODE END Init */ diff --git a/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c similarity index 81% rename from Src/stm32f1xx_it.c rename to Core/Src/stm32f1xx_it.c index 11682ea..e79d987 100644 --- a/Src/stm32f1xx_it.c +++ b/Core/Src/stm32f1xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32f1xx_it.h" +#include "main.h" + /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -67,8 +68,8 @@ /* Cortex-M3 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ @@ -81,68 +82,64 @@ void NMI_Handler(void) } /** - * @brief This function handles Hard fault interrupt. - */ + * @brief This function handles Hard fault interrupt. + */ void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } } /** - * @brief This function handles Memory management fault. - */ + * @brief This function handles Memory management fault. + */ void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } } /** - * @brief This function handles Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch fault, memory access fault. + */ void BusFault_Handler(void) { /* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */ } } /** - * @brief This function handles Undefined instruction or illegal state. - */ + * @brief This function handles Undefined instruction or illegal state. + */ void UsageFault_Handler(void) { /* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */ } } /** - * @brief This function handles System service call via SWI instruction. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { /* USER CODE BEGIN SVCall_IRQn 0 */ @@ -154,8 +151,8 @@ void SVC_Handler(void) } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ @@ -167,8 +164,8 @@ void DebugMon_Handler(void) } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { /* USER CODE BEGIN PendSV_IRQn 0 */ @@ -180,8 +177,8 @@ void PendSV_Handler(void) } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ @@ -201,12 +198,12 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles DMA1 channel4 global interrupt. - */ + * @brief This function handles DMA1 channel4 global interrupt. + */ void DMA1_Channel4_IRQHandler(void) { /* USER CODE BEGIN DMA1_Channel4_IRQn 0 */ - dma1_channel4_irq_handler(); + usart1_tx_dma_isr(); /* USER CODE END DMA1_Channel4_IRQn 0 */ /* USER CODE BEGIN DMA1_Channel4_IRQn 1 */ @@ -214,12 +211,12 @@ void DMA1_Channel4_IRQHandler(void) } /** - * @brief This function handles DMA1 channel5 global interrupt. - */ + * @brief This function handles DMA1 channel5 global interrupt. + */ void DMA1_Channel5_IRQHandler(void) { /* USER CODE BEGIN DMA1_Channel5_IRQn 0 */ - dma1_channel5_irq_handler(); + usart1_rx_dma_isr(); /* USER CODE END DMA1_Channel5_IRQn 0 */ /* USER CODE BEGIN DMA1_Channel5_IRQn 1 */ @@ -227,12 +224,12 @@ void DMA1_Channel5_IRQHandler(void) } /** - * @brief This function handles USART1 global interrupt. - */ + * @brief This function handles USART1 global interrupt. + */ void USART1_IRQHandler(void) { /* USER CODE BEGIN USART1_IRQn 0 */ - usart1_irq_handler(); + usart1_isr(); /* USER CODE END USART1_IRQn 0 */ /* USER CODE BEGIN USART1_IRQn 1 */ diff --git a/Src/syscalls.c b/Core/Src/syscalls.c similarity index 100% rename from Src/syscalls.c rename to Core/Src/syscalls.c diff --git a/Src/sysmem.c b/Core/Src/sysmem.c similarity index 100% rename from Src/sysmem.c rename to Core/Src/sysmem.c diff --git a/Src/system_stm32f1xx.c b/Core/Src/system_stm32f1xx.c similarity index 100% rename from Src/system_stm32f1xx.c rename to Core/Src/system_stm32f1xx.c diff --git a/Src/usart.c b/Core/Src/usart.c similarity index 100% rename from Src/usart.c rename to Core/Src/usart.c diff --git a/Startup/startup_stm32f103c8tx.s b/Startup/startup_stm32f103c8tx.s deleted file mode 100644 index 7614285..0000000 --- a/Startup/startup_stm32f103c8tx.s +++ /dev/null @@ -1,364 +0,0 @@ -/** - *************** (C) COPYRIGHT 2017 STMicroelectronics ************************ - * @file startup_stm32f103xb.s - * @author MCD Application Team - * @brief STM32F103xB Devices vector table for Atollic toolchain. - * This module performs: - * - Set the initial SP - * - Set the initial PC == Reset_Handler, - * - Set the vector table entries with the exceptions ISR address - * - Configure the clock system - * - Branches to main in the C library (which eventually - * calls main()). - * After Reset the Cortex-M3 processor is in Thread mode, - * priority is Privileged, and the Stack is set to Main. - ****************************************************************************** - * @attention - * - * Copyright (c) 2017-2021 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - - .syntax unified - .cpu cortex-m3 - .fpu softvfp - .thumb - -.global g_pfnVectors -.global Default_Handler - -/* start address for the initialization values of the .data section. -defined in linker script */ -.word _sidata -/* start address for the .data section. defined in linker script */ -.word _sdata -/* end address for the .data section. defined in linker script */ -.word _edata -/* start address for the .bss section. defined in linker script */ -.word _sbss -/* end address for the .bss section. defined in linker script */ -.word _ebss - -.equ BootRAM, 0xF108F85F -/** - * @brief This is the code that gets called when the processor first - * starts execution following a reset event. Only the absolutely - * necessary set is performed, after which the application - * supplied main() routine is called. - * @param None - * @retval : None -*/ - - .section .text.Reset_Handler - .weak Reset_Handler - .type Reset_Handler, %function -Reset_Handler: - -/* Call the clock system initialization function.*/ - bl SystemInit - -/* Copy the data segment initializers from flash to SRAM */ - ldr r0, =_sdata - ldr r1, =_edata - ldr r2, =_sidata - movs r3, #0 - b LoopCopyDataInit - -CopyDataInit: - ldr r4, [r2, r3] - str r4, [r0, r3] - adds r3, r3, #4 - -LoopCopyDataInit: - adds r4, r0, r3 - cmp r4, r1 - bcc CopyDataInit - -/* Zero fill the bss segment. */ - ldr r2, =_sbss - ldr r4, =_ebss - movs r3, #0 - b LoopFillZerobss - -FillZerobss: - str r3, [r2] - adds r2, r2, #4 - -LoopFillZerobss: - cmp r2, r4 - bcc FillZerobss - -/* Call static constructors */ - bl __libc_init_array -/* Call the application's entry point.*/ - bl main - bx lr -.size Reset_Handler, .-Reset_Handler - -/** - * @brief This is the code that gets called when the processor receives an - * unexpected interrupt. This simply enters an infinite loop, preserving - * the system state for examination by a debugger. - * - * @param None - * @retval : None -*/ - .section .text.Default_Handler,"ax",%progbits -Default_Handler: -Infinite_Loop: - b Infinite_Loop - .size Default_Handler, .-Default_Handler -/****************************************************************************** -* -* The minimal vector table for a Cortex M3. Note that the proper constructs -* must be placed on this to ensure that it ends up at physical address -* 0x0000.0000. -* -******************************************************************************/ - .section .isr_vector,"a",%progbits - .type g_pfnVectors, %object - .size g_pfnVectors, .-g_pfnVectors - - -g_pfnVectors: - - .word _estack - .word Reset_Handler - .word NMI_Handler - .word HardFault_Handler - .word MemManage_Handler - .word BusFault_Handler - .word UsageFault_Handler - .word 0 - .word 0 - .word 0 - .word 0 - .word SVC_Handler - .word DebugMon_Handler - .word 0 - .word PendSV_Handler - .word SysTick_Handler - .word WWDG_IRQHandler - .word PVD_IRQHandler - .word TAMPER_IRQHandler - .word RTC_IRQHandler - .word FLASH_IRQHandler - .word RCC_IRQHandler - .word EXTI0_IRQHandler - .word EXTI1_IRQHandler - .word EXTI2_IRQHandler - .word EXTI3_IRQHandler - .word EXTI4_IRQHandler - .word DMA1_Channel1_IRQHandler - .word DMA1_Channel2_IRQHandler - .word DMA1_Channel3_IRQHandler - .word DMA1_Channel4_IRQHandler - .word DMA1_Channel5_IRQHandler - .word DMA1_Channel6_IRQHandler - .word DMA1_Channel7_IRQHandler - .word ADC1_2_IRQHandler - .word USB_HP_CAN1_TX_IRQHandler - .word USB_LP_CAN1_RX0_IRQHandler - .word CAN1_RX1_IRQHandler - .word CAN1_SCE_IRQHandler - .word EXTI9_5_IRQHandler - .word TIM1_BRK_IRQHandler - .word TIM1_UP_IRQHandler - .word TIM1_TRG_COM_IRQHandler - .word TIM1_CC_IRQHandler - .word TIM2_IRQHandler - .word TIM3_IRQHandler - .word TIM4_IRQHandler - .word I2C1_EV_IRQHandler - .word I2C1_ER_IRQHandler - .word I2C2_EV_IRQHandler - .word I2C2_ER_IRQHandler - .word SPI1_IRQHandler - .word SPI2_IRQHandler - .word USART1_IRQHandler - .word USART2_IRQHandler - .word USART3_IRQHandler - .word EXTI15_10_IRQHandler - .word RTC_Alarm_IRQHandler - .word USBWakeUp_IRQHandler - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word BootRAM /* @0x108. This is for boot in RAM mode for - STM32F10x Medium Density devices. */ - -/******************************************************************************* -* -* Provide weak aliases for each Exception handler to the Default_Handler. -* As they are weak aliases, any function with the same name will override -* this definition. -* -*******************************************************************************/ - - .weak NMI_Handler - .thumb_set NMI_Handler,Default_Handler - - .weak HardFault_Handler - .thumb_set HardFault_Handler,Default_Handler - - .weak MemManage_Handler - .thumb_set MemManage_Handler,Default_Handler - - .weak BusFault_Handler - .thumb_set BusFault_Handler,Default_Handler - - .weak UsageFault_Handler - .thumb_set UsageFault_Handler,Default_Handler - - .weak SVC_Handler - .thumb_set SVC_Handler,Default_Handler - - .weak DebugMon_Handler - .thumb_set DebugMon_Handler,Default_Handler - - .weak PendSV_Handler - .thumb_set PendSV_Handler,Default_Handler - - .weak SysTick_Handler - .thumb_set SysTick_Handler,Default_Handler - - .weak WWDG_IRQHandler - .thumb_set WWDG_IRQHandler,Default_Handler - - .weak PVD_IRQHandler - .thumb_set PVD_IRQHandler,Default_Handler - - .weak TAMPER_IRQHandler - .thumb_set TAMPER_IRQHandler,Default_Handler - - .weak RTC_IRQHandler - .thumb_set RTC_IRQHandler,Default_Handler - - .weak FLASH_IRQHandler - .thumb_set FLASH_IRQHandler,Default_Handler - - .weak RCC_IRQHandler - .thumb_set RCC_IRQHandler,Default_Handler - - .weak EXTI0_IRQHandler - .thumb_set EXTI0_IRQHandler,Default_Handler - - .weak EXTI1_IRQHandler - .thumb_set EXTI1_IRQHandler,Default_Handler - - .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler,Default_Handler - - .weak EXTI3_IRQHandler - .thumb_set EXTI3_IRQHandler,Default_Handler - - .weak EXTI4_IRQHandler - .thumb_set EXTI4_IRQHandler,Default_Handler - - .weak DMA1_Channel1_IRQHandler - .thumb_set DMA1_Channel1_IRQHandler,Default_Handler - - .weak DMA1_Channel2_IRQHandler - .thumb_set DMA1_Channel2_IRQHandler,Default_Handler - - .weak DMA1_Channel3_IRQHandler - .thumb_set DMA1_Channel3_IRQHandler,Default_Handler - - .weak DMA1_Channel4_IRQHandler - .thumb_set DMA1_Channel4_IRQHandler,Default_Handler - - .weak DMA1_Channel5_IRQHandler - .thumb_set DMA1_Channel5_IRQHandler,Default_Handler - - .weak DMA1_Channel6_IRQHandler - .thumb_set DMA1_Channel6_IRQHandler,Default_Handler - - .weak DMA1_Channel7_IRQHandler - .thumb_set DMA1_Channel7_IRQHandler,Default_Handler - - .weak ADC1_2_IRQHandler - .thumb_set ADC1_2_IRQHandler,Default_Handler - - .weak USB_HP_CAN1_TX_IRQHandler - .thumb_set USB_HP_CAN1_TX_IRQHandler,Default_Handler - - .weak USB_LP_CAN1_RX0_IRQHandler - .thumb_set USB_LP_CAN1_RX0_IRQHandler,Default_Handler - - .weak CAN1_RX1_IRQHandler - .thumb_set CAN1_RX1_IRQHandler,Default_Handler - - .weak CAN1_SCE_IRQHandler - .thumb_set CAN1_SCE_IRQHandler,Default_Handler - - .weak EXTI9_5_IRQHandler - .thumb_set EXTI9_5_IRQHandler,Default_Handler - - .weak TIM1_BRK_IRQHandler - .thumb_set TIM1_BRK_IRQHandler,Default_Handler - - .weak TIM1_UP_IRQHandler - .thumb_set TIM1_UP_IRQHandler,Default_Handler - - .weak TIM1_TRG_COM_IRQHandler - .thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler - - .weak TIM1_CC_IRQHandler - .thumb_set TIM1_CC_IRQHandler,Default_Handler - - .weak TIM2_IRQHandler - .thumb_set TIM2_IRQHandler,Default_Handler - - .weak TIM3_IRQHandler - .thumb_set TIM3_IRQHandler,Default_Handler - - .weak TIM4_IRQHandler - .thumb_set TIM4_IRQHandler,Default_Handler - - .weak I2C1_EV_IRQHandler - .thumb_set I2C1_EV_IRQHandler,Default_Handler - - .weak I2C1_ER_IRQHandler - .thumb_set I2C1_ER_IRQHandler,Default_Handler - - .weak I2C2_EV_IRQHandler - .thumb_set I2C2_EV_IRQHandler,Default_Handler - - .weak I2C2_ER_IRQHandler - .thumb_set I2C2_ER_IRQHandler,Default_Handler - - .weak SPI1_IRQHandler - .thumb_set SPI1_IRQHandler,Default_Handler - - .weak SPI2_IRQHandler - .thumb_set SPI2_IRQHandler,Default_Handler - - .weak USART1_IRQHandler - .thumb_set USART1_IRQHandler,Default_Handler - - .weak USART2_IRQHandler - .thumb_set USART2_IRQHandler,Default_Handler - - .weak USART3_IRQHandler - .thumb_set USART3_IRQHandler,Default_Handler - - .weak EXTI15_10_IRQHandler - .thumb_set EXTI15_10_IRQHandler,Default_Handler - - .weak RTC_Alarm_IRQHandler - .thumb_set RTC_Alarm_IRQHandler,Default_Handler - - .weak USBWakeUp_IRQHandler - .thumb_set USBWakeUp_IRQHandler,Default_Handler - - diff --git a/cmake/stm32cubemx/CMakeLists.txt b/cmake/stm32cubemx/CMakeLists.txt index 7b92cd1..22ca85c 100644 --- a/cmake/stm32cubemx/CMakeLists.txt +++ b/cmake/stm32cubemx/CMakeLists.txt @@ -18,7 +18,7 @@ set(MX_Defines_Syms # STM32CubeMX generated include paths set(MX_Include_Dirs - ${CMAKE_SOURCE_DIR}/Inc + ${CMAKE_SOURCE_DIR}/Core/Inc ${CMAKE_SOURCE_DIR}/Drivers/STM32F1xx_HAL_Driver/Inc ${CMAKE_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32F1xx/Include ${CMAKE_SOURCE_DIR}/Drivers/CMSIS/Include @@ -26,19 +26,19 @@ set(MX_Include_Dirs # STM32CubeMX generated application sources set(MX_Application_Src - ${CMAKE_SOURCE_DIR}/Src/main.c - ${CMAKE_SOURCE_DIR}/Src/gpio.c - ${CMAKE_SOURCE_DIR}/Src/dma.c - ${CMAKE_SOURCE_DIR}/Src/usart.c - ${CMAKE_SOURCE_DIR}/Src/stm32f1xx_it.c - ${CMAKE_SOURCE_DIR}/Src/sysmem.c - ${CMAKE_SOURCE_DIR}/Src/syscalls.c + ${CMAKE_SOURCE_DIR}/Core/Src/main.c + ${CMAKE_SOURCE_DIR}/Core/Src/gpio.c + ${CMAKE_SOURCE_DIR}/Core/Src/dma.c + ${CMAKE_SOURCE_DIR}/Core/Src/usart.c + ${CMAKE_SOURCE_DIR}/Core/Src/stm32f1xx_it.c + ${CMAKE_SOURCE_DIR}/Core/Src/sysmem.c + ${CMAKE_SOURCE_DIR}/Core/Src/syscalls.c ${CMAKE_SOURCE_DIR}/startup_stm32f103xb.s ) # STM32 HAL/LL Drivers set(STM32_Drivers_Src - ${CMAKE_SOURCE_DIR}/Src/system_stm32f1xx.c + ${CMAKE_SOURCE_DIR}/Core/Src/system_stm32f1xx.c ${CMAKE_SOURCE_DIR}/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c ${CMAKE_SOURCE_DIR}/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c ${CMAKE_SOURCE_DIR}/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c diff --git a/app/CMakeLists.txt b/components/app/CMakeLists.txt similarity index 100% rename from app/CMakeLists.txt rename to components/app/CMakeLists.txt diff --git a/app/inc/app.h b/components/app/inc/app.h similarity index 100% rename from app/inc/app.h rename to components/app/inc/app.h diff --git a/app/inc/irq_bridge.h b/components/app/inc/irq_bridge.h similarity index 61% rename from app/inc/irq_bridge.h rename to components/app/inc/irq_bridge.h index 3e95487..6b3ae4a 100644 --- a/app/inc/irq_bridge.h +++ b/components/app/inc/irq_bridge.h @@ -5,9 +5,9 @@ extern "C" { #endif -void dma1_channel4_irq_handler(); -void dma1_channel5_irq_handler(); -void usart1_irq_handler(); +void usart1_tx_dma_isr(); +void usart1_rx_dma_isr(); +void usart1_isr(); #if defined(__cplusplus) } diff --git a/app/src/app.cpp b/components/app/src/app.cpp similarity index 100% rename from app/src/app.cpp rename to components/app/src/app.cpp diff --git a/app/src/irq_bridge.cpp b/components/app/src/irq_bridge.cpp similarity index 67% rename from app/src/irq_bridge.cpp rename to components/app/src/irq_bridge.cpp index 3545f4b..adc5588 100644 --- a/app/src/irq_bridge.cpp +++ b/components/app/src/irq_bridge.cpp @@ -2,17 +2,17 @@ #include -void dma1_channel4_irq_handler() +void usart1_tx_dma_isr() // DMA1 channel 4 { f1ll::console_handler::instance().tx_dma_isr(); } -void dma1_channel5_irq_handler() +void usart1_rx_dma_isr() // DMA1 channel 5 { f1ll::console_handler::instance().rx_dma_isr(); } -void usart1_irq_handler() +void usart1_isr() { f1ll::console_handler::instance().usart_isr(); } \ No newline at end of file diff --git a/f1ll/CMakeLists.txt b/components/f1ll/CMakeLists.txt similarity index 65% rename from f1ll/CMakeLists.txt rename to components/f1ll/CMakeLists.txt index 6277fa8..e1f412c 100644 --- a/f1ll/CMakeLists.txt +++ b/components/f1ll/CMakeLists.txt @@ -10,3 +10,6 @@ target_include_directories(f1ll PUBLIC ) target_link_libraries(f1ll PUBLIC platform stm32cubemx) + +# ST code quality workaround - Suppres register storage class warning (C++17...) +target_compile_options(f1ll PRIVATE -Wno-register) diff --git a/f1ll/inc/f1ll/console_handler.h b/components/f1ll/inc/f1ll/console_handler.h similarity index 53% rename from f1ll/inc/f1ll/console_handler.h rename to components/f1ll/inc/f1ll/console_handler.h index 5c115f1..0798a70 100644 --- a/f1ll/inc/f1ll/console_handler.h +++ b/components/f1ll/inc/f1ll/console_handler.h @@ -19,24 +19,27 @@ class console_handler : public usart_core, public singleton public: void print(char const *s); + void flush(); + void append(char const *s); private: console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t channelRx, uint32_t channelTx); // LL_UsartCore pure virtual function implementations - virtual void receiver_idle(void); - virtual void transmission_complete(void); - virtual void framing_error(void); - virtual void overrun(void); - virtual void rx_dma_transfer_complete(void); - virtual void rx_dma_half_transfer(void); - virtual void rx_dma_error(void); - virtual void tx_dma_transfer_complete(void); - virtual void tx_dma_half_transfer(void); - virtual void tx_dma_error(void); + virtual void receiver_idle(void) override; + virtual void transmission_complete(void) override; + virtual void framing_error(void) override; + virtual void overrun(void) override; + virtual void rx_dma_transfer_complete(void) override; + virtual void rx_dma_half_transfer(void) override; + virtual void rx_dma_error(void) override; + virtual void tx_dma_transfer_complete(void) override; + virtual void tx_dma_half_transfer(void) override; + virtual void tx_dma_error(void) override; char m_buffer[128]; uint16_t m_used = 0; + volatile bool m_busy = false; }; } // namespace f1ll diff --git a/f1ll/inc/f1ll/dma_helper.h b/components/f1ll/inc/f1ll/dma_helper.h similarity index 100% rename from f1ll/inc/f1ll/dma_helper.h rename to components/f1ll/inc/f1ll/dma_helper.h diff --git a/f1ll/inc/f1ll/singleton.h b/components/f1ll/inc/f1ll/singleton.h similarity index 93% rename from f1ll/inc/f1ll/singleton.h rename to components/f1ll/inc/f1ll/singleton.h index 9442e57..671e1fe 100644 --- a/f1ll/inc/f1ll/singleton.h +++ b/components/f1ll/inc/f1ll/singleton.h @@ -3,6 +3,8 @@ #include +namespace f1ll { + template class singleton { public: @@ -23,4 +25,6 @@ protected: template T *singleton::m_instance = nullptr; +} // namespace f1ll { + #endif /* SINGLETON_H_ */ diff --git a/f1ll/inc/f1ll/str_util.h b/components/f1ll/inc/f1ll/str_util.h similarity index 100% rename from f1ll/inc/f1ll/str_util.h rename to components/f1ll/inc/f1ll/str_util.h diff --git a/f1ll/inc/f1ll/usart_core.h b/components/f1ll/inc/f1ll/usart_core.h similarity index 100% rename from f1ll/inc/f1ll/usart_core.h rename to components/f1ll/inc/f1ll/usart_core.h diff --git a/f1ll/src/console_handler.cpp b/components/f1ll/src/console_handler.cpp similarity index 53% rename from f1ll/src/console_handler.cpp rename to components/f1ll/src/console_handler.cpp index ce1e578..4577505 100644 --- a/f1ll/src/console_handler.cpp +++ b/components/f1ll/src/console_handler.cpp @@ -6,32 +6,60 @@ */ #include + #include namespace f1ll { -console_handler::console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, - uint32_t channelRx, uint32_t channelTx) - : usart_core(usart, dma, channelRx, channelTx) {} +console_handler::console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t channelRx, uint32_t channelTx) + : usart_core(usart, dma, channelRx, channelTx) +{ +} void console_handler::receiver_idle(void) {} -void console_handler::transmission_complete(void) {} +void console_handler::transmission_complete(void) +{ + m_busy = false; + m_used = 0; +} void console_handler::framing_error(void) {} void console_handler::overrun(void) {} void console_handler::rx_dma_transfer_complete(void) {} void console_handler::rx_dma_half_transfer(void) {} void console_handler::rx_dma_error(void) {} -void console_handler::tx_dma_transfer_complete(void) { +void console_handler::tx_dma_transfer_complete(void) +{ LL_USART_EnableIT_TC(m_usart); LL_DMA_DisableChannel(m_txDma.get_dma(), m_txDma.get_channel()); } void console_handler::tx_dma_half_transfer(void) {} void console_handler::tx_dma_error(void) {} -void console_handler::print(char const *s) { +void console_handler::append(char const *s) +{ + while (m_busy) + ; size_t len = strlen(s); - strncpy(m_buffer, s, sizeof(m_buffer)); - setup_transmit(m_buffer, len > sizeof(m_buffer) ? sizeof(m_buffer) : len); + size_t max_len = sizeof(m_buffer) - m_used; + strncpy(m_buffer + m_used, s, max_len); + m_used += len < max_len ? len : max_len; +} + +void console_handler::flush() +{ + while (m_busy) + ; + + if (m_used) { + m_busy = true; + setup_transmit(m_buffer, m_used); + } +} + +void console_handler::print(char const *s) +{ + append(s); + flush(); } } // namespace f1ll diff --git a/f1ll/src/dma_helper.cpp b/components/f1ll/src/dma_helper.cpp similarity index 100% rename from f1ll/src/dma_helper.cpp rename to components/f1ll/src/dma_helper.cpp diff --git a/f1ll/src/str_util.cpp b/components/f1ll/src/str_util.cpp similarity index 100% rename from f1ll/src/str_util.cpp rename to components/f1ll/src/str_util.cpp diff --git a/f1ll/src/usart_core.cpp b/components/f1ll/src/usart_core.cpp similarity index 100% rename from f1ll/src/usart_core.cpp rename to components/f1ll/src/usart_core.cpp diff --git a/platform/CMakeLists.txt b/components/platform/CMakeLists.txt similarity index 100% rename from platform/CMakeLists.txt rename to components/platform/CMakeLists.txt diff --git a/platform/platform/crc_ll.h b/components/platform/platform/crc_ll.h similarity index 100% rename from platform/platform/crc_ll.h rename to components/platform/platform/crc_ll.h diff --git a/platform/platform/dma_ll.h b/components/platform/platform/dma_ll.h similarity index 100% rename from platform/platform/dma_ll.h rename to components/platform/platform/dma_ll.h diff --git a/platform/platform/gpio_ll.h b/components/platform/platform/gpio_ll.h similarity index 100% rename from platform/platform/gpio_ll.h rename to components/platform/platform/gpio_ll.h diff --git a/platform/platform/usart_ll.h b/components/platform/platform/usart_ll.h similarity index 100% rename from platform/platform/usart_ll.h rename to components/platform/platform/usart_ll.h diff --git a/platform/platform/utils_ll.h b/components/platform/platform/utils_ll.h similarity index 100% rename from platform/platform/utils_ll.h rename to components/platform/platform/utils_ll.h diff --git a/f103c8_minimal_ll.ioc b/f103c8_minimal_ll.ioc index 20b8995..06af600 100644 --- a/f103c8_minimal_ll.ioc +++ b/f103c8_minimal_ll.ioc @@ -68,9 +68,9 @@ NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA10.Mode=Asynchronous PA10.Signal=USART1_RX -PA13.Mode=Serial_Wire +PA13.Mode=Trace_Asynchronous_SW PA13.Signal=SYS_JTMS-SWDIO -PA14.Mode=Serial_Wire +PA14.Mode=Trace_Asynchronous_SW PA14.Signal=SYS_JTCK-SWCLK PA9.Mode=Asynchronous PA9.Signal=USART1_TX @@ -87,7 +87,7 @@ PD1-OSC_OUT.Mode=HSE-External-Oscillator PD1-OSC_OUT.Signal=RCC_OSC_OUT PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=true +ProjectManager.BackupPrevious=false ProjectManager.CompilerLinker=GCC ProjectManager.CompilerOptimize=6 ProjectManager.ComputerToolchain=false @@ -103,7 +103,7 @@ ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true ProjectManager.LastFirmware=true ProjectManager.LibraryCopy=1 -ProjectManager.MainLocation=Src +ProjectManager.MainLocation=Core/Src ProjectManager.NoMain=false ProjectManager.PreviousToolchain=STM32CubeIDE ProjectManager.ProjectBuild=false