2019-04-17 08:45 PM
Hi,
I am working on STM32F412G Discovery Board to capture audio data from Digital MEMS. For that, I've found an example in the below path
STM32Cube_FW_F4_V1.24.0\Projects\STM32F412GDiscovery\Examples\DFSDM\DFSDM_AudioRecord\.
But I want to write the mic captured data into a file in order to analyze the data characteristics. I tried to insert FILE operations in the above example but getting some HardFault_Handler interrupt. Can somebody help me to sort out this problem.
In below lines, you can found the implementation
while(1)
{
if((DmaLeftRecHalfBuffCplt == 1) && (DmaRightRecHalfBuffCplt == 1))
{
/* Store values on Play buff */
for(i = 0; i < 1024; i++)
{
PlayBuff[2*i] = 0;
PlayBuff[(2*i)+1] = SaturaLH((RightRecBuff[i] >> 8), -32768, 32767);
}
f_write(&Wav_File, file_buffer, 2048*2, (void*)&byteswritten);
if(PlaybackStarted == 0)
{
if(0 != audio_drv->Play(AUDIO_I2C_ADDRESS, (uint16_t *) &PlayBuff[0], 4096))
{
Error_Handler();
}
if(HAL_OK != HAL_I2S_Transmit_DMA(&haudio_i2s, (uint16_t *) &PlayBuff[0], 4096))
{
Error_Handler();
}
PlaybackStarted = 1;
}
DmaLeftRecHalfBuffCplt = 0;
DmaRightRecHalfBuffCplt = 0;
}
if((DmaLeftRecBuffCplt == 1) && (DmaRightRecBuffCplt == 1))
{
/* Store values on Play buff */
for(i = 1024; i < 2048; i++)
{
PlayBuff[2*i] = 0;
PlayBuff[(2*i)+1] = SaturaLH((RightRecBuff[i] >> 8), -32768, 32767);
}
DmaLeftRecBuffCplt = 0;
DmaRightRecBuffCplt = 0;
}
}
trying to write data in the file in the same loop where it is copying to playbuff.
Thanks in advance.
regards,
Jayakanth
2019-04-17 09:15 PM
>>..getting some HardFault_Handler interrupt. Can somebody help me to sort out this problem.
Get yourself a proper handler that outputs usable information, and chase the issue down. You're look at the registers, and the code disassembly of the faulting and surrounding instructions.
I've posted Hard Fault Handlers based on Joseph Yiu's examples to the forum several times, perhaps use one of those.
For FatFs make sure you have an adequate stack. Figure at least 4KB