RISC-V embedded system framework for the DTEK-V board. This repository was created to help the completion of various labs and projects found within the KTH IS1200/1500 course.
This repository is setup as a template making it super simple to get started. All you have to do is press the green "Use this template" button and a repository based on this one will be created.
main/
├── src/ Source files
│ ├── main.c Application entry point
│ ├── boot.S Boot code and interrupt handlers
│ ├── dtekv-lib.c Core system library
│ ├── devices.c Hardware device drivers
│ └── utils.c Utility functions and debug tools
├── include/ Header files
│ ├── dtekv-lib.h Core library API
│ ├── devices.h Device driver API
│ └── utils.h Utility functions API
├── docs/ Documentation
│ └── docs.md Complete API and hardware reference
├── build/ Build artifacts (generated)
├── Makefile Build system
├── dtekv-script.lds Linker script
├── run_lab.sh Upload and run script
└── softfloat.a Floating point library
make # Build release version
make debug # Build debug version with symbols
make clean # Clean build artifactsmake run # Build and upload to DTEK-V boardmake help # Show all available targets- Output:
print(),printc(),print_dec(),print_hex(),print_bin() - Input:
readc(),read_available() - String:
strlen(),strcmp(),strcpy(),strcat() - Timing:
delay() - Interrupts: Automatic handling with user callbacks
- LEDs:
led_init(),led_set(),led_on(),led_off(),led_toggle() - 7-Segment Displays:
display_init(),display_hex(),display_decimal(),display_digit(),display_string(),display_clear() - Buttons:
button_is_pressed() - Switches:
switch_read(),switch_get() - GPIO:
gpio_set_direction(),gpio_write(),gpio_read(),gpio_toggle()
- Printf:
printf()with format specifiers (%d, %u, %x, %s, %c, %p) - Memory Dump:
mem_dump(),mem_dump_words(),mem_read(),mem_write() - Register Inspection:
reg_dump_csr(),reg_dump_timer(),reg_dump_all() - Timing:
get_cycles(),get_time_ms(),sleep_ms() - Debug:
ASSERT()macro
#include "dtekv-lib.h"
#include "devices.h"
#include "utils.h"
int main(void) {
// Initialize devices
led_init();
display_init();
// Use printf
printf("Hello, DTEK-V! Time: %u ms\n", get_time_ms());
// Control LEDs
led_set(0x3FF); // All on
sleep_ms(1000);
led_set(0x000); // All off
// Read switches
unsigned int sw = switch_read();
printf("Switch state: 0x%x\n", sw);
// Display number
display_hex(0x123456); // Shows "123456" in hex
display_decimal(42); // Shows "42" in decimal
display_string("HELLO"); // Shows "HELLO"
// Dump registers for debugging
reg_dump_all();
return 0;
}volatile unsigned int tick_count = 0;
void timer_isr(void) {
tick_count++;
}
int main(void) {
setup_timer();
enable_interrupt();
while (1) {
printf("Ticks: %u\n", tick_count);
sleep_ms(1000);
}
}void switch_isr(unsigned int switch_state) {
printf("Switch changed: 0x%x\n", switch_state);
led_set(switch_state);
}
int main(void) {
led_init();
SW_IRQ_MASK = 0x3FF; // Enable all switches
SW_EDGE_CAPTURE = 0x3FF; // Clear pending
enable_interrupt();
while (1) {
// Main loop
}
}Release (default):
- Optimized with
-O3 - Smaller binary size
- Faster execution
Debug:
- No optimization (
-O0) - Debug symbols (
-g) DEBUGmacro definedASSERT()macros enabled
See docs/COPYING for license information.