Commit 0d5053d9 authored by Zach Fredin's avatar Zach Fredin

added usart roundtrip benchmark

parent 34849529
......@@ -3,6 +3,6 @@ This test uses a pair of dev boards to test sending serial data packets between
![usartbenchmark_setup](usartbenchmark_setup.jpg)
Initial tests suggest that 5.25 Mbit/s works; this is likely limited by the 84 MHz clock rate, since the advertised maximum speed is 6.25 Mbit/s and (84/100) * 6.25 = 5.25. This waveform shows 0x55 (0b01010101) sent at this rate:
Initial tests suggest that USART1 maxes out at 5.25 Mbit/s; this is currently limited by the 84 MHz clock rate, since the advertised maximum speed is 6.25 Mbit/s and (84/100) * 6.25 = 5.25. Using `0x55` as a data payload with a single stop bit (i.e. 9 bits total), along with the `usart_irq` example from `libopencm3-examples` (modified slightly), I measured a round-trip message time of 6.05 microseconds:
![usart_0x5555](usart_0x5555.png)
![usartbenchmark_roundtrip](usartbenchmark_roundtrip.png)
......@@ -21,8 +21,12 @@
/* USART BENCHMARK
This test checks round-trip communication rates on USART1.
USART1 TX: PA15, AF7
USART1 TX: PA15, AF7This waveform shows 0x55 (0b01010101) sent at this rate:
![usart_0x5555](usart_0x5555.png)
USART1 RX: PB3, AF7
This test uses the USART1 receive interrupt and is based on the usart_irq libopencm3 example code.
*/
#include <libopencm3/stm32/rcc.h>
......@@ -60,19 +64,44 @@ static void usart_setup(void)
usart_enable(USART1);
}
int main(void)
{
int i, j;
int i;
clock_setup();
gpio_setup();
usart_setup();
usart_send(USART1, 0x55);
while (1) {
usart_send(USART1, 0x55);
for (i = 0; i < 300000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;
}
void usart1_isr(void)
{
static uint8_t data = 'A';
/* Check if we were called because of RXNE. */
if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
((USART_SR(USART1) & USART_SR_RXNE) != 0)) {
/* Retrieve the data from the peripheral. */
data = usart_recv(USART1);
/* Enable transmit interrupt so it sends back the data. */
usart_enable_tx_interrupt(USART1);
}
/* Check if we were called because of TXE. */
if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
((USART_SR(USART1) & USART_SR_TXE) != 0)) {
/* Put data into the transmit register. */
usart_send(USART1, data);
/* Disable the TXE interrupt as we don't need it anymore. */
usart_disable_tx_interrupt(USART1);
}
}
......@@ -26,4 +26,7 @@ usartbenchmark.o: usartbenchmark.c \
../../libopencm3//include/libopencm3/stm32/f4/usart.h \
../../libopencm3//include/libopencm3/stm32/common/usart_common_f24.h \
../../libopencm3//include/libopencm3/stm32/common/usart_common_f124.h \
../../libopencm3//include/libopencm3/stm32/common/usart_common_all.h
../../libopencm3//include/libopencm3/stm32/common/usart_common_all.h \
../../libopencm3//include/libopencm3/cm3/nvic.h \
../../libopencm3//include/libopencm3/dispatch/nvic.h \
../../libopencm3//include/libopencm3/stm32/f4/nvic.h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment