libDaisy: Can't get ADC working with audio callback
Hi,
I’m very new to Daisy, I have just received my Seed a few days ago.
Basically, I’m trying to modify the oscillator frequency using a potentiometer. But the read of ADC always returns the same value whatever the pot position…
I have tested the Knob example from Web programmer, and it works.
If i comment the line seed.StartAudio(AudioCallback); it works. (PS I have tested with empty AudioCallback, same result, doesn’t work)
I’m using
- libDaisy@
c5c1026like in DaisyExample repo - DaisySP@
5a6b618like in DaisyExample repo - STM32 Cube IDE
- Build in debug
The Cube project was created doing:
- File->New Project -> STM32 project from Existing STM32CubMx Configuration file
- Using
Daisy_Seed_Rev2.iocfrom Daisy_Seed_Rev4 examples repo - Removed all STM32 imported files (since present in libDAisy)
- clone libDaisy and DaisySP, but excluded from build. Libs built using the build script. (I have not been able to build the libs with CubeIDE)
Do you have experienced such issue ?
EDIT : I also have the issue if read the ADC in the AudioCallback
Here is my code :
int main(void)
{
// initialize seed hardware and oscillator daisysp module
float sample_rate;
seed.Configure();
seed.Init();
sample_rate = seed.AudioSampleRate();
// Oscillators init
for (int i = 0; i < OSC_COUNT; i++)
{
freqs[i] = BASE_FREQ + i*FREQ_INC_FACTOR;
oscs[i].Init(sample_rate);
oscs[i].SetWaveform(Oscillator::WAVE_RAMP);
oscs[i].SetFreq(freqs[i]);
oscs[i].SetAmp(0.5);
}
// ADC init
AdcChannelConfig adcConfig;
adcConfig.InitSingle(seed.GetPin(21));
seed.adc.Init(&adcConfig, 1);
seed.adc.Start();
// start callback
seed.StartAudio(AudioCallback);
volatile bool ledState = false;
while(1)
{
freqModifier = seed.adc.GetFloat(0);
seed.SetLed(ledState);
ledState = !ledState;
dsy_system_delay(100);
}
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
Okay, so I cloned your repo, and the submodules (I did update libdaisy because I just updated dfu-util and needed the latest commit for support there…).
I then ran your
build_deps.sh, andbuild.shbefore going intosrcand runningmake program-dfuOn the Daisy Pod hardware this had one knob controlling the frequency of a bunch of oscillators (slightly detuned from each other). I had the exact same result programming the binary you provided in the zip above.
The Daisy pod has KNOB 1 connected to Physical pin 28 (pin 21 in libdaisy) same as in your example’s code, and the seed/Knob example.
You are using the same version of the compiler, and the resulting binary (on windows) is the same size as the one I built here.
If you’re still having bad results with that binary file, I recommend double checking your hardware connections. Specifically that you have DGND and AGND connected, and that your pot is wired to the correct pin (matching the breadboard diagram in the Seed/Knob example). Either of those being wrong could have the effects you’re describing above.
It’s also worth checking continuity of your jumper wires as I have seen a fair amount of them either go bad, or be bad from the start.
Hope that helps.
Sorry for the delay on this, but I can take a look at your project tomorrow and see if there’s something causing an issue either within your project or within libdaisy.
Great news !
This was more like about the issue I have, but probably the way I link the libs or some build flags ?
Good, idea. I’ll try that those days
A lot of work I guess. Feel free to ask if I can help by testing the projects on my side
We’ll be adding a lot of support for the free, cross platform VS Code environment (using Cortex Debug extension) soon.
What kind of ‘strange behavior’ are you seeing when building libs manually with the provided scripts/Makefiles?
Also, since your project appears very simple for the time being. Is it possible to build your example via Make instead of using the STM32CubeIDE just to sanity check whether it’s an issue within libdaisy, your project, or the CubeIDE configuration.
Once we have decent tutorials/examples for using VS Code, I plan on adding VisualStudio/VGDB and STM32CubeIDE project files to the libraries, and having at least one example. But I don’t have an exact timeline on that. I also still need to spend some time looking into PlatformIO as I have not done anything with it yet.
Okay, a couple of thoughts, based on the constant 65535 value it seems like the linker issue, but I’m not sure why it would work correctly if audio is not started.
Check ADC Interrupt/IRQ Handler
Are you able to break in the
HAL_ADC_ConvCpltCallback()function withinlibdaisy/per/adc.cppwhile the audio callback is running?Linker Script Usage
I’m not familiar with STM32Cube, but if it doesn’t use a Makefile (and is using internal build configuration). You will have to set the Linker script to the one located in the core/ directory:
path/to/libdaisy/core/STM32H750IB_flash.ldsOtherwise, the section of memory designated to the DMA Buffers (for ADCs and Audio) would not be configured to be cache-able. This would likely mess up any DMA Receptions (your Audio output might still work, but input data from both Audio and the ADCs would be wrong, or unchanging).
You can confirm that this is cache related by commenting out line 83 of
libdaisy/src/sys/system.cWith the DCache not enabled you’ll have worse memory performance but DMA would function. Linking to the proper linker script should resolve this without having to modify any libdaisy files.