From 7c635c0eded938d6eabf329074a724f5113c0a90 Mon Sep 17 00:00:00 2001 From: duembgen Date: Wed, 21 Apr 2021 15:24:09 +0200 Subject: [PATCH 1/5] Add buffer reading --- .../audio_shield_firmware/Core/Src/main.c | 28 +++++++++++-------- .../audio_shield_firmware/Debug/sources.mk | 1 - 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/firmware/audio_shield_firmware/Core/Src/main.c b/firmware/audio_shield_firmware/Core/Src/main.c index 8bb880eb..cac78c33 100644 --- a/firmware/audio_shield_firmware/Core/Src/main.c +++ b/firmware/audio_shield_firmware/Core/Src/main.c @@ -164,8 +164,10 @@ typedef enum { NOTE_WAIT_START, NOTE_WAIT, NOTE_RESET, NOTE_NEXT_NOTE } state_note_t; +uint8_t spi_counter = 0; +#define N_SPI_PER_NOTE 50 + uint8_t flag_spi_recieved = 0; -uint8_t flag_reset_average = 0; uint32_t note_tickstart; uint16_t note_index = 0; @@ -368,6 +370,7 @@ int main(void) { #ifdef USE_TEST_SIGNALS new_sample_to_process = 1; #endif + read_rx_buffer(); // Start and stop condition detection if (buzzer_freq_idx != buzzer_freq_idx_old) { @@ -390,7 +393,6 @@ int main(void) { break; case NOTE_NEXT_NOTE: - flag_reset_average = 1; HAL_TIM_Base_Init(&htim5); piezoSetMaxCount(freq_list_tim[note_index].ARR); piezoSetRatio(freq_list_tim[note_index].ARR / 2); @@ -445,7 +447,7 @@ int main(void) { frequency_bin_selection(selected_indices); #if 1 // Averaging between SPI communications - uint8_t i_array = 0; + uint16_t i_array = 0; for (int i_fbin = 0; i_fbin < FFTSIZE_SENT; i_fbin++) { mics_f_avg[i_array] += mic0_f[2 * selected_indices[i_fbin]]; i_array += 1; mics_f_avg[i_array] += mic1_f[2 * selected_indices[i_fbin]]; i_array += 1; @@ -477,13 +479,17 @@ int main(void) { if (flag_spi_recieved) { flag_spi_recieved = 0; - note_index++; - if (note_index == NOTE_SEQUENCE_LENGTH) { - state_note_sm = NOTE_WAIT_START; - memset(&mics_f_avg, 0, sizeof(mics_f_avg)); - - } else { - state_note_sm = NOTE_NEXT_NOTE; + spi_counter++; + if (spi_counter == N_SPI_PER_NOTE) { + spi_counter = 0; + note_index++; + if (note_index == NOTE_SEQUENCE_LENGTH) { + state_note_sm = NOTE_WAIT_START; + memset(&mics_f_avg, 0, sizeof(mics_f_avg)); + + } else { + state_note_sm = NOTE_NEXT_NOTE; + } } } #endif @@ -1241,7 +1247,7 @@ void read_rx_buffer() { min_freq = param_array[N_MOTORS]; max_freq = param_array[N_MOTORS + 1]; - //buzzer_freq_idx = param_array[N_MOTORS + 2]; + buzzer_freq_idx = param_array[N_MOTORS + 2]; delta_freq = param_array[N_MOTORS + 3]; n_average = param_array[N_MOTORS + 4]; filter_prop_enable = param_array[N_MOTORS + 5]; diff --git a/firmware/audio_shield_firmware/Debug/sources.mk b/firmware/audio_shield_firmware/Debug/sources.mk index 282583f6..4c1aa9ff 100644 --- a/firmware/audio_shield_firmware/Debug/sources.mk +++ b/firmware/audio_shield_firmware/Debug/sources.mk @@ -1,6 +1,5 @@ ################################################################################ # Automatically-generated file. Do not edit! -# Toolchain: GNU Tools for STM32 (9-2020-q2-update) ################################################################################ ELF_SRCS := From fbd65c070b6da3ef60a0d0b886e9bd6984e3ece8 Mon Sep 17 00:00:00 2001 From: duembgen Date: Wed, 21 Apr 2021 15:34:21 +0200 Subject: [PATCH 2/5] Revert more changes --- .../audio_shield_firmware/Core/Src/main.c | 75 ++----------------- 1 file changed, 8 insertions(+), 67 deletions(-) diff --git a/firmware/audio_shield_firmware/Core/Src/main.c b/firmware/audio_shield_firmware/Core/Src/main.c index cac78c33..5b5bff1e 100644 --- a/firmware/audio_shield_firmware/Core/Src/main.c +++ b/firmware/audio_shield_firmware/Core/Src/main.c @@ -72,11 +72,8 @@ #define DF (32000.0f/FFTSIZE) #define IIR_ALPHA 0.5 // set to 1 for no effect (equivalent to removing IIR_FILTERING flag) -// cannot use both below flags at the same time -//#define USE_TEST_SIGNALS // set this to use test signals instead of real audio data. make sure SPI_N_BYTES MATCHES! - // communication -// in uint16, min_freq, max_freq, buzzer_freq_idx, n_average, delta_freq, snr_enable, propeller_enable, window, tot = 8 +// in uint16, min_freq, max_freq, buzzer_idx, n_average, delta_freq, snr_enable, propeller_enable, window, tot = 8 #define PARAMS_N_INT16 (N_MOTORS + 8) #define CHECKSUM_VALUE (0xAC) @@ -119,16 +116,10 @@ TIM_HandleTypeDef htim5; int16_t dma_1[FULL_BUFFER_SIZE]; int16_t dma_3[FULL_BUFFER_SIZE]; -#ifndef USE_TEST_SIGNALS float mic0[N_ACTUAL_SAMPLES]; float mic2[N_ACTUAL_SAMPLES]; float mic1[N_ACTUAL_SAMPLES]; float mic3[N_ACTUAL_SAMPLES]; -#else -//#include "real_data_1024.h" -#include "simulated_data_1024.h" -//#include "real_data_32.h" -#endif #include "hann_window.h" #include "tukey_window.h" @@ -189,8 +180,8 @@ uint16_t filter_snr_enable = 3; uint16_t window_type = 0; // windowing scheme, 0: none, 1: hann, 2: flattop, 3: tukey(0.2) uint16_t min_freq = 0; uint16_t max_freq = 0; -uint16_t buzzer_freq_idx = 0; -uint16_t buzzer_freq_idx_old = 0; +uint16_t buzzer_idx = 0; +uint16_t buzzer_idx_old = 0; uint16_t delta_freq = 100; uint16_t n_average = 1; // number of frequency bins to average. @@ -241,8 +232,6 @@ void fill_tx_buffer(); void read_rx_buffer(); int compare_amplitudes(const void *a, const void *b); float abs_value_squared(float real_imag[]); -void uint32_to_byte_array(uint32_t input, uint8_t output[]); -void float_to_byte_array(float input, uint8_t output[]); /* USER CODE END PFP */ @@ -250,23 +239,19 @@ void float_to_byte_array(float input, uint8_t output[]); /* USER CODE BEGIN 0 */ void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { -#ifndef USE_TEST_SIGNALS if (hi2s->Instance == hi2s1.Instance) { process(dma_1, mic3, mic2, N_ACTUAL_SAMPLES); } else { process(dma_3, mic1, mic0, N_ACTUAL_SAMPLES); } -#endif } void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) { -#ifndef USE_TEST_SIGNALS if (hi2s->Instance == hi2s1.Instance) { process(&dma_1[HALF_BUFFER_SIZE], mic3, mic2, N_ACTUAL_SAMPLES); } else { process(&dma_3[HALF_BUFFER_SIZE], mic1, mic0, N_ACTUAL_SAMPLES); } -#endif } void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) { @@ -366,20 +351,16 @@ int main(void) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - -#ifdef USE_TEST_SIGNALS - new_sample_to_process = 1; -#endif read_rx_buffer(); // Start and stop condition detection - if (buzzer_freq_idx != buzzer_freq_idx_old) { - if (buzzer_freq_idx == 0) { + if (buzzer_idx != buzzer_idx_old) { + if (buzzer_idx == 0) { state_note_sm = NOTE_WAIT_START; } else { state_note_sm = NOTE_RESET; } - buzzer_freq_idx_old = buzzer_freq_idx; + buzzer_idx_old = buzzer_idx; } switch (state_note_sm) { @@ -1186,8 +1167,6 @@ void fill_tx_buffer() { // m1_real[N], m2_real[N], m3_real[N], m4_real[N], m1_imag[N], m2_imag[N], m3_imag[N], m4_imag[N]] // where N is FFTSIZE_SENT-1 -#if 1 - for (int i = 0; i < 4 * 2 * FFTSIZE_SENT; i++) { mics_f_avg[i] /= f_avg_counter; } @@ -1196,41 +1175,12 @@ void fill_tx_buffer() { i_array = sizeof(mics_f_avg); -#else - - float_to_byte_array(mic0_f[2 * selected_indices[i_fbin]], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic1_f[2 * selected_indices[i_fbin]], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic2_f[2 * selected_indices[i_fbin]], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic3_f[2 * selected_indices[i_fbin]], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic0_f[2 * selected_indices[i_fbin] + 1], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic1_f[2 * selected_indices[i_fbin] + 1], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic2_f[2 * selected_indices[i_fbin] + 1], - &spi_tx_buffer[i_array]); - i_array += 4; - float_to_byte_array(mic3_f[2 * selected_indices[i_fbin] + 1], - &spi_tx_buffer[i_array]); - i_array += 4; - } -#endif - // Fill with bins indices memcpy(&spi_tx_buffer[i_array], selected_indices, sizeof(selected_indices)); i_array += sizeof(selected_indices); // Fill with timestamp - uint32_to_byte_array(timestamp, &spi_tx_buffer[i_array]); + memcpy(&spi_tx_buffer[i_array], ×tamp, sizeof(timestamp)); i_array += sizeof(timestamp); assert(i_array == SPI_N_BYTES - 1); @@ -1247,7 +1197,7 @@ void read_rx_buffer() { min_freq = param_array[N_MOTORS]; max_freq = param_array[N_MOTORS + 1]; - buzzer_freq_idx = param_array[N_MOTORS + 2]; + buzzer_idx = param_array[N_MOTORS + 2]; delta_freq = param_array[N_MOTORS + 3]; n_average = param_array[N_MOTORS + 4]; filter_prop_enable = param_array[N_MOTORS + 5]; @@ -1290,15 +1240,6 @@ float abs_value_squared(float real_imag[]) { return (real_imag[0] * real_imag[0] + real_imag[1] * real_imag[1]); } -void float_to_byte_array(float input, uint8_t output[]) { - uint32_t temp = *((uint32_t*) &input); - memcpy(output, &temp, sizeof(temp)); -} - -void uint32_to_byte_array(uint32_t input, uint8_t output[]) { - memcpy(output, &input, sizeof(input)); -} - /* USER CODE END 4 */ /** From bdd11fbc455c89acce76d6f20736ffdba3d26408 Mon Sep 17 00:00:00 2001 From: duembgen Date: Thu, 22 Apr 2021 12:20:42 +0200 Subject: [PATCH 3/5] Adapt to new state machine --- .../audio_shield_firmware/Core/Inc/sound.h | 69 ++ .../audio_shield_firmware/Core/Src/main.c | 253 ++++---- .../audio_shield_firmware/Debug/sources.mk | 1 + .../audio_shield_firmware.ioc | 587 +++++++++--------- 4 files changed, 497 insertions(+), 413 deletions(-) create mode 100644 firmware/audio_shield_firmware/Core/Inc/sound.h diff --git a/firmware/audio_shield_firmware/Core/Inc/sound.h b/firmware/audio_shield_firmware/Core/Inc/sound.h new file mode 100644 index 00000000..8859386e --- /dev/null +++ b/firmware/audio_shield_firmware/Core/Inc/sound.h @@ -0,0 +1,69 @@ +#ifndef __SOUND_H +#define __SOUND_H + + +#define STOP -1 +#define REPEAT -2 +#define BUZZER_ARR 256 + +typedef const struct { + uint16_t f; + uint16_t PSC; + uint16_t ARR; + uint32_t ERR; +} freq_list_t; + +typedef const struct { + uint16_t index; + int16_t* notes; +} melody; + + +freq_list_t freq_list_tim[] = { + {3000, 26, 1038, 35 }, + {3125, 0, 26879, 0 }, + {3250, 70, 363, 86 }, + {3375, 407, 60, 36 }, + {3500, 0, 23999, 0 }, + {3625, 46, 492, 61 }, + {3750, 0, 22399, 0 }, + {3875, 52, 408, 19 }, + {4000, 0, 20999, 0 }, + {4125, 10, 1850, 12 }, + {4250, 35, 548, 36 }, + {4375, 0, 19199, 0 }, + {4500, 17, 1036, 36 }, + {4625, 2017, 8, 9 }, + {4750, 1359, 12, 125 }, + {4875, 3445, 4, 45 } +}; +/* +freq_list_t freq_list_tim[] = { + {3010, 109, 256, -10}, + {3125, 105, 256, 0}, + {3249, 101, 256, 1}, + {3383, 97, 256, -8}, + {3491, 94, 256, 9}, + {3606, 91, 256, 19}, + {3729, 88, 256, 21}, + {3860, 85, 256, 15}, + {4002, 82, 256, -2}, + {4102, 80, 256, 23}, + {4261, 77, 256, -11}, + {4375, 75, 256, 0}, + {4495, 73, 256, 5}, + {4621, 71, 256, 4}, + {4755, 69, 256, -5}, + {4825, 68, 256, 50}, +}; +*/ + +int16_t sweep[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, REPEAT}; +int16_t mono3000[] = {0, REPEAT}; + +melody melodies[] = { + {1, sweep}, + {3000, mono3000} +}; + +#endif /* __SOUND_H */ diff --git a/firmware/audio_shield_firmware/Core/Src/main.c b/firmware/audio_shield_firmware/Core/Src/main.c index 5b5bff1e..6814358f 100644 --- a/firmware/audio_shield_firmware/Core/Src/main.c +++ b/firmware/audio_shield_firmware/Core/Src/main.c @@ -31,6 +31,7 @@ #include "flattop_window.h" #include "tukey_window.h" #include "buzzer.h" +#include "sound.h" /* USER CODE END Includes */ @@ -54,7 +55,7 @@ // constants #define N_MOTORS 4 // number of motors -#define N_MIC 4 // number of microphones +#define N_MICS 4 // number of microphones //the "f" is super important! otherwise it is a double, and division by double takes too long #define MAX_INT16 32767.0f // max for int16 (2**15-1). @@ -77,7 +78,7 @@ #define PARAMS_N_INT16 (N_MOTORS + 8) #define CHECKSUM_VALUE (0xAC) -#define AUDIO_N_BYTES (N_MIC * FFTSIZE_SENT * FLOAT_PRECISION * 2) +#define AUDIO_N_BYTES (N_MICS * FFTSIZE_SENT * FLOAT_PRECISION * 2) #define FBINS_N_BYTES (FFTSIZE_SENT * INT16_PRECISION) #define SPI_N_BYTES (AUDIO_N_BYTES + FBINS_N_BYTES + 4 + 1) // + 4 for timestamp, + 1 for checksum @@ -130,42 +131,27 @@ float mic2_f[N_ACTUAL_SAMPLES]; float mic1_f[N_ACTUAL_SAMPLES]; float mic3_f[N_ACTUAL_SAMPLES]; -float mics_f_avg[4 * 2 * FFTSIZE_SENT]; // Complex type to feed rfft [real1, real2, imag1, imag2] +float mics_f_sum[N_MICS * 2 * FFTSIZE_SENT]; // Complex type to feed rfft [real1, real2, imag1, imag2] uint16_t f_avg_counter = 0; +uint16_t current_frequency = 0; -#define NUM_TIM_FREQ 15 - -typedef const struct { - uint16_t f; - uint16_t PSC; - uint16_t ARR; - uint32_t ERR; -} freq_list_t; - -#define NOTE_CHANGE_BY_TIMER - -freq_list_t freq_list_tim[] = { { 3000, 26, 1038, 35 }, { 3125, 0, 26879, 0 }, { - 3250, 70, 363, 86 }, { 3375, 407, 60, 36 }, { 3500, 0, 23999, 0 }, { - 3625, 46, 492, 61 }, { 3750, 0, 22399, 0 }, { 3875, 52, 408, 19 }, { - 4000, 0, 20999, 0 }, { 4125, 10, 1850, 12 }, { 4250, 35, 548, 36 }, { - 4375, 0, 19199, 0 }, { 4500, 17, 1036, 36 }, { 4625, 2017, 8, 9 }, { - 4750, 1359, 12, 125 }, { 4875, 3445, 4, 45 } }; - +//#define BUZZER_CHANGE_BY_TIMER typedef enum { - NOTE_WAIT_START, NOTE_WAIT, NOTE_RESET, NOTE_NEXT_NOTE + BUZZER_IDLE, BUZZER_RECORD, BUZZER_PLAY_NEXT, BUZZER_CHOOSE_NEXT, BUZZER_STOP } state_note_t; -uint8_t spi_counter = 0; -#define N_SPI_PER_NOTE 50 - uint8_t flag_spi_recieved = 0; +uint8_t spi_counter = 0; uint32_t note_tickstart; -uint16_t note_index = 0; +uint8_t melody_index = 0; +uint8_t note_index = 0; +int16_t current_note_index; #define NOTE_SEQUENCE_LENGTH 16 #define NOTE_LENGTH 300 +#define N_SPI_PER_NOTE 50 -state_note_t state_note_sm = NOTE_WAIT_START; +state_note_t state_note_sm = BUZZER_IDLE; uint8_t spi_tx_buffer[SPI_N_BYTES]; uint8_t spi_rx_buffer[SPI_N_BYTES]; @@ -181,7 +167,6 @@ uint16_t window_type = 0; // windowing scheme, 0: none, 1: hann, 2: flattop, 3: uint16_t min_freq = 0; uint16_t max_freq = 0; uint16_t buzzer_idx = 0; -uint16_t buzzer_idx_old = 0; uint16_t delta_freq = 100; uint16_t n_average = 1; // number of frequency bins to average. @@ -204,8 +189,6 @@ volatile int32_t time_us; volatile int32_t time_spi_error; volatile int32_t time_spi_ok; -uint16_t freq = 0; - /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -249,6 +232,9 @@ void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) { if (hi2s->Instance == hi2s1.Instance) { process(&dma_1[HALF_BUFFER_SIZE], mic3, mic2, N_ACTUAL_SAMPLES); + HAL_GPIO_TogglePin(LD1_TIM1_CH1_GPIO_Port, LD1_TIM1_CH1_Pin); + + } else { process(&dma_3[HALF_BUFFER_SIZE], mic1, mic0, N_ACTUAL_SAMPLES); } @@ -312,23 +298,21 @@ int main(void) { MX_TIM2_Init(); MX_I2S1_Init(); MX_SPI2_Init(); - MX_TIM5_Init(); MX_TIM1_Init(); MX_TIM3_Init(); + MX_TIM5_Init(); /* USER CODE BEGIN 2 */ - size_t length_tukey = sizeof(tukey_window) / sizeof(tukey_window[0]); - assert(length_tukey == N_ACTUAL_SAMPLES); - // Start DMAs HAL_I2S_Receive_DMA(&hi2s1, (uint16_t*) dma_1, FULL_BUFFER_SIZE); HAL_I2S_Receive_DMA(&hi2s3, (uint16_t*) dma_3, FULL_BUFFER_SIZE); memset(selected_indices, 0x00, sizeof(selected_indices)); memset(amplitude_avg, 0x00, sizeof(amplitude_avg)); + memset(spi_tx_buffer, 0x00, sizeof(spi_tx_buffer)); - HAL_TIM_Base_Init(&htim5); - HAL_TIM_Base_Start(&htim5); + HAL_TIM_Base_Init(&htim3); + HAL_TIM_Base_Start(&htim3); timestamp = 0; // Super important! We need to wait until the bus is idle, otherwise @@ -340,55 +324,69 @@ int main(void) { piezoInit(); + HAL_TIM_Base_Init(&htim5); + piezoSetMaxCount(BUZZER_ARR); + piezoSetRatio(BUZZER_ARR / 10); + HAL_TIM_Base_Start(&htim5); + /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ - // Note that below while loop takes ca. 40ms (fft processing) + 10ms (bin selection and tx-buffer filling). while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ read_rx_buffer(); - // Start and stop condition detection - if (buzzer_idx != buzzer_idx_old) { - if (buzzer_idx == 0) { - state_note_sm = NOTE_WAIT_START; - } else { - state_note_sm = NOTE_RESET; - } - buzzer_idx_old = buzzer_idx; + if(buzzer_idx == 0 && state_note_sm != BUZZER_IDLE){ + state_note_sm = BUZZER_STOP; } switch (state_note_sm) { - case NOTE_RESET: - note_index = 0; - state_note_sm = NOTE_NEXT_NOTE; - - memset(&mics_f_avg, 0, sizeof(mics_f_avg)); + case BUZZER_IDLE: + // start condition detection + if (buzzer_idx > 0) { + + note_index = 0; + state_note_sm = BUZZER_PLAY_NEXT; + // TODO(FD) check for invalid index. + for (int i = 0; i < sizeof(melodies); i++) { + if (melodies[i].index == buzzer_idx) { + melody_index = i; + } + } + memset(&mics_f_sum, 0, sizeof(mics_f_sum)); - f_avg_counter = 0; + f_avg_counter = 0; + } break; - case NOTE_NEXT_NOTE: - HAL_TIM_Base_Init(&htim5); - piezoSetMaxCount(freq_list_tim[note_index].ARR); - piezoSetRatio(freq_list_tim[note_index].ARR / 2); - piezoSetPSC(freq_list_tim[note_index].PSC); - HAL_TIM_Base_Start(&htim5); + case BUZZER_PLAY_NEXT: ; + + // TODO(FD) for readability, create function that takes + // current_melody[note_index] as in put and plays + // the given note. + freq_list_t next_note = freq_list_tim[melodies[melody_index].notes[note_index]]; + current_frequency = next_note.f; + + //HAL_TIM_Base_Init(&htim5); + //piezoSetMaxCount(next_note.ARR); + //piezoSetRatio(next_note.ARR / 2); + piezoSetPSC(next_note.PSC); + //HAL_TIM_Base_Start(&htim5); note_tickstart = HAL_GetTick(); - state_note_sm = NOTE_WAIT; + state_note_sm = BUZZER_RECORD; break; - case NOTE_WAIT: + case BUZZER_RECORD: // we have a new sample to process and want to add it to the buffer if (new_sample_to_process) { flag_fft_processing = 1; - timestamp = __HAL_TIM_GET_COUNTER(&htim5); + timestamp = __HAL_TIM_GET_COUNTER(&htim3); // Compute FFT arm_rfft_fast_init_f32(&rfft_instance, FFTSIZE); @@ -412,84 +410,91 @@ int main(void) { } else { for (int i = 0; i < N_ACTUAL_SAMPLES / 2; i++) { amplitude_avg[i] = (1 - IIR_ALPHA) * amplitude_avg[i] - + IIR_ALPHA - * (abs_value_squared(&mic0_f[i * 2]) - + abs_value_squared( - &mic1_f[i * 2]) - + abs_value_squared( - &mic2_f[i * 2]) - + abs_value_squared( - &mic3_f[i * 2])); + + IIR_ALPHA * (abs_value_squared(&mic0_f[i * 2]) + + abs_value_squared(&mic1_f[i * 2]) + + abs_value_squared(&mic2_f[i * 2]) + + abs_value_squared(&mic3_f[i * 2])); } } flag_fft_processing = 0; new_sample_to_process = 0; } frequency_bin_selection(selected_indices); -#if 1 + // Averaging between SPI communications + // The buffer will be filled like + // [m1_real[0], m2_real[0], m3_real[0], m4_real[0], m1_imag[0], m2_imag[0], m3_imag[0], m4_imag[0], + // m1_real[1], m2_real[1], m3_real[1], m4_real[1], m1_imag[1], m2_imag[1], m3_imag[1], m4_imag[1], + // ... + // m1_real[N], m2_real[N], m3_real[N], m4_real[N], m1_imag[N], m2_imag[N], m3_imag[N], m4_imag[N]] + // where N is FFTSIZE_SENT-1 uint16_t i_array = 0; for (int i_fbin = 0; i_fbin < FFTSIZE_SENT; i_fbin++) { - mics_f_avg[i_array] += mic0_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_avg[i_array] += mic1_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_avg[i_array] += mic2_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_avg[i_array] += mic3_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_avg[i_array] += mic0_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; - mics_f_avg[i_array] += mic1_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; - mics_f_avg[i_array] += mic2_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; - mics_f_avg[i_array] += mic3_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] += mic0_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] += mic1_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] += mic2_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] += mic3_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] += mic0_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] += mic1_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] += mic2_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] += mic3_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; } f_avg_counter++; -#else - f_avg_counter = 1; -#endif fill_tx_buffer(); - read_rx_buffer(); -#ifndef NOTE_CHANGE_BY_TIMER + + // TODO(FD) check that this still works. +#ifdef BUZZER_CHANGE_BY_TIMER if((note_tickstart + NOTE_LENGTH) < HAL_GetTick()){ - note_index++; - if(note_index == NOTE_SEQUENCE_LENGTH){ - state_note_sm = NOTE_WAIT_START; - }else{ - state_note_sm = NOTE_NEXT_NOTE; - } + state_note_sm = BUZZER_CHOOSE_NEXT; } #else - - + // play new note for each new communication. if (flag_spi_recieved) { flag_spi_recieved = 0; spi_counter++; if (spi_counter == N_SPI_PER_NOTE) { + state_note_sm = BUZZER_CHOOSE_NEXT; spi_counter = 0; - note_index++; - if (note_index == NOTE_SEQUENCE_LENGTH) { - state_note_sm = NOTE_WAIT_START; - memset(&mics_f_avg, 0, sizeof(mics_f_avg)); - - } else { - state_note_sm = NOTE_NEXT_NOTE; - } } } #endif break; - case NOTE_WAIT_START: - piezoSetMaxCount(0); - piezoSetRatio(0); + case BUZZER_CHOOSE_NEXT: ; + note_index++; + + // point to next element and get its value. + int16_t frequency_index = melodies[melody_index].notes[note_index]; + + if (frequency_index == STOP) { + + state_note_sm = BUZZER_STOP; + + } else if (frequency_index == REPEAT) { + // go back to beginning of melody + note_index = 0; + + state_note_sm = BUZZER_PLAY_NEXT; + } else { + state_note_sm = BUZZER_PLAY_NEXT; + } + break; + case BUZZER_STOP: + + memset(spi_tx_buffer, 0x00, sizeof(spi_tx_buffer)); + + //HAL_TIM_Base_Init(&htim5); + //piezoSetMaxCount(0); + //piezoSetRatio(0); piezoSetPSC(0); + //HAL_TIM_Base_Start(&htim5); + + state_note_sm = BUZZER_IDLE; break; default: break; } - /* - piezoSetMaxCount(freq_list_tim[note_index].ARR); - piezoSetRatio(freq_list_tim[note_index].ARR / 2); - piezoSetPSC(freq_list_tim[note_index].PSC); - */ - } /* USER CODE END 3 */ } @@ -1005,7 +1010,7 @@ void inline process(int16_t *pIn, float *pOut1, float *pOut2, uint16_t size) { void frequency_bin_selection(uint16_t *selected_indices) { uint16_t freq_idx; - freq_idx = (uint16_t) round(freq_list_tim[note_index].f / DF); + freq_idx = (uint16_t) round( current_frequency / DF); // return fixed frequency bins if (filter_snr_enable == 3) { @@ -1159,21 +1164,30 @@ void frequency_bin_selection(uint16_t *selected_indices) { uint16_t i_array; void fill_tx_buffer() { - // Fill with FFT content - // The spi_tx_buffer will be filled like - // [m1_real[0], m2_real[0], m3_real[0], m4_real[0], m1_imag[0], m2_imag[0], m3_imag[0], m4_imag[0], - // m1_real[1], m2_real[1], m3_real[1], m4_real[1], m1_imag[1], m2_imag[1], m3_imag[1], m4_imag[1], - // ... - // m1_real[N], m2_real[N], m3_real[N], m4_real[N], m1_imag[N], m2_imag[N], m3_imag[N], m4_imag[N]] - // where N is FFTSIZE_SENT-1 + // set the CHECKSUM to 0 so that if we communicate during filling, + // the package is not valid. + spi_tx_buffer[SPI_N_BYTES - 1] = 0; for (int i = 0; i < 4 * 2 * FFTSIZE_SENT; i++) { - mics_f_avg[i] /= f_avg_counter; + mics_f_sum[i] /= f_avg_counter; } - memcpy(&spi_tx_buffer, &mics_f_avg, sizeof(mics_f_avg)); + memcpy(&spi_tx_buffer, &mics_f_sum, sizeof(mics_f_sum)); + i_array = sizeof(mics_f_sum); + +/* + // NOTE: cannot do this inplace because we call fill_tx_buffer + // multiple times on the same buffer. + int i_array = 0; + float averaged_value; + for (int i = 0; i < N_MICS * 2 * FFTSIZE_SENT; i++) { + averaged_value = mics_f_sum[i]/f_avg_counter; + memcpy(&spi_tx_buffer[i_array], &averaged_value, sizeof(mics_f_sum[i])); + i_array += sizeof(mics_f_sum[i]); + } +*/ + //memcpy(&spi_tx_buffer[0], mics_f_sum, sizeof(mics_f_sum)); - i_array = sizeof(mics_f_avg); // Fill with bins indices memcpy(&spi_tx_buffer[i_array], selected_indices, sizeof(selected_indices)); @@ -1201,7 +1215,7 @@ void read_rx_buffer() { delta_freq = param_array[N_MOTORS + 3]; n_average = param_array[N_MOTORS + 4]; filter_prop_enable = param_array[N_MOTORS + 5]; - //filter_snr_enable = param_array[N_MOTORS + 6]; + filter_snr_enable = param_array[N_MOTORS + 6]; // initialize everything if we have changed window. if (param_array[N_MOTORS + 7] != window_type) { @@ -1240,6 +1254,7 @@ float abs_value_squared(float real_imag[]) { return (real_imag[0] * real_imag[0] + real_imag[1] * real_imag[1]); } + /* USER CODE END 4 */ /** diff --git a/firmware/audio_shield_firmware/Debug/sources.mk b/firmware/audio_shield_firmware/Debug/sources.mk index 4c1aa9ff..282583f6 100644 --- a/firmware/audio_shield_firmware/Debug/sources.mk +++ b/firmware/audio_shield_firmware/Debug/sources.mk @@ -1,5 +1,6 @@ ################################################################################ # Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (9-2020-q2-update) ################################################################################ ELF_SRCS := diff --git a/firmware/audio_shield_firmware/audio_shield_firmware.ioc b/firmware/audio_shield_firmware/audio_shield_firmware.ioc index ee2c5625..1670c872 100644 --- a/firmware/audio_shield_firmware/audio_shield_firmware.ioc +++ b/firmware/audio_shield_firmware/audio_shield_firmware.ioc @@ -1,332 +1,331 @@ #MicroXplorer Configuration settings - do not modify -Mcu.Family=STM32F4 -Dma.SPI3_RX.0.Priority=DMA_PRIORITY_LOW -Dma.SPI3_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE -ProjectManager.MainLocation=Core/Src -PH0-OSC_IN.Locked=true -VP_TIM5_VS_ClockSourceINT.Mode=Internal -PH0-OSC_IN.Signal=RCC_OSC_IN -SPI2.VirtualNSS=VM_NSSHARD -SH.S_TIM1_CH4.0=TIM1_CH4,PWM Generation4 CH4 -RCC.CortexFreq_Value=84000000 -Dma.SPI1_RX.1.Mode=DMA_CIRCULAR -I2S1.ErrorAudioFreq=-0.26 % +Dma.Request0=SPI3_RX +Dma.Request1=SPI1_RX +Dma.Request2=SPI2_RX +Dma.Request3=SPI2_TX +Dma.RequestsNb=4 +Dma.SPI1_RX.1.Direction=DMA_PERIPH_TO_MEMORY Dma.SPI1_RX.1.FIFOMode=DMA_FIFOMODE_DISABLE -ProjectManager.KeepUserCode=true -Mcu.UserName=STM32F446RETx -PB10.GPIO_PuPd=GPIO_NOPULL -SPI2.VirtualType=VM_SLAVE -PB10.Mode=Full_Duplex_Slave -VP_TIM5_VS_ClockSourceINT.Signal=TIM5_VS_ClockSourceINT -TIM1.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4 -RCC.PLLCLKFreq_Value=84000000 -PC10.Signal=I2S3_CK -PA14.GPIO_Label=TCK -RCC.PLLQCLKFreq_Value=168000000 -I2S3.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,Mode,DataFormat,AudioFreq -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_I2S3_Init-I2S3-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_I2S1_Init-I2S1-false-HAL-true,7-MX_SPI2_Init-SPI2-false-HAL-true,8-MX_TIM5_Init-TIM5-false-HAL-true,9-MX_TIM1_Init-TIM1-false-HAL-true,10-MX_TIM3_Init-TIM3-false-HAL-true -PA9.GPIOParameters=GPIO_Label -I2S1.Mode=I2S_MODE_MASTER_RX -PA11.GPIOParameters=GPIO_Label -PC3.Locked=true -RCC.RTCFreq_Value=32000 -PA6.GPIO_Label=Buzzer_TIM3_CH1 -RCC.PLLI2SRCLKFreq_Value=96000000 -SH.S_TIM1_CH3.ConfNb=1 -SH.S_TIM1_CH1.ConfNb=1 -NVIC.DMA1_Stream4_IRQn=true\:0\:0\:false\:false\:true\:false\:true +Dma.SPI1_RX.1.Instance=DMA2_Stream0 +Dma.SPI1_RX.1.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +Dma.SPI1_RX.1.MemInc=DMA_MINC_ENABLE +Dma.SPI1_RX.1.Mode=DMA_CIRCULAR +Dma.SPI1_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD +Dma.SPI1_RX.1.PeriphInc=DMA_PINC_DISABLE +Dma.SPI1_RX.1.Priority=DMA_PRIORITY_LOW +Dma.SPI1_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.SPI2_RX.2.Direction=DMA_PERIPH_TO_MEMORY +Dma.SPI2_RX.2.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.SPI2_RX.2.Instance=DMA1_Stream3 +Dma.SPI2_RX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.SPI2_RX.2.MemInc=DMA_MINC_ENABLE +Dma.SPI2_RX.2.Mode=DMA_CIRCULAR +Dma.SPI2_RX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.SPI2_RX.2.PeriphInc=DMA_PINC_DISABLE +Dma.SPI2_RX.2.Priority=DMA_PRIORITY_LOW Dma.SPI2_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -RCC.SAIAFreq_Value=96000000 -PinOutPanel.RotationAngle=0 +Dma.SPI2_TX.3.Direction=DMA_MEMORY_TO_PERIPH +Dma.SPI2_TX.3.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.SPI2_TX.3.Instance=DMA1_Stream4 +Dma.SPI2_TX.3.MemDataAlignment=DMA_MDATAALIGN_BYTE +Dma.SPI2_TX.3.MemInc=DMA_MINC_ENABLE +Dma.SPI2_TX.3.Mode=DMA_CIRCULAR +Dma.SPI2_TX.3.PeriphDataAlignment=DMA_PDATAALIGN_BYTE +Dma.SPI2_TX.3.PeriphInc=DMA_PINC_DISABLE +Dma.SPI2_TX.3.Priority=DMA_PRIORITY_LOW +Dma.SPI2_TX.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +Dma.SPI3_RX.0.Direction=DMA_PERIPH_TO_MEMORY +Dma.SPI3_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE +Dma.SPI3_RX.0.Instance=DMA1_Stream0 +Dma.SPI3_RX.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +Dma.SPI3_RX.0.MemInc=DMA_MINC_ENABLE +Dma.SPI3_RX.0.Mode=DMA_CIRCULAR +Dma.SPI3_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD +Dma.SPI3_RX.0.PeriphInc=DMA_PINC_DISABLE +Dma.SPI3_RX.0.Priority=DMA_PRIORITY_LOW +Dma.SPI3_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode +File.Version=6 +GPIO.groupedBy=Group By Peripherals +I2S1.AudioFreq=I2S_AUDIOFREQ_32K +I2S1.DataFormat=I2S_DATAFORMAT_16B_EXTENDED +I2S1.ErrorAudioFreq=-0.26 % +I2S1.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE +I2S1.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,AudioFreq,Mode,DataFormat I2S1.Instance=SPI$Index -PC3.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -ProjectManager.StackSize=0x400 -Mcu.IP4=RCC -RCC.FCLKCortexFreq_Value=84000000 -Mcu.IP5=SPI2 -Mcu.IP2=I2S3 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false -Mcu.IP3=NVIC +I2S1.Mode=I2S_MODE_MASTER_RX +I2S1.RealAudioFreq=31.914 KHz +I2S1.VirtualMode=I2S_MODE_MASTER +I2S3.AudioFreq=I2S_AUDIOFREQ_32K +I2S3.DataFormat=I2S_DATAFORMAT_16B_EXTENDED +I2S3.ErrorAudioFreq=-0.26 % +I2S3.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE +I2S3.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,Mode,DataFormat,AudioFreq +I2S3.Instance=SPI$Index +I2S3.Mode=I2S_MODE_MASTER_RX +I2S3.RealAudioFreq=31.914 KHz +I2S3.VirtualMode=I2S_MODE_MASTER +KeepUserPlacement=false +Mcu.Family=STM32F4 Mcu.IP0=DMA -Dma.SPI3_RX.0.MemInc=DMA_MINC_ENABLE Mcu.IP1=I2S1 -Mcu.UserConstants= -PA4.Mode=Half_Duplex_Master -PC1.GPIOParameters=GPIO_PuPd -I2S1.DataFormat=I2S_DATAFORMAT_16B_EXTENDED -Mcu.ThirdPartyNb=0 -Dma.SPI1_RX.1.PeriphInc=DMA_PINC_DISABLE -TIM1.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 -Dma.SPI2_RX.2.Direction=DMA_PERIPH_TO_MEMORY -RCC.SDIOFreq_Value=168000000 -RCC.HCLKFreq_Value=84000000 +Mcu.IP10=TIM5 +Mcu.IP2=I2S3 +Mcu.IP3=NVIC +Mcu.IP4=RCC +Mcu.IP5=SPI2 +Mcu.IP6=SYS +Mcu.IP7=TIM1 +Mcu.IP8=TIM2 +Mcu.IP9=TIM3 Mcu.IPNb=11 -I2S3.Mode=I2S_MODE_MASTER_RX -RCC.I2SClocksFreq_Value=96000000 -TIM2.IPParameters=Prescaler,Period -ProjectManager.PreviousToolchain=STM32CubeIDE -RCC.APB2TimFreq_Value=84000000 -RCC.SPDIFRXFreq_Value=168000000 -RCC.VcooutputI2S=96000000 -SH.S_TIM5_CH3.0=TIM5_CH3,PWM Generation3 CH3 -PA8.GPIOParameters=GPIO_Label -PC3.Signal=GPIO_Output -Mcu.Pin6=PC3 -Mcu.Pin7=PA2 -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -Dma.SPI2_TX.3.Priority=DMA_PRIORITY_LOW -NVIC.DMA2_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false\:true -Mcu.Pin8=PA3 -Dma.SPI3_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD -Mcu.Pin9=PA4 -RCC.VCOSAIOutputFreq_Value=192000000 -RCC.AHBFreq_Value=84000000 -PH0-OSC_IN.Mode=HSE-External-Oscillator +Mcu.Name=STM32F446R(C-E)Tx +Mcu.Package=LQFP64 Mcu.Pin0=PC14-OSC32_IN -Dma.SPI2_TX.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode Mcu.Pin1=PC15-OSC32_OUT -TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 -GPIO.groupedBy=Group By Peripherals +Mcu.Pin10=PA6 +Mcu.Pin11=PA7 +Mcu.Pin12=PB0 +Mcu.Pin13=PB10 +Mcu.Pin14=PB12 +Mcu.Pin15=PA8 +Mcu.Pin16=PA9 +Mcu.Pin17=PA10 +Mcu.Pin18=PA11 +Mcu.Pin19=PA13 Mcu.Pin2=PH0-OSC_IN +Mcu.Pin20=PA14 +Mcu.Pin21=PA15 +Mcu.Pin22=PC10 +Mcu.Pin23=PB3 +Mcu.Pin24=VP_SYS_VS_Systick +Mcu.Pin25=VP_TIM1_VS_ClockSourceINT +Mcu.Pin26=VP_TIM2_VS_ClockSourceINT +Mcu.Pin27=VP_TIM3_VS_ClockSourceINT +Mcu.Pin28=VP_TIM5_VS_ClockSourceINT Mcu.Pin3=PH1-OSC_OUT Mcu.Pin4=PC1 -Dma.SPI3_RX.0.Direction=DMA_PERIPH_TO_MEMORY Mcu.Pin5=PC2 -Dma.SPI2_RX.2.Instance=DMA1_Stream3 -ProjectManager.ProjectBuild=false -Dma.SPI2_RX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE -RCC.HSE_VALUE=8000000 -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false +Mcu.Pin6=PC3 +Mcu.Pin7=PA2 +Mcu.Pin8=PA3 +Mcu.Pin9=PA4 +Mcu.PinsNb=29 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32F446RETx +MxCube.Version=6.2.1 +MxDb.Version=DB.6.0.21 +NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false +NVIC.DMA1_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false\:true +NVIC.DMA1_Stream3_IRQn=true\:0\:0\:false\:false\:true\:false\:true +NVIC.DMA1_Stream4_IRQn=true\:0\:0\:false\:false\:true\:false\:true +NVIC.DMA2_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false\:true NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false -PB3.Mode=Half_Duplex_Master -Dma.SPI1_RX.1.Priority=DMA_PRIORITY_LOW -PA4.Locked=true -Mcu.IP10=TIM5 -PC1.GPIO_PuPd=GPIO_NOPULL -Dma.SPI3_RX.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD -PA15.Mode=Half_Duplex_Master +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0 +NVIC.SPI2_IRQn=true\:0\:0\:false\:false\:true\:true\:true +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false NVIC.SysTick_IRQn=true\:0\:0\:true\:false\:true\:true\:true -Dma.SPI2_RX.2.PeriphInc=DMA_PINC_DISABLE -ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.26.0 -MxDb.Version=DB.6.0.20 -I2S3.ErrorAudioFreq=-0.26 % -ProjectManager.BackupPrevious=false -PC14-OSC32_IN.Mode=LSE-External-Oscillator -RCC.VCOInputFreq_Value=1000000 -TIM5.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 -TIM1.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 -PA14.Mode=Serial_Wire -File.Version=6 +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false +PA10.GPIOParameters=GPIO_Label PA10.GPIO_Label=LD3_TIM1_CH3 -PH1-OSC_OUT.Locked=true -Dma.SPI2_RX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -PA8.Signal=S_TIM1_CH1 -I2S1.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,AudioFreq,Mode,DataFormat -NVIC.SPI2_IRQn=true\:0\:0\:false\:false\:true\:true\:true -RCC.PLLRCLKFreq_Value=168000000 -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false -SH.S_TIM3_CH1.0=TIM3_CH1,PWM Generation1 CH1 -Dma.RequestsNb=4 -ProjectManager.HalAssertFull=false -VP_TIM1_VS_ClockSourceINT.Mode=Internal -Dma.SPI1_RX.1.Direction=DMA_PERIPH_TO_MEMORY -ProjectManager.ProjectName=audio_shield_firmware -RCC.FLatency-AdvancedSettings=FLASH_LATENCY_2 +PA10.Signal=S_TIM1_CH3 +PA11.GPIOParameters=GPIO_Label +PA11.GPIO_Label=LD4_TIM1_CH4 +PA11.Signal=S_TIM1_CH4 PA13.GPIOParameters=GPIO_Label -PH1-OSC_OUT.Mode=HSE-External-Oscillator -RCC.MCO2PinFreq_Value=84000000 -Mcu.Package=LQFP64 -TIM2.Prescaler=84 -PA6.Signal=S_TIM3_CH1 -PB12.Mode=NSS_Signal_Hard_Input -SPI2.Mode=SPI_MODE_SLAVE -Dma.SPI2_RX.2.Priority=DMA_PRIORITY_LOW +PA13.GPIO_Label=TMS +PA13.Locked=true +PA13.Mode=Serial_Wire +PA13.Signal=SYS_JTMS-SWDIO +PA14.GPIOParameters=GPIO_Label +PA14.GPIO_Label=TCK PA14.Locked=true -Dma.SPI2_RX.2.MemInc=DMA_MINC_ENABLE -ProjectManager.ToolChainLocation= -RCC.LSI_VALUE=32000 -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -PA10.Signal=S_TIM1_CH3 +PA14.Mode=Serial_Wire +PA14.Signal=SYS_JTCK-SWCLK +PA15.Mode=Half_Duplex_Master PA15.Signal=I2S3_WS -Dma.Request2=SPI2_RX -RCC.CECFreq_Value=32786.88524590164 -Dma.Request1=SPI1_RX -RCC.APB1TimFreq_Value=84000000 -Dma.Request3=SPI2_TX -NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false -NVIC.DMA1_Stream0_IRQn=true\:0\:0\:false\:false\:true\:false\:true -SPI2.Direction=SPI_DIRECTION_2LINES -PB10.GPIOParameters=GPIO_PuPd -RCC.SAIBFreq_Value=96000000 -Dma.Request0=SPI3_RX -Dma.SPI1_RX.1.MemInc=DMA_MINC_ENABLE -ProjectManager.CustomerFirmwarePackage= -VP_TIM3_VS_ClockSourceINT.Mode=Internal -PC14-OSC32_IN.Locked=true -Dma.SPI2_TX.3.Direction=DMA_MEMORY_TO_PERIPH -RCC.PLLSAIQCLKFreq_Value=96000000 -PB3.Locked=true +PA2.Signal=S_TIM5_CH3 PA3.Signal=S_TIM5_CH4 -Dma.SPI1_RX.1.Instance=DMA2_Stream0 +PA4.Locked=true +PA4.Mode=Half_Duplex_Master +PA4.Signal=I2S1_WS PA6.GPIOParameters=GPIO_Label -Dma.SPI2_TX.3.MemInc=DMA_MINC_ENABLE -PC15-OSC32_OUT.Mode=LSE-External-Oscillator -I2S3.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE -ProjectManager.ProjectFileName=audio_shield_firmware.ioc +PA6.GPIO_Label=Buzzer_TIM3_CH1 +PA6.Signal=S_TIM3_CH1 PA7.Mode=Half_Duplex_Master -TIM5.IPParameters=Prescaler,Period,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4 -Mcu.PinsNb=29 -Dma.SPI3_RX.0.PeriphInc=DMA_PINC_DISABLE -ProjectManager.NoMain=false -Dma.SPI2_TX.3.MemDataAlignment=DMA_MDATAALIGN_BYTE -Dma.SPI1_RX.1.MemDataAlignment=DMA_MDATAALIGN_HALFWORD +PA7.Signal=I2S1_SD +PA8.GPIOParameters=GPIO_Label +PA8.GPIO_Label=LD1_TIM1_CH1 +PA8.Signal=S_TIM1_CH1 +PA9.GPIOParameters=GPIO_Label PA9.GPIO_Label=LD2_TIM1_CH2 -RCC.FMPI2C1Freq_Value=42000000 -RCC.VCOI2SInputFreq_Value=1000000 -PC10.Mode=Half_Duplex_Master -PC2.Signal=SPI2_MISO -Dma.SPI3_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -PA11.GPIO_Label=LD4_TIM1_CH4 -ProjectManager.DefaultFWLocation=true -PC2.Mode=Full_Duplex_Slave -I2S1.AudioFreq=I2S_AUDIOFREQ_32K -TIM5.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 +PA9.Signal=S_TIM1_CH2 +PB0.Mode=Half_Duplex_Master +PB0.Signal=I2S3_SD +PB10.GPIOParameters=GPIO_PuPd +PB10.GPIO_PuPd=GPIO_NOPULL +PB10.Mode=Full_Duplex_Slave +PB10.Signal=SPI2_SCK PB12.Locked=true -ProjectManager.DeletePrevious=true -RCC.APB1CLKDivider=RCC_HCLK_DIV2 +PB12.Mode=NSS_Signal_Hard_Input +PB12.Signal=SPI2_NSS +PB3.Locked=true +PB3.Mode=Half_Duplex_Master +PB3.Signal=I2S1_CK +PC1.GPIOParameters=GPIO_PuPd +PC1.GPIO_PuPd=GPIO_NOPULL +PC1.Mode=Full_Duplex_Slave +PC1.Signal=SPI2_MOSI +PC10.Mode=Half_Duplex_Master +PC10.Signal=I2S3_CK +PC14-OSC32_IN.Locked=true +PC14-OSC32_IN.Mode=LSE-External-Oscillator PC14-OSC32_IN.Signal=RCC_OSC32_IN -I2S3.DataFormat=I2S_DATAFORMAT_16B_EXTENDED -boardIOC=true -RCC.FamilyName=M -Dma.SPI2_RX.2.Mode=DMA_CIRCULAR -Dma.SPI2_TX.3.PeriphDataAlignment=DMA_PDATAALIGN_BYTE -PC3.GPIOParameters=GPIO_Speed,GPIO_Label -Dma.SPI3_RX.0.Mode=DMA_CIRCULAR -PA13.Signal=SYS_JTMS-SWDIO -PA8.GPIO_Label=LD1_TIM1_CH1 PC15-OSC32_OUT.Locked=true -SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1 -ProjectManager.TargetToolchain=STM32CubeIDE -Dma.SPI2_RX.2.FIFOMode=DMA_FIFOMODE_DISABLE -PA9.Signal=S_TIM1_CH2 -I2S1.VirtualMode=I2S_MODE_MASTER -VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT -TIM1.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2 -SH.S_TIM5_CH3.ConfNb=1 -I2S3.VirtualMode=I2S_MODE_MASTER -SPI2.IPParameters=VirtualType,Mode,Direction,DataSize,VirtualNSS -Dma.SPI2_TX.3.Mode=DMA_CIRCULAR -RCC.VCOInputMFreq_Value=1000000 -ProjectManager.RegisterCallBack= -RCC.USBFreq_Value=168000000 -VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT +PC15-OSC32_OUT.Mode=LSE-External-Oscillator PC15-OSC32_OUT.Signal=RCC_OSC32_OUT -SH.S_TIM1_CH2.ConfNb=1 -PB10.Signal=SPI2_SCK -RCC.VCOI2SOutputFreq_Value=192000000 -I2S3.AudioFreq=I2S_AUDIOFREQ_32K -Dma.SPI1_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode -PB0.Mode=Half_Duplex_Master -RCC.PLLSAIPCLKFreq_Value=96000000 -board=NUCLEO-F446RE -RCC.VCOOutputFreq_Value=336000000 -ProjectManager.LastFirmware=false -Dma.SPI2_TX.3.Instance=DMA1_Stream4 -RCC.APB2Freq_Value=84000000 -MxCube.Version=6.2.0 -SH.S_TIM1_CH2.0=TIM1_CH2,PWM Generation2 CH2 -VP_TIM2_VS_ClockSourceINT.Mode=Internal -RCC.PLLI2SPCLKFreq_Value=96000000 PC2.GPIOParameters=GPIO_PuPd -PA10.GPIOParameters=GPIO_Label -VP_SYS_VS_Systick.Mode=SysTick -RCC.EthernetFreq_Value=84000000 -TIM3.IPParameters=Channel-PWM Generation1 CH1 -PH1-OSC_OUT.Signal=RCC_OSC_OUT -SH.S_TIM5_CH4.0=TIM5_CH4,PWM Generation4 CH4 -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false -I2S1.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE -SH.S_TIM5_CH4.ConfNb=1 PC2.GPIO_PuPd=GPIO_NOPULL -TIM2.Period=0xFFFFFFFF -PA13.Mode=Serial_Wire +PC2.Mode=Full_Duplex_Slave +PC2.Signal=SPI2_MISO +PC3.GPIOParameters=GPIO_Speed,GPIO_Label +PC3.GPIO_Label=PC3 +PC3.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH +PC3.Locked=true +PC3.Signal=GPIO_Output +PH0-OSC_IN.Locked=true +PH0-OSC_IN.Mode=HSE-External-Oscillator +PH0-OSC_IN.Signal=RCC_OSC_IN +PH1-OSC_OUT.Locked=true +PH1-OSC_OUT.Mode=HSE-External-Oscillator +PH1-OSC_OUT.Signal=RCC_OSC_OUT +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=false +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32F446RETx +ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.26.1 ProjectManager.FreePins=false +ProjectManager.HalAssertFull=false +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=1 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain=STM32CubeIDE +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=audio_shield_firmware.ioc +ProjectManager.ProjectName=audio_shield_firmware +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=STM32CubeIDE +ProjectManager.ToolChainLocation= +ProjectManager.UnderRoot=true +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_I2S3_Init-I2S3-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_I2S1_Init-I2S1-false-HAL-true,7-MX_SPI2_Init-SPI2-false-HAL-true,8-MX_TIM5_Init-TIM5-false-HAL-true,9-MX_TIM1_Init-TIM1-false-HAL-true,10-MX_TIM3_Init-TIM3-false-HAL-true +RCC.48MHZClocksFreq_Value=84000000 +RCC.AHBFreq_Value=84000000 +RCC.APB1CLKDivider=RCC_HCLK_DIV2 +RCC.APB1Freq_Value=42000000 +RCC.APB1TimFreq_Value=84000000 +RCC.APB2Freq_Value=84000000 +RCC.APB2TimFreq_Value=84000000 +RCC.CECFreq_Value=32786.88524590164 +RCC.CortexFreq_Value=84000000 +RCC.EthernetFreq_Value=84000000 +RCC.FCLKCortexFreq_Value=84000000 +RCC.FLatency-AdvancedSettings=FLASH_LATENCY_2 +RCC.FMPI2C1Freq_Value=42000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=84000000 +RCC.HSE_VALUE=8000000 +RCC.HSI_VALUE=16000000 +RCC.I2SClocksFreq_Value=96000000 RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FLatency-AdvancedSettings,FMPI2C1Freq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLN,PLLP,PLLQCLKFreq_Value,PLLRCLKFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PWRFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SAIAFreq_Value,SAIBFreq_Value,SDIOFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USBFreq_Value,VCOI2SInputFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOInputMFreq_Value,VCOOutputFreq_Value,VCOSAIInputFreq_Value,VCOSAIOutputFreq_Value,VcooutputI2S -ProjectManager.AskForMigrate=true -Mcu.Name=STM32F446R(C-E)Tx -Dma.SPI3_RX.0.Instance=DMA1_Stream0 +RCC.LSI_VALUE=32000 +RCC.MCO2PinFreq_Value=84000000 +RCC.PLLCLKFreq_Value=84000000 +RCC.PLLI2SPCLKFreq_Value=96000000 RCC.PLLI2SQCLKFreq_Value=96000000 -Mcu.Pin26=VP_TIM2_VS_ClockSourceINT -Mcu.Pin27=VP_TIM3_VS_ClockSourceINT +RCC.PLLI2SRCLKFreq_Value=96000000 +RCC.PLLN=336 +RCC.PLLP=RCC_PLLP_DIV4 +RCC.PLLQCLKFreq_Value=168000000 +RCC.PLLRCLKFreq_Value=168000000 +RCC.PLLSAIPCLKFreq_Value=96000000 +RCC.PLLSAIQCLKFreq_Value=96000000 +RCC.PWRFreq_Value=84000000 +RCC.RTCFreq_Value=32000 RCC.RTCHSEDivFreq_Value=4000000 -PA2.Signal=S_TIM5_CH3 -PA13.GPIO_Label=TMS -Mcu.Pin24=VP_SYS_VS_Systick -ProjectManager.UnderRoot=true -Mcu.Pin25=VP_TIM1_VS_ClockSourceINT -Mcu.IP8=TIM2 -Mcu.IP9=TIM3 -Mcu.Pin28=VP_TIM5_VS_ClockSourceINT -Dma.SPI1_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD -Mcu.IP6=SYS -RCC.VCOSAIInputFreq_Value=1000000 -Mcu.IP7=TIM1 -ProjectManager.CoupleFile=false -RCC.48MHZClocksFreq_Value=84000000 -PB3.Signal=I2S1_CK -PA4.Signal=I2S1_WS +RCC.SAIAFreq_Value=96000000 +RCC.SAIBFreq_Value=96000000 +RCC.SDIOFreq_Value=168000000 +RCC.SPDIFRXFreq_Value=168000000 RCC.SYSCLKFreq_VALUE=84000000 -Mcu.Pin22=PC10 -Mcu.Pin23=PB3 -Mcu.Pin20=PA14 -Mcu.Pin21=PA15 -NVIC.ForceEnableDMAVector=true -KeepUserPlacement=false -TIM5.Prescaler=1 -PA14.GPIOParameters=GPIO_Label -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false -PA13.Locked=true -ProjectManager.CompilerOptimize=6 -PA11.Signal=S_TIM1_CH4 -PA14.Signal=SYS_JTCK-SWCLK -ProjectManager.HeapSize=0x200 -Mcu.Pin15=PA8 -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false -Mcu.Pin16=PA9 -Mcu.Pin13=PB10 -Mcu.Pin14=PB12 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.USBFreq_Value=168000000 +RCC.VCOI2SInputFreq_Value=1000000 +RCC.VCOI2SOutputFreq_Value=192000000 +RCC.VCOInputFreq_Value=1000000 +RCC.VCOInputMFreq_Value=1000000 +RCC.VCOOutputFreq_Value=336000000 +RCC.VCOSAIInputFreq_Value=1000000 +RCC.VCOSAIOutputFreq_Value=192000000 +RCC.VcooutputI2S=96000000 +SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1 +SH.S_TIM1_CH1.ConfNb=1 +SH.S_TIM1_CH2.0=TIM1_CH2,PWM Generation2 CH2 +SH.S_TIM1_CH2.ConfNb=1 SH.S_TIM1_CH3.0=TIM1_CH3,PWM Generation3 CH3 -Mcu.Pin19=PA13 +SH.S_TIM1_CH3.ConfNb=1 +SH.S_TIM1_CH4.0=TIM1_CH4,PWM Generation4 CH4 +SH.S_TIM1_CH4.ConfNb=1 +SH.S_TIM3_CH1.0=TIM3_CH1,PWM Generation1 CH1 SH.S_TIM3_CH1.ConfNb=1 -ProjectManager.ComputerToolchain=false -Mcu.Pin17=PA10 -RCC.HSI_VALUE=16000000 -Mcu.Pin18=PA11 -RCC.PLLP=RCC_PLLP_DIV4 -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0 -Mcu.Pin11=PA7 -I2S3.RealAudioFreq=31.914 KHz -Mcu.Pin12=PB0 -RCC.PLLN=336 -Mcu.Pin10=PA6 -Dma.SPI2_TX.3.PeriphInc=DMA_PINC_DISABLE -PC3.GPIO_Label=PC3 -RCC.PWRFreq_Value=84000000 -NVIC.DMA1_Stream3_IRQn=true\:0\:0\:false\:false\:true\:false\:true -TIM5.Period=100 +SH.S_TIM5_CH3.0=TIM5_CH3,PWM Generation3 CH3 +SH.S_TIM5_CH3.ConfNb=1 +SH.S_TIM5_CH4.0=TIM5_CH4,PWM Generation4 CH4 +SH.S_TIM5_CH4.ConfNb=1 SPI2.DataSize=SPI_DATASIZE_8BIT -Dma.SPI2_TX.3.FIFOMode=DMA_FIFOMODE_DISABLE -I2S1.RealAudioFreq=31.914 KHz -I2S3.Instance=SPI$Index +SPI2.Direction=SPI_DIRECTION_2LINES +SPI2.IPParameters=VirtualType,Mode,Direction,DataSize,VirtualNSS +SPI2.Mode=SPI_MODE_SLAVE +SPI2.VirtualNSS=VM_NSSHARD +SPI2.VirtualType=VM_SLAVE +TIM1.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 +TIM1.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2 TIM1.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 -RCC.APB1Freq_Value=42000000 -PB0.Signal=I2S3_SD -SH.S_TIM1_CH4.ConfNb=1 -ProjectManager.DeviceId=STM32F446RETx -PC1.Signal=SPI2_MOSI -PB12.Signal=SPI2_NSS -ProjectManager.LibraryCopy=1 -PC1.Mode=Full_Duplex_Slave -PA7.Signal=I2S1_SD -isbadioc=false +TIM1.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 +TIM1.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4 +TIM2.IPParameters=Prescaler,Period +TIM2.Period=0xFFFFFFFF +TIM2.Prescaler=84 +TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 +TIM3.IPParameters=Channel-PWM Generation1 CH1 +TIM5.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 +TIM5.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 +TIM5.IPParameters=Prescaler,Period,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4 +TIM5.Period=100 +TIM5.Prescaler=1 +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_TIM1_VS_ClockSourceINT.Mode=Internal +VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT +VP_TIM2_VS_ClockSourceINT.Mode=Internal +VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT +VP_TIM3_VS_ClockSourceINT.Mode=Internal +VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT +VP_TIM5_VS_ClockSourceINT.Mode=Internal +VP_TIM5_VS_ClockSourceINT.Signal=TIM5_VS_ClockSourceINT +board=NUCLEO-F446RE +boardIOC=true From c9566d7197d5b9785dfd1d24ce275f1c35087e26 Mon Sep 17 00:00:00 2001 From: duembgen Date: Thu, 22 Apr 2021 14:54:03 +0200 Subject: [PATCH 4/5] Working version --- firmware/audio_shield_firmware/Core/Inc/sound.h | 6 +++--- firmware/audio_shield_firmware/Core/Src/main.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware/audio_shield_firmware/Core/Inc/sound.h b/firmware/audio_shield_firmware/Core/Inc/sound.h index 8859386e..6f1f84ea 100644 --- a/firmware/audio_shield_firmware/Core/Inc/sound.h +++ b/firmware/audio_shield_firmware/Core/Inc/sound.h @@ -18,7 +18,7 @@ typedef const struct { int16_t* notes; } melody; - +/* freq_list_t freq_list_tim[] = { {3000, 26, 1038, 35 }, {3125, 0, 26879, 0 }, @@ -37,7 +37,7 @@ freq_list_t freq_list_tim[] = { {4750, 1359, 12, 125 }, {4875, 3445, 4, 45 } }; -/* +*/ freq_list_t freq_list_tim[] = { {3010, 109, 256, -10}, {3125, 105, 256, 0}, @@ -56,7 +56,7 @@ freq_list_t freq_list_tim[] = { {4755, 69, 256, -5}, {4825, 68, 256, 50}, }; -*/ + int16_t sweep[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, REPEAT}; int16_t mono3000[] = {0, REPEAT}; diff --git a/firmware/audio_shield_firmware/Core/Src/main.c b/firmware/audio_shield_firmware/Core/Src/main.c index 6814358f..a2353982 100644 --- a/firmware/audio_shield_firmware/Core/Src/main.c +++ b/firmware/audio_shield_firmware/Core/Src/main.c @@ -358,14 +358,14 @@ int main(void) { melody_index = i; } } - memset(&mics_f_sum, 0, sizeof(mics_f_sum)); - - f_avg_counter = 0; } break; case BUZZER_PLAY_NEXT: ; + memset(mics_f_sum, 0x00, sizeof(mics_f_sum)); + f_avg_counter = 0; + // TODO(FD) for readability, create function that takes // current_melody[note_index] as in put and plays // the given note. From 7cf34bb75d13e19838778378de2e774cbd5e425c Mon Sep 17 00:00:00 2001 From: duembgen Date: Thu, 22 Apr 2021 16:20:01 +0200 Subject: [PATCH 5/5] Remove averaging --- .../audio_shield_firmware/Core/Src/main.c | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/firmware/audio_shield_firmware/Core/Src/main.c b/firmware/audio_shield_firmware/Core/Src/main.c index a2353982..773499e0 100644 --- a/firmware/audio_shield_firmware/Core/Src/main.c +++ b/firmware/audio_shield_firmware/Core/Src/main.c @@ -430,14 +430,14 @@ int main(void) { // where N is FFTSIZE_SENT-1 uint16_t i_array = 0; for (int i_fbin = 0; i_fbin < FFTSIZE_SENT; i_fbin++) { - mics_f_sum[i_array] += mic0_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_sum[i_array] += mic1_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_sum[i_array] += mic2_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_sum[i_array] += mic3_f[2 * selected_indices[i_fbin]]; i_array += 1; - mics_f_sum[i_array] += mic0_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; - mics_f_sum[i_array] += mic1_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; - mics_f_sum[i_array] += mic2_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; - mics_f_sum[i_array] += mic3_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] = mic0_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] = mic1_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] = mic2_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] = mic3_f[2 * selected_indices[i_fbin]]; i_array += 1; + mics_f_sum[i_array] = mic0_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] = mic1_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] = mic2_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; + mics_f_sum[i_array] = mic3_f[2 * selected_indices[i_fbin] + 1]; i_array += 1; } f_avg_counter++; fill_tx_buffer(); @@ -1168,17 +1168,20 @@ void fill_tx_buffer() { // the package is not valid. spi_tx_buffer[SPI_N_BYTES - 1] = 0; + // NOTE: cannot do this inplace because we call fill_tx_buffer + // multiple times on the same buffer. +/* for (int i = 0; i < 4 * 2 * FFTSIZE_SENT; i++) { mics_f_sum[i] /= f_avg_counter; } - memcpy(&spi_tx_buffer, &mics_f_sum, sizeof(mics_f_sum)); + */ + memcpy(spi_tx_buffer, mics_f_sum, sizeof(mics_f_sum)); i_array = sizeof(mics_f_sum); -/* - // NOTE: cannot do this inplace because we call fill_tx_buffer - // multiple times on the same buffer. - int i_array = 0; + /* + i_array = 0; + float averaged_value; for (int i = 0; i < N_MICS * 2 * FFTSIZE_SENT; i++) { averaged_value = mics_f_sum[i]/f_avg_counter; @@ -1186,7 +1189,6 @@ void fill_tx_buffer() { i_array += sizeof(mics_f_sum[i]); } */ - //memcpy(&spi_tx_buffer[0], mics_f_sum, sizeof(mics_f_sum)); // Fill with bins indices