Hi, I’m trying to use persistent memory for some firmware I’m writing for the Versio board using the Daisy Seed. It wasn’t working, so I re-cloned the DaisyExamples repository and created a boilerplate using the exact same method described here:
Saving values to Flash memory using PersistentStorage class on Daisy Pod
Here’s my code:
#include "daisy_versio.h"
#include "daisysp.h"
using namespace daisy;
using namespace daisysp;
DaisyVersio hw;
//Setting Struct containing parameters we want to save to flash
struct Settings {
float p1; // DryWet
float p2; // Feedback
//Overloading the != operator
//This is necessary as this operator is used in the PersistentStorage source code
bool operator!=(const Settings& a) const {
return !(a.p1==p1 && a.p2==p2);
}
};
//Persistent Storage Declaration. Using type Settings and passed the devices qspi handle
PersistentStorage<Settings> SavedSettings(hw.seed.qspi);
//Reverb and Parameters
//ReverbSc Verb;
float test1 = 0.f;
float test2 = 0.f;
bool use_preset = false;
bool trigger_save = false;
void Load() {
//Reference to local copy of settings stored in flash
Settings &LocalSettings = SavedSettings.GetSettings();
test1 = LocalSettings.p1;
test2 = LocalSettings.p2;
use_preset = true;
}
void Save() {
//Reference to local copy of settings stored in flash
Settings &LocalSettings = SavedSettings.GetSettings();
LocalSettings.p1 = test1;
LocalSettings.p2 = test2;
trigger_save = true;
}
void ProcessControls() {
hw.ProcessAllControls();
//Switches
if(hw.tap.RisingEdge()){
if(use_preset)
use_preset = false;
else
Load();
}
if(hw.tap.FallingEdge()){
Save();
}
// //Knobs
// if(!use_preset){
// Verb.SetFeedback(Feedback.Process());
// DryWet = hw.knob1.Process();
// }
// //LEDs
// if(use_preset)
// hw.led1.Set(0, 1, 0); // green
// else
// hw.led1.Set(1, 0, 0); // red
// if(trigger_save)
// hw.led2.Set(0, 1, 0); // green
// else
// hw.led2.Set(0, 0, 0); // red
// hw.UpdateLeds();
}
void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out, size_t size)
{
hw.ProcessAllControls();
for (size_t i = 0; i < size; i++)
{
out[0][i] = in[0][i];
out[1][i] = in[1][i];
}
}
int main(void)
{
hw.Init();
hw.SetAudioBlockSize(4); // number of samples handled per callback
hw.SetAudioSampleRate(SaiHandle::Config::SampleRate::SAI_48KHZ);
// Verb.Init(hw.AudioSampleRate());
// Feedback.Init(hw.knob2, 0.0f, 1.0f, daisy::Parameter::LINEAR);
float test = 1.f;
test *= 2;
//Initilize the PersistentStorage Object with default values.
//Defaults will be the first values stored in flash when the device is first turned on. They can also be restored at a later date using the RestoreDefaults method
Settings DefaultSettings = {test, 0.0f};
SavedSettings.Init(DefaultSettings);
hw.StartAdc();
hw.StartAudio(AudioCallback);
while(1) {
if(trigger_save) {
SavedSettings.Save(); // Writing locally stored settings to the external flash
trigger_save = false;
}
System::Delay(100);
}
}
When the code is executed, the line
SavedSettings.Init(DefaultSettings);
creates a bus fault here:
if(SCB->CFSR & SCB_CFSR_BFARVALID_Msk)
__asm("BKPT #0");
in system.cpp.
Then it creates a second bus fault here:
if(SCB->CFSR & SCB_CFSR_PRECISERR_Msk)
__asm("BKPT #0");
Then it goes down here:
else if(SCB->HFSR & SCB_HFSR_VECTTBL_Msk)
{
// Vector table bus fault
__asm("BKPT #0");
}
Then here:
__asm("BKPT #0");
Then loops forever.
The debug console says the following:
Program
-> ~" received signal SIGTRAP, Trace/breakpoint trap.\n"
received signal SIGTRAP, Trace/breakpoint trap.
-> ~"HardFault_Handler () at src/sys/system.cpp:197\n"
HardFault_Handler () at src/sys/system.cpp:197
-> ~"197\t __asm(\"BKPT #0\");\n"
197 __asm("BKPT #0");
-> *stopped,reason="signal-received",signal-name="SIGTRAP",signal-meaning="Trace/breakpoint trap",frame={addr="0x08002882",func="HardFault_Handler",args=[],file="src/sys/system.cpp",fullname="C:\\Users\\digit\\OneDrive\\Desktop\\DaisyExamples2~\\libDaisy\\src\\sys\\system.cpp",line="197",arch="armv7e-m"},thread-id="1",stopped-threads="all"
Am I do something wrong in my code? Perhaps the implementation is supposed to be slightly different. I really am just a beginner when it comes to programming for microcontrollers. Any help would be much appreciated!
Thanks