diff options
Diffstat (limited to 'projects')
-rw-r--r-- | projects/board-test/Makefile | 2 | ||||
-rw-r--r-- | projects/board-test/fmc-probe.c | 77 | ||||
-rw-r--r-- | projects/board-test/fmc-test.c | 28 | ||||
-rw-r--r-- | projects/board-test/uart-test.c | 2 | ||||
-rw-r--r-- | projects/rtos-test/Makefile | 18 | ||||
-rw-r--r-- | projects/rtos-test/mutex-test.c | 40 | ||||
-rw-r--r-- | projects/rtos-test/semaphore-test.c | 34 | ||||
-rw-r--r-- | projects/rtos-test/thread-test.c | 24 |
8 files changed, 223 insertions, 2 deletions
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(); diff --git a/projects/rtos-test/Makefile b/projects/rtos-test/Makefile new file mode 100644 index 0000000..dd2cab5 --- /dev/null +++ b/projects/rtos-test/Makefile @@ -0,0 +1,18 @@ +TEST = thread-test semaphore-test mutex-test + +all: $(TEST:=.elf) + +%.elf: %.o $(BOARD_OBJS) $(LIBS) + $(CC) $(CFLAGS) $^ -o $@ -T$(LDSCRIPT) -g -Wl,-Map=$*.map + $(OBJCOPY) -O ihex $*.elf $*.hex + $(OBJCOPY) -O binary $*.elf $*.bin + $(OBJDUMP) -St $*.elf >$*.lst + $(SIZE) $*.elf + +clean: + rm -f *.o + rm -f *.elf + rm -f *.hex + rm -f *.bin + rm -f *.map + rm -f *.lst diff --git a/projects/rtos-test/mutex-test.c b/projects/rtos-test/mutex-test.c new file mode 100644 index 0000000..402f9ba --- /dev/null +++ b/projects/rtos-test/mutex-test.c @@ -0,0 +1,40 @@ +#include "cmsis_os.h" + +#include "stm-init.h" +#include "stm-uart.h" + +osMutexId stdio_mutex; +osMutexDef(stdio_mutex); + +void notify(const char* name, int state) { + osMutexWait(stdio_mutex, osWaitForever); + //printf("%s: %d\n\r", name, state); + uart_send_string(name); + uart_send_string(": "); + uart_send_integer(state, 1); + uart_send_string("\r\n"); + osMutexRelease(stdio_mutex); +} + +void test_thread(void const *args) { + while (1) { + notify((const char*)args, 0); osDelay(1000); + notify((const char*)args, 1); osDelay(1000); + } +} + +void t2(void const *argument) {test_thread("Th 2");} +osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE); + +void t3(void const *argument) {test_thread("Th 3");} +osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE); + +int main() { + stm_init(); + stdio_mutex = osMutexCreate(osMutex(stdio_mutex)); + + osThreadCreate(osThread(t2), NULL); + osThreadCreate(osThread(t3), NULL); + + test_thread((void *)"Th 1"); +} diff --git a/projects/rtos-test/semaphore-test.c b/projects/rtos-test/semaphore-test.c new file mode 100644 index 0000000..3a3b5de --- /dev/null +++ b/projects/rtos-test/semaphore-test.c @@ -0,0 +1,34 @@ +#include "cmsis_os.h" + +#include "stm-init.h" +#include "stm-uart.h" + +osSemaphoreId two_slots; +osSemaphoreDef(two_slots); + +void test_thread(void const *name) { + while (1) { + osSemaphoreWait(two_slots, osWaitForever); + //printf("%s\n\r", (const char*)name); + uart_send_string((const char*)name); + uart_send_string("\r\n"); + osDelay(1000); + osSemaphoreRelease(two_slots); + } +} + +void t2(void const *argument) {test_thread("Th 2");} +osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE); + +void t3(void const *argument) {test_thread("Th 3");} +osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE); + +int main (void) { + stm_init(); + two_slots = osSemaphoreCreate(osSemaphore(two_slots), 2); + + osThreadCreate(osThread(t2), NULL); + osThreadCreate(osThread(t3), NULL); + + test_thread((void *)"Th 1"); +} diff --git a/projects/rtos-test/thread-test.c b/projects/rtos-test/thread-test.c new file mode 100644 index 0000000..8b31a26 --- /dev/null +++ b/projects/rtos-test/thread-test.c @@ -0,0 +1,24 @@ +#include "cmsis_os.h" + +#include "stm-init.h" +#include "stm-led.h" + +void led2_thread(void const *args) +{ + while (1) { + led_toggle(LED_BLUE); + osDelay(1000); + } +} +osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); + +int main() +{ + stm_init(); + osThreadCreate(osThread(led2_thread), NULL); + + while (1) { + led_toggle(LED_GREEN); + osDelay(500); + } +} |