How to access to memory of portenta

Hi,
Can someone give me a link or some suggestions to store some calibration data (in order to restore it at the next power on) in the flash of portenta? Noticing that it has no an integrated EEPROM, I would like to use a special library to access to the ram. I saw some examples about <sdram.h> but I didn't find the reference of it with all the functions and examples.
Thank you

Hi @zewrx. You might find the information in this forum topic to be useful:

It is about the Nano 33 BLE, but the Portenta H7 is also using Mbed OS.

2 Likes

Thank you so much @in0 I think that your tip is the right tool to have the solution. Can you help me to modify the code to complete my aim, please? I need only the mbed version of EEprom.get and EEPROM.put in my setup (all the calls refer to my sensor).

void setup(void)
{
    Serial.begin(115200);
    delay(1000);
    Serial.println("Orientation Sensor Test"); Serial.println("");

    /* Initialise the sensor */
    if (!bno.begin())
    {
        /* There was a problem detecting the BNO055 ... check your connections */
        Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
        while (1);
    }

    int eeAddress = 0;
    long bnoID;
    bool foundCalib = false;

    EEPROM.get(eeAddress, bnoID);

    adafruit_bno055_offsets_t calibrationData;
    sensor_t sensor;

    /*
    *  Look for the sensor's unique ID at the beginning oF EEPROM.
    *  This isn't foolproof, but it's better than nothing.
    */
    bno.getSensor(&sensor);
    if (bnoID != sensor.sensor_id)
    {
        Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
        delay(500);
    }
    else
    {
        Serial.println("\nFound Calibration for this sensor in EEPROM.");
        eeAddress += sizeof(long);
        EEPROM.get(eeAddress, calibrationData);

        displaySensorOffsets(calibrationData);

        Serial.println("\n\nRestoring Calibration data to the BNO055...");
        bno.setSensorOffsets(calibrationData);

        Serial.println("\n\nCalibration data loaded into BNO055");
        foundCalib = true;
    }

    delay(1000);

    /* Display some basic information on this sensor */
    displaySensorDetails();

    /* Optional: Display current status */
    displaySensorStatus();

   /* Crystal must be configured AFTER loading calibration data into BNO055. */
    bno.setExtCrystalUse(true);

    sensors_event_t event;
    bno.getEvent(&event);
    /* always recal the mag as It goes out of calibration very often */
    if (foundCalib){
        Serial.println("Move sensor slightly to calibrate magnetometers");
        while (!bno.isFullyCalibrated())
        {
            bno.getEvent(&event);
            delay(BNO055_SAMPLERATE_DELAY_MS);
        }
    }
    else
    {
        Serial.println("Please Calibrate Sensor: ");
        while (!bno.isFullyCalibrated())
        {
            bno.getEvent(&event);

            Serial.print("X: ");
            Serial.print(event.orientation.x, 4);
            Serial.print("\tY: ");
            Serial.print(event.orientation.y, 4);
            Serial.print("\tZ: ");
            Serial.print(event.orientation.z, 4);

            /* Optional: Display calibration status */
            displayCalStatus();

            /* New line for the next sample */
            Serial.println("");

            /* Wait the specified delay before requesting new data */
            delay(BNO055_SAMPLERATE_DELAY_MS);
        }
    }

    Serial.println("\nFully calibrated!");
    Serial.println("--------------------------------");
    Serial.println("Calibration Results: ");
    adafruit_bno055_offsets_t newCalib;
    bno.getSensorOffsets(newCalib);
    displaySensorOffsets(newCalib);

    Serial.println("\n\nStoring calibration data to EEPROM...");

    eeAddress = 0;
    bno.getSensor(&sensor);
    bnoID = sensor.sensor_id;

    EEPROM.put(eeAddress, bnoID);

    eeAddress += sizeof(long);
    EEPROM.put(eeAddress, newCalib);
    Serial.println("Data stored to EEPROM.");

    Serial.println("\n--------------------------------\n");
    delay(500);
}

SDRAM on Portenta H7:

#include <SDRAM.h>
...
void setup() {
#if 1
    //change to 480 MHz core clock - we need a different SPI clock config!
    extern uint8_t SetSysClock_PLL_HSE(uint8_t bypass, bool lowspeed);
    SetSysClock_PLL_HSE(1, (bool)false);
#endif

    //with CM4:
    //bootM4();         //Boot CM4 core

    //initialize SDRAM, even we do not use yet
    sdram.begin();
#if 0
    GsdramStart = (uint8_t*)sdram.malloc((8 * 1024 * 1024)/8 - 12);     //first 12 bytes are used for malloc?
#else
    GsdramStart = (uint8_t*)0x60000000;                                 //hard-coded start of SDRAM (bank 1, NOR/PSRAM)
#endif
    if (GsdramStart)
        strcpy((char*)GsdramStart, (const char *)"SDRAM");              //0x60000000, but string starts at 0x6000000C
    //before, on 0x60000008 seems to be the allocated length

Just initialize SDRAM and use it like dynamic memory. It appears at address 0x60000000.
But use the SRAM just after you have done the sdram.begin() - never before.

#include <SDRAM.h>
...
void setup() {
#if 1
    //change to 480 MHz core clock - we need a different SPI clock config!
    extern uint8_t SetSysClock_PLL_HSE(uint8_t bypass, bool lowspeed);
    SetSysClock_PLL_HSE(1, (bool)false);
#endif

    //with CM4:
    //bootM4();         //Boot CM4 core

    //initialize SDRAM, even we do not use yet
    sdram.begin();
#if 0
    GsdramStart = (uint8_t*)sdram.malloc((8 * 1024 * 1024)/8 - 12);     //first 12 bytes are used for malloc?
#else
    GsdramStart = (uint8_t*)0x60000000;                                 //hard-coded start of SDRAM (bank 1, NOR/PSRAM)
#endif
    if (GsdramStart)
        strcpy((char*)GsdramStart, (const char *)"SDRAM");              //0x60000000, but string starts at 0x6000000C
    //before, on 0x60000008 seems to be the allocated length

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.