himem.h
Posted: Sat Oct 19, 2019 11:53 pm
First, I got some code here to access the 1st 4MB of PSRAM of a WROVER model that you may find useful at some point.
I want to access the other 4 MB of PSRAM on my WROVER-B rev1. I understand about paging of memory. Anyways I am trying to include "himem.h" so I can work on figuring out how to do paging in the Arduino IDE. What is the proper "path" to enter so that I can use; I have tried #include "esp32/himem.h", #include <himem.h>, and a few others with no luck. What is the syntax to include "himem.h" in the Arduino IDE?
Code: Select all
#include "esp_system.h" //This inclusion configures the peripherals in the ESP system.
#include "esp32-hal-psram.h"
// #include "himem.h"
////
struct stuTime
{
int iSeconds = 0;
int iMinutes = 0;
int iHours = 0;
};
////
void setup()
{
// log_d("Total heap: %d", ESP.getHeapSize());
// log_d("Free heap: %d", ESP.getFreeHeap());
log_d("Total PSRAM: %d", ESP.getPsramSize());
log_d("Free PSRAM: %d", ESP.getFreePsram());
////
int *ptr, *ptr1;
int n, n1, i, sum = 0;
// Get the number of elements for the array
n = 10;
n1 = 20;
log_d("Number of elements ptr: %d", n);
log_d("Number of elements ptr1: %d", n1);
// log_d("Number of elements ptr1: %d\n", n1);
// Dynamically allocate memory using malloc()
// ptr = (int*)ps_malloc(n * sizeof(int)); //works
ptr = (int*)ps_calloc( n, sizeof(int) ); // works
log_d("Free PSRAM: %d", ESP.getFreePsram());
//
ptr1 = (int*)ps_calloc( n1, sizeof(int) ); // works
log_d("Free PSRAM: %d", ESP.getFreePsram());
// Check if the memory has been successfully
// allocated in ps_ram
if (ptr == NULL) {
log_d(" ptr memory not allocated.\n");
exit(0);
}
if (ptr1 == NULL)
{
log_d("ptr1 memory not allocated.\n");
exit(0);
}
else
{
// Memory has been successfully allocated
log_d("ps_ram memory successfully allocated using ps_calloc.");
// put elements into ps_ram array
for (i = 0; i < n; ++i)
{
ptr[i] = i + 1;
}
for (i = 0; i < n1; ++i)
{
ptr1[i] = i + 2;
}
// Print the elements of the array
log_d("The elements of the ptr array are: ");
for (i = 0; i < n; ++i) {
log_d("%d, ", ptr[i]);
}
log_d("The elements of the ptr1 array are: ");
for (i = 0; i < n1; ++i) {
log_d("%d, ", ptr1[i]);
}
}
free(ptr);
free(ptr1);
// put a structure into psram
struct stuTime *ptrTime;
// log_i("Free PSRAM before structure: %d", ESP.getFreePsram());
ptrTime = (struct stuTime *)ps_malloc(sizeof(struct stuTime));
// log_i("Free PSRAM after structure: %d", ESP.getFreePsram());
ptrTime->iSeconds = 10;
ptrTime->iMinutes = 60;
ptrTime->iHours = 100;
log_i("Seconds: %d Minutes: %d Hours: %d", ptrTime->iSeconds, ptrTime->iMinutes, ptrTime->iHours );
free(ptrTime);
} // setup()
////
void loop() {}