From 4a38cf6f44d1c013cbe794093ea6c5b50337431a Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Thu, 14 Apr 2016 18:50:38 -0400 Subject: import mbed rtos library --- projects/board-test/Makefile | 2 +- projects/board-test/fmc-probe.c | 77 +++++++++++++++++++++++++++++++++++++++++ projects/board-test/fmc-test.c | 28 +++++++++++++++ projects/board-test/uart-test.c | 2 +- 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 projects/board-test/fmc-probe.c (limited to 'projects/board-test') diff --git a/projects/board-test/Makefile b/projects/board-test/Makefile index 21f24c9..a4a0a70 100644 --- a/projects/board-test/Makefile +++ b/projects/board-test/Makefile @@ -1,4 +1,4 @@ -TEST = led-test short-test uart-test fmc-test fmc-perf +TEST = led-test short-test uart-test fmc-test fmc-perf fmc-probe all: $(TEST:=.elf) diff --git a/projects/board-test/fmc-probe.c b/projects/board-test/fmc-probe.c new file mode 100644 index 0000000..55d3521 --- /dev/null +++ b/projects/board-test/fmc-probe.c @@ -0,0 +1,77 @@ +/* Read all registers from the FPGA. In some cases, this will be garbage; + * in other cases, it will be the core name and version strings. + */ + +#include "stm32f4xx_hal.h" +#include "stm-init.h" +#include "stm-led.h" +#include "stm-fmc.h" +#include "stm-uart.h" + +#define CORE_SIZE (0x100) +#define SEGMENT_SIZE (0x40 * CORE_SIZE) +#define SEGMENT_OFFSET_GLOBALS (0 * SEGMENT_SIZE) +#define SEGMENT_OFFSET_HASHES (1 * SEGMENT_SIZE) +#define BOARD_ADDR_BASE (SEGMENT_OFFSET_GLOBALS + (0 * CORE_SIZE)) +#define COMM_ADDR_BASE (SEGMENT_OFFSET_GLOBALS + (1 * CORE_SIZE)) +#define SHA1_ADDR_BASE (SEGMENT_OFFSET_HASHES + (0 * CORE_SIZE)) +#define SHA256_ADDR_BASE (SEGMENT_OFFSET_HASHES + (1 * CORE_SIZE)) +#define SHA512_ADDR_BASE (SEGMENT_OFFSET_HASHES + (2 * CORE_SIZE)) + +static uint32_t read0(uint32_t addr) +{ + uint32_t data; + + if (fmc_read_32(addr, &data) != 0) { + uart_send_string("fmc_read_32 failed\r\n"); + Error_Handler(); + } + + return data; +} + +int main(void) +{ + int i; + + stm_init(); + + uart_send_string("Keep calm for Novena boot...\r\n"); + + // Blink blue LED for six seconds to not upset the Novena at boot. + led_on(LED_BLUE); + for (i = 0; i < 12; i++) { + HAL_Delay(500); + led_toggle(LED_BLUE); + } + + // prepare fmc interface + fmc_init(); + + // turn on green led, turn off other leds + led_on(LED_GREEN); + led_off(LED_YELLOW); + led_off(LED_RED); + led_off(LED_BLUE); + + for (uint32_t addr = 0; addr < 0x00080000; addr += 4) { + uint32_t data = read0(addr); + if (data != 0) { + uart_send_hex(addr, 8); + uart_send_string(": "); + uart_send_hex(data, 8); + uart_send_char(' '); + for (int i = 24; i >= 0; i -= 8) { + uint8_t c = (data >> i) & 0xff; + if (c < 0x20 || c > 0x7e) + uart_send_char('.'); + else + uart_send_char(c); + } + uart_send_string("\r\n"); + } + } + uart_send_string("Done.\r\n"); + + return 0; +} diff --git a/projects/board-test/fmc-test.c b/projects/board-test/fmc-test.c index cf17087..a6efbef 100644 --- a/projects/board-test/fmc-test.c +++ b/projects/board-test/fmc-test.c @@ -2,6 +2,34 @@ // main.c //------------------------------------------------------------------------------ +/* + This requires a special bitstream with a special test register. + See core/platform/novena/fmc/rtl/novena_fmc_top.v, sections marked + `ifdef test: + //---------------------------------------------------------------- + // Dummy Register + // + // General-purpose register to test FMC interface using STM32 + // demo program instead of core selector logic. + // + // This register is a bit tricky, but it allows testing of both + // data and address buses. Reading from FPGA will always return + // value, which is currently stored in the test register, + // regardless of read transaction address. Writing to FPGA has + // two variants: a) writing to address 0 will store output data + // data value in the test register, b) writing to any non-zero + // address will store _address_ of write transaction in the test + // register. + // + // To test data bus, write some different patterns to address 0, + // then readback from any address and compare. + // + // To test address bus, write anything to some different non-zero + // addresses, then readback from any address and compare returned + // value with previously written address. + // + //---------------------------------------------------------------- + */ //------------------------------------------------------------------------------ // Headers diff --git a/projects/board-test/uart-test.c b/projects/board-test/uart-test.c index 8fe7795..f32fde7 100644 --- a/projects/board-test/uart-test.c +++ b/projects/board-test/uart-test.c @@ -21,7 +21,7 @@ main() while (1) { - HAL_GPIO_TogglePin(LED_PORT, LED_RED); + HAL_GPIO_TogglePin(LED_PORT, LED_GREEN); uart_send_char(c); DELAY(); -- cgit v1.2.3