Other Parts Discussed in Thread: SYSCONFIG
Tool/software:
I would like to detect the supply of an external clock on McASP0.
I’m implementing this based on the sample located at:C:\ti\mcu_plus_sdk_am62x_10_01_00_33\examples\drivers\mcasp\mcasp_playback_codec_aic31.
Although I’ve read the documentation (see page 1073 of www.ti.com/.../spruiv7b.pdf), I couldn’t figure out how to achieve this.
Specifically, I want to implement the following four functions:
- Detect when the external clock is supplied for the first time (initially not supplied).
- Detect when the external clock stops.
- Detect when the external clock is supplied again.
- Once the external clock is detected, restart McASP and output to the speaker.
This is related to the following thread:
e2e.ti.com/.../sk-am62-how-to-properly-restart-mcasp0-after-calling-mcasp_close
If possible, I’d appreciate guidance based on source code.
What I’ve tried so far (for reference):
Working:
- Syscfg is configured to receive clock from AUDIO_EXT_ERFCLK1.
- Audio output works when the clock is supplied from AUDIO_EXT_ERFCLK1.
- If
Drivers_mcaspOpen()is called beforehand, the initial clock detection works.
Not working:
- The logic for initial clock detection seems incorrect.
- Behavior of
Drivers_mcaspOpen()andDrivers_mcaspClose()is problematic.
Steps I’ve tried for clock detection: (Assuming no external clock is supplied initially)
- Call
Drivers_mcaspOpen() - An error occurs but I continue processing:
ERROR: Drivers_mcaspOpen:295: MCASP open failed for instance 0 !!! - Initialize based on documentation:
void init_mcasp0_rclkchk() { uint32_t val = CSL_REG32_RD(MCASP0_RCLKCHK); val &= ((0x00 << 16) | (0x00 << 8)); val |= (RCKCHK_MAX << 16); val |= (RCKCHK_MIN << 8); val |= (2 << 0); CSL_REG32_WR(MCASP0_RCLKCHK, val); CSL_REG32_FINS((CSL_MCASP0_CFG_BASE + MCASP_RSTAT_OFFSET), MCASP_RSTAT_RCKFAIL, 1u); } - Check
MCASP0_RCNTandRCKFAIL:void chk_mcasp0_rcnt() { uint32_t rcnt = (CSL_REG32_RD(MCASP0_RCLKCHK) >> 24) & 0xFF; uint32_t rmax = (CSL_REG32_RD(MCASP0_RCLKCHK) >> 16) & 0xFF; uint32_t rmin = (CSL_REG32_RD(MCASP0_RCLKCHK) >> 8) & 0xFF; DebugP_log("[MCASP0]RCNT: %3u | RMAX: %3u | RMIN: %3u\r\n", rcnt, rmax, rmin); } bool poll_mcasp0_rckfail() { uint32_t isFail = CSL_REG32_FEXT((CSL_MCASP0_CFG_BASE + MCASP_RSTAT_OFFSET), MCASP_RSTAT_RCKFAIL); if (isFail == CSL_MCASP_RSTAT_RCKFAIL_YES) { DebugP_log("RCKFAIL: clock NG\r\n"); CSL_REG32_FINS((CSL_MCASP0_CFG_BASE + MCASP_RSTAT_OFFSET), MCASP_RSTAT_RCKFAIL, 1u); return false; } else if (isFail == CSL_MCASP_RSTAT_RCKFAIL_NO) { DebugP_log("clock OK\r\n"); return true; } else { DebugP_log("ERROR!! %d\r\n", isFail); return false; } } - Supply external clock
poll_mcasp0_rckfail()returns trueDrivers_mcaspOpen()fails, but after callingDrivers_mcaspClose()and reopening, it succeeds- Re-run
init_mcasp0_rclkchk() - Call
MCASP_startTransferRx()/MCASP_startTransferTx()→ speaker output works - Stop external clock
poll_mcasp0_rckfail()detects clock stop- Stop McASP as per documentation (
MCASP_stopTransferRx,MCASP_stopTransferTx,MCASP_withdrawRx,MCASP_withdrawTx) - Re-run
init_mcasp0_rclkchk() - External clock is not detected again
- Calling
Drivers_mcaspClose()/Drivers_mcaspOpen()causes the program to hang