From e0cd5850f9ab02ef6dbe924800cbfdda51505d6b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 21 Apr 2019 12:02:30 +0200 Subject: [PATCH] usart: clean, doc, now uart_posix 60ms --- common/usart.c | 22 +++++++--------------- doc/new_frame_format.txt | 18 ++++++++++++++++-- uart/uart_posix.c | 7 ++++--- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/common/usart.c b/common/usart.c index 56f6bb446..ecbd3a8e3 100644 --- a/common/usart.c +++ b/common/usart.c @@ -119,7 +119,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) { us_rxfifo_low = 0; } if (try++ == maxtry) { - Dbprintf_usb("Dbg USART TIMEOUT"); +// Dbprintf_usb("Dbg USART TIMEOUT"); break; } } @@ -133,8 +133,6 @@ inline int16_t usart_writebuffer(uint8_t *data, size_t len) { // Wait for one free PDC bank while (pUS1->US_TCR && pUS1->US_TNCR) {}; - // ? alternative to wait for end of transmissions? - // while (!(pUS1->US_CSR & AT91C_US_ENDTX)) {}; // Check if the current PDC bank is free if (pUS1->US_TCR == 0) { @@ -149,8 +147,6 @@ inline int16_t usart_writebuffer(uint8_t *data, size_t len) { // we shouldn't be here return 0; } - // Make sure TX transfer is enabled - pUS1->US_PTCR = AT91C_PDC_TXTEN;// | AT91C_PDC_RXTEN; //wait until finishing all transfers while (pUS1->US_TNCR || pUS1->US_TCR) {}; return len; @@ -202,19 +198,15 @@ void usart_init(void) { pUS1->US_TCR = 0; pUS1->US_TNPR = (uint32_t)0; pUS1->US_TNCR = 0; - pUS1->US_RPR = (uint32_t)0; - pUS1->US_RCR = 0; - pUS1->US_RNPR = (uint32_t)0; - pUS1->US_RNCR = 0; - - // re-enable receiver / transmitter - pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN); - - // ready to receive pUS1->US_RPR = (uint32_t)us_inbuf1; pUS1->US_RCR = USART_BUFFLEN; usart_cur_inbuf = us_inbuf1; pUS1->US_RNPR = (uint32_t)us_inbuf2; pUS1->US_RNCR = USART_BUFFLEN; - pUS1->US_PTCR = AT91C_PDC_RXTEN; + + // re-enable receiver / transmitter + pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN); + + // ready to receive and transmit + pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; } diff --git a/doc/new_frame_format.txt b/doc/new_frame_format.txt index 3ca272be4..58aacc3d6 100644 --- a/doc/new_frame_format.txt +++ b/doc/new_frame_format.txt @@ -197,11 +197,25 @@ New bootrom might need to also still support old frame format, to ease flashing Timings ======= -Needed to increase client RX uart timeout: it was 30ms, we put arbitrarily 300ms as for TCP +(common/usart.h) +USART_BAUD_RATE defined + + 9600: #db# USB Transfer Speed PM3 -> Client = 934 Bytes/s + 115200: #db# USB Transfer Speed PM3 -> Client = 11137 Bytes/s + 460800: #db# USB Transfer Speed PM3 -> Client = 43119 Bytes/s +linux usb: #db# USB Transfer Speed PM3 -> Client = 666624 Bytes/s (~7Mbaud) + + +At some point, when still activating AT91C_PDC_TXTEN in usart_writebuffer, we needed to increase client uart timeout. +We tried 300ms, but then USB flasher failed : +[=] UART Setting serial baudrate 460800 +.Found +Error: Unknown Proxmark3 mode +Now we're at 60ms (uart/uart_posix.c) struct timeval timeout = { .tv_sec = 0, // 0 second - .tv_usec = 300000 // 300 000 micro seconds + .tv_usec = 60000 // 60 000 micro seconds }; Add automatically some communication delay in the WaitForResponseTimeout timeout diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 41e4338b0..dac473379 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -70,11 +70,12 @@ typedef struct { term_info tiNew; // Terminal info during the transaction } serial_port_unix; -// Set time-out on 300 milliseconds -// It was 30 ms for USB but we need more to receive from USART +// To be checked, receiving from USART might need more than 30ms +// if we get errors about partial packet reception +// but e.g. extending to 300ms makes USB flasher failing struct timeval timeout = { .tv_sec = 0, // 0 second - .tv_usec = 300000 // 300 000 micro seconds + .tv_usec = 60000 // 60 000 micro seconds }; serial_port uart_open(const char *pcPortName, uint32_t speed) {