Skip to content

Commit 938a969

Browse files
tjurtschgalak
authored andcommitted
boards: SiFive HiFive1 board
Added support for the HiFive1 board from SiFive Signed-off-by: Tomasz Michalak <[email protected]> Signed-off-by: Karol Gugala <[email protected]> Signed-off-by: Tomasz Jurtsch <[email protected]>
1 parent 6dae38c commit 938a969

File tree

9 files changed

+257
-0
lines changed

9 files changed

+257
-0
lines changed

boards/riscv32/hifive1/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
zephyr_library()
2+
zephyr_library_sources(pinmux.c)
3+
zephyr_library_sources(clock.c)
4+
zephyr_library_include_directories(${PROJECT_SOURCE_DIR}/drivers)

boards/riscv32/hifive1/Kconfig.board

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
config BOARD_HIFIVE1
2+
bool "HiFive1 target"
3+
depends on SOC_RISCV32_FE310
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if BOARD_HIFIVE1
2+
3+
config BOARD
4+
default "hifive1"
5+
6+
endif

boards/riscv32/hifive1/board.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2017 Jean-Paul Etienne <[email protected]>
3+
* Copyright (c) 2017 Palmer Dabbelt <[email protected]>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#ifndef __INC_BOARD_H
9+
#define __INC_BOARD_H
10+
11+
#include <soc.h>
12+
13+
/*
14+
* UART clock configurations
15+
*
16+
* Define them here so that it can be replaced by global variables
17+
* on other boards where the uart clock is determined dynamically
18+
* following the PLL configuration
19+
*/
20+
#define uart_fe310_port_0_clk_freq 16000000
21+
#define uart_fe310_port_1_clk_freq 16000000
22+
23+
/* LEDS configuration */
24+
#define LED0_GPIO_PORT "gpio0"
25+
#define LED1_GPIO_PORT "gpio0"
26+
#define LED2_GPIO_PORT "gpio0"
27+
28+
#define LED0_GPIO_PIN 19
29+
#define LED1_GPIO_PIN 21
30+
#define LED2_GPIO_PIN 22
31+
32+
#endif /* __INC_BOARD_H */

boards/riscv32/hifive1/clock.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2017 Jean-Paul Etienne <[email protected]>
3+
* Copyright (c) 2017 Palmer Dabbelt <[email protected]>
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <init.h>
9+
#include <board.h>
10+
#include "prci.h"
11+
12+
/* Selects the 16MHz oscilator on the HiFive1 board, which provides a clock
13+
* that's accurate enough to actually drive serial ports off of.
14+
*/
15+
static int hifive1_clock_init(struct device *dev)
16+
{
17+
ARG_UNUSED(dev);
18+
19+
PRCI_REG(PRCI_PLLCFG) = PLL_REFSEL(1) | PLL_BYPASS(1);
20+
PRCI_REG(PRCI_PLLDIV) = (PLL_FINAL_DIV_BY_1(1) | PLL_FINAL_DIV(0));
21+
PRCI_REG(PRCI_PLLCFG) |= PLL_SEL(1);
22+
PRCI_REG(PRCI_HFROSCCFG) &= ~ROSC_EN(1);
23+
return 0;
24+
}
25+
26+
SYS_INIT(hifive1_clock_init, PRE_KERNEL_1, CONFIG_PINMUX_INIT_PRIORITY);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.. _hifive1:
2+
3+
SiFive HiFive1
4+
##############
5+
6+
Overview
7+
********
8+
9+
The HiFive1 is an Arduino-compatible development board with
10+
an FE310 RISC-V SoC.
11+
More information can be found on
12+
`SiFive's wesite <https://www.sifive.com/products/hifive1>`_.
13+
14+
Programming and debugging
15+
*************************
16+
17+
Building
18+
========
19+
20+
Applications for the ``HiFive1`` board configuration can be built as usual
21+
(see :ref:`build_an_application`).
22+
In order to build the application for ``HiFive1``, set the ``BOARD`` variable
23+
to ``hifive1``.
24+
25+
.. code-block:: bash
26+
27+
export BOARD="hifive1"
28+
29+
Flashing
30+
========
31+
32+
In order to upload the application to the device, you'll need OpenOCD and GDB
33+
with RISC-V support.
34+
Download and installation instructions can be found in the
35+
`SiFive's Freedom-E-SDK GitHub repository
36+
<https://github.com/sifive/freedom-e-sdk>`_.
37+
38+
With the necessary tools installed, you can connect to the board using OpenOCD.
39+
To establish an OpenOCD connection, switch to the
40+
:file:`utils` directory and run:
41+
42+
.. code-block:: bash
43+
44+
# assuming that the location of the openocd is in PATH
45+
sudo openocd -f ${SDK_PATH}/bsp/env/freedom-e300-hifive1/openocd.cfg
46+
47+
48+
Leave it running, and in a different terminal, use GDB to upload the binary to
49+
the board. Use the RISC-V GDB from SiFive's Freedom-E-SDK toolchain.
50+
51+
Before loading the binary image to the device, the device's flash protection
52+
must be disabled. Here are the GDB terminal commands to connect to the device,
53+
disable the flash protection, load the binary, and start it running:
54+
55+
.. code-block:: console
56+
57+
gdb
58+
(gdb) set remotetimeout 240
59+
(gdb) target extended-remote localhost:3333
60+
(gdb) monitor reset halt
61+
(gdb) monitor flash protect 0 64 last off
62+
(gdb) load {path to repository}/build/zephyr/zephyr.elf
63+
(gdb) monitor resume
64+
65+
Debugging
66+
=========
67+
68+
Refer to the detailed overview about :ref:`application_debugging`.
69+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CONFIG_RISCV32=y
2+
CONFIG_SOC_SERIES_RISCV32_FE310=y
3+
CONFIG_SOC_RISCV32_FE310=y
4+
CONFIG_BOARD_HIFIVE1=y
5+
CONFIG_CONSOLE=y
6+
CONFIG_PRINTK=y
7+
CONFIG_SERIAL=y
8+
CONFIG_UART_FE310=y
9+
CONFIG_UART_FE310_PORT_0=y
10+
CONFIG_UART_FE310_PORT_0_BAUD_RATE=115200
11+
CONFIG_UART_FE310_PORT_0_NAME="uart0"
12+
CONFIG_UART_CONSOLE=y
13+
CONFIG_UART_CONSOLE_ON_DEV_NAME="uart0"
14+
CONFIG_PLIC_FE310=y
15+
CONFIG_PINMUX=y
16+
CONFIG_PINMUX_FE310=y
17+
CONFIG_RISCV_MACHINE_TIMER=y
18+
CONFIG_GPIO=y
19+
CONFIG_GPIO_FE310=y
20+
CONFIG_BOOT_BANNER=y

boards/riscv32/hifive1/pinmux.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2017 Jean-Paul Etienne <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <init.h>
8+
#include <pinmux.h>
9+
#include <board.h>
10+
11+
static int hifive1_pinmux_init(struct device *dev)
12+
{
13+
ARG_UNUSED(dev);
14+
15+
struct device *p = device_get_binding(CONFIG_PINMUX_FE310_0_NAME);
16+
17+
/* UART0 RX */
18+
pinmux_pin_set(p, 16, FE310_PINMUX_IOF0);
19+
20+
/* UART0 TX */
21+
pinmux_pin_set(p, 17, FE310_PINMUX_IOF0);
22+
23+
/* SPI1 */
24+
pinmux_pin_set(p, 2, FE310_PINMUX_IOF0); /* SS0 */
25+
pinmux_pin_set(p, 3, FE310_PINMUX_IOF0); /* MOSI */
26+
pinmux_pin_set(p, 4, FE310_PINMUX_IOF0); /* MISO */
27+
pinmux_pin_set(p, 5, FE310_PINMUX_IOF0); /* SCK */
28+
pinmux_pin_set(p, 9, FE310_PINMUX_IOF0); /* SS2 */
29+
pinmux_pin_set(p, 10, FE310_PINMUX_IOF0); /* SS3 */
30+
31+
return 0;
32+
}
33+
34+
SYS_INIT(hifive1_pinmux_init, PRE_KERNEL_1, CONFIG_PINMUX_INIT_PRIORITY);

boards/riscv32/hifive1/prci.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2017 SiFive Inc
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _SIFIVE_PRCI_H
8+
#define _SIFIVE_PRCI_H
9+
10+
#define _REG32(p, i) (*(volatile uint32_t *) ((p) + (i)))
11+
#define PRCI_REG(offset) _REG32(PRCI_BASE_ADDR, offset)
12+
13+
/* Register offsets */
14+
15+
#define PRCI_HFROSCCFG (0x0000)
16+
#define PRCI_HFXOSCCFG (0x0004)
17+
#define PRCI_PLLCFG (0x0008)
18+
#define PRCI_PLLDIV (0x000C)
19+
#define PRCI_PROCMONCFG (0x00F0)
20+
21+
/* Fields */
22+
#define ROSC_DIV(x) (((x) & 0x2F) << 0)
23+
#define ROSC_TRIM(x) (((x) & 0x1F) << 16)
24+
#define ROSC_EN(x) (((x) & 0x1) << 30)
25+
#define ROSC_RDY(x) (((x) & 0x1) << 31)
26+
27+
#define XOSC_EN(x) (((x) & 0x1) << 30)
28+
#define XOSC_RDY(x) (((x) & 0x1) << 31)
29+
30+
#define PLL_R(x) (((x) & 0x7) << 0)
31+
/* single reserved bit for F LSB. */
32+
#define PLL_F(x) (((x) & 0x3F) << 4)
33+
#define PLL_Q(x) (((x) & 0x3) << 10)
34+
#define PLL_SEL(x) (((x) & 0x1) << 16)
35+
#define PLL_REFSEL(x) (((x) & 0x1) << 17)
36+
#define PLL_BYPASS(x) (((x) & 0x1) << 18)
37+
#define PLL_LOCK(x) (((x) & 0x1) << 31)
38+
39+
#define PLL_R_default 0x1
40+
#define PLL_F_default 0x1F
41+
#define PLL_Q_default 0x3
42+
43+
#define PLL_REFSEL_HFROSC 0x0
44+
#define PLL_REFSEL_HFXOSC 0x1
45+
46+
#define PLL_SEL_HFROSC 0x0
47+
#define PLL_SEL_PLL 0x1
48+
49+
#define PLL_FINAL_DIV(x) (((x) & 0x3F) << 0)
50+
#define PLL_FINAL_DIV_BY_1(x) (((x) & 0x1) << 8)
51+
52+
#define PROCMON_DIV(x) (((x) & 0x1F) << 0)
53+
#define PROCMON_TRIM(x) (((x) & 0x1F) << 8)
54+
#define PROCMON_EN(x) (((x) & 0x1) << 16)
55+
#define PROCMON_SEL(x) (((x) & 0x3) << 24)
56+
#define PROCMON_NT_EN(x) (((x) & 0x1) << 28)
57+
58+
#define PROCMON_SEL_HFCLK 0
59+
#define PROCMON_SEL_HFXOSCIN 1
60+
#define PROCMON_SEL_PLLOUTDIV 2
61+
#define PROCMON_SEL_PROCMON 3
62+
63+
#endif /* _SIFIVE_PRCI_H */

0 commit comments

Comments
 (0)