usart: clean, doc, now uart_posix 60ms

This commit is contained in:
Philippe Teuwen 2019-04-21 12:02:30 +02:00
parent 59963eb41e
commit e0cd5850f9
3 changed files with 27 additions and 20 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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) {