I am using Pixhawk and recently I've been developing a module/function to read a large size (around 1.5MB) 4-D matrix of float type from a binary file in the SD card and store the read matrix into the flash memory, 2MB on Pixhawk. The matrix is used for controller gain scheduling, so it should be accessed every time the main loop runs.
As I am starting from scratch, I tried reading a 2*4 test matrix of float type and it went well. However, when I tried with the large matrix, I could not build because I ran out of SRAM, as shown in the error message "region `sram' overflowed by 524024 bytes". So I suppose that once the large matrix is read in, it's stored in the RAM, 256KB on pixhawk, yet it's way less than enough. Therefore, I was wondering how can I read the matrix from the SD card and store it directly into the flash memory, in order not to overflow the RAM?
Here's a snippet of my coding, it's rather simple:
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
hal.console->printf("SD Card reading test startup...\n");
fp = fopen("/fs/microsd/table/T_pixhawk.bin", "rb");
fread(&T_hat_in, sizeof(float), 103*103*16, fp);
hal.console->printf("Read %f \n",T_hat_in);