FX2LP I2C Based Debug with SDCC on Eclipse IDE- KBA229648

Version 12

    Author: SananyaM_56           Version: **

     

     

    Question:

    How can I send I2C debug messages through FX2LP when using the SDCC compiler?

     

    Answer
    Eclipse integrated development environment (IDE) that can be installed from the FX3 SDK contains a SDCC compiler suite plugin and can be used to build FX2LP projects. See the EZ-USB Suite User Guide for details on creating a FX2LP project using the template present with the Eclipse IDE. This knowledge base article (KBA) discusses the steps to configure the project on Eclipse IDE to receive debug messages from FX2LP over an I2C interface.

     

    For using the USB-Serial Device (CY7C65215) as an I2C slave for sending the messages from the FX2LP, see Debugging of FX2LP Firmware using I2C - KBA229175.

     

    Creating a project using FX2LP Project template

     

    1.In Eclipse IDE, follow the menu path File → New → Project.

    Figure 1. Opening a new project in Eclipse IDE

     

    2. In the New Project dialog, select FX2LP Project.

    Figure 2. Selecting the FX2LP Project

     

    3. Select the Create the Project using one of the Templates checkbox. Enter the name of the project and select the Bulkloop_SDCC template. Click Finish to create the project

    Figure 3. Creating the Project using Bulklopp_SDCC Template

    Note: Make sure that you have downloaded the SDCC complier suite as explained in the EZ-USB Suite User Guide.

     

    4. Once the project is created, go to Properties → C/C++ Build. Add C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\Eclipse\plugins\net.sourceforge.eclipsesdcc.win32_1.0.0\os\win32\x86\make.exe -k in the Build command space. Click OK.

     

    Debug Files

     

    The following files attached with this KBA include functions to send messages in byte, word, character, or string format, and can be included with any FX2LP project.

     

    • fX2lpi2c.h - This header file contains the function definitions for all functions in fx2lpi2c.c. This header file must be included in the project to access the functions in fx2lpi2c.c.
    • fx2lpi2c.c - This source file includes all required functions for I2C debug.

     

    Test Setup

     

    The Bulkloop template firmware is used to demonstrate the debugging procedure. For enabling the general I2C operations, the USBJmpTb.asm file needs to be modified. This is done to hard code the address of I2C ISR since SDCC compiler, by default places the address in an arbitrary location, which will cause issues in the ISR call and the USB enumeration. Add the following lines in the file:

    .area INTI2C (CODE,ABS) 

    .org 0x004B

       ljmp  _i2c_isr

    Figure 4. Adding ISR Address in the USB Jump Table File

    Modify the template project to include the debug files attached with this KBA.

     

    Adding Files to the Target Project

     

    Follow these steps to add the debug files to the target project:
    1. Add the debug files to the project folder.

     

    Figure 5. Adding Files to the Project

     

    2. Open the project in the Eclipse IDE and ensure that the files are added.

    Figure 6. Checking whether Files are Added

     

    3. Open the bulkloop.c file and add the fx2lpi2c.h header file reference.

    Figure 7. Adding Header File Reference

    4. Compile once and make sure that the files fx2lpi2c.c and fx2lpi2c.h are included in the project.

     

    Modifying Firmware

     

    Modify the bulkloop.c example project to use the I2C debug functions as shown in the following example.

    The FX2LPI2C_Init () function is called within the TD_Init () function in bulkloop.c. This ensures that the I2C bus is initialized and ready for use at any point during code execution. The other required functions are called wherever necessary as described in following sections.

    Note that the I2C slave address and frequency can be modified in the fx2lpi2c.h debug file.

     

    • TD_Init () – The following code snippet initializes the I2C bus and prints a string to reflect the same. Then, prints the value of IFCONFIG.

           FX2LPI2C_Init();// I2C Debug Code Start

       FX2LPI2C_XmitString("Debug mode initialized\r\n");

      

       // set the slave FIFO interface to 48MHz

       IFCONFIG |= 0x40;

       FX2LPI2C_XmitHex2(IFCONFIG); //Printing the value of IFCONFIG

       FX2LPI2C_XmitString("\r\n");

    • TD_Poll () – The following code snippet prints a string to indicate the transfer of a packet from EP2 to EP6 and the byte count of the packet.

           FX2LPI2C_XmitChar('P');

       FX2LPI2C_XmitString("acket of Byte Count = ");

       FX2LPI2C_XmitHex4(count);

       FX2LPI2C_XmitString(" being moved to EP6\r\n");

     

    See the attached project, which includes all changes in the firmware files for debugging.

     

    References