diff --git a/components/hardware/uart/zuart_helper.cpp b/components/hardware/uart/zuart_helper.cpp index 7a07495..d5c97ae 100644 --- a/components/hardware/uart/zuart_helper.cpp +++ b/components/hardware/uart/zuart_helper.cpp @@ -19,6 +19,8 @@ ZUARTHelper::ZUARTHelper(const char* tag, UART_HandleTypeDef* uart, DMA_HandleTy m_hdma_tx = hdma_tx; m_hdma_rx = hdma_rx; m_tag = tag; + ZASSERT(hdma_rx->Init.Direction == DMA_PERIPH_TO_MEMORY); + ZASSERT(hdma_tx->Init.Direction == DMA_MEMORY_TO_PERIPH); } void ZUARTHelper::cleanRxBuff() { diff --git a/components/mini_servo_motor/feite_servo_motor.cpp b/components/mini_servo_motor/feite_servo_motor.cpp index 7854a6c..9a8bb57 100644 --- a/components/mini_servo_motor/feite_servo_motor.cpp +++ b/components/mini_servo_motor/feite_servo_motor.cpp @@ -22,10 +22,13 @@ static void dumphex(const char* tag, uint8_t* data, uint8_t len) { printf("\n"); #endif } -void FeiTeServoMotor::initialize2(UART_HandleTypeDef* uart, DMA_HandleTypeDef* hdma_tx,DMA_HandleTypeDef* hdma_rx) { +void FeiTeServoMotor::initialize(UART_HandleTypeDef* uart, DMA_HandleTypeDef* hdma_rx, DMA_HandleTypeDef* hdma_tx) { m_uart = uart; m_hdma_rx = hdma_rx; m_hdma_tx = hdma_tx; + ZASSERT(hdma_rx->Init.Direction == DMA_PERIPH_TO_MEMORY); + ZASSERT(hdma_tx->Init.Direction == DMA_MEMORY_TO_PERIPH); + m_mutex.init(); } bool FeiTeServoMotor::ping(uint8_t id) { @@ -366,10 +369,10 @@ bool FeiTeServoMotor::tx_and_rx(uint8_t* tx, uint8_t txdatalen, uint8_t* rx, uin #if 1 HAL_UART_Receive_DMA(m_uart, (uint8_t*)rx, expectrxsize); - HAL_UART_Transmit(m_uart, tx, txdatalen,1000); + HAL_UART_Transmit(m_uart, tx, txdatalen, 1000); bool overtime_flag = false; - while (HAL_UART_GetState(m_uart) != HAL_UART_STATE_READY ) { + while (HAL_UART_GetState(m_uart) != HAL_UART_STATE_READY) { osDelay(1); int rxsize = expectrxsize - __HAL_DMA_GET_COUNTER(m_hdma_rx); if (rxsize == expectrxsize) { diff --git a/components/mini_servo_motor/feite_servo_motor.hpp b/components/mini_servo_motor/feite_servo_motor.hpp index ca96bd1..f88e1fe 100644 --- a/components/mini_servo_motor/feite_servo_motor.hpp +++ b/components/mini_servo_motor/feite_servo_motor.hpp @@ -128,7 +128,7 @@ class FeiTeServoMotor { zmutex m_mutex; public: - void initialize2(UART_HandleTypeDef* uart, DMA_HandleTypeDef* hdma_tx,DMA_HandleTypeDef* hdma_rx); + void initialize(UART_HandleTypeDef* uart, DMA_HandleTypeDef* hdma_rx, DMA_HandleTypeDef* hdma_tx); bool ping(uint8_t id); bool readversion(uint8_t id, uint8_t& mainversion, uint8_t& subversion, uint8_t& miniserv_mainversion, uint8_t& miniserv_subversion);