Hi. we are trying to save the ADC data to SDRAM of Portenta H7, but not works.
As you can see in the end of the code we use digitalWrite(LEDG, LOW); to see if the code go to there, but we never reach it.
We don't know why.
Any suggestion?
Thanks
//#include "FATFileSystem.h"
//#include "SDMMCBlockDevice.h"
#include "SDRAM.h"
#define analogPin A5
//SDMMCBlockDevice block_device;
//mbed::FATFileSystem fs("fs");
// REDIRECT_STDOUT_TO(Serial);
void setup() {
// put your setup code here, to run once:
pinMode(A5, INPUT);
pinMode(LEDB, OUTPUT);
pinMode(LEDG, OUTPUT);
// while(1){
// int err = fs.mount(&block_device);
// if(err){
// digitalWrite(LEDR, LOW); // Not detect the SD CARD
// delay(50);
// }else{
// digitalWrite(LEDR, HIGH); //detect the SD CARD
// break;
// }
// // int err = fs.reformat(&block_device); // seriously don't want to format your good data
// }
SDRAM.begin();
Serial.begin(115200);
while (!Serial);
analogReadResolution(16);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LEDB, LOW);
int arrSize = 1000, iter;
analogReadResolution(16);
unsigned int previousTime = 0;
float ref_voltage = 5.0;
uint16_t *analogVal =
(uint16_t *)SDRAM.malloc(arrSize * sizeof(uint16_t)); // 2MB array;
if (analogVal == NULL) {
Serial.print("Oops, too big :)");
}
//int a = analogRead(analogPin);
delay(1000);
Serial.print("000");
Serial.print("000");
for (int iter = 0; iter < arrSize; iter++) {
analogVal[iter] = analogRead(analogPin);
// while (1) {
// Pause 50 microseconds (the samping rate is 20000 sampling/s)
// unsigned int currentTime = micros();
// if (currentTime - previousTime >= 50) {
// previousTime = currentTime;
// break;
// }
// }
}
// char myFileName[] = "fs/01.txt"; // "fs/" needs to be there, think fileSystem
// //
// FILE *myFile = fopen(myFileName, "w"); // "a" for append (add to file), "w" write, "r" read ??
// //
// float adc_voltage = 0;
// //int tem = 0;
// for(iter = 0; iter < arrSize; iter++){
// //adc_voltage = (*(analogVal+iter) * ref_voltage) / 65536.0 * 1000.0;
// fprintf(myFile,"%d\r\n",analogVal[iter]);
// }
// //
// fclose(myFile);
digitalWrite(LEDG, LOW);
//Serial.print(analogVal[5326]);
SDRAM.free(analogVal);
//Serial.print("Finish");
while (1)
;
}
I think the issue is: SDRAM is a class. You call .begin() directly on the class, NOT at an object.
I do this in my code:
#include <SDRAM.h>
Sorry, too early...
#include <SDRAM.h>
SDRAMClass sdram;
void setup() {
//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
I think, you need an instance of SDRAM, not SDRAM.begin() (on the class directly).
The fact, that you never reach this digitalWrite(LEDG, LOW) is:
-
you crash when trying to write to SDRAM
-
your code ends up in HardFaultHandler (do you see a red "morse-coding" LED?)
-
your SDRAM was initialized (not enabled) via SDRAM.begin() (because you need instance of SDRAM and then sdram.begin())
This is the "trouble" with OOP, C++ on embedded system. You can have a CLASS.begin() method (a static function), but it is not the same as SDRAM sdram.begin() - now the constructor, the static function is not really a constructor).
You do not get a compile error when doing SDRAM.begin() ? Very strange, it should complain if static member function is not defined.
Try really:
SDRAM sdram;
sdram.begin();
instead of:
SDRAM.begin();
(and have an instance, object of SDRAM, not just the class definition only).
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.