diff --git a/cores/arduino/Serial.cpp b/cores/arduino/Serial.cpp index d905edd90..7d7a0ad87 100644 --- a/cores/arduino/Serial.cpp +++ b/cores/arduino/Serial.cpp @@ -61,9 +61,13 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) { case UART_EVENT_TX_COMPLETE: case UART_EVENT_TX_DATA_EMPTY: { - //uint8_t to_enqueue = uart_ptr->txBuffer.available() < uart_ptr->uart_ctrl.fifo_depth ? uart_ptr->txBuffer.available() : uart_ptr->uart_ctrl.fifo_depth; - //while (to_enqueue) { - uart_ptr->tx_done = true; + if(uart_ptr->txBuffer.available()){ + static char txc; + txc = uart_ptr->txBuffer.read_char(); + R_SCI_UART_Write(&(uart_ptr->uart_ctrl), (uint8_t*)&txc , 1); + } else { + uart_ptr->tx_done = true; + } break; } case UART_EVENT_RX_CHAR: @@ -108,27 +112,31 @@ bool UART::setUpUartIrqs(uart_cfg_t &cfg) { /* -------------------------------------------------------------------------- */ size_t UART::write(uint8_t c) { /* -------------------------------------------------------------------------- */ - if(init_ok) { - tx_done = false; - R_SCI_UART_Write(&uart_ctrl, &c, 1); - while (!tx_done) {} - return 1; - } - else { - return 0; - } + if(init_ok) { + while(txBuffer.isFull()){;} + txBuffer.store_char(c); + if(tx_done){ + tx_done = false; + txc = txBuffer.read_char(); // clear out the char we just added and send it to start transmission. + R_SCI_UART_Write(&uart_ctrl, (uint8_t*)&txc , 1); + } + return 1; + } + else { + return 0; + } } size_t UART::write(uint8_t* c, size_t len) { - if(init_ok) { - tx_done = false; - R_SCI_UART_Write(&uart_ctrl, c, len); - while (!tx_done) {} - return len; - } - else { - return 0; - } + if(init_ok) { + for(int i = 0; iTDR = *(c+i); - while (uart_ctrl.p_reg->SSR_b.TEND == 0) {} - i++; - } - return len; + return write(c, len); } \ No newline at end of file diff --git a/cores/arduino/Serial.h b/cores/arduino/Serial.h index cc818d466..e53a55c71 100644 --- a/cores/arduino/Serial.h +++ b/cores/arduino/Serial.h @@ -78,7 +78,8 @@ class UART : public arduino::HardwareSerial { arduino::SafeRingBufferN rxBuffer; arduino::SafeRingBufferN txBuffer; - volatile bool tx_done; + volatile bool tx_done = true; + char txc; sci_uart_instance_ctrl_t uart_ctrl; uart_cfg_t uart_cfg; diff --git a/extras/fsp b/extras/fsp index 5d13f916c..8ec537bc8 160000 --- a/extras/fsp +++ b/extras/fsp @@ -1 +1 @@ -Subproject commit 5d13f916c72f9d1471864361dfaf8f492cab5979 +Subproject commit 8ec537bc86b1b71203d72d0cbb28e6e75b353ebd diff --git a/extras/uno-r4-wifi-usb-bridge b/extras/uno-r4-wifi-usb-bridge index a634856e5..3f4e668d1 160000 --- a/extras/uno-r4-wifi-usb-bridge +++ b/extras/uno-r4-wifi-usb-bridge @@ -1 +1 @@ -Subproject commit a634856e5467022bc7587e7c8a856811255ea890 +Subproject commit 3f4e668d1318feeaa7088c788e7fd88a26a5a671