forked from tinygo-org/tinygo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: add HiFive1 rev B board with RISC-V architecture
This page has been a big help in adding support for this new chip: https://wiki.osdev.org/HiFive-1_Bare_Bones
- Loading branch information
1 parent
f0eb4ee
commit ffa38b1
Showing
37 changed files
with
485 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cmsis-svd
updated
31 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package riscv | ||
|
||
// Run the given assembly code. The code will be marked as having side effects, | ||
// as it doesn't produce output and thus would normally be eliminated by the | ||
// optimizer. | ||
func Asm(asm string) | ||
|
||
// ReadRegister returns the contents of the specified register. The register | ||
// must be a processor register, reachable with the "mov" instruction. | ||
func ReadRegister(name string) uintptr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.section .init | ||
.global _start | ||
.type _start,@function | ||
|
||
_start: | ||
// Workaround for missing support of the la pseudo-instruction in Clang 8: | ||
// https://reviews.llvm.org/D55325 | ||
lui sp, %hi(_stack_top) | ||
addi sp, sp, %lo(_stack_top) | ||
// see https://gnu-mcu-eclipse.github.io/arch/riscv/programmer/#the-gp-global-pointer-register | ||
lui gp, %hi(__global_pointer$) | ||
addi gp, gp, %lo(__global_pointer$) | ||
call main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// +build hifive1b | ||
|
||
package machine | ||
|
||
const ( | ||
P00 Pin = 0 | ||
P01 Pin = 1 | ||
P02 Pin = 2 | ||
P03 Pin = 3 | ||
P04 Pin = 4 | ||
P05 Pin = 5 | ||
P06 Pin = 6 | ||
P07 Pin = 7 | ||
P08 Pin = 8 | ||
P09 Pin = 9 | ||
P10 Pin = 10 | ||
P11 Pin = 11 | ||
P12 Pin = 12 | ||
P13 Pin = 13 | ||
P14 Pin = 14 | ||
P15 Pin = 15 | ||
P16 Pin = 16 | ||
P17 Pin = 17 | ||
P18 Pin = 18 | ||
P19 Pin = 19 | ||
P20 Pin = 20 | ||
P21 Pin = 21 | ||
P22 Pin = 22 | ||
P23 Pin = 23 | ||
P24 Pin = 24 | ||
P25 Pin = 25 | ||
P26 Pin = 26 | ||
P27 Pin = 27 | ||
P28 Pin = 28 | ||
P29 Pin = 29 | ||
P30 Pin = 30 | ||
P31 Pin = 31 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build hifive1b | ||
|
||
package machine | ||
|
||
const ( | ||
LED = LED1 | ||
LED1 = LED_RED | ||
LED2 = LED_GREEN | ||
LED3 = LED_BLUE | ||
LED_RED = P22 | ||
LED_GREEN = P19 | ||
LED_BLUE = P21 | ||
) | ||
|
||
const ( | ||
// TODO: figure out the pin numbers for these. | ||
UART_TX_PIN = NoPin | ||
UART_RX_PIN = NoPin | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build !stm32f4disco | ||
// +build !stm32f4disco,!hifive1b | ||
|
||
package machine | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// +build fe310 | ||
|
||
package machine | ||
|
||
import ( | ||
"device/sifive" | ||
) | ||
|
||
type PinMode uint8 | ||
|
||
const ( | ||
PinInput PinMode = iota | ||
PinOutput | ||
) | ||
|
||
// Configure this pin with the given configuration. | ||
func (p Pin) Configure(config PinConfig) { | ||
sifive.GPIO0.INPUT_EN.SetBits(1 << uint8(p)) | ||
if config.Mode == PinOutput { | ||
sifive.GPIO0.OUTPUT_EN.SetBits(1 << uint8(p)) | ||
} | ||
} | ||
|
||
// Set the pin to high or low. | ||
func (p Pin) Set(high bool) { | ||
if high { | ||
sifive.GPIO0.PORT.SetBits(1 << uint8(p)) | ||
} else { | ||
sifive.GPIO0.PORT.ClearBits(1 << uint8(p)) | ||
} | ||
} | ||
|
||
type UART struct { | ||
Bus *sifive.UART_Type | ||
Buffer *RingBuffer | ||
} | ||
|
||
var ( | ||
UART0 = UART{Bus: sifive.UART0, Buffer: NewRingBuffer()} | ||
) | ||
|
||
func (uart UART) Configure(config UARTConfig) { | ||
// Assuming a 16Mhz Crystal (which is Y1 on the HiFive1), the divisor for a | ||
// 115200 baud rate is 138. | ||
sifive.UART0.DIV.Set(138) | ||
sifive.UART0.TXCTRL.Set(sifive.UART_TXCTRL_ENABLE) | ||
} | ||
|
||
func (uart UART) WriteByte(c byte) { | ||
for sifive.UART0.TXDATA.Get()&sifive.UART_TXDATA_FULL != 0 { | ||
} | ||
|
||
sifive.UART0.TXDATA.Set(uint32(c)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build !avr,!nrf,!sam,!stm32 | ||
// +build !avr,!nrf,!sam,!sifive,!stm32 | ||
|
||
package machine | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build !stm32f407,!avr | ||
// +build !stm32f407,!avr,!hifive1b | ||
|
||
package machine | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build avr nrf sam stm32 | ||
// +build avr nrf sam sifive stm32 | ||
|
||
package machine | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build avr cortexm wasm | ||
// +build avr cortexm tinygo.riscv wasm | ||
|
||
package os | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build darwin linux,!avr,!cortexm | ||
// +build darwin linux,!avr,!cortexm,!tinygo.riscv | ||
|
||
package os | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build arm,!avr,!cortexm | ||
// +build arm,!avr,!cortexm,!tinygo.riscv | ||
|
||
package runtime | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.