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/include/sta/devices/stm32/can.hpp b/include/sta/devices/stm32/can.hpp index e935cf5..598b2bd 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; + // Return pending RX FIFOs as iterable container + 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/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 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 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); diff --git a/src/devices/stm32/can.cpp b/src/devices/stm32/can.cpp index 0c485ea..7a5cd59 100644 --- a/src/devices/stm32/can.cpp +++ b/src/devices/stm32/can.cpp @@ -168,6 +168,38 @@ namespace sta config->SlaveStartFilterBank = MAX_FILTER_COUNT; } } + + CanPendingRxFifos STM32CanController::getPendingRxFifos(){ + + + 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{ + return MAX_FILTER_COUNT; + } + + uint8_t STM32CanController::maxFifoCount() const { + return MAX_FIFO_COUNT; + } + + uint8_t STM32CanController::maxPayloadSize() const { + return MAX_PAYLOAD_SIZE; + } + } // namespace sta