CAN Demo in MPLAB X on SAMe54 Xplained Pro - gneidermeier/CANFDDemo_SAMe54_START GitHub Wiki
Introduction
The Microchip SAMe54 Xplained Pro is a hardware platform for evaluation of SAM D5x and SAME5x MCUs. The SAM E MCU is a family of MCUs based on 32-bit ARM Cortex M4 core introduced by Atmel, but now acquired and incorporated into the Microchip product line. The SAMe54 XP eval board is supported in MPLAB X IDE with a variety of reference projects. This guide will follow the setup of MPLAB X and bringing up the example software for demonstration of the CAN bus.
Requirements
The intent of this specific document is to provide a quick guide to setup and configure the MPLAB environment and all required software tools to work with the SAMe54 XP - to that end, no previous previous requirements or setup are necessary. However, please follow instructions in my introductory guide to SAMe54 and CAN bus in order to run the demo code introduced later in the document. This guide definitely does NOT provide a beginner introduction to CAN bus.
Optional - setup CAN bus. In the introductory tutorial of this series, a minimal CAN bus was connected between the SAMe54 XP and the PC using the Peak System USB to CAN adapter. Please refer to appropriate section of that document to ensure that the CAN bus hardware is properly connected and associated software tools are installed.
Setup
Links to MPLAB-X and related software install packages will be found on the Microchip Developer Help website, specifically "Peripheral Libraries on SAM D5x/E5x" section. Open the web page and scroll down to "Software Tools" (under >Materials) to find download links for MPLAB X and MPLAB XC32 installers.
This guide was prepared in support of the Windows 10 environment, so the following installers were downloaded for MPLAB X and MPLAB XC32 (under "Software Tools"):
- MPLABX-v5.30-windows-installer
- xc32-v2.30-full-install-windows-installer
Install MPLAB-X
- run the MPLABX installer, which upon completion will offer additional websites to additional downloads for additional downloads e.g. XC32 and MPLAB® Harmony v3.
- after the MPLABX installation completes, run the installer for XC32. When prompted, select Free mode
MPLAB Harmony Configurator (MHC3) plugin
After completing MPLAB X and XC32 installs, the MPLAB Harmony Configurator (MHC3) plug-in should be installed. Detailed instructions can be found on microchipdeveloper.com/harmony3:mhc-overview#install section of Microchip Developer Help website. The plug-in is installed from within the MPLAB X IDE, so be sure MPLAB X is installed first. (Note: the online instructions are fairly clear that Harmony Configurator 3 is to be installed and not the previous version 2)
MPLAB Harmony Framework
After installing the MPLAB Harmony Configurator (MHC3) plug-in, continue following instructions in the section Download MPLAB Harmony Framework. In the Harmony Content Manager dialog box, be sure that Framework Path is set to a suitable user directory (e.g. C:\Users\gneidermeier\Microchip-MPLAB-Harmony). The remote URL for downloading should be set to https://github.com/microchip-mplab-harmony.
The Harmony Content Manager plug-in dialog should open with items mhc, devpacks, and csp selected for download. Click download for these items (requires acceptance checkbox for software license to continue download).
Opening a demo project in MPLAB X
Open a project in MPLAB X IDE by selecting Open Project from under the File menu. Demo apps should be available downloaded into Microchip-MPLAB-Harmony directory (this would be the user directory that was setup in the Harmony Content Manager plugin installation). In MPLAB X Open Project dialog, try browsing to the MPLAB user directory e.g. C:\Users\gneidermeier\Microchip-MPLAB-Harmony\csp\apps.
Underneath the MPLAB user directory hierarchy, the demo projects are organized according to peripheral module e.g. Microchip-MPLAB-Harmony\csp\apps\can. The CAN bus peripheral has several demo apps available - open the > CAN-normal-operation-blocking project e.g. C:...\Microchip-MPLAB-Harmony\csp\apps\can\can_normal_operation_blocking\firmware, select the project file for SAM e54 Xplained-Pro, (sam_e54_xpro.X) and click Open Project.
Setting Device Firmware Pack
At this point, the 'can_demo_sam_e54_xpro' project should be open in MPLAB X IDE. However, it is possible that the DFP (Device Firmware Pack) loaded in the previous steps may actually be newer than (and thus incompatible with) the DFP configuration reference by the example project - the error message seen would be something like load error: SAME54_DFP 3.0.27 is used in the configuration and it is not installed
.
Follow these additional steps to install compatible DFP (Device Firmware Pack) version:
- In MPLAB-X, open [File | Project Properties] and expand the hierarchy under Conf: [sam_e54_xpro]. In the Packs pane, find SAME54_DFP. My setup had SAME54_DFP v3.1.43 installed by default. Close the Project Properties window to continue.
- To install a new DFP pack version: in MPLAB-X IDE select the menu item [Tools | Packs] to open the Packs tab - first click Check for Updates. The search box can be used e.g. enter "same54" to locate SAME54_DFP in the available packs. To install DFP 3.0.27 for the SAMe54-XP, click the Install hypertext to the right of the 3.0.27 line item.
Once the 3.0.27 pack is downloaded and installed, open open [File | Project Properties] to confirm installation of DFP 3.0.27.
Running/debugging demo project
There are several demo apps available to demonstrate the CAN bus. Locate the CAN-normal-operation-blocking project by browsing for it under the Microchip user directory e.g. _C:...\Microchip-MPLAB-Harmony_. Open the project by selecting project file for SAM e54 Xplained-Pro csp\apps\can\can_normal_operation_blocking\firmware\sam_e54_xpro.X and clicking Open Project.
Choose Debug->Debug Project to build the project and flash the resulting firmware image to the device.
Open the PCAN-View program and connect to the CAN bus with default settings and 500kBit/s bitrate. Open a terminal emulator program on the host PC and connect to the EDBG virtual COM port. In the terminal emulator setup, configure the session connection for 115200 bit/s (8-n-1-none on the other settings which is typically the default in terminal programs I use).
The demo firmware prints the text of its menu options to the serial port, which should be seen on the terminal emulator if configured properly.
Transmit test
With PCAN-View open, connected to the CAN bus and configured for 500kbs, press '1' to transmit a CAN message from the SAMe54, standard 11-bit CAN ID $469. Message should be displayed in Receive pane of PCAN-View - transmit test can be repeated, with PCAN-View updating message count and timestamp each time it receives the repeated message transmission.
Receive test
Create a new message to transmit from PCAN-View. This needs to be a standard ID message for now (firmware on e54 is fixed to standard ID). Set the message for periodic transmission at e.g. 1000mS. Each press of '2' on the terminal emulator keyboard should display the content (ID and data byes) of the received message.