Transferring PDM_PCM component data to FreeRTOS xQueue

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Jdo300
Level 1
Level 1
10 sign-ins 5 questions asked 5 sign-ins

For my application, I need to read data from the PDM mic on the development board (later to be replaced with an I2S mic for the final application), and transfer the data to an xQueue to be sent over Bluetooth to an app. I have the xQueue Bluetooth component working well, but I'm having trouble configuring and activating the PDM_PCM component. What is the best approach to do this?

I have reviewed the PDM_PCM code example and see that they are using an interrupt to transfer. Unfortinately, I am unable to run this code example directly on my current dev kit (I have an older PSoC6 Dev board with the CY8C6347BZI-BLD53). So in my code, I tried setting up an interrupt to read data from the FIFO and enqueue it into my xQueue object using a semaphore. I then attached a SysInt component to the interrupt pin to fire an ISR. However, it seems that the PDM_PCM component is never enabled even though I start it in my main program. Below are some screenshots of my program and the settings:

System Schematic

Jdo300_0-1617977909330.png

PDM_PCM Settings

Jdo300_6-1617978377923.pngJdo300_7-1617978391520.png

Interrupt Pin Settings

Jdo300_5-1617978328520.png

Jdo300_4-1617978279602.png

As mentioned earlier, I'm using FreeRTOS and created a microphoneTask to handle setup and transfer of the microphone data to a queue called txQueue. Here's the code in the task that sets up the PDM_PCM component and interrupt:

void microphoneTask(void *arg)
{
byte count = 0;
word data = {0};
(void)arg;

printf("Microphone Task started\r\n");

// Initialize the microphone semaphore
microphoneSemaphore = xSemaphoreCreateCounting(UINT_MAX, 0);

/* Initialize and enable the microphone interrupt */
Cy_SysInt_Init(&SysInt_PDMDataArrived_cfg, ISR_MicrophoneDataArrived);
NVIC_ClearPendingIRQ(SysInt_PDMDataArrived_cfg.intrSrc);
NVIC_EnableIRQ(SysInt_PDMDataArrived_cfg.intrSrc);

/* Start the PCM component */
Cy_PDM_PCM_Init(PDM_PCM_HW, &PDM_PCM_config);
Cy_PDM_PCM_Enable(PDM_PCM_HW);

for(;;)
{
count = Cy_PDM_PCM_GetNumInFifo(PDM_PCM_HW);
printf("%u Items in Queue\r\n", count);
Cy_GPIO_Inv(BLUE_LED_PORT, BLUE_LED_NUM);
vTaskDelay(100);

// Pend on the microphone semaphore until the microphone has some data available to transfer to the BLE queue
//xSemaphoreTake(microphoneSemaphore, portMAX_DELAY);

// Read data word from the microphone FIFO and transfer to the BLE TX queue
//data.value = Cy_PDM_PCM_ReadFifo(PDM_PCM_HW);
//xQueueSendToBack(txQueue, &data, portMAX_DELAY);
}
}

// Microphone Data transfer interrupt
void ISR_MicrophoneDataArrived()
{
// Trigger the microphone semaphore to handle the data transfer to the BLE queue
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(microphoneSemaphore, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

int main(void)
{
__enable_irq(); /* Enable global interrupts. */

/* Initialize Hardware peripherals */
UART_Start();
Cy_GPIO_Write(LED_PORT, LED_NUM, LED_OFF);

/* disable Stdin/out buffers */
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);

/* Start Hardware Tasks */
xTaskCreate(bleTask,"bleTask", 8 * 1024, 0, 3, 0);
xTaskCreate(bleQueueReader,"bleQueueReader", 400, 0, 3, 0);
//xTaskCreate(timerTask,"timerTask", 400, 0, 1, 0);
xTaskCreate(microphoneTask, "microphoneTask", 400, 0, 1, 0);

/* Start RTOS task scheduler */
vTaskStartScheduler();

printf("Problem running scheduler!");

for(;;)
{

}
}

The microphoneTask task is able to execute when the program is started, but it just pended forever on the semaphore, indicating that something is either wrong with my ISR or it is never being triggered. To test this, I commented the semaphore code out and tried directly polling the value of the FIFO and noted that the value was always zero. It seems that the PDM_PCM component is not running even though I have it enabled. What am I missing here?

 

0 Likes
1 Solution
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @Jdo300 

As discussed, you were able get the I2S mic that you will be using in the final application working.

Kindly let me know if you face any issues with that.

Best Regards

Ekta

View solution in original post

0 Likes
1 Reply
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @Jdo300 

As discussed, you were able get the I2S mic that you will be using in the final application working.

Kindly let me know if you face any issues with that.

Best Regards

Ekta

0 Likes