All source I‘ve found so far is focused on generating many I2S interfaces,
which is not very similar to HackRF‘s needs.
But reviewing the code is still valuable in grasping how the SGPIO peripheral operates.
There are a few common details to setting up the SGPIO peripheral:
// Configure the PLL to generate a reasonable clock. The SGPIO
// will operate with a clock of up to 204MHz (the same as the
// M4 clock.
CGU_SetPLL1(12);
// Set the BASE_PERIPH clock to come from PLL1.
CGU_EnableEntity(CGU_BASE_PERIPH, ENABLE);
CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_PERIPH);
// Compute and commit clock configuration changes.
CGU_UpdateClock();
Jiggle SGPIO Pins From GPIO Mode
My first test was to ensure I had the right pin(s) hooked up to my scope:
// Jiggle one of the SGPIO pins in GPIO mode, to make sure
// I‘m looking at the right pin on the scope.
scu_pinmux(9, 0, MD_PLN_FAST, 0);
GPIO_SetDir(4, 1L << 12, 1);
while(1) {
volatile int i;
GPIO_SetValue(4, 1L << 12);
for(i=0; i<1000; i++);
GPIO_ClearValue(4, 1L << 12);
for(i=0; i<1000; i++);
}
Jiggle Pins from SGPIO Mode
You can also control SGPIO pins, GPIO-style, from within the SGPIO peripheral.
This helped me understand the basics of operating the SGPIO output mux.