AnsweredAssumed Answered

Initialising USB host interferes with SAI drivers

Question asked by Sam Tyler on Aug 26, 2015
Latest reply on Aug 27, 2015 by Sam Tyler

Hi.

 

I'm trying to create an application which includes I2S and a USB device. I'm having a problem in which initialising the USB host drivers will cause the I2S callback to never be called.

 

Is there any over lap in the two drivers? Do they use common hardware? Is it likely to be caused by the tasks created in USB stack initialisation?

 

Offending code is shown below. The callback is repeatedly called when lines 27 to 32 are commented, but never when they are included.

 

Any comments / suggestions would be appreaciated.

 

Thanks in advance,

 

Sam

 

 

Code:

 

#if 1

#include "board.h"

#include "fsl_sai_driver.h"

#include "usb_host_config.h"
#include "usb.h"
#include "usb_host_stack_interface.h"
#include "usb_host_hub_sm.h"
#include "usb_host_ch9.h"

void i2s_callback(void* params)
{
    PRINTF("Callback\r\n");
}

static void primary_thread(void *params)
{
    const uint32_t size = 5120;
    uint8_t buffer[size];
    uint8_t instance = 0;
    uint32_t status;
    usb_host_handle host_handle;

    /* Uncommenting these lines causes SAI interrupt to never be called! */
//    status = usb_host_init(USB_CONTROLLER_KHCI_0, &host_handle);
//    if (status != USB_OK)
//    {
//        PRINTF("ERROR\r\n");
//        while(1);
//    }

    sai_user_config_t i2s_config;
    sai_state_t i2s_state = {0};
    sai_data_format_t i2s_data_format = {0};

    i2s_data_format.bits = 16;
    i2s_data_format.sample_rate = 8000;
    i2s_data_format.mclk = 13000000;
    i2s_data_format.mono_stereo = kSaiStereo;

    i2s_config.bclk_source = kSaiBclkSourceBusclk;
    i2s_config.channel = 0;
    i2s_config.mclk_source = kSaiMclkSourceSelect1;
    i2s_config.protocol = kSaiBusI2SType;
    i2s_config.slave_master = kSaiSlave;
    i2s_config.sync_mode = kSaiModeAsync;
    i2s_config.watermark = 1;
    i2s_config.dma_source = kDmaRequestMux0I2S0Rx;

    uint32_t i;
    for (i = 0; i < size; i++)
    {
        buffer[i] = 0;
    }

    status = SAI_DRV_RxInit(instance, &i2s_config, &i2s_state);
    if (status != kStatus_SAI_Success)
    {
        PRINTF("ERROR\r\n");
        while(1);
    }

    status = SAI_DRV_RxConfigDataFormat(instance, &i2s_data_format);
    if (status != kStatus_SAI_Success)
    {
        PRINTF("ERROR\r\n");
        while(1);
    }

    SAI_DRV_RxRegisterCallback(instance, &i2s_callback, NULL);


    status = SAI_DRV_ReceiveDataInt(instance, buffer, size);
    if (status != size)
    {
        PRINTF("ERROR\r\n");
        while(1);
    }

    while(1)
    {
        OSA_TimeDelay(100);
    }
}


int main()
{
    OSA_Init();

    hardware_init();

    uint8_t status;

    status = OSA_TaskCreate(primary_thread, (uint8_t*)"primary_thread", 10000L, NULL, 4L, NULL , false, NULL);
    if (kStatus_OSA_Success != status)
    {
        PRINTF("Error Creating thread \"primary_thread\" \r\n");
        while(1)
            ;
    }

    OSA_Start();

    return 0;
}

#endif

Outcomes