Coder Social home page Coder Social logo

riscv-gd32vf103-demo's Introduction

How to boot a modern RISC-V chip

RISC-V Website

The source of this firmware demo is carefully crafted to demonstrate the simplest possible way to boot and get a single threaded system up and running on a modern 32 bit RISC-V microcontroller such as the feature rich GD32VF103 from GigaDevice.

The author is not happy with the complexity nor abstraction level of the example code already available from various sources. Why make it hard when you can keep it simple?

The overall goal of this demo is to minimize the use of assembly language in favor of C and use as little as possible of it to get things moving. Also, no details are abstracted away or tied to some silly IDE.

The code is open source under the modified BSD license - happy hacking!

Authored by [email protected]

Demo firmware

The demo firmware blinks the D3 LED and writes hello world to USART0!

It also includes use of the official GD32VF103 driver library from GigaDevice which includes examples on how to use every peripheral on the chip.

Example code:

void main(void)
{
    int count = 10;

    /* Initialize system (clocks, power, etc.)*/
    SystemInit();

    /* Setup LED D3 */
    setup_blinking_led();

    /* Setup USART0 (115200,8n1) */
    setup_usart0();

    while(count--)
    {
        /* Turn on LED D3 */
        gpio_bit_set(GPIOC, GPIO_PIN_13);
        delay_1ms(500);

        /* Turn off LED D3 */
        gpio_bit_reset(GPIOC, GPIO_PIN_13);
        delay_1ms(500);

        /* Lets say hello */
        printf("Hello world!\n");
    }

    /* Throw environment call exception (system call) */
    asm volatile("ecall");
}

Hardware

Polos GD32VF103 Alef Board

Polos GD32VF103 Alef Board from AnalogLamb:

https://www.analoglamb.com/product/gd32vf-risc-v-mcu-board-polos-gd32vf-alef

GD32VF103CBT6 features the following:

  • 128KB FLASH and 32KB RAM
  • 4 x universal 16-bit timer
  • 2 x basic 16-bit timer
  • 1 x advanced 16-bit timer
  • Watchdog timer
  • RTC
  • Systick
  • 3 x USART
  • 2 x I2C
  • 3 x SPI
  • 2 x I2S
  • 2 x CAN
  • 1 x USBFS(OTG)
  • 2 x ADC(10 channel)
  • 2 x DAC

Toolchain

Use crosstool-ng (see http://crosstool-ng.github.io) to build a modern gcc toolchain that supports the RISC-V flavor (ilp32,imac) of the GD32VF103.

Simply install latest version of crosstool-ng and build the "riscv32-unknown-elf" sample.

How to get source

Use git to clone the main repository but also its submodules.

$ git clone --recurse-submodules https://github.com/lundmar/riscv-gd32vf103-demo.git

How to build

Use your favorite gcc riscv toolchain like so:

$ cd riscv-gd32vf103-demo
$ make CROSS_COMPILE=riscv32-unknown-elf-

Results in the output file firmware.bin

How to flash

Install the modified dfu-utils found here: https://github.com/riscv-mcu/gd32-dfu-utils

Then simply connect the board via USB and enter boot mode by pressing the boot0 key + reset key, then unpress reset.

To flash the firmware simply do:

$ dfu-util -a 0 -d 28e9:0189 -s 0x8000000:mass-erase:force -D firmware.bin

Documentation

GD32VF103 datasheet

GD32VF103 user manual

RISC-V ISA specification - Vol I

RISC-V ISA specification - Vol II

riscv-gd32vf103-demo's People

Contributors

lundmar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

riscv-gd32vf103-demo's Issues

Vectored interrupts and USB

Hi Martin,

I came across this and though you might want to have a look at gd32vf103inator. The interrupt controller on the gd32vf103 has a vectored mode and some special CSRs to handle nested interrupts and tail-chaining.

In the same repo is also code to get USB up and running and a DFU bootloader that works with a non-patched dfu-utils.

/Emil

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.