From 6ebd1a667d6e58ca355387af24bbe2a5b00baa50 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 27 Nov 2020 14:42:52 +0100 Subject: FW bidir comms work --- prototype/fw/src/main.c | 28 ++++++++++++++++------------ prototype/fw/tools/ser_test.py | 4 +++- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'prototype') diff --git a/prototype/fw/src/main.c b/prototype/fw/src/main.c index fb3c302..16e1b78 100644 --- a/prototype/fw/src/main.c +++ b/prototype/fw/src/main.c @@ -53,7 +53,7 @@ int main(void) { USART1->CR1 = USART_CR1_TE | USART_CR1_RE; USART1->BRR = (apb2_clock + baudrate/2) / baudrate; - USART1->CR1 |= USART_CR2_RXINV; + USART1->CR2 |= USART_CR2_RXINV; USART1->CR1 |= USART_CR1_UE; int req_seq = 0; @@ -71,6 +71,7 @@ int main(void) { USART1->TDR = 0; /* Kick off transmission */ while (23) { + /* if (tx_st.remaining_bytes == 0) { res_buf.req_seq = req_seq; res_buf.res_seq = res_seq; @@ -87,6 +88,7 @@ int main(void) { tx_st.tx_char += 1; tx_st.remaining_bytes -= 1; } + */ if (USART1->ISR & USART_ISR_ORE) USART1->ICR = USART_ICR_ORECF; @@ -100,19 +102,21 @@ int main(void) { if (USART1->ISR & USART_ISR_RXNE) { uint8_t c = USART1->RDR; if (!c) { - int rc = cobs_decode(rx_buf, rx_char, (uint8_t *)&req_buf, sizeof(req_buf)); - if (rc < 0) { - rx_cobs_error += 1; - } else { - if (rc == sizeof(req_buf)) { - crc32_t check_crc = pkt_crc(&req_buf, &req_buf.trailer); - if (check_crc != req_buf.trailer.crc32) { - rx_crc_error += 1; + if (rx_char < sizeof(rx_buf)) { + int rc = cobs_decode(rx_buf, rx_char, (uint8_t *)&req_buf, sizeof(req_buf)); + if (rc < 0) { + rx_cobs_error += 1; + } else { + if (rc == sizeof(req_buf)) { + crc32_t check_crc = pkt_crc(&req_buf, &req_buf.trailer); + if (check_crc != req_buf.trailer.crc32) { + rx_crc_error += 1; + } else { + req_seq = req_buf.req_seq; + } } else { - req_seq = req_buf.req_seq; + rx_framing_error += 1; } - } else { - rx_framing_error += 1; } } rx_char = 0; diff --git a/prototype/fw/tools/ser_test.py b/prototype/fw/tools/ser_test.py index 191124b..d9dec62 100644 --- a/prototype/fw/tools/ser_test.py +++ b/prototype/fw/tools/ser_test.py @@ -66,8 +66,10 @@ if __name__ == '__main__': if time.time() - last_tx > 0.01: + seq = int((time.time() - start_time) * 10) data = struct.pack('