Skip to content

Commit

Permalink
Add OVERCLOCK option
Browse files Browse the repository at this point in the history
This adds the option to run things at 20 MHz instead of 15 MHz which
is about 50% faster than the fmax reported by nextpnr, but in good
condition (good/high vcore, normal temp, ...) works OK.

UART divider need to be updated at various places though, so adapt
for this too

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
  • Loading branch information
smunaut committed Feb 15, 2023
1 parent 9c23114 commit 4af8014
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion firmware/bios/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ CROSS ?= riscv-none-embed-
CC = $(CROSS)gcc
OBJCOPY = $(CROSS)objcopy

CFLAGS=-Wall -Os -march=rv32i -mabi=ilp32 -ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section --specs=nano.specs
UART_DIV ?= 13
CFLAGS=-Wall -Os -march=rv32i -mabi=ilp32 -ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section --specs=nano.specs -DUART_DIV=$(UART_DIV)

all: bios.bin

Expand Down
6 changes: 5 additions & 1 deletion firmware/bios/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

#define BOOT_DEBUG

#ifndef UART_DIV
# define UART_DIV 13
#endif

.section .text.start
.global _start
_start:

#ifdef BOOT_DEBUG
// Set UART divisor
li a0, 0x81000000
li a1, 13
li a1, UART_DIV
sw a1, 4(a0)

// Output '1'
Expand Down
8 changes: 5 additions & 3 deletions firmware/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ OBJCOPY = $(CROSS)objcopy

CFLAGS=-Wall -Os -march=rv32i -mabi=ilp32 -ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section --specs=nano.specs

UART_DIV ?= 13

all: boot-hram.hex boot-qpi.hex boot-sim.hex

boot-hram.elf: lnk-boot.lds boot.S
$(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DMEM_HRAM -o $@ boot.S
$(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DMEM_HRAM -DUART_DIV=$(UART_DIV) -o $@ boot.S

boot-qpi.elf: lnk-boot.lds boot.S
$(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DMEM_QPI -o $@ boot.S
$(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DMEM_QPI -DUART_DIV=$(UART_DIV) -o $@ boot.S

boot-sim.elf: lnk-boot.lds boot.S
$(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DBOOT_SIM -o $@ boot.S
$(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DBOOT_SIM -DUART_DIV=$(UART_DIV) -o $@ boot.S

%.bin: %.elf
$(OBJCOPY) -O binary $< $@
Expand Down
6 changes: 5 additions & 1 deletion firmware/boot/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
//#define MEM_HRAM
//#define MEM_QPI

#ifndef UART_DIV
# define UART_DIV 13
#endif

/* Config */
.equ HRAM_BASE, 0x80000000
.equ QPI_BASE, 0x80000000
Expand All @@ -33,7 +37,7 @@ _start:
#ifdef BOOT_DEBUG
// Set UART divisor
li a0, UART_BASE
li a1, 13
li a1, UART_DIV
sw a1, 4(a0)

// Output banner
Expand Down
20 changes: 18 additions & 2 deletions gateware/riscv_linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ ifeq ($(MEM),qpi)
YOSYS_READ_ARGS += -DMEM_QPI=1
endif

OVERCLOCK ?= 0

ifeq ($(OVERCLOCK),1)
UART_DIV := 18
YOSYS_READ_ARGS += -DOVERCLOCK=1
else
UART_DIV := 13
endif

# Include default rules
include ../build/project-rules.mk

Expand All @@ -69,10 +78,10 @@ $(BUILD_TMP)/boot.hex:

# Build of BootLoader, BIOS code and DTB
../../firmware/boot/%.hex: _force_run_
make -C ../../firmware/boot/ $*.hex
make -C ../../firmware/boot/ UART_DIV=$(UART_DIV) $*.hex

../../firmware/bios/%.hex: _force_run_
make -C ../../firmware/bios/ $*.hex
make -C ../../firmware/bios/ UART_DIV=$(UART_DIV) $*.hex

../../firmware/dt/ice40linux.dtb: _force_run_
make -C ../../firmware/dt/ ice40linux.dtb
Expand All @@ -87,6 +96,13 @@ $(BUILD_TMP)/boot-hw.hex: $(FW_BOOT_HW) $(FW_BIOS)
$(BUILD_TMP)/boot-sim.hex: $(FW_BOOT_SIM) $(FW_BIOS)
./sw/hexmerge.py 0:$(FW_BOOT_SIM) 256:$(FW_BIOS) > $@

# Clean
clean-fw:
make -C ../../firmware/boot/ clean
make -C ../../firmware/bios/ clean
make -C ../../firmware/dt/ clean
.PHONY: clean-fw

# Force call to update .hex from other Makefiles
_force_run_:
.PHONY: _force_run_
Expand Down
8 changes: 7 additions & 1 deletion gateware/riscv_linux/data/clocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
BASE = 15
# Find PLL
pll = [v for k,v in ctx.cells if 'PLL' in v.type][0]

BASE = {
('0000', '1001111', '100'): 15,
('0000', '0110100', '011'): 20,
}[(pll.params['DIVR'], pll.params['DIVF'], pll.params['DIVQ'])]

ctx.addClock("clk_1x", 1 * BASE)
ctx.addClock("clk_4x", 4 * BASE)
Expand Down

0 comments on commit 4af8014

Please sign in to comment.