2021-05-06 02:15 PM
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "pdm2pcm.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define HSEM_ID_0 (0U) /* HW semaphore 0*/
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
CRC_HandleTypeDef hcrc;
SAI_HandleTypeDef hsai_BlockA1;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SAI1_Init(void);
static void MX_CRC_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* USER CODE BEGIN Boot_Mode_Sequence_0 */
int32_t timeout;
/* USER CODE END Boot_Mode_Sequence_0 */
/* USER CODE BEGIN Boot_Mode_Sequence_1 */
/* Wait until CPU2 boots and enters in stop mode or timeout*/
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
/* USER CODE END Boot_Mode_Sequence_1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN Boot_Mode_Sequence_2 */
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of
HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
HAL_HSEM_FastTake(HSEM_ID_0);
/*Release HSEM in order to notify the CPU2(CM4)*/
HAL_HSEM_Release(HSEM_ID_0,0);
/* wait until CPU2 wakes up from stop mode */
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
/* USER CODE END Boot_Mode_Sequence_2 */
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SAI1_Init();
MX_CRC_Init();
MX_PDM2PCM_Init();
/* USER CODE BEGIN 2 */
volatile shared_data_t * const shared_data = (shared_data_t *)0x38000000;
uint32_t pdmData[16];
int32_t pcmData[16];
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
__HAL_SAI_ENABLE(&hsai_BlockA1);
while (1)
{
HAL_SAI_Receive(&hsai_BlockA1, pdmData, 2, HAL_SAI_ERROR_TIMEOUT);
PDM_Filter(&pdmData[0], &pcmData[0], &PDM1_filter_handler);
share_information_write((shared_data_t*)shared_data, pcmData);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
I am using the STM32CubeIde to initialize it and everything, so all of that is there. I have it set to 1 channel input and output since I am testing only one mic at the moment.
So when I run the code, it get a hard fault when I enter the PDM_Filter function. It gives me a hard fault.
I've tried changing the buffers, pcm/pdm arrays size. I also tried changing them to int16_t and uin16_t. I've looked at other examples. The library seems pretty simple to use, but I'm just stuck on what could be wrong. Are there any verified examples?
Solved! Go to Solution.
2021-05-06 02:45 PM
Seems like you are overrunning the bounds of an array. 0x20020000 is the end of the DTCM, which is where pdmData/pcmData probably exist. How many samples are you processing in each call.
2021-05-06 02:45 PM
Seems like you are overrunning the bounds of an array. 0x20020000 is the end of the DTCM, which is where pdmData/pcmData probably exist. How many samples are you processing in each call.
2021-05-06 04:08 PM
It should only be processing a byte of PDM information and outputting a 16-bit PCM signal at a time, unless I am misreading the application's note.
2021-05-06 04:17 PM
Wait, when I change the output_samples_number it started working. I thought that number was asking for how many bits you wanted the outputted number. Like a 16-bit PCM value. What exactly is 16 samples? Is it just 16 values of the same PCM number?