CH582芯片。我嘗試將printf重定向到USB。移植了BLE_USB例程中的app_usb.c,并將CH58x_sys.c中的_write函數(shù)修改為:
int?_write(int?fd,?char?*buf,?int?size) { #if?DEBUG?==?Debug_USB ????USBSendData(buf,?size); ????while(!EP2_GetINSta()); #else ????int?i; ????for(i?=?0;?i?<?size;?i++) ????{ #if?DEBUG?==?Debug_UART0 ????????while(R8_UART0_TFC?==?UART_FIFO_SIZE);??????????????????/*?等待數(shù)據(jù)發(fā)送?*/ ????????R8_UART0_THR?=?*buf++;?/*?發(fā)送數(shù)據(jù)?*/ #elif?DEBUG?==?Debug_UART1 ????????while(R8_UART1_TFC?==?UART_FIFO_SIZE);??????????????????/*?等待數(shù)據(jù)發(fā)送?*/ ????????R8_UART1_THR?=?*buf++;?/*?發(fā)送數(shù)據(jù)?*/ #elif?DEBUG?==?Debug_UART2 ????????while(R8_UART2_TFC?==?UART_FIFO_SIZE);??????????????????/*?等待數(shù)據(jù)發(fā)送?*/ ????????R8_UART2_THR?=?*buf++;?/*?發(fā)送數(shù)據(jù)?*/ #elif?DEBUG?==?Debug_UART3??????? ????????while(R8_UART3_TFC?==?UART_FIFO_SIZE);??????????????????/*?等待數(shù)據(jù)發(fā)送?*/ ????????R8_UART3_THR?=?*buf++;?/*?發(fā)送數(shù)據(jù)?*/ #endif ????} #endif?//DEBUG?==?Debug_USB ????return?size; } #endif
當(dāng)printf函數(shù)調(diào)用頻率較低時(shí),能夠正常運(yùn)行。但調(diào)用頻率較高或和藍(lán)牙協(xié)議棧同時(shí)運(yùn)行時(shí),會(huì)在運(yùn)行一段時(shí)間(數(shù)十秒)后卡死,請(qǐng)問應(yīng)如何修改?