This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SK-AM62: Detecting External Clock Supply on McASP0

Part Number: SK-AM62
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:

  1. Detect when the external clock is supplied for the first time (initially not supplied).
  2. Detect when the external clock stops.
  3. Detect when the external clock is supplied again.
  4. 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):

White check mark 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.

X Not working:

  • The logic for initial clock detection seems incorrect.
  • Behavior of Drivers_mcaspOpen() and Drivers_mcaspClose() is problematic.

Mag Steps I’ve tried for clock detection: (Assuming no external clock is supplied initially)

  1. Call Drivers_mcaspOpen()
  2. An error occurs but I continue processing:
    ERROR: Drivers_mcaspOpen:295: MCASP open failed for instance 0 !!!
  3. 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);
    }
    
  4. Check MCASP0_RCNT and RCKFAIL:
    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;
        }
    }
    
  5. Supply external clock
  6. poll_mcasp0_rckfail() returns true
  7. Drivers_mcaspOpen() fails, but after calling Drivers_mcaspClose() and reopening, it succeeds
  8. Re-run init_mcasp0_rclkchk()
  9. Call MCASP_startTransferRx() / MCASP_startTransferTx() → speaker output works
  10. Stop external clock
  11. poll_mcasp0_rckfail() detects clock stop
  12. Stop McASP as per documentation (MCASP_stopTransferRx, MCASP_stopTransferTx, MCASP_withdrawRx, MCASP_withdrawTx)
  13. Re-run init_mcasp0_rclkchk()
  14. External clock is not detected again
  15. Calling Drivers_mcaspClose() / Drivers_mcaspOpen() causes the program to hang
  • Hi Satoshi,

    Thank you for your query and apologies for the delayed response. I will look into your query this week and will get back to you.

    Regards,
    Ritapravo

  • Hi Ritapravo,

    Thank you for your initial response. My original question may have been unclear due to its length, so I’d like to add some clarification.

    What I’m trying to achieve is detecting the clock input state. To do this, I want to poll the status of MCASP_RSTAT_RCKFAIL.

    Currently, unless I call Drivers_mcaspOpen(), the function poll_mcasp0_rckfail() keeps returning FALSE. Based on my understanding, it seems that even if I don’t call Drivers_mcaspOpen() directly, having some part of its implementation might be sufficient to enable detection of MCASP_RSTAT_RCKFAIL.

    However, I couldn’t identify which part of the Drivers_mcaspOpen() implementation is responsible for enabling the detection of MCASP_RSTAT_RCKFAIL.

  • MCASP_RSTAT_RCKFAIL

    Hi Satoshi, 

    To detect external clock failure detection using MCASP_RSTAT_RCKFAIL, you have have to configure the RMAX and RMIN parameters MCASP_RCLKCHK register first. You can check section 12.1.1.4.15.6.1 Clock Failure Check Startup of AM62 TRM.

    Regards,
    Ritapravo

  • Hi Ritapravo,

    To detect external clock failure detection using MCASP_RSTAT_RCKFAIL, you have have to configure the RMAX and RMIN parameters MCASP_RCLKCHK register first.

    We were unable to correctly retrieve MCASP_RSTAT_RCKFAIL without implementing Drivers_mcaspOpen().
    (Even when an external clock input was provided, MCASP_RSTAT_RCKFAIL remained set to YES.)

    After executing Drivers_mcaspOpen() beforehand, we were able to successfully detect the external clock failure.

    Is it mandatory to execute Drivers_mcaspOpen() in advance to enable proper detection of external clock failures?

  • Hi Satoshi,

    Is it mandatory to execute Drivers_mcaspOpen() in advance to enable proper detection of external clock failures?

    Drivers_mcaspOpen() will configure the mcasp instance with the parameters you have chosen on the sysConfig. It also configures the DMA and the clocks. So, Drivers_mcaspOpen() has to be called before.

    Regards,
    Ritapravo

  • Hi Ritapravo,

    Understood that Drivers_mcaspOpen() is required for clock detection.
    This issue can be considered closed.

    Regards,
    Satoshi