Skip to content

Commit 8880cab

Browse files
committed
Fix Risc-V build
1 parent f714343 commit 8880cab

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

src/rp2_common/pico_crt0/crt0_riscv.S

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#define PICO_CRT0_INCLUDE_PICOBIN_END_BLOCK (PICO_CRT0_INCLUDE_PICOBIN_BLOCK && !PICO_NO_FLASH)
3131
#endif
3232

33+
// PICO_CONFIG: PICO_CRT0_NO_DATA_COPY, Whether crt0 should perform the data copies - usually copying from flash into sram, default=1 for no_flash builds, 0 otherwise, type=bool, group=pico_crt0
34+
#ifndef PICO_CRT0_NO_DATA_COPY
35+
#define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH
36+
#endif
37+
3338
// If vectors are in RAM, we put them in the .data section, so that they are
3439
// preloaded by _reset_handler (assuming this is not a loaded-in-place
3540
// binary).
@@ -340,7 +345,7 @@ _call_xip_setup:
340345

341346
// In a NO_FLASH binary, don't perform .data etc copy, since it's loaded
342347
// in-place by the SRAM load. Still need to clear .bss
343-
#if !PICO_NO_FLASH
348+
#if !PICO_CRT0_NO_DATA_COPY
344349
la a4, data_cpy_table
345350

346351
// assume there is at least one entry
@@ -379,14 +384,25 @@ platform_entry: // symbol for stack traces
379384
ebreak
380385
j 1b
381386

387+
#if !PICO_CRT0_NO_DATA_COPY
388+
#if PICO_NO_FLASH
389+
data_cpy:
390+
// skip copies with same source and destination
391+
bne a0, a1, data_cpy_start
392+
ret
393+
#else
394+
// go straight into the copy
395+
#define data_cpy_start data_cpy
396+
#endif
382397
data_cpy_loop:
383398
lw a0, (a1)
384399
sw a0, (a2)
385400
addi a1, a1, 4
386401
addi a2, a2, 4
387-
data_cpy:
402+
data_cpy_start:
388403
bltu a2, a3, data_cpy_loop
389404
ret
405+
#endif
390406

391407
.align 2
392408
data_cpy_table:
@@ -412,6 +428,10 @@ data_cpy_table:
412428
.word __scratch_y_start__
413429
.word __scratch_y_end__
414430

431+
#ifdef PICO_DATA_COPY_EXTRA_SECTIONS_FILE
432+
#include PICO_DATA_COPY_EXTRA_SECTIONS_FILE
433+
#endif
434+
415435
.word 0 // null terminator
416436

417437
// ----------------------------------------------------------------------------

src/rp2_common/pico_standard_link/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ if (NOT TARGET pico_standard_link)
184184
set(ADDITIONAL_MEMORY "set(ADDITIONAL_MEMORY \" XIP_RAM(rwx) : ORIGIN = ${XIP_SRAM_BASE}, LENGTH = ${XIP_SRAM_END} - ${XIP_SRAM_BASE}\")" PARENT_SCOPE)
185185
endfunction()
186186
target_compile_definitions(${TARGET} PRIVATE PICO_DATA_COPY_EXTRA_SECTIONS_FILE="data_cpy_xip_text.S" PICO_USE_XIP_CACHE_AS_RAM=1)
187-
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/data_cpy_xip_text.S "
187+
file(CONFIGURE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/data_cpy_xip_text.S CONTENT "
188188
.word __xip_ram_text_source__
189189
.word __xip_ram_text_start__
190190
.word __xip_ram_text_end__
191-
")
191+
" @ONLY)
192192
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
193193
if (TYPE STREQUAL "no_flash_using_xip_ram")
194194
pico_set_modified_binary_type(${TARGET} sram EXTRAS pico_internal_add_xip_text_section)

test/pico_xip_sram_test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
add_executable(pico_xip_sram_test pico_xip_sram_test.c)
33
target_link_libraries(pico_xip_sram_test PRIVATE pico_stdlib)
44
pico_set_binary_type(pico_xip_sram_test xip_sram)
5-
pico_minimize_runtime(pico_xip_sram_test INCLUDE PRINTF PRINTF_MINIMAL DEFAULT_ALARM_POOL PANIC)
5+
pico_minimize_runtime(pico_xip_sram_test INCLUDE PRINTF PRINTF_MINIMAL DEFAULT_ALARM_POOL PANIC FLOAT)
66
target_compile_definitions(pico_xip_sram_test PRIVATE PICO_HEAP_SIZE=0x200)
77
pico_add_extra_outputs(pico_xip_sram_test)
88

99
# Use XIP SRAM for time critical functions
1010
add_executable(pico_critical_xip_sram_test pico_critical_xip_sram_test.c)
1111
target_link_libraries(pico_critical_xip_sram_test PRIVATE pico_stdlib pico_multicore hardware_dma)
12+
if (NOT PICO_RP2040)
13+
target_link_libraries(pico_critical_xip_sram_test PRIVATE hardware_riscv_platform_timer)
14+
endif()
1215
pico_set_binary_type(pico_critical_xip_sram_test copy_to_ram_using_xip_ram)
1316
pico_add_extra_outputs(pico_critical_xip_sram_test)

test/pico_xip_sram_test/pico_critical_xip_sram_test.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,57 @@
22
#include "pico/stdlib.h"
33
#include "pico/multicore.h"
44
#include "hardware/dma.h"
5+
#if PICO_RP2040
56
#include "hardware/structs/systick.h"
7+
#else
8+
#include "hardware/riscv_platform_timer.h"
9+
#endif
610
#include "hardware/structs/busctrl.h"
711

812

913
int __time_critical_func(test_func_xip)(void) {
14+
#if PICO_RP2040
1015
systick_hw->rvr = 0x00ffffff;
1116
systick_hw->cvr = 0;
17+
#else
18+
riscv_timer_set_mtimecmp(0xffffffffffffffff);
19+
riscv_timer_set_mtime(0);
20+
#endif
1221

1322
volatile uint32_t i = 0;
1423
i += 4;
1524
i += i;
1625

26+
#if PICO_RP2040
1727
return systick_hw->rvr - systick_hw->cvr;
28+
#else
29+
return riscv_timer_get_mtime();
30+
#endif
1831
}
1932

2033
int __not_in_flash_func(test_func_sram)(void) {
34+
#if PICO_RP2040
2135
systick_hw->rvr = 0x00ffffff;
2236
systick_hw->cvr = 0;
37+
#else
38+
riscv_timer_set_mtimecmp(0xffffffffffffffff);
39+
riscv_timer_set_mtime(0);
40+
#endif
2341

2442
volatile uint32_t i = 0;
2543
i += 4;
2644
i += i;
2745

46+
#if PICO_RP2040
2847
return systick_hw->rvr - systick_hw->cvr;
48+
#else
49+
return riscv_timer_get_mtime();
50+
#endif
2951
}
3052

3153

3254
void core1_entry() {
55+
#ifndef __riscv
3356
// Just read memory repeatedly
3457
pico_default_asm_volatile(
3558
"1:\n"
@@ -45,6 +68,29 @@ void core1_entry() {
4568
"b 1b\n"
4669
: : "i" (SRAM_BASE) : "r0", "r1", "r2", "r3", "r4"
4770
);
71+
#else
72+
pico_default_asm_volatile(
73+
"1:\n"
74+
"li a0, %0\n"
75+
"lw a1, 0(a0)\n"
76+
"lw a2, 4(a0)\n"
77+
"lw a3, 8(a0)\n"
78+
"lw a4, 12(a0)\n"
79+
"addi a0, a0, 16\n"
80+
"lw a1, 0(a0)\n"
81+
"lw a2, 4(a0)\n"
82+
"lw a3, 8(a0)\n"
83+
"lw a4, 12(a0)\n"
84+
"addi a0, a0, 16\n"
85+
"lw a1, 0(a0)\n"
86+
"lw a2, 4(a0)\n"
87+
"lw a3, 8(a0)\n"
88+
"lw a4, 12(a0)\n"
89+
"addi a0, a0, 16\n"
90+
"j 1b\n"
91+
: : "i" (SRAM_BASE) : "a0", "a1", "a2", "a3", "a4"
92+
);
93+
#endif
4894
}
4995

5096

@@ -74,7 +120,13 @@ int main(void) {
74120

75121
multicore_launch_core1(core1_entry);
76122

123+
#if PICO_RP2040
77124
systick_hw->csr = 0x4 | 0x1; // clock source and enable
125+
#else
126+
riscv_timer_set_fullspeed(true);
127+
riscv_timer_set_enabled(true);
128+
riscv_timer_set_mtimecmp(0xffffffffffffffff);
129+
#endif
78130

79131
// Give core1 and DMA high priority
80132
hw_set_bits(&busctrl_hw->priority, BUSCTRL_BUS_PRIORITY_PROC1_BITS | BUSCTRL_BUS_PRIORITY_DMA_R_BITS | BUSCTRL_BUS_PRIORITY_DMA_W_BITS);

0 commit comments

Comments
 (0)