Browse Source

暂时屏蔽部分代码,把串口DMA发送调通了,原因是DMA只能访问0x24000000,现在默认全局变量分配在0x20000000

master
Lizongdi 2 weeks ago
parent
commit
42922913cd
  1. 17
      bspMCU/My_print.c
  2. 12
      project/RBcore/BHBF_robot.c
  3. 39
      project/RBcore/drv_interface.c

17
bspMCU/My_print.c

@ -30,12 +30,19 @@ volatile uint8_t g_flow_control_paused = 0;
TComCtrl *g_ptUartCtrl; TComCtrl *g_ptUartCtrl;
__attribute__((section(".dma_buffer"), aligned(32)))
static uint8_t uart_tx_buffer[512];
int USART_Send(char *_pBuffer, uint32_t _iSize) 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; TUartUserData *ptUartUserData = (TUartUserData *)g_ptUartCtrl->m_pUserData;
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); // int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10,GPIO_PIN_RESET); // 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; return iRet;
} }
@ -187,14 +194,14 @@ WEAK int Myprint_putchar(uint8_t ch)
// 遇到换行,发送 \r\n // 遇到换行,发送 \r\n
tx_buf[0] = '\r'; tx_buf[0] = '\r';
tx_buf[1] = '\n'; 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; return 2;
} }
else else
{ {
// 普通字符 // 普通字符
tx_buf[0] = ch; 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; return 1;
} }
} }

12
project/RBcore/BHBF_robot.c

@ -82,11 +82,11 @@ void GF_Init(void)
{ {
Drv_InterfaceInit(); Drv_InterfaceInit();
const osThreadAttr_t GF_Dispatch_attributes = { // const osThreadAttr_t GF_Dispatch_attributes = {
.name = "GF_Task", // .name = "GF_Task",
.stack_size = 1024, // .stack_size = 1024,
.priority = (osPriority_t) osPriorityRealtime1, // .priority = (osPriority_t) osPriorityRealtime1,
}; // };
(void)osThreadNew(GF_Dispatch, NULL, &GF_Dispatch_attributes); // (void)osThreadNew(GF_Dispatch, NULL, &GF_Dispatch_attributes);
} }

39
project/RBcore/drv_interface.c

@ -127,6 +127,7 @@ int FDCAN2_Send(char *_pBuffer, uint32_t _iSize)
} }
#ifndef CONFIG_UART_IT_IDLEDMA #ifndef CONFIG_UART_IT_IDLEDMA
extern TComCtrl *g_ptUartCtrl;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{ {
if (huart->Instance == USART1) if (huart->Instance == USART1)
@ -139,7 +140,8 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
} }
else if (huart->Instance == USART3) 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) else if (huart->Instance == UART4)
{ {
@ -160,6 +162,30 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
} }
#endif #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) void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
{ {
if (hfdcan->Instance == FDCAN1) if (hfdcan->Instance == FDCAN1)
@ -203,7 +229,8 @@ void SendAll_Task(void *argument)
{ {
rd_ComSendProc(g_ptRS485_1); rd_ComSendProc(g_ptRS485_1);
Rd_Delay(1); Rd_Delay(1);
rd_ComSendProc(g_ptRS485_2); //rd_ComSendProc(g_ptRS485_2);
rd_ComSendProc(g_ptUartCtrl);
Rd_Delay(1); Rd_Delay(1);
rd_ComSendProc(g_ptRS485_3); rd_ComSendProc(g_ptRS485_3);
Rd_Delay(1); Rd_Delay(1);
@ -224,21 +251,21 @@ void SendAll_Task(void *argument)
void Drv_InterfaceInit(void) void Drv_InterfaceInit(void)
{ {
MK32_Init(); //MK32_Init();
const osThreadAttr_t Read_RS485_1_attributes = { const osThreadAttr_t Read_RS485_1_attributes = {
.name = "RS485_1", .name = "RS485_1",
.stack_size = 512, .stack_size = 512,
.priority = (osPriority_t) osPriorityHigh7, .priority = (osPriority_t) osPriorityHigh6,
}; };
(void)osThreadNew(Read_RS485_1, NULL, &Read_RS485_1_attributes); (void)osThreadNew(Read_RS485_1, NULL, &Read_RS485_1_attributes);
const osThreadAttr_t send_task_attributes = { const osThreadAttr_t send_task_attributes = {
.name = "send_task", .name = "send_task",
.stack_size = 512, .stack_size = 512,
.priority = (osPriority_t) osPriorityRealtime, .priority = (osPriority_t) osPriorityHigh7,
}; };
(void)osThreadNew(SendAll_Task, NULL, &send_task_attributes); (void)osThreadNew(SendAll_Task, NULL, &send_task_attributes);
MoveWheel_Init(); //MoveWheel_Init();
} }

Loading…
Cancel
Save