cancel
Showing results for 
Search instead for 
Did you mean: 

BSP_AUDIO_IN_Record() issues on SensorTile

David Heise
Associate
Posted on June 21, 2018 at 18:53

I am running into a roadblock working with BSP_AUDIO_IN_Record().

Overarching goal is to record audio from the MEMS microphone while also monitoring other (environmental) sensor data --- then record audio to one file, sensor data to another.

I have two separate, working programs --- one that records audio to the SD card, and another that records environmental sensor data to the SD card.  I am trying to incrementally combine these.

At this juncture, I have been working from the DataLog sample and am adding the audio pieces one by one.  I have found though, that BSP_AUDIO_IN_Record() causes the program to lock at the next function call.  For instance, after calling BSP_AUDIO_IN_Record(), I can't even make a call to BSP_LED_On() without the program stalling.

I have carefully reviewed the differences between the datalog_application.c files, associated header files, and so on, and I can't determine the cause.  This is especially boggling because I am executing the same calls as my working code to write audio to the SD card.

As one added piece of info, though, trying to add sensor monitoring (in particular, the gas gauge) to the working audio recording program (rather than starting from DataLog) seemed to produce the same result.  I restarted development working from DataLog, however, so I have not explored that angle quite as much.

Is there some fundamental restriction I am missing?  I know accelerometer data can be monitored with audio recording, as the double-tap was used to trigger recording on/off in the working program.  Is there something with DMA transfer of the audio that I'm missing?  Is is something with the gas gauge?

I appreciate any pointers or information anyone can provide.  Here is the beginning of my main() function:

==========

/* BEGIN main() */

int main( void )

{

  uint32_t msTick, msTickPrev = 0;

  uint8_t doubleTap = 0;

  uint32_t soc;

  uint32_t seconds = 0;

 

  /* STM32L4xx HAL library initialization:

  - Configure the Flash prefetch, instruction and Data caches

  - Configure the Systick to generate an interrupt each 1 msec

  - Set NVIC Group Priority to 4

  - Global MSP (MCU Support Package) initialization

  */

  HAL_Init();

 

  /* Configure the system clock */

  SystemClock_Config();

 

  if(SendOverUSB)

  {

    /* Initialize LED */

    BSP_LED_Init(LED1);

    BSP_LED_On(LED1);

  }

#ifdef NOT_DEBUGGING     

  else

  {

    /* Initialize LEDSWD: Cannot be used during debug because it overrides SWDCLK pin configuration */

    BSP_LED_Init(LEDSWD);

    BSP_LED_Off(LEDSWD);

  }

#endif

 

  /* Initialize RTC */

  RTC_Config();

  RTC_TimeStampConfig();

 

  /* enable USB power on Pwrctrl CR2 register */

  HAL_PWREx_EnableVddUSB();

 

  if(SendOverUSB) /* Configure the USB */

  {

    /*** USB CDC Configuration ***/

    /* Init Device Library */

    USBD_Init(&USBD_Device, &VCP_Desc, 0);

    /* Add Supported Class */

    USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS);

    /* Add Interface callbacks for AUDIO and CDC Class */

    USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);

    /* Start Device Process */

    USBD_Start(&USBD_Device);

  }

  /* modification by D. Heise */

  /* else removed -- always init SD card */

  DATALOG_SD_Init();

  HAL_Delay(200);

 

  /* Configure and disable all the Chip Select pins */

  Sensor_IO_SPI_CS_Init_All();

 

  /* Initialize and Enable the available sensors */

  initializeAllSensors();

  enableAllSensors();

 

  /* next six lines added by D. Heise for audio */

  BSP_LED_Init(LED1);

 /* BSP_LED_On(LED1);

  HAL_Delay(200);

  BSP_LED_Off(LED1); */

  /* Added by D. Heise */

  /* Enable (audio) logging */

  /**** will add momentarily, just environ sensors for now ****/

  while (SD_Log_Enabled != 1)

  {

      if (DATALOG_SD_Log_Enable())

      {

          SD_Log_Enabled = 1;

      }

      else

      {

          DATALOG_SD_Log_Disable();

          /*DATALOG_SD_DeInit();*/

          DATALOG_SD_Init();

      }

  }

  /* Check battery */

  soc= Gas_Gauge_Handler_return_soc( GG_handle );

  while (BSP_AUDIO_IN_Init(AUDIO_SAMPLING_FREQUENCY, 16, AUDIO_CHANNELS) != AUDIO_OK)

   {

       BSP_LED_On(LED1);

       HAL_Delay(500);

       BSP_LED_Off(LED1);

   }

   while (BSP_AUDIO_IN_Record(PCM_Buffer, 0) != AUDIO_OK)

   {

       BSP_LED_On(LED1);

       HAL_Delay(500);

       BSP_LED_Off(LED1);

   }

  while (soc > 1)

  {

    if (SD_Log_Enabled)

    {

            BSP_LED_On(LED1);    /* PROGRAM STALLS HERE */

            HAL_Delay(500);

            BSP_LED_Off(LED1);

    }

    /* Get sysTick value and check if it's time to execute the task */

    msTick = HAL_GetTick();

/* END CODE SNIPPET --- main() continues */

==========

Note that SendOverUSB is set to 0, as I am interested in writing to the SD card.  The program stalls, though, without respect to the SD card.  If I comment the datalog enable and gas gauge check, I get the same result, leading me to believe it has to do with BSP_AUDIO_IN_Record().  Commenting BSP_AUDIO_IN_Record() allows everything else to work.

Thanks again for any guidance.

3 REPLIES 3
David Heise
Associate
Posted on June 22, 2018 at 05:37

Update:  I have made *significant* progress on my overarching goal.  I changed course and made revisions to the code which recorded audio to the SD card.  This proved to be much more fruitful than trying to modify the stock DataLog example.  Thus, perhaps with some limitations, I can now record both audio and environmental sensor data to separate files.

I am still curious about the reason(s) why the code above does not work, so if anyone has ideas I will be glad to learn.

Davide G
ST Employee

Hi David,

When you modified the stock DataLog example to add Audio, did you also add the DFSDM IRQ Handler to the "stm32l4xx_it.c" file?

Should be something like this:

/**
  * @brief This function handles DFSDM Left DMAinterrupt request.
  * @param None
  * @retval None
  */
void AUDIO_IN_DFSDM_DMA_1st_CH_IRQHandler(void)
{ 
  HAL_DMA_IRQHandler(&hdma_dfsdmReg_FLT[0]);
}

Davide

Frank W
Associate II

I am trying to change the sample rate in the Datalog_Audio example from 16k to 22k but without success. I tried it by just changing the #define AUDIO_SAMPLING_FREQUENCY. It is writing data to WAV-Files but they are wrong in length and sound very strange (too slow). If i try to change the sample rate up to 44k i dont hear any sound in the WAV-Files generated.

Do you have any hint what else i have to adapt in order to change the sample rate ?