Я использую платформу io. < /p>
platformio.ini: < /p>
Код: Выделить всё
[env:rpipico2]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
build_flags = -fexceptions
board = rpipico2
board_build.core = earlephilhower
framework = arduino
lib_deps =
SPI
1 - библиотека Andrewcapon
Эта библиотека: https: // github .com/Andrewcapon/picopluspspram, однако плата замерзает, когда я позвонил getInstance.
2 - Использование непосредственно < /h3>
Я пытался выполнить простую подпрограмму добавления чисел в массив, а затем печатать их: < /p>
// ChatGPT slop:
#include
#include
//---------------------------------------------------------------------------
// 1) Configure PSRAM region
// (Addresses/size may differ on your board)
//---------------------------------------------------------------------------
#define PSRAM_LOCATION (0x11000000) // Common base address on some Pico-like boards
#define PSRAM_SIZE (8 * 1024 * 1024) // Example: 8 MB PSRAM
static lwmem_region_t psram_regions[] = {
{(void *)PSRAM_LOCATION, PSRAM_SIZE},
{NULL, 0} // Terminator
};
//---------------------------------------------------------------------------
// 2) Global variables
//---------------------------------------------------------------------------
static int *myArray = nullptr; // Pointer to array in PSRAM
static size_t arraySize = 10; // How many elements in our array
static size_t currentIndex = 0; // Tracks where we write next
//---------------------------------------------------------------------------
// 3) Setup
//---------------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
while (!Serial)
{
// Wait for Serial on some boards
}
delay(1000);
// Let lwmem know it can use our PSRAM region
lwmem_assignmem(psram_regions);
Serial.println("Assigned PSRAM region to lwmem.");
// Use calloc so the array is zero-initialized
myArray = (int *)lwmem_calloc(arraySize, sizeof(int));
if (!myArray)
{
Serial.println("PSRAM allocation failed!");
while (true)
{ /* halt */
}
}
Serial.println("Allocated zero-initialized array in PSRAM.");
// Print initial contents (should all be zero)
Serial.println("Initial array contents:");
for (size_t i = 0; i < arraySize; i++)
{
Serial.print(myArray);
if (i < arraySize - 1)
{
Serial.print(", ");
}
}
Serial.println();
}
//---------------------------------------------------------------------------
// 4) Loop
//---------------------------------------------------------------------------
void loop()
{
static unsigned long lastPrint = 0;
if (millis() - lastPrint >= 5000)
{
lastPrint = millis();
// Store a random value in the array
int value = random(0, 1000); // Range: [0 .. 999]
myArray[currentIndex] = value;
Serial.print("Added ");
Serial.print(value);
Serial.print(" at index ");
Serial.println(currentIndex);
// Print entire array
Serial.print("Current array contents: ");
for (size_t i = 0; i < arraySize; i++)
{
Serial.print(myArray);
if (i < arraySize - 1)
{
Serial.print(", ");
}
}
Serial.println();
// Move to next index, wrap around at the end
currentIndex = (currentIndex + 1) % arraySize;
}
}
< /code>
Вывод был так, чтобы я полагаю, что ОЗУ не была отображена? < /p>
-initialized array in PSRAM.
Initial array contents:
0, -858993524, 0, -858993524, 0, -858993524, 0, -858993524, 0, -858993524
Added 933 at index 0
Current array contents: 0, -858993524, 0, -858993524, 0, -858993524, 0, -858993524, 0, -858993524
Added 743 at index 1
Current array contents: 0, -858993524, 0, -858993524, 0, -858993524, 0, -858993524, 0, -858993524
< /code>
3 - Попытайтесь отобразить PSRAM < /h3>
Я попросил Chatgpt настройку PSRAM перед тем, как запустить ту же демонстрацию. Это дало следующее, и когда я запустил его, я получил бы такое же заморозовое поведение, что и первая попытка.// main.cpp
#include
// ============== Attempt to pull in Pico SDK hardware headers ==============
extern "C" {
#include
}
#include "pico/stdlib.h"
#include "hardware/structs/ioqspi.h"
#include "hardware/structs/qmi.h"
#include "hardware/structs/xip_ctrl.h"
#include "hardware/sync.h"
#include "hardware/clocks.h"
// ------------- Config for your external PSRAM -------------
#define PIMORONI_PICO_PLUS2_PSRAM_CS_PIN 29
#define PSRAM_BASE_ADDR 0x11000000
#define PSRAM_SIZE_BYTES (8 * 1024 * 1024) // 8 MB example
// ------------- lwmem region for PSRAM -------------
static lwmem_region_t psram_regions[] = {
{ (void*)PSRAM_BASE_ADDR, PSRAM_SIZE_BYTES },
{ NULL, 0 }
};
// ------------- Mark function to (try to) place in ramfunc -------------
#define PSRAM_INIT_FN __attribute__((section(".ramfunc")))
// ------------- Minimal PSRAM init function -------------
PSRAM_INIT_FN bool psram_init_minimal(uint cs_pin) {
// 1) Setup CS pin for XIP
gpio_set_function(cs_pin, GPIO_FUNC_XIP_CS1);
// Disable interrupts
uint32_t save = save_and_disable_interrupts();
// Enter direct mode with safe divider
qmi_hw->direct_csr = (30 direct_csr & QMI_DIRECT_CSR_BUSY_BITS) {
tight_loop_contents();
}
// Example: Send "QPI enable" command (0x35)
qmi_hw->direct_csr |= QMI_DIRECT_CSR_ASSERT_CS1N_BITS;
qmi_hw->direct_tx = 0x35;
// Wait for TX empty
while (!(qmi_hw->direct_csr & QMI_DIRECT_CSR_TXEMPTY_BITS)) {
tight_loop_contents();
}
// Wait for not busy
while (qmi_hw->direct_csr & QMI_DIRECT_CSR_BUSY_BITS) {
tight_loop_contents();
}
qmi_hw->direct_csr &= ~QMI_DIRECT_CSR_ASSERT_CS1N_BITS;
// Setup M1 region
int clk_sys_hz = clock_get_hz(clk_sys);
int desired_psram_freq = 133000000;
int divisor = (clk_sys_hz + desired_psram_freq - 1) / desired_psram_freq;
if (divisor < 2) {
divisor = 2;
}
int rxdelay = divisor;
int max_select = 10;
int min_deselect = 2;
qmi_hw->m[1].timing =
(1
Подробнее здесь: https://stackoverflow.com/questions/794 ... platformio
Мобильная версия