From 340f0329fae3670463ee44d11bad2b9545bfc212 Mon Sep 17 00:00:00 2001 From: Attila Body Date: Wed, 28 May 2025 09:13:56 +0200 Subject: [PATCH 1/2] Make it work --- .clang-format | 33 +++++++++++ .vscode/settings.json | 3 +- Src/main.c | 85 ++++++++++++++------------- Src/stm32f1xx_it.c | 101 ++++++++++++++++++-------------- app/inc/irq_bridge.h | 1 + app/src/app.cpp | 5 +- app/src/irq_bridge.cpp | 11 +++- f1ll/inc/f1ll/console_handler.h | 6 +- f1ll/inc/f1ll/dma_helper.h | 55 +++++++++-------- f1ll/inc/f1ll/singleton.h | 6 +- f1ll/inc/f1ll/usart_core.h | 6 +- 11 files changed, 187 insertions(+), 125 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2e7f699 --- /dev/null +++ b/.clang-format @@ -0,0 +1,33 @@ +BasedOnStyle: LLVM +UseTab: Never +IndentWidth: 2 +TabWidth: 2 +BreakBeforeBraces: Custom +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: true +AllowAllArgumentsOnNextLine: true +IndentCaseLabels: true +AccessModifierOffset: -2 +NamespaceIndentation: None +FixNamespaceComments: false +PackConstructorInitializers: Never +AlignAfterOpenBracket: AlwaysBreak +InsertBraces: true +BraceWrapping: + AfterClass: true # false + AfterControlStatement: false + AfterEnum: true # false + AfterFunction: true # false + AfterNamespace: false + AfterObjCDeclaration: true # false + AfterStruct: true # false + AfterUnion: true # false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +ColumnLimit: 140 diff --git a/.vscode/settings.json b/.vscode/settings.json index c5c2fbb..87f6b90 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,6 @@ ], "cmake.preferredGenerators": [ "Ninja" - ] + ], + "sonarlint.pathToCompileCommands": "${workspaceFolder}/compile_commands.json" } \ No newline at end of file diff --git a/Src/main.c b/Src/main.c index fabea7d..37fd826 100644 --- a/Src/main.c +++ b/Src/main.c @@ -19,8 +19,8 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "dma.h" -#include "gpio.h" #include "usart.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -57,21 +57,15 @@ void SystemClock_Config(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -void SendStr(char const *str) { - while (*str) { - LL_USART_ClearFlag_TC(USART1); - LL_USART_TransmitData8(USART1, *str++); - while (!LL_USART_IsActiveFlag_TC(USART1)) - ; - } -} + /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ -int main(void) { + * @brief The application entry point. + * @retval int + */ +int main(void) +{ /* USER CODE BEGIN 1 */ @@ -79,8 +73,7 @@ int main(void) { /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. - */ + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); @@ -88,7 +81,7 @@ int main(void) { NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled - */ + */ LL_GPIO_AF_Remap_SWJ_NOJTAG(); /* USER CODE BEGIN Init */ @@ -113,38 +106,46 @@ int main(void) { /* Infinite loop */ /* USER CODE BEGIN WHILE */ app_main(); - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) { + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2) { + while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_2) + { } LL_RCC_HSE_Enable(); - /* Wait till HSE is ready */ - while (LL_RCC_HSE_IsReady() != 1) { + /* Wait till HSE is ready */ + while(LL_RCC_HSE_IsReady() != 1) + { + } LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) { + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } LL_Init1msTick(72000000); LL_SetSystemCoreClock(72000000); @@ -155,10 +156,11 @@ void SystemClock_Config(void) { /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) { + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); @@ -167,15 +169,16 @@ void Error_Handler(void) { /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) { + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, diff --git a/Src/stm32f1xx_it.c b/Src/stm32f1xx_it.c index bc84c8a..11682ea 100644 --- a/Src/stm32f1xx_it.c +++ b/Src/stm32f1xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32f1xx_it.h" #include "main.h" - +#include "stm32f1xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -68,9 +67,10 @@ /* Cortex-M3 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ -void NMI_Handler(void) { + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) +{ /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ @@ -81,61 +81,70 @@ void NMI_Handler(void) { } /** - * @brief This function handles Hard fault interrupt. - */ -void HardFault_Handler(void) { + * @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. - */ -void MemManage_Handler(void) { + * @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. - */ -void BusFault_Handler(void) { + * @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. - */ -void UsageFault_Handler(void) { + * @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. - */ -void SVC_Handler(void) { + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) +{ /* USER CODE BEGIN SVCall_IRQn 0 */ /* USER CODE END SVCall_IRQn 0 */ @@ -145,9 +154,10 @@ void SVC_Handler(void) { } /** - * @brief This function handles Debug monitor. - */ -void DebugMon_Handler(void) { + * @brief This function handles Debug monitor. + */ +void DebugMon_Handler(void) +{ /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ @@ -157,9 +167,10 @@ void DebugMon_Handler(void) { } /** - * @brief This function handles Pendable request for system service. - */ -void PendSV_Handler(void) { + * @brief This function handles Pendable request for system service. + */ +void PendSV_Handler(void) +{ /* USER CODE BEGIN PendSV_IRQn 0 */ /* USER CODE END PendSV_IRQn 0 */ @@ -169,9 +180,10 @@ void PendSV_Handler(void) { } /** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) { + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) +{ /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ @@ -189,9 +201,10 @@ void SysTick_Handler(void) { /******************************************************************************/ /** - * @brief This function handles DMA1 channel4 global interrupt. - */ -void DMA1_Channel4_IRQHandler(void) { + * @brief This function handles DMA1 channel4 global interrupt. + */ +void DMA1_Channel4_IRQHandler(void) +{ /* USER CODE BEGIN DMA1_Channel4_IRQn 0 */ dma1_channel4_irq_handler(); /* USER CODE END DMA1_Channel4_IRQn 0 */ @@ -201,9 +214,10 @@ void DMA1_Channel4_IRQHandler(void) { } /** - * @brief This function handles DMA1 channel5 global interrupt. - */ -void DMA1_Channel5_IRQHandler(void) { + * @brief This function handles DMA1 channel5 global interrupt. + */ +void DMA1_Channel5_IRQHandler(void) +{ /* USER CODE BEGIN DMA1_Channel5_IRQn 0 */ dma1_channel5_irq_handler(); /* USER CODE END DMA1_Channel5_IRQn 0 */ @@ -213,11 +227,12 @@ void DMA1_Channel5_IRQHandler(void) { } /** - * @brief This function handles USART1 global interrupt. - */ -void USART1_IRQHandler(void) { + * @brief This function handles USART1 global interrupt. + */ +void USART1_IRQHandler(void) +{ /* USER CODE BEGIN USART1_IRQn 0 */ - + usart1_irq_handler(); /* USER CODE END USART1_IRQn 0 */ /* USER CODE BEGIN USART1_IRQn 1 */ diff --git a/app/inc/irq_bridge.h b/app/inc/irq_bridge.h index 9a329c5..3e95487 100644 --- a/app/inc/irq_bridge.h +++ b/app/inc/irq_bridge.h @@ -7,6 +7,7 @@ extern "C" { void dma1_channel4_irq_handler(); void dma1_channel5_irq_handler(); +void usart1_irq_handler(); #if defined(__cplusplus) } diff --git a/app/src/app.cpp b/app/src/app.cpp index 32c975b..0533976 100644 --- a/app/src/app.cpp +++ b/app/src/app.cpp @@ -4,7 +4,8 @@ #include -void app_main() { +void app_main() +{ f1ll::console_handler::init(USART1, DMA1, LL_DMA_CHANNEL_5, LL_DMA_CHANNEL_4); while (true) { @@ -12,4 +13,4 @@ void app_main() { LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); LL_mDelay(500); } -} \ No newline at end of file +} diff --git a/app/src/irq_bridge.cpp b/app/src/irq_bridge.cpp index 7cc11cc..3545f4b 100644 --- a/app/src/irq_bridge.cpp +++ b/app/src/irq_bridge.cpp @@ -2,10 +2,17 @@ #include -void dma1_channel4_irq_handler() { +void dma1_channel4_irq_handler() +{ f1ll::console_handler::instance().tx_dma_isr(); } -void dma1_channel5_irq_handler() { +void dma1_channel5_irq_handler() +{ f1ll::console_handler::instance().rx_dma_isr(); } + +void usart1_irq_handler() +{ + f1ll::console_handler::instance().usart_isr(); +} \ No newline at end of file diff --git a/f1ll/inc/f1ll/console_handler.h b/f1ll/inc/f1ll/console_handler.h index c85122b..5c115f1 100644 --- a/f1ll/inc/f1ll/console_handler.h +++ b/f1ll/inc/f1ll/console_handler.h @@ -13,15 +13,15 @@ namespace f1ll { -class console_handler : public usart_core, public singleton { +class console_handler : public usart_core, public singleton +{ friend class singleton; public: void print(char const *s); private: - console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t channelRx, - uint32_t channelTx); + 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); diff --git a/f1ll/inc/f1ll/dma_helper.h b/f1ll/inc/f1ll/dma_helper.h index 466121d..0c7d52b 100644 --- a/f1ll/inc/f1ll/dma_helper.h +++ b/f1ll/inc/f1ll/dma_helper.h @@ -11,39 +11,38 @@ #include #include -namespace f1ll +namespace f1ll { + +class dma_helper { +public: + dma_helper(DMA_TypeDef *dma, uint32_t channel); + dma_helper(dma_helper const &base) = default; - class dma_helper - { - public: - dma_helper(DMA_TypeDef *dma, uint32_t channel); - dma_helper(dma_helper const &base) = default; + inline DMA_TypeDef *get_dma() const { return m_dma; } + inline uint32_t get_channel() const { return m_channel; } + inline volatile uint32_t *get_is_reg() const { return m_is_reg; } + inline volatile uint32_t *get_ifc_reg() const { return m_ifc_reg; } + inline uint32_t get_te_mask() const { return m_te_masks[m_channel - 1]; } + inline uint32_t get_ht_mask() const { return m_ht_masks[m_channel - 1]; } + inline uint32_t get_tc_mask() const { return m_tc_masks[m_channel - 1]; } + inline uint32_t get_gi_mask() const { return m_gi_masks[m_channel - 1]; } - inline DMA_TypeDef *get_dma() const { return m_dma; } - inline uint32_t get_channel() const { return m_channel; } - inline volatile uint32_t *get_is_reg() const { return m_is_reg; } - inline volatile uint32_t *get_ifc_reg() const { return m_ifc_reg; } - inline uint32_t get_te_mask() const { return m_te_masks[m_channel - 1]; } - inline uint32_t get_ht_mask() const { return m_ht_masks[m_channel - 1]; } - inline uint32_t get_tc_mask() const { return m_tc_masks[m_channel - 1]; } - inline uint32_t get_gi_mask() const { return m_gi_masks[m_channel - 1]; } + inline bool is_enabled_it_te() { return LL_DMA_IsEnabledIT_TE(m_dma, m_channel) != 0; } + inline bool is_enabled_it_ht() { return LL_DMA_IsEnabledIT_HT(m_dma, m_channel) != 0; } + inline bool is_enabled_it_tc() { return LL_DMA_IsEnabledIT_TC(m_dma, m_channel) != 0; } - inline bool is_enabled_it_te() { return LL_DMA_IsEnabledIT_TE(m_dma, m_channel) != 0; } - inline bool is_enabled_it_ht() { return LL_DMA_IsEnabledIT_HT(m_dma, m_channel) != 0; } - inline bool is_enabled_it_tc() { return LL_DMA_IsEnabledIT_TC(m_dma, m_channel) != 0; } +private: + DMA_TypeDef *m_dma; + uint32_t m_channel; + volatile uint32_t *m_is_reg; + volatile uint32_t *m_ifc_reg; - private: - DMA_TypeDef *m_dma; - uint32_t m_channel; - volatile uint32_t *m_is_reg; - volatile uint32_t *m_ifc_reg; - - static const uint32_t m_te_masks[7]; - static const uint32_t m_ht_masks[7]; - static const uint32_t m_tc_masks[7]; - static const uint32_t m_gi_masks[7]; - }; + static const uint32_t m_te_masks[7]; + static const uint32_t m_ht_masks[7]; + static const uint32_t m_tc_masks[7]; + static const uint32_t m_gi_masks[7]; +}; } /* namespace f4ll */ diff --git a/f1ll/inc/f1ll/singleton.h b/f1ll/inc/f1ll/singleton.h index 92a6c93..9442e57 100644 --- a/f1ll/inc/f1ll/singleton.h +++ b/f1ll/inc/f1ll/singleton.h @@ -3,10 +3,12 @@ #include -template class singleton { +template class singleton +{ public: static T &instance() { return *m_instance; } - template static T &init(args_t &&...args) { + template static T &init(args_t &&...args) + { static T instance{std::forward(args)...}; m_instance = &instance; return instance; diff --git a/f1ll/inc/f1ll/usart_core.h b/f1ll/inc/f1ll/usart_core.h index c013f91..80103bd 100644 --- a/f1ll/inc/f1ll/usart_core.h +++ b/f1ll/inc/f1ll/usart_core.h @@ -13,7 +13,8 @@ namespace f1ll { -class usart_core { +class usart_core +{ public: static inline void usart_irq(usart_core *_this) { _this->usart_isr(); } static inline void rx_dma_irq(usart_core *_this) { _this->rx_dma_isr(); } @@ -23,8 +24,7 @@ public: void setup_receive(void *buffer, uint16_t length); protected: - usart_core(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t channel_rx, - uint32_t stream_tx); + usart_core(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t channel_rx, uint32_t stream_tx); USART_TypeDef *m_usart; dma_helper m_rxDma; From 45141798d8d88f49cbd18e8f67abd49619eb16e0 Mon Sep 17 00:00:00 2001 From: Attila Body Date: Sat, 31 May 2025 17:45:15 +0200 Subject: [PATCH 2/2] Clan up the structure --- .clang-format | 2 +- .gitignore | 1 - .mxproject | 28 +- CMakeLists.txt | 6 +- {Inc => Core/Inc}/dma.h | 0 {Inc => Core/Inc}/gpio.h | 0 {Inc => Core/Inc}/main.h | 0 {Inc => Core/Inc}/stm32_assert.h | 0 {Inc => Core/Inc}/stm32f1xx_it.h | 0 {Inc => Core/Inc}/usart.h | 0 {Src => Core/Src}/dma.c | 0 {Src => Core/Src}/gpio.c | 0 {Src => Core/Src}/main.c | 4 - {Src => Core/Src}/stm32f1xx_it.c | 69 ++-- {Src => Core/Src}/syscalls.c | 0 {Src => Core/Src}/sysmem.c | 0 {Src => Core/Src}/system_stm32f1xx.c | 0 {Src => Core/Src}/usart.c | 0 Startup/startup_stm32f103c8tx.s | 364 ------------------ cmake/stm32cubemx/CMakeLists.txt | 18 +- {app => components/app}/CMakeLists.txt | 0 {app => components/app}/inc/app.h | 0 {app => components/app}/inc/irq_bridge.h | 6 +- {app => components/app}/src/app.cpp | 0 {app => components/app}/src/irq_bridge.cpp | 6 +- {f1ll => components/f1ll}/CMakeLists.txt | 3 + .../f1ll}/inc/f1ll/console_handler.h | 23 +- .../f1ll}/inc/f1ll/dma_helper.h | 0 .../f1ll}/inc/f1ll/singleton.h | 4 + {f1ll => components/f1ll}/inc/f1ll/str_util.h | 0 .../f1ll}/inc/f1ll/usart_core.h | 0 .../f1ll}/src/console_handler.cpp | 44 ++- {f1ll => components/f1ll}/src/dma_helper.cpp | 0 {f1ll => components/f1ll}/src/str_util.cpp | 0 {f1ll => components/f1ll}/src/usart_core.cpp | 0 .../platform}/CMakeLists.txt | 0 .../platform}/platform/crc_ll.h | 0 .../platform}/platform/dma_ll.h | 0 .../platform}/platform/gpio_ll.h | 0 .../platform}/platform/usart_ll.h | 0 .../platform}/platform/utils_ll.h | 0 f103c8_minimal_ll.ioc | 8 +- 42 files changed, 134 insertions(+), 452 deletions(-) rename {Inc => Core/Inc}/dma.h (100%) rename {Inc => Core/Inc}/gpio.h (100%) rename {Inc => Core/Inc}/main.h (100%) rename {Inc => Core/Inc}/stm32_assert.h (100%) rename {Inc => Core/Inc}/stm32f1xx_it.h (100%) rename {Inc => Core/Inc}/usart.h (100%) rename {Src => Core/Src}/dma.c (100%) rename {Src => Core/Src}/gpio.c (100%) rename {Src => Core/Src}/main.c (94%) rename {Src => Core/Src}/stm32f1xx_it.c (81%) rename {Src => Core/Src}/syscalls.c (100%) rename {Src => Core/Src}/sysmem.c (100%) rename {Src => Core/Src}/system_stm32f1xx.c (100%) rename {Src => Core/Src}/usart.c (100%) delete mode 100644 Startup/startup_stm32f103c8tx.s rename {app => components/app}/CMakeLists.txt (100%) rename {app => components/app}/inc/app.h (100%) rename {app => components/app}/inc/irq_bridge.h (61%) rename {app => components/app}/src/app.cpp (100%) rename {app => components/app}/src/irq_bridge.cpp (67%) rename {f1ll => components/f1ll}/CMakeLists.txt (65%) rename {f1ll => components/f1ll}/inc/f1ll/console_handler.h (53%) rename {f1ll => components/f1ll}/inc/f1ll/dma_helper.h (100%) rename {f1ll => components/f1ll}/inc/f1ll/singleton.h (93%) rename {f1ll => components/f1ll}/inc/f1ll/str_util.h (100%) rename {f1ll => components/f1ll}/inc/f1ll/usart_core.h (100%) rename {f1ll => components/f1ll}/src/console_handler.cpp (53%) rename {f1ll => components/f1ll}/src/dma_helper.cpp (100%) rename {f1ll => components/f1ll}/src/str_util.cpp (100%) rename {f1ll => components/f1ll}/src/usart_core.cpp (100%) rename {platform => components/platform}/CMakeLists.txt (100%) rename {platform => components/platform}/platform/crc_ll.h (100%) rename {platform => components/platform}/platform/dma_ll.h (100%) rename {platform => components/platform}/platform/gpio_ll.h (100%) rename {platform => components/platform}/platform/usart_ll.h (100%) rename {platform => components/platform}/platform/utils_ll.h (100%) 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