遥控器应用测试时,发现配置成2400打印,输出乱码 分析发现SDK 中的函数在32Mhz里输出2400波特率错误。 修改后 一下,解决输出问题。 /* 6621E Cpu 32Mhz Uart1 baud rate = 2400~57600 115200 以上时,使用SDK默认的接口 仅配置了 输出,未配置收入! */ void uart1_open(HS_UART_Type *uart, uint32_t baud_rate, uart_flow_ctrl_t flow_ctrl, uart_rx_callback_t uart_rx_cb) { uint16_t baud_divisor; // Reset and Bypass UART1 register_set1(&HS_PSO->UART1_CFG, CPM_UART_SOFT_RESET_MASK); register_set0(&HS_PSO->UART1_CFG, CPM_UART_DIV_SEL_MASK | CPM_UART_GATE_EN_MASK); HS_PSO_UPD_RDY(); /* Compute divisor value. Normally, we should simply return: * NS16550_CLK / MODE_X_DIV / baudrate * but we need to round that value by adding 0.5. * Rounding is especially important at high baud rates. */ if (cpm_get_clock(CPM_TOP_CLK) >= 32000000 && baud_rate < 19200) baud_divisor = 4; // make sure 9600bps is supported else baud_divisor = 1; cpm_set_clock(CPM_UART1_CLK, baud_divisor * baud_rate * 16); // Disable LCR and irq uart->LCR = 0x00; uart->IER = 0; if (flow_ctrl == UART_FLOW_CTRL_ENABLED) uart->MCR = UART_MCR_RTS | UART_MCR_AFCE; else uart->MCR = 0x00; uart->FCR = UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_FIFO_EN | UART_FCR_TRIGGER_1; /* Baud rate setting.*/ uart->LCR = UART_LCR_DLAB; uart->DLL = baud_divisor & 0xff; uart->DLH = (baud_divisor >> 8) & 0xff; /* 8 data, 1 stop, no parity */ uart->LCR = UART_LCR_8N1; /* Set UARTs int mask */ } 调用 取代默认代码 static void peripheral_init(void) { // Init GPIO /********************************/ /********************************/ // Init UART uart1_open(DEBUG_UART, 2400, UART_FLOW_CTRL_DISABLED, NULL); } static void peripheral_restore(void) { // Init UART uart1_open(DEBUG_UART, 2400, UART_FLOW_CTRL_DISABLED, NULL); } |