From 22dd70cb706eeab335271ac4ac26be655cd25ee5 Mon Sep 17 00:00:00 2001 From: "@CarlWachter" Date: Wed, 25 Oct 2023 15:57:52 +0200 Subject: [PATCH 1/5] CAN bus completion of abstract class Can additions --- include/sta/devices/stm32/can.hpp | 8 ++++++++ src/devices/stm32/can.cpp | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/sta/devices/stm32/can.hpp b/include/sta/devices/stm32/can.hpp index e935cf5..cd75304 100644 --- a/include/sta/devices/stm32/can.hpp +++ b/include/sta/devices/stm32/can.hpp @@ -80,6 +80,14 @@ namespace sta void disableFilter(uint8_t idx) override; void clearFilters() override; + // TODO + CanPendingRxFifos getPendingRxFifos() override; + + // Const getters + uint8_t maxFilterCount() const override; + uint8_t maxFifoCount() const override; + uint8_t maxPayloadSize() const override; + private: /** * @brief Initialize filter settings. diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 0c485ea..66b07ac 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -168,6 +168,29 @@ namespace sta config->SlaveStartFilterBank = MAX_FILTER_COUNT; } } + + CanPendingRxFifos STM32CanController::getPendingRxFifos(){ + CanPendingRxFifos pendingFifos(42, 3); + + // Example implementation: + //pendingFifos.fifo0Pending = HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0; + //pendingFifos.fifo1Pending = HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0; + + return pendingFifos; + } + + uint8_t STM32CanController::maxFilterCount() const{ + return MAX_FILTER_COUNT; + } + + uint8_t STM32CanController::maxFifoCount() const { + return MAX_FIFO_COUNT; + } + + uint8_t STM32CanController::maxPayloadSize() const { + return MAX_PAYLOAD_SIZE; + } + } // namespace sta From e8f7261030b71d8e80843d68532e595f545866fe Mon Sep 17 00:00:00 2001 From: "@CarlWachter" Date: Thu, 4 Jan 2024 16:54:53 +0100 Subject: [PATCH 2/5] Completed getPendingRxFifos --- include/sta/devices/stm32/can.hpp | 2 +- src/devices/stm32/can.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/sta/devices/stm32/can.hpp b/include/sta/devices/stm32/can.hpp index cd75304..598b2bd 100644 --- a/include/sta/devices/stm32/can.hpp +++ b/include/sta/devices/stm32/can.hpp @@ -80,7 +80,7 @@ namespace sta void disableFilter(uint8_t idx) override; void clearFilters() override; - // TODO + // Return pending RX FIFOs as iterable container CanPendingRxFifos getPendingRxFifos() override; // Const getters diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 66b07ac..7a5cd59 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -170,13 +170,22 @@ namespace sta } CanPendingRxFifos STM32CanController::getPendingRxFifos(){ - CanPendingRxFifos pendingFifos(42, 3); - // Example implementation: - //pendingFifos.fifo0Pending = HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0; - //pendingFifos.fifo1Pending = HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0; - return pendingFifos; + uint32_t rxFlags = 0; + + // Conditions to set the least significant bits + if (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0) { + // Set the first least significant bit + rxFlags |= 0x01; // 0x01 is 00000001 in binary (LSB set, others cleared) + } + + if (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0) { + // Set the second least significant bit + rxFlags |= 0x02; // 0x02 is 00000010 in binary (2nd LSB set, others cleared) + } + + return CanPendingRxFifos(rxFlags, MAX_FIFO_COUNT);; } uint8_t STM32CanController::maxFilterCount() const{ From 8901abdb9cc393b3e7f2de295e75ba4205d6de39 Mon Sep 17 00:00:00 2001 From: CarlWachter Date: Tue, 30 Jan 2024 15:24:38 +0100 Subject: [PATCH 3/5] Added CAN to ASEAG --- include/sta/devices/stm32/mcu/STM32F407xx.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/sta/devices/stm32/mcu/STM32F407xx.hpp b/include/sta/devices/stm32/mcu/STM32F407xx.hpp index 48db885..f390ad0 100644 --- a/include/sta/devices/stm32/mcu/STM32F407xx.hpp +++ b/include/sta/devices/stm32/mcu/STM32F407xx.hpp @@ -14,9 +14,10 @@ #include -// uart setup +// uart/CAN setup #ifdef STA_STM32_ASEAG # define STA_STM32_USART_HANDLE huart1 +# define STA_STM32_CAN_HANDLE hcan1 #else # ifdef STA_STM32_SWD_USART_IDX # define STA_STM32_USART_HANDLE CONCAT(huart, STA_STM32_SWD_USART_IDX) @@ -100,4 +101,4 @@ /** @} */ -#endif // STA_CORE_STM32_MCU_STM32F407xx_HPP \ No newline at end of file +#endif // STA_CORE_STM32_MCU_STM32F407xx_HPP From 1fc34fa5742df03d324440b80ac2cd4939311849 Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 15 Mar 2024 13:00:23 +0100 Subject: [PATCH 4/5] Added DMA support for ADC --- include/sta/devices/stm32/adc.hpp | 8 ++++++++ src/devices/stm32/adc.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/sta/devices/stm32/adc.hpp b/include/sta/devices/stm32/adc.hpp index 62b2985..e9b6292 100644 --- a/include/sta/devices/stm32/adc.hpp +++ b/include/sta/devices/stm32/adc.hpp @@ -31,6 +31,14 @@ namespace sta */ void start(); + /** + * @brief Starts conversion of the incoming analog signal in DMA mode. + * + * @param buffer The buffer to write the converted values to. + * @param length The length of the buffer to write the converted values to. + */ + void startDMA(uint32_t * buffer, size_t length); + /** * @brief Polls for the converted analog signal. * diff --git a/src/devices/stm32/adc.cpp b/src/devices/stm32/adc.cpp index 5c5d663..fa57930 100644 --- a/src/devices/stm32/adc.cpp +++ b/src/devices/stm32/adc.cpp @@ -17,6 +17,17 @@ namespace sta HAL_ADC_Start(handle_); } + void STM32ADC::startDMA(uint32_t * buffer, size_t length) + { + STA_ASSERT(buffer != nullptr); + STA_ASSERT(length != 0); + STA_ASSERT(handle_->DMA_Handle != nullptr); + + HAL_StatusTypeDef res = HAL_ADC_Start_DMA(handle_, buffer, length); + + STA_ASSERT(res == HAL_OK); + } + void STM32ADC::poll(uint32_t timeout) { HAL_StatusTypeDef res = HAL_ADC_PollForConversion(handle_, timeout); From 9f0defa24f6f384770bbf791e8765165840eb33d Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 15 Mar 2024 17:19:26 +0100 Subject: [PATCH 5/5] Fixed breaking bug in printable --- src/debug/printing/printable_uart.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/debug/printing/printable_uart.cpp b/src/debug/printing/printable_uart.cpp index 76a63f8..f3f7453 100644 --- a/src/debug/printing/printable_uart.cpp +++ b/src/debug/printing/printable_uart.cpp @@ -19,7 +19,9 @@ namespace sta void PrintableUART::print(const char * str, size_t length) { + intf_->acquire(); intf_->transfer(reinterpret_cast(str), length); + intf_->release(); } } // namespace sta