Clock generation and configuration for sgtl5000

Status
Not open for further replies.

skyler

Member
Hi there!

I've been diving through the audio lib source code, audio shield schematics, and the sgtl5000 datasheet to try and piece together how the whole embedded system works together, sort of as an exercise.

My question: MCLK, BCLK, LRCLK, TX, RX and ADDR are pins on the sgtl5000 connected to pins 11,9,23,22,13 and 15 respectively on the teensy 3.6 through the audio shield. Where in the code are these teensy pins configured to be inputs, outputs or to generate clock signals, etc. I was unable to find any occurrences of the pins 11,9,23,22,13 and 15 at all in the audio library source.

I looked through control_sgtl5000.cpp where I thought I would find my answers but that all seemed like sgtl5000 configuration using the I2C channel on and nothing about the specific pins on the teensy being configured to do things like generate MCLK, BCLK , etc that the sgtl5000 needs in order to operate. I attached the audio shield schematic for reference.

On a related note: different teensy boards and different version of the audio shield have different pinouts and yet all use the same audio library that seamlessly talk the the sgtl5000. How is this possible and where in the code are these board distinctions handled?

I hope all this makes sense and thanks for helping! I'm just getting into embedded systems and I've been having so much fun getting closer and closer to where hardware meets software. :)

Screen Shot 2020-03-27 at 8.34.08 PM.jpg
 
The control objects just set codec configuration via i2c or maybe spi. The input_xxx and output_xxx stuff has the actual i2s configuration.

In input_i2s.cpp ...

CORE_PIN13_CONFIG = PORT_PCR_MUX(4); // pin 13, PTC5, I2S0_RXD0

In output_i2s.cpp...

CORE_PIN22_CONFIG = PORT_PCR_MUX(6); // pin 22, PTC1, I2S0_TXD0

// configure pin mux for 3 clock signals
CORE_PIN23_CONFIG = PORT_PCR_MUX(6); // pin 23, PTC2, I2S0_TX_FS (LRCLK)
CORE_PIN9_CONFIG = PORT_PCR_MUX(6); // pin 9, PTC3, I2S0_TX_BCLK
CORE_PIN11_CONFIG = PORT_PCR_MUX(6); // pin 11, PTC6, I2S0_MCLK

If you look in those files you will see ...

#if defined(KINETISK)
.....
#elif defined(__IMXRT1062__)
....
#endif

...to differentiate different Teensy versions based on the microcontroller used.
 
Im curious about how these device defines work ex: #if defined(KINETISK) Are these key works KINETISK and __IMXRT1062__ saved into the core of the device at time of manufactoring? I don't quite understand how the device core is able to know what version it is. Thanks!
 
In Arduino, click File > Preferences, and turn on verbose output while compiling. Then Arduino will show you the exact commands it is using to run the compiler. You'll see -D__IMXRT1062__ is one of them. The exact commands Arduino uses are determined by which board you select in the Tools > Boards menu, and the contents of 2 configuration files "boards.txt" and "platform.txt".

Others names are defined in the core lib .h files. Using "grep" or other file search is generally a good way to find such thing. Search for all lines having both the name you want to understand and "#define".
 
Ah! So selecting the specific board in Tools > Board as we normally do defines the terms like __IMXRT1062__ into a configuration file? After a board is selected in the IDE and hence that board identifier for example __IMXRT1062__ is defined, then during compilation certain board specific code like setting pinouts can use #if defined to only run valid code meant for that board. Is that the general idea?

Thanks for the grep file search idea, that should make the scavenger hunt a bit easier now! :)
 
Status
Not open for further replies.
Back
Top