diff --git a/bspMCU/My_print.c b/bspMCU/My_print.c index 0aedec5..3e73549 100644 --- a/bspMCU/My_print.c +++ b/bspMCU/My_print.c @@ -30,12 +30,19 @@ volatile uint8_t g_flow_control_paused = 0; TComCtrl *g_ptUartCtrl; +__attribute__((section(".dma_buffer"), aligned(32))) +static uint8_t uart_tx_buffer[512]; + int USART_Send(char *_pBuffer, uint32_t _iSize) { - HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10,GPIO_PIN_SET); + HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin,GPIO_PIN_SET); TUartUserData *ptUartUserData = (TUartUserData *)g_ptUartCtrl->m_pUserData; - int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); - HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10,GPIO_PIN_RESET); +// int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); +// HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin,GPIO_PIN_RESET); + RD_MEMCPY(uart_tx_buffer, _pBuffer, _iSize); + SCB_CleanDCache_by_Addr((uint32_t*)uart_tx_buffer, _iSize); + int iRet = HAL_UART_Transmit_DMA(ptUartUserData->m_uart, (uint8_t *)uart_tx_buffer, _iSize); + return iRet; } @@ -187,14 +194,14 @@ WEAK int Myprint_putchar(uint8_t ch) // 遇到换行,发送 \r\n tx_buf[0] = '\r'; tx_buf[1] = '\n'; - if (rd_ComSend(g_ptUartCtrl, tx_buf, 2) < 0) return EOF; + if (rd_ComWrite(g_ptUartCtrl, tx_buf, 2) < 0) return EOF; return 2; } else { // 普通字符 tx_buf[0] = ch; - if (rd_ComSend(g_ptUartCtrl, tx_buf, 1) < 0) return EOF; + if (rd_ComWrite(g_ptUartCtrl, tx_buf, 1) < 0) return EOF; return 1; } } diff --git a/project/RBcore/BHBF_robot.c b/project/RBcore/BHBF_robot.c index a745c9b..cdfc005 100644 --- a/project/RBcore/BHBF_robot.c +++ b/project/RBcore/BHBF_robot.c @@ -82,11 +82,11 @@ void GF_Init(void) { Drv_InterfaceInit(); - const osThreadAttr_t GF_Dispatch_attributes = { - .name = "GF_Task", - .stack_size = 1024, - .priority = (osPriority_t) osPriorityRealtime1, - }; - (void)osThreadNew(GF_Dispatch, NULL, &GF_Dispatch_attributes); +// const osThreadAttr_t GF_Dispatch_attributes = { +// .name = "GF_Task", +// .stack_size = 1024, +// .priority = (osPriority_t) osPriorityRealtime1, +// }; +// (void)osThreadNew(GF_Dispatch, NULL, &GF_Dispatch_attributes); } diff --git a/project/RBcore/drv_interface.c b/project/RBcore/drv_interface.c index a8dafb8..6c4843f 100644 --- a/project/RBcore/drv_interface.c +++ b/project/RBcore/drv_interface.c @@ -127,6 +127,7 @@ int FDCAN2_Send(char *_pBuffer, uint32_t _iSize) } #ifndef CONFIG_UART_IT_IDLEDMA +extern TComCtrl *g_ptUartCtrl; void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) @@ -139,7 +140,8 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } else if (huart->Instance == USART3) { - UART_RX_IRQHandler(g_ptRS485_2); + //UART_RX_IRQHandler(g_ptRS485_2); + UART_RX_IRQHandler(g_ptUartCtrl); } else if (huart->Instance == UART4) { @@ -160,6 +162,30 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } #endif +void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) +{ + if (huart->Instance == USART1) //**RS485_1 + { + HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, + GPIO_PIN_RESET); + } + else if (huart->Instance == USART3) //**RS485_2 + { + HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin, + GPIO_PIN_RESET); + } + else if (huart->Instance == USART6) //**RS485_3 + { + HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port, + RS485_3_DIR_Pin, GPIO_PIN_RESET); + } + else if (huart->Instance == UART7) //**RS485_4 + { + HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port, + RS485_4_DIR_Pin, GPIO_PIN_RESET); + } +} + void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs) { if (hfdcan->Instance == FDCAN1) @@ -203,7 +229,8 @@ void SendAll_Task(void *argument) { rd_ComSendProc(g_ptRS485_1); Rd_Delay(1); - rd_ComSendProc(g_ptRS485_2); + //rd_ComSendProc(g_ptRS485_2); + rd_ComSendProc(g_ptUartCtrl); Rd_Delay(1); rd_ComSendProc(g_ptRS485_3); Rd_Delay(1); @@ -224,21 +251,21 @@ void SendAll_Task(void *argument) void Drv_InterfaceInit(void) { - MK32_Init(); + //MK32_Init(); const osThreadAttr_t Read_RS485_1_attributes = { .name = "RS485_1", .stack_size = 512, - .priority = (osPriority_t) osPriorityHigh7, + .priority = (osPriority_t) osPriorityHigh6, }; (void)osThreadNew(Read_RS485_1, NULL, &Read_RS485_1_attributes); const osThreadAttr_t send_task_attributes = { .name = "send_task", .stack_size = 512, - .priority = (osPriority_t) osPriorityRealtime, + .priority = (osPriority_t) osPriorityHigh7, }; (void)osThreadNew(SendAll_Task, NULL, &send_task_attributes); - MoveWheel_Init(); + //MoveWheel_Init(); }