Other Parts Discussed in Thread: BOOSTXL-AUDIO
I have a code that calculates some mathematical coefficients for a neural network. During the debugging process, I have a variable that needs to be of the 'double' datatype. When I use it in the code at a particular place, the code crashes during debugging. I am using the BOOSTXL-AUDIO Playback sample as a reference. Over the last couple of days, I tested different cases to observe in which cases this crash occurs. Out of the two scenarios I found, in one case the code works properly and continues with the execution when I use the 'double' datatype for declaring a variable but in the other case, the exact same code fails to execute and goes into either 'spin forever' condition or just shuts the code down and branches into the 'boot.c' file. I have absolutely no idea why it would behave differently for the exact same code except for one change where a variable is defined as 'double' and not 'float'.
PS. The variable needs to be in 'double' format according to the function definition.
Here is a part of the code where the crash occurs. I am adding both the 'main.c' and 'application.c' file from the project.
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initClock(); initGpio(); PM5CTL0 &= ~LOCKLPM5; // Clear lock bit // vm1010 mode pin (P6.1), o/p, low at start for normal mode P6OUT &= ~BIT1; // vm1010 P6DIR |= BIT1; // vm1010 // vm1010 mic power on (P6.2) P6OUT |= BIT2; // vm1010 P6DIR |= BIT2; // vm1010 // vm1010 mode pin, o/p, high for WoS mode P6OUT |= BIT1; // vm1010 P5IFG &= ~BIT6; // Clear interrupt on P5.6 P5IE |= BIT6; // Enable interrupt on P5.6 P5IFG &= ~BIT5; // Clear interrupt on P5.5 P5IE |= BIT5; // Enable interrupt on P5.5 // vm1010 P5IFG &= ~BIT7; // Clear interrupt on P5.7 P5IE |= BIT7; // Enable interrupt on P5.7 // Enable Switch interrupt GPIO_clearInterrupt(PUSHBUTTON1_PORT, PUSHBUTTON1_PIN); GPIO_enableInterrupt(PUSHBUTTON1_PORT, PUSHBUTTON1_PIN); // Initialize DAC DAC8311_init(); // Set the DAC to low power mode with output high-Z DAC8311_setLowPowerMode(DAC8311_OUTPUT_HIGHZ); __bis_SR_register(GIE); // Starts the application. It is a function that never returns. runApplication(); return 1; }
void runApplication(void) { while(1) { P5IE &= ~BIT7; // Disable interrupt on P5.7 // vm1010 P5IE &= ~BIT6; // Disable interrupt on P5.6 P5IE &= ~BIT5; // Disable interrupt on P5.5 // Disable button interrupt GPIO_disableInterrupt(PUSHBUTTON1_PORT, PUSHBUTTON1_PIN); switch(applicationMode) { volatile uint16_t j; case RECORD: * runRecord(); * amplify_data(); * fft_init(); while(window_number < 64) { fft_cal(); } window_number=0; for(j = 1; j < (VECTOR_SIZE / 2); j++) // vm1010 { // vm1010 real = fft_res[2 * j] << 2; imag = fft_res[2 * j + 1] << 2; if(real < 0) { real_abs = ~real + 1; } else { real_abs = real; } if(imag < 0) { imag_abs = ~imag + 1; } else { imag_abs = imag; } if(real_abs >= imag_abs) { max = real_abs; min = imag_abs; } else { max = imag_abs; min = real_abs; } mag = max + 3 * (min >> 3); FFT_data[j] = mag << 1; } break; default: break; } // Toggle app mode applicationMode = DEFAULT; P6OUT &= ~BIT1; // vm1010 // Set a Switch debounce to 500ms __delay_cycles(0.5 * __SYSTEM_FREQUENCY_MHZ__); P5IFG &= ~BIT6; // Clear interrupt on P5.6 P5IE |= BIT6; // Enable interrupt on P5.6 P5IFG &= ~BIT5; // Clear interrupt on P5.5 P5IE |= BIT5; // Enable interrupt on P5.5 P5IFG &= ~BIT7; // Clear interrupt on P5.7 // vm1010 P5IE |= BIT7; // Enable interrupt on P5.7 // vm1010 // vm1010 mode pin, o/p, high for WoS mode P6OUT |= BIT1; // vm1010 GPIO_clearInterrupt(PUSHBUTTON1_PORT, PUSHBUTTON1_PIN); // Clear the interrupt flag GPIO_enableInterrupt(PUSHBUTTON1_PORT, PUSHBUTTON1_PIN); // Re-enable the interrupt // Enter low power mode * __bis_SR_register(LPM4_bits + GIE); float mfcc_result; float mfcc_value[13]; float mfcc_features_f[12]; * if(FFT_data[1] != 0) { // MFCC Calculations can be included here double spectrum[512]; // when double changes to float - the code runs correctly int i; for(i=0;i<512;i++) { spectrum[i] = (double)FFT_data[i]; }
I have also marked with an ' * ' the locations of my debug points in the second file. I tried looking at different documents detailing the behavior of the data type and declarations but I could not find a reason for this behavior. The calculation of coefficients does work correctly when executed with the exact same logic - including the 'double' declaration - when executed separately in another project. If I could get any idea about what might be going wrong here, I could try it out. Please let me know if any more details are needed to help understand the question better.