Hey, I’d like to load some samples and store them as float variables in SDRAM without using sd card.
How can I do this? Can someone provide me an example?
Many Thanks! K
Hey, I’d like to load some samples and store them as float variables in SDRAM without using sd card.
How can I do this? Can someone provide me an example?
Many Thanks! K
Data can’t be “stored” in the SDRAM because SDRAM is volatile – it’s not retained across power cycles, and probably not even across MCU restarts (e.g. when flashing a new firmware). DRAM must be continually refreshed by the memory controller to maintain its contents.
You should look into using the QSPI flash memory to store persistent data. Your application can copy data from flash into SDRAM, or even read directly from flash. You’ll be limited to 8MB, though.
nice, thanks! a small example would be really helpful
There is a QSPI
project in the Seed examples, but it doesn’t do quite what you want.
You’ll need to do something like create a C-style array with your sample data, with the DSY_QSPI_BSS
attribute to tell the linker to put it in flash (see line 12 in QSPI.cpp
). There are various bin2c
utilities that will generate a C-style array from a binary file, so you should check them out.
The details of how to make this all work depend on your application. I’d start with just getting something into the QSPI flash, and then take it from there.
I’ve come to the point where I need to use the QSPI flash in order to recover a bit of code space, but unfortunately I’m not sure how it works in practice.
I have a handful of big lookup tables that are statically initialized. They total a few kilobytes. Since I’ve exhausted the 128KB program flash, I’d like to move the tables into the QSPI flash to make a little more room for my code.
I’ve added the DSY_QSPI_BSS
attribute to the arrays, but unfortunately the QSPI flash is not initialized with my values (AFAICT). Maybe the linker script needs to be adjusted in order for the values to be copied over when programming. I’ll take a look.
Oh, duh … my old systems professor is probably rolling in his grave.
Of course we don’t want to use DSY_QSPI_BSS
for this kind of initialized data, but rather DSY_QSPI_DATA
… Unfortunately when I try to put my tables in that section, I’m unable to flash my program at all:
$ make program-dfu
dfu-util -a 0 -s 0x08000000:leave -D build/SamplePlayer.bin -d ,0483:df11
dfu-util 0.10
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2020 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
Warning: Invalid DFU suffix signature
A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 1024
DfuSe interface name: "Internal Flash "
Downloading element to address = 0x08000000, size = -2013258752
Last page at 0x90001bff is not writeable
make: *** [../../libDaisy//core/Makefile:330: program-dfu] Error 74
I don’t know what that error is all about, but I’ll keep digging.
I keep reading this thread since I wasn’t able to get my project working.
As a beginner I heavily relay on working examples…
Did you manage to make this work? I am also trying to store some wave tables into QSPI when uploading my firmware. I have the same behavior as @miminashi when using DSY_QSPI_BSS
or DSY_QSPI_DATA
.
This is my simplified code which could be a nice example for this use case with the QSPI:
#include "daisy_seed.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
DaisySeed hw;
Line line;
uint8_t lineFinished;
const float DSY_QSPI_BSS clapWave[20] = {
0, 0.25, 0.5, 0.75, 1,
0, 0.25, 0.5, 0.75, 1,
0, 0.25, 0.5, 0.75, 1,
0, 0.25, 0.5, 0.75, 1
};
void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out, size_t size)
{
for (size_t i = 0; i < size; i++) {
if(lineFinished) line.Start(0, 19, 0.1);
float wavePosition = line.Process(&lineFinished);
float mix = clapWave[(int)wavePosition];
out[0][i] = mix;
out[1][i] = mix;
}
}
int main(void)
{
hw.Configure();
hw.Init();
hw.SetAudioBlockSize(64);
hw.SetAudioSampleRate(SaiHandle::Config::SampleRate::SAI_48KHZ);
line.Init(48000);
lineFinished = 1;
hw.StartLog();
hw.StartAudio(AudioCallback);
}