Mbed OS PSoC 6 I2S

Hello,

Mbed OS: 6.15.1
PSoC 6 dev kit: CY8CKIT_062S2_43012

I would like to use the I2S interface from PSoC 6 in Mbed OS. I noticed that Mbed OS doesn’t have a driver for it. Do you have any working example?

I tried to use cyhal and followed the PSoC 6 example to setup i2s but the cyhal_i2s_init function returns with an error:
// Initialize the PLL
cyhal_clock_get(&this->pllClock, &CYHAL_CLOCK_PLL[1]);
cy_rslt_t result = cyhal_clock_init(&this->pllClock);
if (result != CY_RSLT_SUCCESS) {
GetLogger()->error(“cyhal_clock_init error 0x%x %x %x %x”, result, CY_RSLT_GET_TYPE(result), CY_RSLT_GET_MODULE(result), CY_RSLT_GET_CODE(result));
}
cyhal_clock_set_frequency(&this->pllClock, Audio::ClockFrequency, NULL);
cyhal_clock_set_enabled(&this->pllClock, true, true);

// Initialize the audio subsystem clock (HFCLK1)
cyhal_clock_get(&this->audioClock, &CYHAL_CLOCK_HF[1]);
result = cyhal_clock_init(&this->audioClock);
if (result != CY_RSLT_SUCCESS) {
    GetLogger()->error("cyhal_clock_init error 0x%x %x %x %x", result, CY_RSLT_GET_TYPE(result), CY_RSLT_GET_MODULE(result), CY_RSLT_GET_CODE(result));
}

result = cyhal_clock_set_source(&this->audioClock, &this->pllClock);
if (result != CY_RSLT_SUCCESS) {
    GetLogger()->error("cyhal_clock_set_source error 0x%x %x %x %x", result, CY_RSLT_GET_TYPE(result), CY_RSLT_GET_MODULE(result), CY_RSLT_GET_CODE(result));
}

result = cyhal_i2s_init(&this->i2s, &this->txPins, &this->rxPins, NC, &this->config, &this->audioClock);

Here are my pins and configuration of I2S:
this->txPins = {
.sck = P5_1,
.ws = P5_2,
.data = P5_3
};
this->rxPins = {
.sck = P5_4,
.ws = P5_5,
.data = P5_6
};
this->config = {
.is_tx_slave = false,
.is_rx_slave = true,
.mclk_hz = 0,
.channel_length = 32,
.word_length = 32,
.sample_rate_hz = Audio::SamplingFrequency
};

Digging into cyhal_i2s_init code I found out that cyhal_hwmgr_reserve throws the error.

Does Mbed OS use any pins that might conflict with the I2S pins of PSoC 6? I noticed the conflict between the USB-UART bridge pins and I2S (UART uses P5_x pins same as I2S). I commented out all code related to printing any debugging info to console and serial initialization but I get the same error. Do I need to do something extra to explicitly disable the USB-UART bridge?

I’ve been googling around but I couldn’t find any Mbed OS PSoC 6 examples with I2S. Have you got any?

Many thanks!

Here is the error I get when calling cyhal_i2s_init (cy_rslt_t 0x4020101):
[00:00:00] [CY-ERROR]: 0x4020101 0x2 0x100 0x101 cyhal_i2s_init

I got it to work by using I2S1. I haven’t tested with real audio yet but no more errors for now.

this->txPins = {
        .sck = P11_1,
        .ws = P11_2,
        .data = P11_3
    };
    this->rxPins = {
        .sck = P11_4,
        .ws = P11_5,
        .data = P11_6
    };
    this->config = {
        .is_tx_slave = false,
        .is_rx_slave = true,
        .mclk_hz = 0,
        .channel_length = 32,
        .word_length = 32,
        .sample_rate_hz = Audio::SamplingFrequency
    };