UltimaSerial Tech Blog: To move codes from one existing AVR project to another

Data logger
UltimaSerial

 

Windaq add-ons
Windaq Add-ons

 

Spectrogram
UltimaWaterfall

 

Ultimaserial XChart
XChart

 

FFT1024
FFT1024

 

Ultimaserial Classroom
Lessons

Here is a practice to move codes from project test2 to test1

Preparation:

  1. Start AVR32 Studio

  2. Right click inside Project Explorer 

  3. Follow New->Example...->EVK1100-Services->LWIP example to create a project name test1

  4. Repeat step 1 to 3  to create a new project test2 based on EVK1100->COMPONENTS->Data Flash Memory example

  5. Build both 

  6. Right click project test1, follow Run/Debug Settings->New...->AVR32 Application, select the proper Target, for example JTAGICE mkII

  7. Repeat 6 on test2

  8. Make sure both test1 and test2 run properly on the target

Combine the two projects by copy-and-pasting codes from test2 to test1. The following copy-and-paste are done inside AVR32 studio, not Window's File Explorer. Make sure keeping the same file/folder structure

  1. Copy two files test2->src->CONFIG->conf_access.h and conf_at45dbx.h from test2 to the same CONFIG folder under test1

  2. Copy test2->src->SOFTWARE_FRAMEWORK->COMPONENTS->MEMORY folder to test1 

  3. Copy test2->src->SOFTWARE_FRAMEWORK->DRIVERS->SPI  folder to test1 

  4. Copy test2->src->SOFTWARE_FRAMEWORK->DRIVERS->USART folder to test1 

  5. Copy test2->src->SOFTWARE_FRAMEWORK->SERVICES->MEMORY folder to test1

  6. Copy test2->src->SOFTWARE_FRAMEWORK->UTILS->DEBUG folder to test1

Examine directory path used by test2

  1. Right click on test2, follow Properties->C/C++ General->Paths and Symbols

  2. Select All for Configuration

  3. Select GNU C in Languages pane, and you should see all the directories used by test2. 

Copy *ALL* directory path used by test2 to test1

  1. src/SOFTWARE_FRAMEWORK/UTILS/DEBUG

  2. src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS

  3. src/SOFTWARE_FRAMEWORK/DRIVERS/SPI

  4. src/SOFTWARE_FRAMEWORK/DRIVERS/USART

  5. src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX

Copy codes from test2::main.c to test1to confirm a successful transplant

  1. Open at45dbx_example.c under project test2

  2. Copy the include files from test2 to test1

    #include "compiler.h"

    #include "preprocessor.h"

    #include "board.h"

    #include "gpio.h"

    #include "spi.h"

    #include "print_funcs.h"

    #include "conf_at45dbx.h"

    #include "at45dbx.h"

  3. Copy everything after #include "at45dbx.h", before int main (void) from test2

  4. Copy everything in main() of test2 and paste to the main() of test1 so that it looks like this:

    int main( void )

    {

    volatile avr32_pm_t* pm = &AVR32_PM;

     

    /* 1) Initialize the microcontroller and the shared hardware resources of the board. */

     

    /* Switch to external oscillator 0 */

    pm_switch_to_osc0( pm, FOSC0, OSC0_STARTUP );

     

    init_dbg_rs232(FOSC0);

    print_dbg(MSG_WELCOME);

     

    // Initialize AT45DBX resources: GPIO, SPI and AT45DBX.

    at45dbx_resources_init();

     

    // Perform a memory check on all DFs.

    print_dbg("Entering Memory Check:\n");

    at45dbx_example_check_mem();

     

    // Test single-byte access functions.

    print_dbg("Entering Memory Test (Byte Access):\n");

    at45dbx_example_test_byte_mem();

     

    // Test single-sector access functions.

    print_dbg("Entering Memory Test (RAM Access):\n");

    at45dbx_example_test_RAM_mem();

     

    // Test multiple-sector access functions.

    print_dbg("Entering Multiple Sector Test:\n");

    at45dbx_example_test_multiple_sector();

     

Build test1 and run

Note: If you've changed some derived definition files in the source project, such as EVK1100.h, make sure carrying them over to the target project