Tool/software: Code Composer Studio
As stated in the title, my code was running as predicted, but I added in some comments and rebuilt the code (to test the timing), and now the code does not work. The previous Flash/FRAM usage was 900+ bytes, but after rebuilding the code, it is now reduced to 666 bytes. I have taken out the comments which I had added (in case that was the problem), but it does not revert back to the original, intended size and functionality. Besides adding the comments, there were no changes made to the code. Please help, as I have no idea why this happened or how to fix it. Please/thank you. My code shown below.
#include <msp430.h> #include <string.h> #include <stdint.h> #include <stdlib.h> #define INTERRUPT_VALUE 0x2 // counter for interrupts (see above for calculations) #define START_RAM 0x220 // start address of RAM for data array #define END_RAM 0x5FF // end address of RAM for data array #define ARRAY_STEP 0x80 // increase/decrease movement of data (128 bytes) #define ARRAY_SIZE 0x80 // size of data (128 bytes) /* function declarations */ void configWDT(void); // halts the watchdog timer void configClocks(void); // selects ACLK/8 as frequency void configGPIO(void); // disables/enables GPIO pins void configTimerA(void); // configures TimerA for interrupt counter uint32_t *memory_copy(uint32_t *, uint32_t *); // moves data around RAM and clears previous location /* global variables */ static volatile unsigned char toggle_LED; // toggles red LED (used for debugging) static volatile unsigned short intrp_flg; // counts number of interrupts of TimerA /* forces processor to place data arrays in RAM */ #pragma DATA_SECTION(dest_loc, ".ram_data") char cur_loc[128]; // current location of array in RAM char dest_loc[128]; // next memory location in RAM for array int main(void) { /* initalize globals */ toggle_LED = 0; intrp_flg = 0; int reverse_dataflow = 0; /* configure watchdog timer, clocks, GPIO pins, and TimerA of processor */ configWDT(); configClocks(); configGPIO(); configTimerA(); /* initialize data arrays to be moved throughout RAM */ int dest = START_RAM; // starting position is beginning of available RAM uint32_t *cur_loc = (void *)dest; // pointer to initial position in RAM (dest) memset(cur_loc, '$', ARRAY_SIZE); // fill memory with arbitrary data (used for debugging) dest += ARRAY_STEP; // next memory location for data is 128 bytes away from starting location) uint32_t *dest_loc = (void *)dest; // pointer to next memory location in RAM __no_operation(); // (used for debugging) /* * remain in this loop for the duration of the program * > enters low-power mode until # of interrupts have passed * > exits low-power mode, moves data to new location in RAM * > re-enters low-power mode */ while(1) { __bis_SR_register(LPM3_bits + GIE); // enter LPM3 if(toggle_LED) { P1OUT ^= BIT0; if(!reverse_dataflow) // moves data to higher memory address { dest += ARRAY_STEP; // increase new memory location in RAM by size of data if(START_RAM <= dest && dest <= END_RAM) // check to see if next memory location falls within bounds of RAM data space { cur_loc = memory_copy(dest_loc, cur_loc); // copy memory from current location to new location dest_loc = (void *)dest; // new memory location is current location + size of data (128 bytes) __no_operation(); // (used for debugging) } else if(dest >= END_RAM) { // next memory location is above available RAM space dest -= ARRAY_STEP * 2; // decrement new destination to 128 bytes below current location reverse_dataflow = 1; // reverse the movement of data through RAM (used for debugging) __no_operation(); // (used for debugging) } } else { dest -= ARRAY_STEP; // decrease new memory location in RAM by size of data if(START_RAM <= dest && dest <= END_RAM) // check to see if next memory location falls within bounds of RAM data space { dest_loc = (void *)dest; // new memory location is current location - size of data (128 bytes) cur_loc = memory_copy(dest_loc, cur_loc); // copy memory from current location to new location __no_operation(); // (used for debugging) } else if(dest <= START_RAM) // next memory location is below available RAM space { dest += ARRAY_STEP * 2; dest_loc = (void *)dest; reverse_dataflow = 0; // reverse the movement of data through RAM (used for debugging) __no_operation(); // (used for debugging) } } } } } uint32_t *memory_copy(uint32_t *destination, uint32_t *source) { memmove(destination, source, ARRAY_SIZE); // move data to new memory location memset(source, '\0', (int)destination - (int)source); // clear previous memory location source = destination; // new memory location is now current memory location return source; } void configWDT(void) { WDTCTL = WDTPW + WDTHOLD; // WDTCTL = 0x5A80 } void configClocks() { DCOCTL |= DCO1 + DCO0; // DCOCTL = 0x60 BCSCTL1 |= XT2OFF + DIVA_3 + RSEL2 + RSEL1 + RSEL0; // BCSCTL1 = 0xB7 BCSCTL2 |= SELM_3 + SELS; // BCSCTL2 = 0xC8 BCSCTL3 |= XT2S_3; // BCSCTL3 = 0xC0 } void configGPIO(void) { P1DIR |= 0x03; P1SEL |= 0x02; } void configTimerA(void) { TACCTL0 |= OUTMOD_4; // TACCTL0 = 0x0081 TACCR0 |= 0xFFFF; TACTL |= TASSEL_1 + ID_3 + MC_3 + TAIE; // TACTL = 0x01F2 } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMERA1_VECTOR __interrupt void Timer_A(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMERA1_VECTOR))) Timer_A (void) #else #error Compiler not supported! #endif { intrp_flg++; // increment flag counter switch(TAIV) { case 2: // capture/compare 1 interrupt break; case 4: // capture/compare 2 interrupt break; case 10: // timer overflow interrupt if(intrp_flg % INTERRUPT_VALUE == 0) { // toggle_LED = 1; intrp_flg = 0; __bic_SR_register_on_exit(LPM3_bits); } else { toggle_LED = 0; } break; } }