From dd71fc76e9c40b394a923e3007cb69be787d9af9 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 24 Jan 2017 10:14:13 -0800 Subject: Use consistent OpenOCD config for Arty and HiFive1 --- bsp/env/freedom-e300-arty/openocd.cfg | 16 +++++++++++++++- bsp/env/freedom-e300-hifive1/openocd.cfg | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bsp/env/freedom-e300-arty/openocd.cfg b/bsp/env/freedom-e300-arty/openocd.cfg index 251dc52..f4b28ed 100644 --- a/bsp/env/freedom-e300-arty/openocd.cfg +++ b/bsp/env/freedom-e300-arty/openocd.cfg @@ -1,6 +1,16 @@ adapter_khz 10000 -source [find interface/ftdi/olimex-arm-usb-tiny-h.cfg] +#source [find interface/ftdi/olimex-arm-usb-tiny-h.cfg] + +interface ftdi +ftdi_device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H" +ftdi_vid_pid 0x15ba 0x002a + +ftdi_layout_init 0x0808 0x0a1b +ftdi_layout_signal nSRST -oe 0x0200 +ftdi_layout_signal nTRST -data 0x0100 -oe 0x0100 +ftdi_layout_signal LED -data 0x0800 +# set _CHIPNAME riscv jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x10e31913 @@ -12,5 +22,9 @@ $_TARGETNAME configure -work-area-phys 0x80000000 -work-area-size 10000 -work-ar flash bank my_first_flash fespi 0x20000000 0 0 0 $_TARGETNAME init #reset +if {[ info exists pulse_srst]} { + ftdi_set_signal nSRST 0 + ftdi_set_signal nSRST z +} halt #flash protect 0 64 last off diff --git a/bsp/env/freedom-e300-hifive1/openocd.cfg b/bsp/env/freedom-e300-hifive1/openocd.cfg index b0a8e26..b531e9c 100644 --- a/bsp/env/freedom-e300-hifive1/openocd.cfg +++ b/bsp/env/freedom-e300-hifive1/openocd.cfg @@ -31,4 +31,4 @@ if {[ info exists pulse_srst]} { sleep 1500 } halt -flash protect 0 64 last off +#flash protect 0 64 last off -- cgit v1.2.3 From aa51b264d5435834f182f82135c5880f19ee4957 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 24 Jan 2017 14:50:07 -0800 Subject: Bump riscv-toolchain to pick up GDB which can handle 'C' --- riscv-gnu-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riscv-gnu-toolchain b/riscv-gnu-toolchain index e3e50c5..ee0cf24 160000 --- a/riscv-gnu-toolchain +++ b/riscv-gnu-toolchain @@ -1 +1 @@ -Subproject commit e3e50c50f05c747c4a80faed706ded02b7e9b046 +Subproject commit ee0cf248173a2482b8c0f393749edcab70e09f46 -- cgit v1.2.3 From e57c482625638fc10d90eab282c77fd410c9b46d Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 24 Jan 2017 15:11:14 -0800 Subject: Use register macros instead of volatile addresses --- Makefile | 14 +++++++++----- software/demo_gpio/demo_gpio.c | 40 ++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index ffc2e77..bd715d2 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,10 @@ help : @echo " run_openocd [BOARD=$(DEFAULT_BOARD)]:" @echo " run_gdb [PROGRAM=$(DEFAULT_PROGRAM) BOARD=$(DEFAULT_BOARD)]:" @echo " Launch OpenOCD or GDB seperately" - @echo "" + @echo "" + @echo " dasm [PROGRAM=$(DEFAULT_BOARD)]:" + @echo " Generates the dissassembly output of objdump -D to stdout." + @echo "" @echo " For more information, visit dev.sifive.com" @@ -88,13 +91,14 @@ PROGRAM ?= $(DEFAULT_PROGRAM) PROGRAM_DIR = $(srcdir)/software/$(PROGRAM) PROGRAM_ELF = $(srcdir)/software/$(PROGRAM)/$(PROGRAM) -.PHONY: software -software: - $(MAKE) -C $(PROGRAM_DIR) - +.PHONY: software_clean software_clean: $(MAKE) -C $(PROGRAM_DIR) clean +.PHONY: software +software: software_clean + $(MAKE) -C $(PROGRAM_DIR) + dasm: software $(toolchain_dest)/bin/riscv32-unknown-elf-objdump -D $(PROGRAM_ELF) diff --git a/software/demo_gpio/demo_gpio.c b/software/demo_gpio/demo_gpio.c index dec91b5..c780cbe 100644 --- a/software/demo_gpio/demo_gpio.c +++ b/software/demo_gpio/demo_gpio.c @@ -25,12 +25,6 @@ function_ptr_t g_ext_interrupt_handlers[PLIC_NUM_INTERRUPTS]; plic_instance_t g_plic; -// Simple variables for LEDs, buttons, etc. -volatile unsigned int* g_output_vals = (unsigned int *) (GPIO_BASE_ADDR + GPIO_OUTPUT_VAL); -volatile unsigned int* g_input_vals = (unsigned int *) (GPIO_BASE_ADDR + GPIO_INPUT_VAL); -volatile unsigned int* g_output_en = (unsigned int *) (GPIO_BASE_ADDR + GPIO_OUTPUT_EN); -volatile unsigned int* g_pullup_en = (unsigned int *) (GPIO_BASE_ADDR + GPIO_PULLUP_EN); -volatile unsigned int* g_input_en = (unsigned int *) (GPIO_BASE_ADDR + GPIO_INPUT_EN); /*Entry Point for PLIC Interrupt Handler*/ void handle_m_ext_interrupt(){ @@ -60,12 +54,12 @@ void handle_m_time_interrupt(){ *mtimecmp = then; // read the current value of the LEDS and invert them. - uint32_t leds = *g_output_vals; - - *g_output_vals ^= ((0x1 << RED_LED_OFFSET) | - (0x1 << GREEN_LED_OFFSET) | - (0x1 << BLUE_LED_OFFSET)); + uint32_t leds = GPIO_REG(GPIO_OUTPUT_VAL); + GPIO_REG(GPIO_OUTPUT_VAL) ^= ((0x1 << RED_LED_OFFSET) | + (0x1 << GREEN_LED_OFFSET) | + (0x1 << BLUE_LED_OFFSET)); + // Re-enable the timer interrupt. set_csr(mie, MIP_MTIP); @@ -114,7 +108,7 @@ void print_instructions() { void button_0_handler(void) { // Red LED on - * g_output_vals |= (0x1 << RED_LED_OFFSET); + GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << RED_LED_OFFSET); // Clear the GPIO Pending interrupt by writing 1. GPIO_REG(GPIO_RISE_IP) = (0x1 << BUTTON_0_OFFSET); @@ -124,7 +118,7 @@ void button_0_handler(void) { void button_1_handler(void) { // Green LED On - * g_output_vals |= (1 << GREEN_LED_OFFSET); + GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << GREEN_LED_OFFSET); // Clear the GPIO Pending interrupt by writing 1. GPIO_REG(GPIO_RISE_IP) = (0x1 << BUTTON_1_OFFSET); @@ -135,7 +129,7 @@ void button_1_handler(void) { void button_2_handler(void) { // Blue LED On - * g_output_vals |= (1 << BLUE_LED_OFFSET); + GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << BLUE_LED_OFFSET); GPIO_REG(GPIO_RISE_IP) = (0x1 << BUTTON_2_OFFSET); @@ -204,15 +198,15 @@ int main(int argc, char **argv) // can be used as both Inputs and Outputs. #ifdef HAS_BOARD_BUTTONS - * g_output_en &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET)); - * g_pullup_en &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET)); - * g_input_en |= ((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET)); + GPIO_REG(GPIO_OUTPUT_EN) &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET)); + GPIO_REG(GPIO_PULLUP_EN) &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET)); + GPIO_REG(GPIO_INPUT_EN) |= ((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET)); #endif - * g_input_en &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ; - * g_output_en |= ((0x1<< RED_LED_OFFSET)| (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ; - * g_output_vals |= (0x1 << BLUE_LED_OFFSET) ; - * g_output_vals &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ; + GPIO_REG(GPIO_INPUT_EN) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ; + GPIO_REG(GPIO_OUTPUT_EN) |= ((0x1<< RED_LED_OFFSET)| (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ; + GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << BLUE_LED_OFFSET) ; + GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ; /************************************************************************** * Set up the PLIC @@ -225,7 +219,9 @@ int main(int argc, char **argv) reset_demo(); - while (1); + while (1){ + + } return 0; -- cgit v1.2.3 From c72e4fcd4a77354d0d427cef263ebe438aeeae6e Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 24 Jan 2017 16:00:53 -0800 Subject: Add atomic bit-banging to the demo --- software/demo_gpio/demo_gpio.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/software/demo_gpio/demo_gpio.c b/software/demo_gpio/demo_gpio.c index c780cbe..040d864 100644 --- a/software/demo_gpio/demo_gpio.c +++ b/software/demo_gpio/demo_gpio.c @@ -7,6 +7,7 @@ #include "plic_driver.h" #include "encoding.h" #include +#include "stdatomic.h" #define RTC_FREQUENCY 32768 @@ -95,6 +96,8 @@ const char * instructions_msg = " \ SiFive E-Series Software Development Kit 'demo_gpio' program.\n\ Every 1.5 second, the Timer Interrupt will invert the LEDs.\n\ (Arty Dev Kit Only): Press Buttons 0, 1, 2 to Set the LEDs.\n\ +Pin 19 (HiFive1) or A5 (Arty Dev Kit) is being bit-banged\n\ +for GPIO speed demonstration.\n\ \n\ "; @@ -208,6 +211,9 @@ int main(int argc, char **argv) GPIO_REG(GPIO_OUTPUT_VAL) |= (0x1 << BLUE_LED_OFFSET) ; GPIO_REG(GPIO_OUTPUT_VAL) &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ; + // For Bit-banging with Atomics demo. + GPIO_REG(GPIO_OUTPUT_EN) |= (0x1 << PIN_19_OFFSET); + /************************************************************************** * Set up the PLIC * @@ -219,8 +225,17 @@ int main(int argc, char **argv) reset_demo(); - while (1){ + /************************************************************************** + * Demonstrate fast GPIO bit-banging. + * One can bang it faster than this if you know + * the entire OUTPUT_VAL that you want to write, but + * Atomics give a quick way to control a single bit. + *************************************************************************/ + uint32_t mask = (1 << PIN_19_OFFSET); + uint32_t other_mask = (1 << PIN_19_OFFSET); + while (1){ + atomic_fetch_xor(&GPIO_REG(GPIO_OUTPUT_VAL), mask); } return 0; -- cgit v1.2.3 From d6e76482adced83f835a1d1f075826ccf24034ca Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Tue, 24 Jan 2017 17:02:02 -0800 Subject: use relaxed memory model for bitbang demo to avoid unncessary fences in the output --- software/demo_gpio/demo_gpio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/software/demo_gpio/demo_gpio.c b/software/demo_gpio/demo_gpio.c index 040d864..00bc8cd 100644 --- a/software/demo_gpio/demo_gpio.c +++ b/software/demo_gpio/demo_gpio.c @@ -232,10 +232,9 @@ int main(int argc, char **argv) * Atomics give a quick way to control a single bit. *************************************************************************/ uint32_t mask = (1 << PIN_19_OFFSET); - uint32_t other_mask = (1 << PIN_19_OFFSET); while (1){ - atomic_fetch_xor(&GPIO_REG(GPIO_OUTPUT_VAL), mask); + atomic_fetch_xor_explicit(&GPIO_REG(GPIO_OUTPUT_VAL), mask, memory_order_relaxed); } return 0; -- cgit v1.2.3 From 93803735dbb3925df706dc9a2ea73641d85272e1 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Wed, 25 Jan 2017 21:37:06 -0800 Subject: Use proper version of GDB and GCC --- riscv-gnu-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riscv-gnu-toolchain b/riscv-gnu-toolchain index e3e50c5..3f7b369 160000 --- a/riscv-gnu-toolchain +++ b/riscv-gnu-toolchain @@ -1 +1 @@ -Subproject commit e3e50c50f05c747c4a80faed706ded02b7e9b046 +Subproject commit 3f7b3696217548bc31aeccf9a0c89bdfa4e16a8f -- cgit v1.2.3 From d2f2e885f0453d6b06bc177654c2952fea07af4c Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Thu, 26 Jan 2017 11:07:46 -0800 Subject: bump openocd to disable interrupts while programming --- openocd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openocd b/openocd index 193f630..9bab078 160000 --- a/openocd +++ b/openocd @@ -1 +1 @@ -Subproject commit 193f63094891cd3fe6a5032fef2c71d09f063ff4 +Subproject commit 9bab0782d313679bb0bfb634e6e87c757b8d5503 -- cgit v1.2.3