Assembly examples for Red-V Thing Plus (SiFive FE310-G002)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

60 lines
2.0 KiB

#
# main.s
#
# 2021 flabbergast <flabbergast@drak.xyz>
# Unlicense: https://unlicense.org/
#
.option norelax
.equ compressed_isa, 1
# -----------------------------------------------------------------------------
# Code begins here
# -----------------------------------------------------------------------------
.text
j Reset # Instead of a true vector table
# -----------------------------------------------------------------------------
# Include any supporting code
# -----------------------------------------------------------------------------
.include "platform_regs.inc"
.include "p_clock.s"
.include "p_delay.s"
.include "p_uart0.s"
# -----------------------------------------------------------------------------
Reset: # Execution begins here
# -----------------------------------------------------------------------------
# Set base address for interrupt handler
# la x15, irq_collection
# csrrs zero, mtvec, x15
# the board (usually) runs on 13.8MHz HFROSC on boot?
jal clock_extcryst # switch to external crystal, 16MHz
jal uart_init # initialise UART0 (115200baud)
# if you change clock, you'll need to adjust the
# baud divisor in p_uart0.s
li s1, GPIO_BASE # prepare LED pin
li s2, 0b1 << 5 # pin 5 (SPI_SCK1)
lw t0, GPIO_OUTPUT_EN(s1) # set as output ... read existing
or t0, t0, s2 # twiddle bits
sw t0, GPIO_OUTPUT_EN(s1) # write back
# disable iof_en (bldr leaves SPI0 pins as iof/SPI):
# twiddling using (A)tomic extension:
not t1, s2 # invert bits
addi t0, s1, GPIO_IOF_EN # get address
amoand.w zero, t1, (t0) # (t0)->zero; (t0) = (t0) & t2
addi s1, s1, GPIO_OUTPUT_VAL
1:
amoxor.w zero, s2, (s1) # invert the led
jal uart_recv # wait for a byte through uart
jal uart_emit # ...and send it back
j 1b
end:
j end