Commit 34849529 authored by Zach Fredin's avatar Zach Fredin

added usart benchmark

parent e48fba3a
......@@ -6,7 +6,7 @@ This environment makes use of the following tools:
[stlink](https://github.com/texane/stlink), an open-source command-line tool for interfacing with ST's STLINK chips (present on Discovery and Nucleo boards). I discuss installing this program in the [nucleo-f412zg directory](/nucleo-f412zg).
[libopencm3](https://github.com/libopencm3/libopencm3) and [libopencm3-examples](https://github.com/libopencm3/libopencm3-examples), an open-source firmware library for a variety of Cortex-M microcontrollers.
[libopencm3](https://github.com/libopencm3/libopencm3) and [libopencm3-examples](https://github.com/libopencm3/libopencm3-examples), an open-source firmware library for a variety of Cortex-M microcontrollers. The library has extensive documentation available [here](http://libopencm3.org/docs/latest/html/).
These tools allow us to use the STM32F412 platform without installing proprietary vendor-specific software or giving away our contact information. They are referenced in this repository as submodules from their respective homes on GitHub; that means you'll have a local copy on your system but updates will get pulled in from the maintained versions. In order for the submodules' content to pull in, run the following commands in the root folder after cloning this repo:
......
# Ring Test
This ring test uses PD5 and PD6. It's best to solder a loop of bare wire between the two pads, as they're next to each other on the Nucleo board and a loop allows easy hookup of an oscilloscope probe. I set the system clock to high-speed internal (HSI) running at 84 MHz, and used libopencm3's `gpio_get`, `gpio_set`, `and gpio_clear` to run the test:
This ring test uses PD5 and PD6. It's best to solder a loop of bare wire between the two pads, as they're next to each other on the Nucleo board and a loop allows easy hookup of an oscilloscope probe:
![ringtest_setup](ringtest_setup.jpg)
I set the system clock to high-speed internal (HSI) running at 84 MHz, and used libopencm3's `gpio_get`, `gpio_set`, `and gpio_clear` to run the test:
![ringtest](ringtest.png)
1.97 MHz is good; I believe this could improve to 2.35 MHz if the HSI ran at the full rated STM32F412 speed of 100 MHz. libopencm3 doesn't have a built-in configuration function for this clock speed so this will take more investigation.
1.97 MHz is good; I believe this could improve to 2.35 MHz if the HSI ran at the full rated STM32F412 speed of 100 MHz. libopencm3 doesn't have a built-in configuration function for this clock speed so this will take more investigation.
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
BINARY = usartbenchmark
LDSCRIPT = ../../stm32f412xExG.ld
include ../Makefile.include
# USART benchmark
This test uses a pair of dev boards to test sending serial data packets between nodes. The Nucleo boards have a labeled USART port which corresponds to USART3; by default, this port is jumpered to the ST-LINK chip for mbed debugging. To avoid having to remove jumpers, we'll use USART1, available on PA15 (TX) and PB3 (RX). Per the Nucleo schematic, these are broken out on the top right black double-row header (CN7) as pin 9 (PA15) and pin 15 (PB3). These are labeled as the first I2S_B pin and the second SPI_B pin, respectively. Orient the boards back-to-front so the jumpers reach, as shown here:
![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:
![usart_0x5555](usart_0x5555.png)
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com>
* Copyright (c) 2015 Chuck McManis <cmcmanis@mcmanis.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/* USART BENCHMARK
This test checks round-trip communication rates on USART1.
USART1 TX: PA15, AF7
USART1 RX: PB3, AF7
*/
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/cm3/nvic.h>
static void clock_setup(void){
//no built-in libopencm3 support for a 100 MHz clock
rcc_clock_setup_pll(&rcc_hsi_configs[RCC_CLOCK_3V3_84MHZ]);
rcc_periph_clock_enable(RCC_GPIOA);
rcc_periph_clock_enable(RCC_GPIOB);
rcc_periph_clock_enable(RCC_USART1);
}
static void gpio_setup(void)
{
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO15);
gpio_set_af(GPIOA, GPIO_AF7, GPIO15);
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3);
gpio_set_af(GPIOB, GPIO_AF7, GPIO3);
}
static void usart_setup(void)
{
nvic_enable_irq(NVIC_USART1_IRQ);
usart_set_baudrate(USART1, 5250000);
usart_set_databits(USART1, 8);
usart_set_stopbits(USART1, USART_STOPBITS_1);
usart_set_mode(USART1, USART_MODE_TX_RX);
usart_set_parity(USART1, USART_PARITY_NONE);
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
usart_enable_rx_interrupt(USART1);
usart_enable(USART1);
}
int main(void)
{
int i, j;
clock_setup();
gpio_setup();
usart_setup();
while (1) {
usart_send(USART1, 0x55);
for (i = 0; i < 300000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;
}
usartbenchmark.o: usartbenchmark.c \
../../libopencm3//include/libopencm3/stm32/rcc.h \
../../libopencm3//include/libopencm3/cm3/common.h \
/usr/lib/gcc/arm-none-eabi/7.3.1/include/stdint.h \
/usr/arm-none-eabi/include/stdint.h \
/usr/arm-none-eabi/include/machine/_default_types.h \
/usr/arm-none-eabi/include/sys/features.h \
/usr/arm-none-eabi/include/_newlib_version.h \
/usr/arm-none-eabi/include/sys/_intsup.h \
/usr/arm-none-eabi/include/sys/_stdint.h \
/usr/lib/gcc/arm-none-eabi/7.3.1/include/stdbool.h \
../../libopencm3//include/libopencm3/stm32/memorymap.h \
../../libopencm3//include/libopencm3/stm32/f4/memorymap.h \
../../libopencm3//include/libopencm3/cm3/memorymap.h \
../../libopencm3//include/libopencm3/stm32/f4/rcc.h \
../../libopencm3//include/libopencm3/stm32/pwr.h \
../../libopencm3//include/libopencm3/stm32/f4/pwr.h \
../../libopencm3//include/libopencm3/stm32/common/pwr_common_v1.h \
../../libopencm3//include/libopencm3/stm32/common/rcc_common_all.h \
../../libopencm3//include/libopencm3/stm32/gpio.h \
../../libopencm3//include/libopencm3/stm32/f4/gpio.h \
../../libopencm3//include/libopencm3/stm32/common/gpio_common_f24.h \
../../libopencm3//include/libopencm3/stm32/common/gpio_common_f234.h \
../../libopencm3//include/libopencm3/stm32/common/gpio_common_all.h \
../../libopencm3//include/libopencm3/stm32/usart.h \
../../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
This diff is collapsed.
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