Merge pull request 'adc-dma' (#22) from adc-dma into main

Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/sta-core/pulls/22
Reviewed-by: carlwachter <carlwachter@noreply.git.intern.spaceteamaachen.de>
This commit is contained in:
carlwachter 2024-03-16 14:27:29 +00:00
commit 7cc6108a40
6 changed files with 64 additions and 2 deletions

View File

@ -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.
*

View File

@ -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.

View File

@ -14,9 +14,10 @@
#include <sta/devices/stm32/mcu/common.hpp>
// 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
#endif // STA_CORE_STM32_MCU_STM32F407xx_HPP

View File

@ -19,7 +19,9 @@ namespace sta
void PrintableUART::print(const char * str, size_t length)
{
intf_->acquire();
intf_->transfer(reinterpret_cast<const uint8_t *>(str), length);
intf_->release();
}
} // namespace sta

View File

@ -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);

View File

@ -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