Skip to content

Add opt-in exact PLL3 audio clock - #733

Open
Ninety-Days wants to merge 1 commit into
daisyaudio:masterfrom
Ninety-Days:exact-audio-clock
Open

Ninety-Days wants to merge 1 commit into
daisyaudio:masterfrom
Ninety-Days:exact-audio-clock

Conversation

@Ninety-Days

Copy link
Copy Markdown

Stop gap for #731, as discussed there.

Adds an opt-in exact_audio_clock flag. When it is set, System::ConfigureClocks() uses PLL3 M=5, N=192, P=25, R=25 (614.4 MHz VCO, 24.576 MHz SAI and ADC kernel clocks) instead of M=6, N=295, P=16, R=32, so 8, 16, 32, 48 and 96 kHz run at their nominal rates. The default is unchanged.

DaisyPod hw;
hw.seed.exact_audio_clock = true; // before Init()
hw.Init();

Code that calls System::Init() directly can set the same flag on System::Config.

192 kHz: from a 24.576 MHz kernel clock, SAI_192KHZ would need MCKDIV below 1, and the HAL would run it at 96 kHz without an error. SaiHandle::Init() now checks this first, with the same rounding as HAL_SAI_Init(), and returns Result::ERR before changing any state, so the previous rate keeps running and GetSampleRate() keeps reporting it. The check only applies when a block is master; with the default clock every rate passes it.

Open points:

  • The flag is a public DaisySeed member read by Init(), because the board classes only pass boost through to DaisySeed::Init(). Happy to expose it another way if you prefer.
  • DaisyPatchSM builds its own System::Config and is not covered here; it would be a one-line addition.
  • The flag has no effect when skip_clocks is set (bootloader older than v6, running from QSPI), since the clocks then come from the bootloader.
  • If C becomes the default later, this flag can go.

Tested on a Daisy Pod (Seed rev7, PCM3060, STM32H750 rev V) at 48 kHz, reading the registers over USB:

  • flag off: PLL3DIVR = 0x1F031F26, MCKDIV = 4, 48014.32 Hz, as before
  • flag on: PLL3DIVR = 0x180330BF, MCKDIV = 2, 48000.0000 Hz

The 192 kHz error path is not tested on hardware.

System::Config::exact_audio_clock (and DaisySeed::exact_audio_clock,
read by DaisySeed::Init()) sets PLL3 to M=5, N=192, P=25, R=25 for an
exact 24.576 MHz SAI kernel clock, so 8-96 kHz run at their nominal
rates instead of ~298 ppm fast. The default PLL3 setting is unchanged.

SAI_192KHZ cannot be reached from that clock. SaiHandle::Init() now
returns an error, before changing any state, when the kernel clock is
too slow for the requested rate, instead of letting the HAL run it at
a lower rate.

Refs daisyaudio#731
@github-actions

Copy link
Copy Markdown

Test Results

167 tests  ±0   164 ✅  - 3   0s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     3 ❌ +3 

For more details on these failures, see this check.

Results for commit 48f24c5. ± Comparison against base commit 1289a00.

@Ninety-Days

Copy link
Copy Markdown
Author

CI note: the failing checks look unrelated to this change. The 3 util_WavWriter tests fail the same way on clean master when built with -D_GLIBCXX_ASSERTIONS (f_write() in tests/FatFsMock.cpp indexes file_data at size() for a 0-byte write), and build-makefile stops at "Setup python" because Python 3.8 is no longer available for ubuntu-latest.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant