Skip to content

Commit b44dbd8

Browse files
Low power fixups (#2941)
* Move persistent data reset into C code Doesn't need to be in crt0, and that is less maintainable anyway * Fix low power compilation issue with clang Clang sometimes tries to place persistent_data in a differet region Fix is to add `> XXX` to the end, to explicitly put it in RAM/XIP_RAM * Update memmap annotations * nit of include order --------- Co-authored-by: Graham Sanderson <graham.sanderson@raspberrypi.com>
1 parent d6e3fe1 commit b44dbd8

17 files changed

Lines changed: 52 additions & 141 deletions

src/rp2040/pico_platform/memmap_blocked_ram.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ INCLUDE "memmap_default.incl"
1212
* └── memmap_default.incl rp2_common/pico_standard_link
1313
* ├── set_memory_locations.incl rp2_common/pico_standard_link
1414
* ├── memory_flash.incl rp2_common/pico_standard_link
15+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1516
* ├── memory_ram.incl rp2_common/pico_standard_link
1617
* ├── memory_scratch.incl rp2_common/pico_standard_link
1718
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2040/pico_platform/memmap_copy_to_ram.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INCLUDE "memmap_copy_to_ram.incl"
99
* └── memmap_copy_to_ram.incl rp2_common/pico_standard_link
1010
* ├── set_memory_locations.incl rp2_common/pico_standard_link
1111
* ├── memory_flash.incl rp2_common/pico_standard_link
12+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1213
* ├── memory_ram.incl rp2_common/pico_standard_link
1314
* ├── memory_scratch.incl rp2_common/pico_standard_link
1415
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2040/pico_platform/memmap_default.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INCLUDE "memmap_default.incl"
99
* └── memmap_default.incl rp2_common/pico_standard_link
1010
* ├── set_memory_locations.incl rp2_common/pico_standard_link
1111
* ├── memory_flash.incl rp2_common/pico_standard_link
12+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1213
* ├── memory_ram.incl rp2_common/pico_standard_link
1314
* ├── memory_scratch.incl rp2_common/pico_standard_link
1415
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2040/pico_platform/memmap_no_flash.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ INCLUDE "memmap_no_flash.incl"
88
* memmap_no_flash.ld rp2040/pico_platform
99
* └── memmap_no_flash.incl rp2_common/pico_standard_link
1010
* ├── set_memory_locations.incl rp2_common/pico_standard_link
11+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1112
* ├── memory_ram.incl rp2_common/pico_standard_link
1213
* ├── memory_scratch.incl rp2_common/pico_standard_link
1314
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2350/pico_platform/memmap_copy_to_ram.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INCLUDE "memmap_copy_to_ram.incl"
99
* └── memmap_copy_to_ram.incl rp2_common/pico_standard_link
1010
* ├── set_memory_locations.incl rp2_common/pico_standard_link
1111
* ├── memory_flash.incl rp2_common/pico_standard_link
12+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1213
* ├── memory_ram.incl rp2_common/pico_standard_link
1314
* ├── memory_scratch.incl rp2_common/pico_standard_link
1415
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2350/pico_platform/memmap_default.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INCLUDE "memmap_default.incl"
99
* └── memmap_default.incl rp2_common/pico_standard_link
1010
* ├── set_memory_locations.incl rp2_common/pico_standard_link
1111
* ├── memory_flash.incl rp2_common/pico_standard_link
12+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1213
* ├── memory_ram.incl rp2_common/pico_standard_link
1314
* ├── memory_scratch.incl rp2_common/pico_standard_link
1415
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2350/pico_platform/memmap_no_flash.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ INCLUDE "memmap_no_flash.incl"
88
* memmap_no_flash.ld rp2350/pico_platform
99
* └── memmap_no_flash.incl rp2_common/pico_standard_link
1010
* ├── set_memory_locations.incl rp2_common/pico_standard_link
11+
* ├── memory_xip_ram.incl rp2_common/pico_standard_link
1112
* ├── memory_ram.incl rp2_common/pico_standard_link
1213
* ├── memory_scratch.incl rp2_common/pico_standard_link
1314
* ├── memory_generated.incl rp2_common/pico_standard_link

src/rp2_common/pico_crt0/crt0.S

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#include "boot/picobin.h"
1616
#include "pico/bootrom.h"
1717

18-
#if HAS_POWMAN_TIMER
19-
#include "hardware/regs/powman.h"
20-
#endif
21-
2218
// PICO_CONFIG: PICO_CRT0_NEAR_CALLS, Whether calls from crt0 into the binary are near (<16M away) - ignored for PICO_COPY_TO_RAM, default=0, type=bool, group=pico_crt0
2319
#ifndef PICO_CRT0_NEAR_CALLS
2420
#define PICO_CRT0_NEAR_CALLS 0
@@ -497,7 +493,6 @@ _call_xip_setup:
497493
// Zero out the BSS
498494
ldr r1, =__bss_start__
499495
ldr r2, =__bss_end__
500-
1:
501496
movs r0, #0
502497
b bss_fill_test
503498
bss_fill_loop:
@@ -506,27 +501,6 @@ bss_fill_test:
506501
cmp r1, r2
507502
bne bss_fill_loop
508503

509-
#if LIB_PICO_LOW_POWER && HAS_POWMAN_TIMER
510-
// Check if we're done
511-
ldr r6, =__bss_end__
512-
cmp r2, r6
513-
bne 1f
514-
// Zero out persistent_data on non-powman boot
515-
ldr r1, =__persistent_data_start__
516-
ldr r2, =__persistent_data_end__
517-
// Skip if there is no persistent data
518-
cmp r1, r2
519-
beq 1f
520-
// Load previous power state into r6
521-
ldr r6, =(POWMAN_BASE+POWMAN_SCRATCH6_OFFSET)
522-
ldr r6, [r6]
523-
// Check if we should skip zeroing
524-
bl persistent_zero_check
525-
cmp r0, #0
526-
beq 1b
527-
1:
528-
#endif
529-
530504
platform_entry: // symbol for stack traces
531505
#if PICO_CRT0_NEAR_CALLS && !PICO_COPY_TO_RAM
532506
bl runtime_init
@@ -558,49 +532,6 @@ data_cpy:
558532
bx lr
559533
#endif
560534

561-
#if LIB_PICO_LOW_POWER && HAS_POWMAN_TIMER
562-
persistent_zero_check:
563-
// uses r5 and r7 as scratch
564-
// uses the powman_power_state in r6
565-
// returns in r0
566-
mov r0, #0
567-
// First check __persistent_data_start__
568-
ldr r7, =__persistent_data_start__
569-
check_r7:
570-
ldr r5, =SRAM_BASE
571-
cmp r5, r7
572-
bgt check_xip_sram
573-
ldr r5, =SRAM4_BASE
574-
cmp r5, r7
575-
bgt check_sram0
576-
check_sram1:
577-
mov r5, #(1 << 0) // POWMAN_POWER_DOMAIN_SRAM_BANK1
578-
b do_check
579-
check_xip_sram:
580-
mov r5, #(1 << 2) // POWMAN_POWER_DOMAIN_XIP_CACHE
581-
b do_check
582-
check_sram0:
583-
mov r5, #(1 << 1) // POWMAN_POWER_DOMAIN_SRAM_BANK0
584-
b do_check
585-
do_check:
586-
and r7, r5, r6
587-
cmp r5, r7
588-
beq skip
589-
b noskip
590-
skip:
591-
cmp r0, #1
592-
bne check_end
593-
bx lr
594-
check_end:
595-
add r0, #1
596-
// If start was skipped, check __persistent_data_end__
597-
ldr r7, =__persistent_data_end__
598-
b check_r7
599-
noskip:
600-
mov r0, #0
601-
bx lr
602-
#endif
603-
604535
// Note the data copy table is still included for NO_FLASH builds, even though
605536
// we skip the copy, because it is listed in binary info
606537

src/rp2_common/pico_crt0/crt0_riscv.S

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
#include "boot/picobin.h"
1313
#include "pico/bootrom_constants.h"
1414

15-
#if HAS_POWMAN_TIMER
16-
#include "hardware/regs/powman.h"
17-
#endif
18-
1915
#ifdef NDEBUG
2016
#ifndef COLLAPSE_IRQS
2117
#define COLLAPSE_IRQS
@@ -373,24 +369,6 @@ bss_fill_loop:
373369
bss_fill_test:
374370
bne a1, a2, bss_fill_loop
375371

376-
#if LIB_PICO_LOW_POWER && HAS_POWMAN_TIMER
377-
// Check if we're done
378-
la a6, __bss_end__
379-
bne a2, a6, 1f
380-
// Zero out persistent_data on non-powman boot
381-
la a1, __persistent_data_start__
382-
la a2, __persistent_data_end__
383-
// Skip if there is no persistent data
384-
beq a1, a2, 1f
385-
// Load previous power state into r6
386-
li a6, POWMAN_BASE+POWMAN_SCRATCH6_OFFSET
387-
lw a6, 0(a6)
388-
// Check if we should skip zeroing
389-
jal persistent_zero_check
390-
beqz a0, bss_fill_test
391-
1:
392-
#endif
393-
394372
platform_entry: // symbol for stack traces
395373
// Use `call` pseudo-instruction instead of a bare `jal` so that the
396374
// linker can use longer sequences if these are out of `jal` range. Will
@@ -417,45 +395,6 @@ data_cpy:
417395
ret
418396
#endif
419397

420-
#if LIB_PICO_LOW_POWER && HAS_POWMAN_TIMER
421-
persistent_zero_check:
422-
// uses a5 and a7 as scratch
423-
// uses the powman_power_state in a6
424-
// returns in a0
425-
li a0, 0
426-
// First check __persistent_data_start__
427-
la a7, __persistent_data_start__
428-
check_a7:
429-
li a5, SRAM_BASE
430-
bgt a5, a7, check_xip_sram
431-
li a5, SRAM4_BASE
432-
bgt a5, a7, check_sram0
433-
check_sram1:
434-
li a5, 1 << 0 // POWMAN_POWER_DOMAIN_SRAM_BANK1
435-
j do_check
436-
check_xip_sram:
437-
li a5, 1 << 2 // POWMAN_POWER_DOMAIN_XIP_CACHE
438-
j do_check
439-
check_sram0:
440-
li a5, 1 << 1 // POWMAN_POWER_DOMAIN_SRAM_BANK0
441-
j do_check
442-
do_check:
443-
and a7, a5, a6
444-
beq a5, a7, skip
445-
j noskip
446-
skip:
447-
beqz a0, check_end
448-
ret
449-
check_end:
450-
addi a0, a0, 1
451-
// If start was skipped, check __persistent_data_end__
452-
la a7, __persistent_data_end__
453-
j check_a7
454-
noskip:
455-
li a0, 0
456-
ret
457-
#endif
458-
459398
.align 2
460399
data_cpy_table:
461400
#if PICO_RP2350 && PICO_EMBED_XIP_SETUP && !PICO_NO_FLASH

src/rp2_common/pico_low_power/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ function(pico_set_persistent_data_loc TARGET PERSISTENT_DATA_LOC)
4040
message(FATAL_ERROR "pico_set_persistent_data_loc is not supported on RP2040")
4141
endif()
4242

43-
# Configure override section_persistent_data.incl for the target
44-
configure_file(${PICO_LOW_POWER_CURRENT_PATH}/section_persistent_data.incl.template ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/section_persistent_data.incl @ONLY)
45-
pico_add_linker_script_override_path(${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET})
46-
4743
if (PERSISTENT_DATA_LOC LESS 0x20000000)
4844
# XIP_SRAM, so pin the XIP_SRAM
4945
target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_PIN_XIP_SRAM=1)
46+
set(PERSISTENT_DATA_SECTION "XIP_RAM")
5047
elseif (PERSISTENT_DATA_LOC LESS 0x20040000)
5148
# SRAM0, so heap should come after persistent data
5249
pico_set_linker_script_var(${TARGET} HEAP_LOC __persistent_data_end__)
50+
set(PERSISTENT_DATA_SECTION "RAM")
5351
elseif(PERSISTENT_DATA_LOC LESS 0x20080000)
5452
# SRAM1, so heap should come before persistent data
5553
pico_set_linker_script_var(${TARGET} HEAP_LIMIT ${PERSISTENT_DATA_LOC})
54+
set(PERSISTENT_DATA_SECTION "RAM")
5655
else()
5756
# Not supported in scratch, as the linker script will overwrite persistent data with scratch data
5857
message(FATAL_ERROR "pico_set_persistent_data_loc only supports persistent data in XIP_SRAM or SRAM0-7")
5958
endif()
59+
60+
# Configure override section_persistent_data.incl for the target
61+
configure_file(${PICO_LOW_POWER_CURRENT_PATH}/section_persistent_data.incl.template ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/section_persistent_data.incl @ONLY)
62+
pico_add_linker_script_override_path(${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET})
6063
endfunction()

0 commit comments

Comments
 (0)