Skip to content

Commit f078324

Browse files
committed
Current tests
1 parent fc812b1 commit f078324

File tree

9 files changed

+445
-3
lines changed

9 files changed

+445
-3
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Set the prefix for `riscvXX-unknown-elf-*`
2+
# On installations using `multilib`, this will be `riscv64` even for compiling to 32-bit targets
3+
TOOLCHAIN_PREFIX=riscv32-none-elf
4+
#TOOLCHAIN_PREFIX=riscv32
5+
# ARCH=rv32i
6+
ARCH=rv32i_zicsr
7+
8+
# ---- Project Configuration ----
9+
SRCDIR = src
10+
INCDIR = include
11+
SOURCES = $(wildcard $(SRCDIR)/*.c)
12+
PROJECT = current
13+
14+
# ---- Test patterns for project raven ----
15+
16+
.SUFFIXES:
17+
18+
hex: $(PROJECT).hex
19+
20+
$(PROJECT).elf: $(SOURCES) ../sections.lds ../crt0_vex.S
21+
#$(TOOLCHAIN_PREFIX)-gcc -O0 -march=rv32i -Wl,-Bstatic,-T,../sections.lds,--strip-debug -ffreestanding -nostdlib -o $@ ../start.s ../print_io.c $<
22+
$(TOOLCHAIN_PREFIX)-gcc -I../ -I../generated/ -I$(INCDIR) -O0 -mabi=ilp32 -march=$(ARCH) -D__vexriscv__ -Wl,-Bstatic,-T,../sections.lds,--strip-debug -ffreestanding -nostdlib -o $@ ../crt0_vex.S ../isr.c ../stub.c $(SOURCES)
23+
$(TOOLCHAIN_PREFIX)-objdump -D $(PROJECT).elf > $(PROJECT).lst
24+
25+
%.hex: %.elf
26+
$(TOOLCHAIN_PREFIX)-objcopy -O verilog $< $@
27+
sed -ie 's/@1000/@0000/g' $@
28+
29+
%.bin: %.elf
30+
$(TOOLCHAIN_PREFIX)-objcopy -O binary $< $@
31+
32+
client: client.c
33+
gcc client.c -o client
34+
35+
flash: $(PROJECT).hex
36+
python3 ../util/caravel_hkflash.py $(PROJECT).hex
37+
38+
flash2: $(PROJECT).hex
39+
python3 ../util/caravel_flash.py $(PROJECT).hex
40+
41+
show_projectid:
42+
python3 ../util/caravel_projectid.py
43+
44+
# ---- Clean ----
45+
46+
clean:
47+
rm -f $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).lst *.vvp *.vcd
48+
49+
.PHONY: clean hex all flash
50+

firmware/chipignite/current/README.md

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Constants
2+
#define BAUD_RATE 9600
3+
4+
// Variables
5+
String receivedData = "";
6+
unsigned long lastReceiveTime = 0;
7+
const unsigned long DISPLAY_TIMEOUT = 500; // ms
8+
9+
void setup() {
10+
Serial.begin(BAUD_RATE); // Initialize serial communication with computer
11+
Serial1.begin(BAUD_RATE); // Initialize serial communication with chip
12+
13+
Serial.println("Chip Serial Monitor Started");
14+
Serial.println("Waiting for data...");
15+
}
16+
17+
void loop() {
18+
// Read data from the chip
19+
while (Serial1.available() > 0) {
20+
char inByte = Serial1.read();
21+
receivedData += inByte;
22+
lastReceiveTime = millis();
23+
}
24+
25+
// Print complete messages after timeout
26+
if (receivedData.length() > 0 && (millis() - lastReceiveTime > DISPLAY_TIMEOUT)) {
27+
Serial.print("Received: ");
28+
29+
// Print as ASCII
30+
Serial.print("ASCII: \"");
31+
Serial.print(receivedData);
32+
Serial.print("\" | HEX: ");
33+
34+
// Print as HEX
35+
for (int i = 0; i < receivedData.length(); i++) {
36+
char c = receivedData.charAt(i);
37+
if (c < 0x10) Serial.print("0");
38+
Serial.print(c, HEX);
39+
Serial.print(" ");
40+
}
41+
42+
Serial.println();
43+
receivedData = "";
44+
}
45+
46+
// Send data to chip if entered in Serial Monitor
47+
if (Serial.available() > 0) {
48+
String input = Serial.readStringUntil('\n');
49+
Serial1.println(input);
50+
Serial.println("Sent: " + input);
51+
}
52+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file slip.h
3+
* @brief GPIO implementation header
4+
*
5+
* Provides functions to interface with the GPIO pins.
6+
*/
7+
8+
#pragma once
9+
10+
#include <stdint.h>
11+
#include <stdbool.h>
12+
13+
/* Begin typedef declarations */
14+
15+
/* Begin function prototype declarations */
16+
17+
bool valid_pin(uint32_t pin);
18+
void gpio_set(uint32_t pin, bool value);
19+
void gpio_clear(uint32_t pin);
20+
void gpio_toggle(uint32_t pin);
21+
bool gpio_get(uint32_t pin);
22+
23+
/* Begin inline function declarations */
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file uart.h
3+
* @brief Universal Asynchronous Receiver/Transmitter (UART) implementation header
4+
*
5+
* Provides functions to configure and use the UART for serial communication.
6+
*/
7+
8+
#pragma once
9+
10+
#include <stdint.h>
11+
12+
#define UART_BAUD_RATE 9600
13+
#define CRYSTAL_CLK 10000000
14+
#define UART_CLKDIV ((CRYSTAL_CLK / UART_BAUD_RATE))
15+
16+
/* Begin typedef declarations */
17+
18+
/* Begin function prototype declarations */
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#define UART_EV_TX 0x1
24+
#define UART_EV_RX 0x2
25+
26+
void uart_init(void);
27+
void uart_sync(void);
28+
29+
void uart_write(uint8_t ch);
30+
uint8_t uart_read(void);
31+
int uart_read_available(void);
32+
int uart_write_available(void);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#include <defs.h>
2+
#include <stub.h>
3+
#include <csr.h>
4+
#include "../include/slip.h"
5+
#include "../include/uart.h"
6+
#include "../include/gpio.h"
7+
8+
#define ARRAY_SIZE 100
9+
10+
// --------------------------------------------------------
11+
// Firmware routines
12+
// --------------------------------------------------------
13+
14+
/** @brief Configure the IO pins
15+
*/
16+
void configure_io() {
17+
// ======= Useful GPIO mode values =============
18+
19+
// GPIO_MODE_MGMT_STD_INPUT_NOPULL
20+
// GPIO_MODE_MGMT_STD_INPUT_PULLDOWN
21+
// GPIO_MODE_MGMT_STD_INPUT_PULLUP
22+
// GPIO_MODE_MGMT_STD_OUTPUT
23+
// GPIO_MODE_MGMT_STD_BIDIRECTIONAL
24+
// GPIO_MODE_MGMT_STD_ANALOG
25+
26+
// GPIO_MODE_USER_STD_INPUT_NOPULL
27+
// GPIO_MODE_USER_STD_INPUT_PULLDOWN
28+
// GPIO_MODE_USER_STD_INPUT_PULLUP
29+
// GPIO_MODE_USER_STD_OUTPUT
30+
// GPIO_MODE_USER_STD_BIDIRECTIONAL
31+
// GPIO_MODE_USER_STD_ANALOG
32+
33+
// ======= set each IO to the desired configuration =============
34+
35+
// GPIO 0 is turned off to prevent toggling the debug pin; For debug, make this an output and
36+
// drive it externally to ground.
37+
38+
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_ANALOG;
39+
40+
// Changing configuration for IO[1-4] will interfere with programming flash. if you change them,
41+
// You may need to hold reset while powering up the board and initiating flash to keep the process
42+
// configuring these IO from their default values.
43+
44+
// SPI
45+
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
46+
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
47+
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
48+
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
49+
50+
// -------------------------------------------
51+
52+
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // UART Rx
53+
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT; // UART Tx
54+
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // Used for reset
55+
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_OUTPUT;
56+
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_OUTPUT;
57+
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_OUTPUT;
58+
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_OUTPUT;
59+
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_OUTPUT;
60+
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_OUTPUT;
61+
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
62+
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
63+
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
64+
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
65+
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
66+
67+
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
68+
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_OUTPUT;
69+
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_OUTPUT;
70+
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
71+
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
72+
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
73+
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
74+
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
75+
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
76+
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_OUTPUT;
77+
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_OUTPUT;
78+
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_OUTPUT; // High
79+
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_OUTPUT; // Low
80+
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_OUTPUT; // High
81+
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT; // Controlled by the code
82+
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_OUTPUT;
83+
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_OUTPUT;
84+
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_OUTPUT;
85+
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_OUTPUT;
86+
87+
// Initialize UART
88+
uart_init();
89+
90+
// Initiate the serial transfer to configure IO
91+
reg_mprj_xfer = 1;
92+
while (reg_mprj_xfer == 1)
93+
;
94+
}
95+
96+
/** @brief Delay in microseconds
97+
*
98+
* @param d Delay in microseconds.
99+
*/
100+
void delay(const int d) {
101+
/* Configure timer for a single-shot countdown */
102+
reg_timer0_config = 0;
103+
reg_timer0_data = d;
104+
reg_timer0_config = 1;
105+
106+
// Loop, waiting for value to reach zero
107+
reg_timer0_update = 1; // latch current value
108+
while (reg_timer0_value > 0) { reg_timer0_update = 1; }
109+
}
110+
111+
/** @brief Turn off the LED
112+
*/
113+
void led_off() { reg_gpio_out = 1; }
114+
115+
/** @brief Turn on the LED
116+
*/
117+
void led_on() { reg_gpio_out = 0; }
118+
119+
/** @brief Entry point
120+
*/
121+
void main() {
122+
// Initialize GPIO
123+
reg_gpio_mode1 = 1;
124+
reg_gpio_mode0 = 0;
125+
reg_gpio_ien = 1;
126+
reg_gpio_oe = 1;
127+
128+
// Configure IO pins including UART pins
129+
configure_io();
130+
131+
// Configure All LA probes as inputs to the cpu
132+
reg_la0_oenb = reg_la0_iena = 0x00000000; // [31:0]
133+
reg_la1_oenb = reg_la1_iena = 0x00000000; // [63:32]
134+
reg_la2_oenb = reg_la2_iena = 0x00000000; // [95:64]
135+
reg_la3_oenb = reg_la3_iena = 0x00000000; // [127:96]
136+
137+
// write data to la output
138+
// reg_la0_data = 0x00;
139+
// reg_la1_data = 0x00;
140+
// reg_la2_data = 0x00;
141+
// reg_la3_data = 0x00;
142+
143+
// read data from la input
144+
// data0 = reg_la0_data;
145+
// data1 = reg_la1_data;
146+
// data2 = reg_la2_data;
147+
// data3 = reg_la3_data;
148+
149+
// Turn off all GPIO outputs
150+
reg_mprj_datah = 0x00000000; // Set all high pins (32-37) low
151+
reg_mprj_datal = 0x00000000; // Set all low pins (0-31) low
152+
153+
// Define a static array of items initialized to zero
154+
static uint8_t zero_array[ARRAY_SIZE] = {0};
155+
156+
// Main loop - echo received characters and blink LED and
157+
while (true) {
158+
// Set all GPIO pins to high
159+
for (uint32_t i = 0; i <= 37; i++) { gpio_set(i); }
160+
161+
// Wait for 1 second
162+
delay(10000000);
163+
}
164+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "../include/gpio.h"
2+
3+
#include <defs.h>
4+
5+
/** @brief Set the value of a GPIO pin (high)
6+
*
7+
* @param pin The pin to set.
8+
* @param value The value to set the pin to.
9+
*/
10+
void gpio_set(uint32_t pin, bool value) {
11+
if (pin < 32) {
12+
// Register for low pins (0-31)
13+
reg_mprj_datal |= (1 << (pin % 32));
14+
} else if (pin <= 37) {
15+
// Register for high pins (32-37)
16+
reg_mprj_datah |= (1 << (pin % 32));
17+
}
18+
}
19+
20+
/** @brief Clear the value of a GPIO pin (low)
21+
*
22+
* @param pin The pin to clear.
23+
*/
24+
void gpio_clear(uint32_t pin) {
25+
if (pin < 32) {
26+
// Register for low pins (0-31)
27+
reg_mprj_datal &= ~(1 << (pin % 32));
28+
} else if (pin <= 37) {
29+
// Register for high pins (32-37)
30+
reg_mprj_datah &= ~(1 << (pin % 32));
31+
}
32+
}
33+
34+
/** @brief Toggle the value of a GPIO pin
35+
*
36+
* @param pin The pin to toggle.
37+
*/
38+
void gpio_toggle(uint32_t pin) {
39+
if (pin < 32) {
40+
// Register for low pins (0-31)
41+
reg_mprj_datal ^= (1 << (pin % 32));
42+
} else if (pin <= 37) {
43+
// Register for high pins (32-37)
44+
reg_mprj_datah ^= (1 << (pin % 32));
45+
}
46+
}
47+
48+
/** @brief Get the value of a GPIO pin
49+
*
50+
* @param pin The pin to get.
51+
* @return The value of the pin.
52+
*/
53+
bool gpio_get(uint32_t pin) {
54+
if (pin < 32) {
55+
// Register for low pins (0-31)
56+
return (reg_mprj_datal & (1 << (pin % 32))) != 0;
57+
} else if (pin <= 37) {
58+
// Register for high pins (32-37)
59+
return (reg_mprj_datah & (1 << (pin % 32))) != 0;
60+
}
61+
return false;
62+
}

0 commit comments

Comments
 (0)