2024-12-06 10:16 AM
Hello,
I made simpler project, where led is switched on button to represent binary, and there it works. Two RNG values (0-7 and 8-15) are generated and with button press switches between LED binary representation of two RNG values.
I made the same thing in main project and it don't work there. If first RNG number is 6 or 7 it work fine, but 0 to 5 LED dont change to other number.
I debuged it and the values are changing correctly, checked memory in Build Analiser and its fine there too, i have DSP filters there that change to same value and they works fine. What could be the reason why it dont work now.
main project:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "filter_coef.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 */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
I2S_HandleTypeDef hi2s2;
DMA_HandleTypeDef hdma_i2s2_ext_rx;
DMA_HandleTypeDef hdma_spi2_tx;
/* USER CODE BEGIN PV */
uint16_t mode=0;
uint16_t fa=0;
uint32_t f1=0;
uint32_t f2=0;
RNG_HandleTypeDef hrng;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_RNG_Init(void);
static void MX_DMA_Init(void);
static void MX_I2S2_Init(void);
uint16_t rxBuf[8];
uint16_t txBuf[8];
static float firdata1 [FILTER_TAP_NUM1];
static int firptr1 [FILTER_TAP_NUM1];
static int fir_w_ptr1=0;
static float firdata2 [FILTER_TAP_NUM2];
static int firptr2 [FILTER_TAP_NUM2];
static int fir_w_ptr2=0;
static float firdata3 [FILTER_TAP_NUM3];
static int firptr3 [FILTER_TAP_NUM3];
static int fir_w_ptr3=0;
static float firdata4 [FILTER_TAP_NUM4];
static int firptr4 [FILTER_TAP_NUM4];
static int fir_w_ptr4=0;
static float firdata5 [FILTER_TAP_NUM5];
static int firptr5 [FILTER_TAP_NUM5];
static int fir_w_ptr5=0;
static float firdata6 [FILTER_TAP_NUM6];
static int firptr6 [FILTER_TAP_NUM6];
static int fir_w_ptr6=0;
static float firdata9 [FILTER_TAP_NUM9];
static int firptr9 [FILTER_TAP_NUM9];
static int fir_w_ptr9=0;
static float firdata10 [FILTER_TAP_NUM10];
static int firptr10 [FILTER_TAP_NUM10];
static int fir_w_ptr10=0;
static float firdata11 [FILTER_TAP_NUM11];
static int firptr11 [FILTER_TAP_NUM11];
static int fir_w_ptr11=0;
static float firdata12 [FILTER_TAP_NUM12];
static int firptr12 [FILTER_TAP_NUM12];
static int fir_w_ptr12=0;
static float firdata13 [FILTER_TAP_NUM13];
static int firptr13 [FILTER_TAP_NUM13];
static int fir_w_ptr13=0;
static float firdata14 [FILTER_TAP_NUM14];
static int firptr14 [FILTER_TAP_NUM14];
static int fir_w_ptr14=0;
static float firdata15 [FILTER_TAP_NUM15];
static int firptr15 [FILTER_TAP_NUM15];
static int fir_w_ptr15=0;
static float firdata16 [FILTER_TAP_NUM16];
static int firptr16 [FILTER_TAP_NUM16];
static int fir_w_ptr16=0;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_RNG_Init();
MX_I2S2_Init();
HAL_I2SEx_TransmitReceive_DMA (&hi2s2, txBuf, rxBuf, 4);
HAL_RNG_GenerateRandomNumber(&hrng,&f1);
f1=f1%8;
//f2=f1+8;
HAL_RNG_GenerateRandomNumber(&hrng,&f2);
f2=(f2%8)+8;
mode=f1;
while (1)
{
if(mode == 0){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 1){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 2){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 3){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 4){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 5){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 6){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 7){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);}
if(mode == 8){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 9){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 10){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 11){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 12){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 13){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 14){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
if(mode == 15){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);}
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
fa=fa+1;
if(fa>1)
fa=0;
if(fa==0)
mode=f1;
if(fa==1)
mode=f2;
}
int Calc_FIR1 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM1; i++) {
outdata += (firdata1[i]*filter_taps1[firptr1[i]]);
firptr1[i]++;
}
firdata1[fir_w_ptr1] = inSampleF;
firptr1[fir_w_ptr1] = 0;
fir_w_ptr1++;
if (fir_w_ptr1 == FILTER_TAP_NUM1) fir_w_ptr1=0;
return (int) outdata;
}
int Calc_FIR2 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM2; i++) {
outdata += (firdata2[i]*filter_taps2[firptr2[i]]);
firptr2[i]++;
}
firdata2[fir_w_ptr2] = inSampleF;
firptr2[fir_w_ptr2] = 0;
fir_w_ptr2++;
if (fir_w_ptr2 == FILTER_TAP_NUM2) fir_w_ptr2=0;
return (int) outdata;
}
int Calc_FIR3 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM3; i++) {
outdata += (firdata3[i]*filter_taps3[firptr3[i]]);
firptr3[i]++;
}
firdata3[fir_w_ptr3] = inSampleF;
firptr3[fir_w_ptr3] = 0;
fir_w_ptr3++;
if (fir_w_ptr3 == FILTER_TAP_NUM3) fir_w_ptr3=0;
return (int) outdata;
}
int Calc_FIR4 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM4; i++) {
outdata += (firdata4[i]*filter_taps4[firptr4[i]]);
firptr4[i]++;
}
firdata4[fir_w_ptr4] = inSampleF;
firptr4[fir_w_ptr4] = 0;
fir_w_ptr4++;
if (fir_w_ptr4 == FILTER_TAP_NUM4) fir_w_ptr4=0;
return (int) outdata;
}
int Calc_FIR5 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM5; i++) {
outdata += (firdata5[i]*filter_taps5[firptr5[i]]);
firptr5[i]++;
}
firdata5[fir_w_ptr5] = inSampleF;
firptr5[fir_w_ptr5] = 0;
fir_w_ptr5++;
if (fir_w_ptr5 == FILTER_TAP_NUM5) fir_w_ptr5=0;
return (int) outdata;
}
int Calc_FIR6 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM6; i++) {
outdata += (firdata6[i]*filter_taps6[firptr6[i]]);
firptr6[i]++;
}
firdata6[fir_w_ptr6] = inSampleF;
firptr6[fir_w_ptr6] = 0;
fir_w_ptr6++;
if (fir_w_ptr6 == FILTER_TAP_NUM6) fir_w_ptr6=0;
return (int) outdata;
}
/*
int Calc_FIR7 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM7; i++) {
outdata += (firdata7[i]*filter_taps7[firptr7[i]]);
firptr7[i]++;
}
firdata7[fir_w_ptr7] = inSampleF;
firptr7[fir_w_ptr7] = 0;
fir_w_ptr7++;
if (fir_w_ptr7 == FILTER_TAP_NUM7) fir_w_ptr7=0;
return (int) outdata;
}
int Calc_FIR8 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM8; i++) {
outdata += (firdata8[i]*filter_taps8[firptr8[i]]);
firptr8[i]++;
}
firdata8[fir_w_ptr8] = inSampleF;
firptr8[fir_w_ptr8] = 0;
fir_w_ptr8++;
if (fir_w_ptr8 == FILTER_TAP_NUM8) fir_w_ptr8=0;
return (int) outdata;
}
*/
int Calc_FIR9 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM9; i++) {
outdata += (firdata9[i]*filter_taps9[firptr9[i]]);
firptr9[i]++;
}
firdata9[fir_w_ptr9] = inSampleF;
firptr9[fir_w_ptr9] = 0;
fir_w_ptr9++;
if (fir_w_ptr9 == FILTER_TAP_NUM9) fir_w_ptr9=0;
return (int) outdata;
}
int Calc_FIR10 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM10; i++) {
outdata += (firdata10[i]*filter_taps10[firptr10[i]]);
firptr10[i]++;
}
firdata10[fir_w_ptr10] = inSampleF;
firptr10[fir_w_ptr10] = 0;
fir_w_ptr10++;
if (fir_w_ptr10 == FILTER_TAP_NUM10) fir_w_ptr10=0;
return (int) outdata;
}
int Calc_FIR11 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM11; i++) {
outdata += (firdata11[i]*filter_taps11[firptr11[i]]);
firptr11[i]++;
}
firdata11[fir_w_ptr11] = inSampleF;
firptr11[fir_w_ptr11] = 0;
fir_w_ptr11++;
if (fir_w_ptr11 == FILTER_TAP_NUM11) fir_w_ptr11=0;
return (int) outdata;
}
int Calc_FIR12 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM12; i++) {
outdata += (firdata12[i]*filter_taps12[firptr12[i]]);
firptr12[i]++;
}
firdata12[fir_w_ptr12] = inSampleF;
firptr12[fir_w_ptr12] = 0;
fir_w_ptr12++;
if (fir_w_ptr12 == FILTER_TAP_NUM12) fir_w_ptr12=0;
return (int) outdata;
}
int Calc_FIR13 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM13; i++) {
outdata += (firdata13[i]*filter_taps13[firptr13[i]]);
firptr13[i]++;
}
firdata13[fir_w_ptr13] = inSampleF;
firptr13[fir_w_ptr13] = 0;
fir_w_ptr13++;
if (fir_w_ptr13 == FILTER_TAP_NUM13) fir_w_ptr13=0;
return (int) outdata;
}
int Calc_FIR14 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM14; i++) {
outdata += (firdata14[i]*filter_taps14[firptr14[i]]);
firptr14[i]++;
}
firdata14[fir_w_ptr14] = inSampleF;
firptr14[fir_w_ptr14] = 0;
fir_w_ptr14++;
if (fir_w_ptr14 == FILTER_TAP_NUM14) fir_w_ptr14=0;
return (int) outdata;
}
int Calc_FIR15 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM15; i++) {
outdata += (firdata15[i]*filter_taps15[firptr15[i]]);
firptr15[i]++;
}
firdata15[fir_w_ptr15] = inSampleF;
firptr15[fir_w_ptr15] = 0;
fir_w_ptr15++;
if (fir_w_ptr15 == FILTER_TAP_NUM15) fir_w_ptr15=0;
return (int) outdata;
}
int Calc_FIR16 (int inSample) {
float inSampleF = (float)inSample;
float outdata = 0;
for (int i=0;i < FILTER_TAP_NUM16; i++) {
outdata += (firdata16[i]*filter_taps16[firptr16[i]]);
firptr16[i]++;
}
firdata16[fir_w_ptr16] = inSampleF;
firptr16[fir_w_ptr16] = 0;
fir_w_ptr16++;
if (fir_w_ptr16 == FILTER_TAP_NUM16) fir_w_ptr16=0;
return (int) outdata;
}
int Calc_IIR_Left (int inSample) {
float inSampleF = (float)inSample;
float outSampleF =
l_a0 * inSampleF
+ l_a1 * lin_z1
+ l_a2 * lin_z2
- l_b1 * lout_z1
- l_b2 * lout_z2;
lin_z2 = lin_z1;
lin_z1 = inSampleF;
lout_z2 = lout_z1;
lout_z1 = outSampleF;
return (int) outSampleF;
}
int Calc_IIR_Right (int inSample) {
float inSampleF = (float)inSample;
float outSampleF =
r_a0 * inSampleF
+ r_a1 * rin_z1
+ r_a2 * rin_z2
- r_b1 * rout_z1
- r_b2 * rout_z2;
rin_z2 = rin_z1;
rin_z1 = inSampleF;
rout_z2 = rout_z1;
rout_z1 = outSampleF;
return (int) outSampleF;
}
void HAL_I2SEx_TxRxHalfCpltCallback(I2S_HandleTypeDef *hi2s){
//restore signed 24 bit sample from 16-bit buffers
int lSample = (int) (rxBuf[0]<<16)|rxBuf[1];
int rSample = (int) (rxBuf[2]<<16)|rxBuf[3];
// divide by 2 (rightshift) -> -6dB per sample
lSample = lSample>>1;
rSample = rSample>>1;
//sum to mono
lSample = rSample + lSample;
/*
//run HP on left channel and LP on right channel
lSample = Calc_FIR(lSample);
*/
if(mode == 0)
lSample = Calc_FIR1(lSample);
if(mode == 1)
lSample = Calc_FIR2(lSample);
if(mode == 2)
lSample = Calc_FIR3(lSample);
if(mode == 3)
lSample = Calc_FIR4(lSample);
if(mode == 4)
lSample = Calc_FIR5(lSample);
if(mode == 5)
lSample = Calc_FIR6(lSample);
if(mode == 6)
lSample = Calc_IIR_Left(lSample);
if(mode == 7)
lSample = Calc_IIR_Right(lSample);
if(mode == 8)
lSample = Calc_FIR9(lSample);
if(mode == 9)
lSample = Calc_FIR10(lSample);
if(mode == 10)
lSample = Calc_FIR11(lSample);
if(mode == 11)
lSample = Calc_FIR12(lSample);
if(mode == 12)
lSample = Calc_FIR13(lSample);
if(mode == 13)
lSample = Calc_FIR14(lSample);
if(mode == 14)
lSample = Calc_FIR15(lSample);
if(mode == 15)
lSample = Calc_FIR16(lSample);
//restore to buffer
txBuf[0] = (lSample>>16)&0xFFFF;
txBuf[1] = lSample&0xFFFF;
txBuf[2] = (lSample>>16)&0xFFFF;
txBuf[3] = lSample&0xFFFF;
}
void HAL_I2SEx_TxRxCpltCallback(I2S_HandleTypeDef *hi2s){
//restore signed 24 bit sample from 16-bit buffers
int lSample = (int) (rxBuf[4]<<16)|rxBuf[5];
int rSample = (int) (rxBuf[6]<<16)|rxBuf[7];
// divide by 2 (rightshift) -> -6dB per sample
lSample = lSample>>1;
rSample = rSample>>1;
//sum to mono
lSample = rSample + lSample;
/*
//run HP on left channel and LP on right channel
lSample = Calc_FIR(lSample);
*/
if(mode == 0)
lSample = Calc_FIR1(lSample);
if(mode == 1)
lSample = Calc_FIR2(lSample);
if(mode == 2)
lSample = Calc_FIR3(lSample);
if(mode == 3)
lSample = Calc_FIR4(lSample);
if(mode == 4)
lSample = Calc_FIR5(lSample);
if(mode == 5)
lSample = Calc_FIR6(lSample);
if(mode == 6)
lSample = Calc_IIR_Left(lSample);
if(mode == 7)
lSample = Calc_IIR_Right(lSample);
if(mode == 8)
lSample = Calc_FIR9(lSample);
if(mode == 9)
lSample = Calc_FIR10(lSample);
if(mode == 10)
lSample = Calc_FIR11(lSample);
if(mode == 11)
lSample = Calc_FIR12(lSample);
if(mode == 12)
lSample = Calc_FIR13(lSample);
if(mode == 13)
lSample = Calc_FIR14(lSample);
if(mode == 14)
lSample = Calc_FIR15(lSample);
if(mode == 15)
lSample = Calc_FIR16(lSample);
//restore to buffer
txBuf[4] = (lSample>>16)&0xFFFF;
txBuf[5] = lSample&0xFFFF;
txBuf[6] = (lSample>>16)&0xFFFF;
txBuf[7] = lSample&0xFFFF;
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
Error_Handler();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;//96 kHz 192 -2,34% 197+0,23% 196-0,36%
PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief I2S2 Initialization Function
* @PAram None
* @retval None
*/
static void MX_I2S2_Init(void)
{
/* USER CODE BEGIN I2S2_Init 0 */
/* USER CODE END I2S2_Init 0 */
/* USER CODE BEGIN I2S2_Init 1 */
/* USER CODE END I2S2_Init 1 */
hi2s2.Instance = SPI2;
hi2s2.Init.Mode = I2S_MODE_MASTER_TX;
hi2s2.Init.Standard = I2S_STANDARD_PHILIPS;
hi2s2.Init.DataFormat = I2S_DATAFORMAT_24B;
hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_48K;
hi2s2.Init.CPOL = I2S_CPOL_LOW;
hi2s2.Init.ClockSource = I2S_CLOCK_PLL;
hi2s2.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_ENABLE;
if (HAL_I2S_Init(&hi2s2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2S2_Init 2 */
/* USER CODE END I2S2_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Stream3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);
/* DMA1_Stream4_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);
}
/**
* @brief GPIO Initialization Function
* @PAram None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
|GPIO_PIN_4, GPIO_PIN_RESET);
/*Configure GPIO pin : PE3 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pin : PC0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PA4 */
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PA5 PA6 PA7 */
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PB2 */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : PD12 PD13 PD14 PD15
PD4 */
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
|GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pins : PC7 PC10 PC12 */
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_10|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PA9 */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PA10 PA11 PA12 */
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PD5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pins : PB6 PB9 */
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : PE1 */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
}
// @brief RNG Initialization Function
static void MX_RNG_Init(void)
{
/* USER CODE BEGIN RNG_Init 0 */
/* USER CODE END RNG_Init 0 */
/* USER CODE BEGIN RNG_Init 1 */
/* USER CODE END RNG_Init 1 */
hrng.Instance = RNG;
if (HAL_RNG_Init(&hrng) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RNG_Init 2 */
/* USER CODE END RNG_Init 2 */
}
void HAL_RNG_MspInit(RNG_HandleTypeDef* hrng)
{
if(hrng->Instance==RNG)
{
/* USER CODE BEGIN RNG_MspInit 0 */
/* USER CODE END RNG_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_RNG_CLK_ENABLE();
/* USER CODE BEGIN RNG_MspInit 1 */
/* USER CODE END RNG_MspInit 1 */
}
}
/**
* @brief RNG MSP De-Initialization
* This function freeze the hardware resources used in this example
* @PAram hrng: RNG handle pointer
* @retval None
*/
void HAL_RNG_MspDeInit(RNG_HandleTypeDef* hrng)
{
if(hrng->Instance==RNG)
{
/* USER CODE BEGIN RNG_MspDeInit 0 */
/* USER CODE END RNG_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RNG_CLK_DISABLE();
/* USER CODE BEGIN RNG_MspDeInit 1 */
/* USER CODE END RNG_MspDeInit 1 */
}
}
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @PAram file: pointer to the source file name
* @PAram line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2024-12-06 10:26 AM
Variables you change in interrupt/callback will need to be volatile
You could check the LED code by cycling through the mode value with a delay.
2024-12-06 10:50 AM - edited 2024-12-06 10:51 AM
Changing to volatile dont help, i dont think it is a issue because value are changing, changing filter work, but the same variable dont work with LED.
LED cycling dont work too, but it work in fresh project.
2024-12-06 11:10 AM
So is it ending up in the Error_Handler() or HardFault_Handler() ?
Have you checked the GPIOD initialization / register in the debugger?
Unfortunately "Not Working" is not an unduly helpful observation, you'll have to dig into WHY
Break the problem down. Put sections onto their own functions. Do the cycling test, then investigate why the changing doesn't work.
Make sure it's not stuck in an interrupt storm, where the main() loop never gets to execute.
2024-12-06 12:29 PM
I left only 2 filters calculations functions out of 16 and it works now.
But i need to have 16 filters.