Skip to content

Use the SDK XIP cache clean method #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: feature/psram
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ elseif(PICO_RISCV)
)
endif()

if(MICROPY_HW_ENABLE_PSRAM)
list(APPEND MICROPY_SOURCE_PORT
rp2_psram.c
)
list(APPEND PICO_SDK_COMPONENTS
hardware_xip_cache
)
target_compile_definitions(${MICROPY_TARGET} PRIVATE
MICROPY_HW_ENABLE_PSRAM=1
)
endif()

# Use our custom pico_float_micropython float implementation. This is needed for two reasons:
# - to fix inf handling in pico-sdk's __wrap___aeabi_fadd();
# - so we can use our own libm functions, to fix inaccuracies in the pico-sdk versions.
Expand Down Expand Up @@ -591,7 +603,11 @@ if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
if(PICO_RP2040)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld)
elseif(PICO_RP2350)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld)
if (MICROPY_HW_ENABLE_PSRAM)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350_psram.ld)
else()
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld)
endif()
endif()
endif()

Expand Down
29 changes: 29 additions & 0 deletions ports/rp2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <stdio.h>

#include "rp2_psram.h"
#include "rp2_flash.h"
#include "py/compile.h"
#include "py/cstack.h"
#include "py/runtime.h"
Expand Down Expand Up @@ -68,6 +70,7 @@

extern uint8_t __StackTop, __StackBottom;
extern uint8_t __GcHeapStart, __GcHeapEnd;
extern uint8_t __PsramGcHeapStart, __PsramGcHeapEnd;

// Embed version info in the binary in machine readable form
bi_decl(bi_program_version_string(MICROPY_GIT_TAG));
Expand All @@ -93,6 +96,13 @@ int main(int argc, char **argv) {
// Hook for setting up anything that needs to be super early in the bootup process.
MICROPY_BOARD_STARTUP();

// Set the flash divisor to an appropriate value
rp2_flash_set_timing();

#if defined(MICROPY_HW_PSRAM_CS_PIN) && MICROPY_HW_ENABLE_PSRAM
size_t psram_size = psram_init(MICROPY_HW_PSRAM_CS_PIN);
#endif

#if MICROPY_HW_ENABLE_UART_REPL
bi_decl(bi_program_feature("UART REPL"))
setup_default_uart();
Expand Down Expand Up @@ -120,7 +130,26 @@ int main(int argc, char **argv) {

// Initialise stack extents and GC heap.
mp_cstack_init_with_top(&__StackTop, &__StackTop - &__StackBottom);

#if defined(MICROPY_HW_PSRAM_CS_PIN) && MICROPY_HW_ENABLE_PSRAM
if (psram_size) {
// Linker script assumes a 2MB PSRAM, increase the size accordingly.
size_t psram_additional_size = 0;
if (psram_size > 2 * 1024 * 1024) {
psram_additional_size = psram_size - 2 * 1024 * 1024;
}
#if MICROPY_GC_SPLIT_HEAP
gc_init(&__GcHeapStart, &__GcHeapEnd);
gc_add(&__PsramGcHeapStart, &__PsramGcHeapEnd + psram_additional_size);
#else
gc_init(&__PsramGcHeapStart, &__PsramGcHeapEnd + psram_additional_size);
#endif
} else {
gc_init(&__GcHeapStart, &__GcHeapEnd);
}
#else
gc_init(&__GcHeapStart, &__GcHeapEnd);
#endif

#if MICROPY_PY_LWIP
// lwIP doesn't allow to reinitialise itself by subsequent calls to this function
Expand Down
Loading