Link Search Menu Expand Document

                                                                                                     

Note:

This document shows you how to create an MPLAB X IDE Harmony v3 project for a SAM9X60 Curiosity Development Board from scratch using the MPLAB Harmony v3 software framework.

Introduction

This document shows you how to create an MPLAB X IDE Harmony v3 project for a SAM9X60D1G MPU from scratch using the MPLAB Harmony v3 software framework. This document explains how to write and read from the onboard EEPROM on SAM9X60 Curiosity Development Board and display the data using serial debug interface. This project demonstrates below:

  • Print serial console debug messages.
  • Write, Read and Compare the data from the EEPROM .
  • Print TEST PASS if write and read data from EEPROM matches and turn ON the blue LED on the board.

Hardware Used:

Software/Tools Used:

This project has been verified to work with the following versions of software tools:

  • mcc_version: v5.4.1
  • mcc_core_version: v5.6.1
  • mplabx_version: v6.15
  • harmony_version: v1.2.0
  • compiler: XC32 (v4.40)

Hardware Setup :

  • Power up the board by connecting the USB cable to the USB port J1 on the SAM9X60 curiosity development board.
  • Connect external debugger to J12.
  • Ensure J14(1-2) and J15(1-2) jumpers on the board are closed towards DBGU to enable UART serial debug.

Create a new MPLAB Harmony v3 SAM9X60 Curiosity project Using MCC on MPLAB X IDE

Step 1: Create project and configure the MPU

Details


  • 1.1. Select File –> New Project from the main IDE menu.
  • 1.2. In the Categories pane of the New Project dialog, select Microchip Embedded. In the Projects pane, select 32-bit MCC Harmony Project, then click Next.

Note: If 32-bit MCC Harmony Project is not displayed, install MCC.

  • 1.3. In the Framework Path edit box, browse to the folder where you downloaded the framework.

    Note: For more information on the content manager, see the Download MPLAB Harmony Framework section.

  • 1.4. In the Project Settings window, apply the following settings:
    • Location: Indicates the path to the root folder of the new project. All project files will be placed inside this folder. The project location can be any valid path, for example: Folder of your choice/dev/sam9x60_getting_started.
    • Folder: Indicates the name of the MPLABX .X folder. Enter “sam9x60_cu” to create a sam9x60_cu.X folder.

      Note: This must be a valid directory name for your operating system.

    • Name: Enter the project’s logical name as “getting_started_sam9x60”. This is the name that will be shown from within MPLAB X IDE.

      Note: The Path box is read-only. It will update as you make changes to the other entries.

    • Click Next to proceed to Configuration Settings.

Note: Clicking on the Show Visual Help button will open a help window providing a detailed description of the various fields in the Project Settings window.

  • 1.5. Follow the steps below to set the project’s Configuration Settings:
    • Name: Enter the configuration name as “sam9x60_cu”.
    • Device Family: SAM.
    • Target Device: Select SAM9X60D1G as the target device.
    • After selecting the target device, click Finish to create and open MPLAB Harmony v3 Project.

      This creates an empty project.

Step 2: Launch MCC and Project graph

Details


  • 2.1. After the project is created, MCC will be automatically launched. To launch MCC manually, from main menu –> click on “Tools” –> “Embedded” –> “MPLAB Code Configurator” or click simply MCC logo . It will launch Content manger Wizard.

    Then select MPLAB Harmony.

  • 2.2. In addition to the required package (csp), download the optional packages bsp, core, gfx_apps_sam_9x60, csp_apps_sam_9x60,core_apps_sam_9x60 and then click Finish. Content download will take some time, please wait till all the contents are downloaded.

  • 2.3. Save the MCC configuration inside your project directory.

  • 2.4. Now, the MCC plugin’s main window for the project will be displayed.

  • Resource Manager has two sections one is Project Resources and another one is Device Resources.
    • Project Resources area displays all the peripherals currently configured for the project. For example (CMSIS and Device Family Packs (DFP)).
    • Device Resources area displays available peripherals for the device. Click on the peripheral you want to add to your project. The peripheral moves to the MCC Project Resources area and is ready to be figured to your project’s requirements.
  • 2.5. To autosave the MCC configuration, go to Tools –> Option –> Plugins –> Editor Behavior –> Autosave MCC Configuration File.

Step 3: Configure the required peripheral libraries

Details


  • 3.1. Observe the Project Graph pane in the top center of the window. The Device Family Pack (DFP) and System libraries have been automatically added to the project.

  • 3.2. Before proceeding to the next step refer SAM9X60 Curiosity user guide, SAM9X60 data sheet and find the pin details for the peripherals/modules used in this project.
    • Refer section 3.3.3 of the user guide and find that PA0 and PA1 are used to read/write data from/to EEPROM via I2C compatible 2-wire serial interface.
      • Refer SAM9X60 data sheet and find that PA0 and PA1 are flexcom0 , 2-wire serial interface peripherals.
    • Refer section 3.5.1 of the user guide and find that PA9 and PA10 are used to transmit and receive data for serial debug com port.
    • Refer section 3.5.4 of the user guide and find that PD21 is used to connect Blue LED.
  • 3.3. Now, add SAM9X60 Curiosity BSP to the project graph by clicking “+” symbol from Device Resource –> Libraries –> Board Support Packages(BSPs) –> SAM9X60 curiosity BSP. This will configure LEDs and SWITCH (user push button).

  • 3.4. Add Flexcom0 to the project graph by clicking “+” symbol from Device Resource –> Peripherals —> Flexcom –> Flexcom0.

  • 3.5. Add serial debug peripheral to the project graph by clicking “+” symbol from Device Resource –> Peripherals –> DBGU. This will add the serial debug com port to the project graph.

  • 3.6. Open the configuration option of debug peripheral, added by clicking on the DBGU peripheral in the project graph.
    • Ensure the com port settings of serial debug as follows:

    • Ensure flexcom configurations are proper as shown below , by clicking flexcom.

    • Similarly check clock configurations for flexcom and debug unit are enabled by clicking system .

  • 3.7. From the Project Graph tab, select Plugins –> Pin Configuration to launch the Pin Configuration windows.

  • 3.8. The Pin Configuration window provides three different views:
    1. Pin Settings (which can be ordered by Pins or Ports)
    2. Pin Table
    3. Pin Diagram
  • 3.9. In the Pin Settings view, select Ports from the Order drop-down menu. The view will be ordered by Port name (labeled as Pin ID).
    Ensure the pins mentioned in the above section 3.2. is configured as follows.
  • 3.10. Save your configuration by clicking on the Save icon or selecting File –> Save Configuration from the menu bar. This completes the configuration of the required peripheral libraries.

Step 4: Generate Code

Details


  • 4.1. Now, generate the code by using MCC. From the left side tab, Resource Management (MCC), go to Project Resources and click on the Generate button.

  • 4.2. As the code is generated, MCC displays the progress.

  • 4.3. Examine the generated code files.
    MCC will include all the MPLAB Harmony v3 library files and generate the code based on the MCC selections. The generated code will add files and folders to your Harmony project. Among the generated code, notice the library files generated for BSP and peripheral libraries Debug, Flexcom. MCC also generates a template main file main.c.

Step 5: Add application Code to the Project and build the application

Details


  • 5.1. Up to this point in the project creation process, MPLAB Code Configurator(MCC) generated code to initialize the device (SAM9X60D1G) and initialize the peripherals. All that is left is for the user to write the application code in main.c file. Documentation for each of the peripheral libraries or diver libraries can be accessed as follows:
    1. Peripheral libraries APIs can be accessed as a HTML file (*.html) from the Harmony 3 Framework path. (framework_path/csp/docs/index.html)
    2. BSP libraries APIs can be found in bsp.h
    3. Driver libraries APIs can be accessed as a HTML file (*.html) from the Harmony 3 Framework path. (framework_path/core/docs/index.html)
  • 5.2. User can see DBGU_Initialize(), BSP_Initialize(), FLEXCOM0_TWI_Initialize() getting called in SYS_Initialze() function called from main.c.

  • 5.3. This project demonstrates below:
    • Print serial console debug messages.
    • Write, Read and Compare the data from the EEPROM .
    • Print TEST PASS if write and read data from EEPROM matches and turn ON the blue LED on the board.
  • 5.4. API used are as follows:
    • bool DBGU_Write( void* buffer, const size_t size );
    • bool DBGU_WriteIsBusy( void );
    • bool FLEXCOMx_TWI_Write(uint16_t address, uint8_t *pdata, size_t length);
    • bool FLEXCOMx_TWI_WriteRead(uint16_t address, uint8_t *wdata, size_t wlength, uint8_t *rdata, size_t rlength);
    • bool FLEXCOMx_TWI_IsBusy(void);
    • LED_BLUE_On();

Note: Refer section 5.1. to get the detailed API informations.

  • 5.5. Sample code to do the functionality mentioned in 5.3. is given below.
    • Global definition snippet:

    • Initialization snippet:

    • Main code snippet:

  • 5.6. Sample code to access EEPROM is available here.

    Note: Modify the code as per the requirement.
    
  • 5.7. Click on the Clean and Build Project icon from the tools bar or select Project –> Clean and Build Project from the menu bar. Observe that the build was completed successfully from the Output pane.

Step 6: Console Serial Communications

Details


Console Serial communications between the Host PC and the SAM9X60 Curiosity Development Board take place through UART debug port J11. A terminal emulation program running on the Host PC communicates with the SAM9X60 Curiosity DBGU UART port. Ensure the terminal emulation program(Eg: PUTTY) is configured to the COM port and settings are:

  • Speed: 115200
  • Data: 8
  • Parity: None
  • Stop Bits: 1

Step 7: Building/Downloading the at19Bootstrap

Details


The boot process of SAM9X60 begins with the MPU’s power-ON reset and progresses in stages reading binary files from external Non-Volatile Memory (NVM) and loading them into volatile memory (internal Static RAM (SRAM) and external Dynamic RAM (DRAM)).

  • 7.1. User can build the at91bootstrap file required to debug the application on MPLAB X IDE by following the steps mentioned here or

  • 7.2. User can get the pre-built at91bootstrap libraries by downloading the project from here as shown below.

Unzip the downloaded project, at91bootstrap.elf can be found in the project folder(sam9x60_cu_graphics_getting_started/firmware/sam9x60_cu.X)

Step 8: Debugging the Project

Details


Ensure external JTAG debugger is connected to J12.

  • 8.1. Now, check debugger settings are proper . To do that right click on project –> project properties –> In the Categories pane (on left), select Conf: –> J-Link –> choose the connected external JTAG.

    Ensure, the device chosen is SAM9X60D1G. Choose the latest compiler version and latest Device Family Pack(DFP) as shown below.

  • 8.2. Click Apply.

  • 8.3. Now, load at91bootstrap. From Project properties –> Config –> Bootstrap –> load bootstrap File(Use boot file from section 7) –> Apply –> Ok.

  • 8.4. By default, MPLAB X only produces ELF and Hex format output files. To generate binary files for SAM-BA programming, a post build step needs to be added to the project properties. To do this project properties –> Building –> Click the check box “Execute this line after build” –> Enter the below command.

    ${MP_CC_DIR}/xc32-objcopy -O binary ${DISTDIR}/${PROJECTNAME}.${IMAGE_TYPE}.elf ${DISTDIR}/harmony.bin

    Click Apply and ok.

  • 8.5. Observe debug reset and startup options.

    • To do this, In MPLAB X IDE, click on Tools –> Options. An Options window opens.
    • Click on the Embedded icon at the top and the Generic Settings tab.
    • Observe the settings for:
      • Debug Reset – Main
      • Debug startup – Halt at Main

In the next step, when you debug the project, MPLAB X IDE will compile the project and download it to the target. With the debug settings listed above, the IDE will reset and halt at the beginning of main.c.

  • 8.6. Click on the Debug Main Project by left clicking the Debug icon on the toolbar. The project will build with debugging parameters and load the application binary to the SAM9X60 Curiosity Development Board(otherwise known as the target).

    Once the build is complete and the application binary is loaded into the target, the toolbar expands to show additional debugging icons.

  • 8.7. Click on the Continue button. The application binary runs within the target. User can observe the following output in the serial console terminal emulation application as shown below.

Congratulations! You have opened, configured, built, and debugged an application program for MPLAB Harmony 3 Software Framework in MPLAB X IDE on SAM9X60 Curiosity Development Board.

               



Copyright © 2020 Microchip Technology.