MPLAB® Code Configurator Support for Dual-Core Devices

Introduction

This section provides a brief introduction to Microchip's MPLAB® Code Configurator (MCC) support for dual-core devices.

MCC support for Microchip’s portfolio of dual-core devices (dsPIC33CH) provides an easy-to-use interface that enables users to speed up the development of dual-core devices. The dsPIC33CH Master and Slave Cores are designed so that the Slave Core can execute dedicated, time-critical control code while the Master Core is running the user interface and other applications such as system monitoring and communication functions.

The dsPIC33CH family is optimized to execute high-performance digital power, motor control and other applications requiring sophisticated algorithms. Some of the target applications are wireless power, server power supplies, drones and automotive sensors.

The dsPIC33CH is designed specifically to facilitate code development for each core by different design teams independently and allows seamless integration when codes are brought together on one chip.

The dsPIC33CH Slave Core subsystem is a PRAM-based application accelerator. The Slave Core’s code will reside in the flash memory of the Master Core. After a designated time lapse following the system start-up, the Master Core under user control transfers the Slave’s programming image from the flash memory to the Slave’s PRAM. Once the initialization of the Slave is completed, the Master empowers the Slave. The Slave code is executed by the Slave Core and its first task is to initialize its peripherals. Once the Master and Slave Cores are operating, they can exchange information, commands, and status through the Master/Slave Interface (MSI) module.

The MSI module provides several registers (mailboxes) by which information can be shared between the cores. There is an interrupt logic associated with the MSI registers, which are used as semaphores (flags) to notify the other core when information is ready for transfer.

There are different ways to develop code for Master and Slave Cores, projects can be developed and debugged on the Master and Slave Cores independently or simultaneously. The user code for each core can be optimized individually.

Overview

This document provides information to use the MCC to customize Master and Slave Cores to leverage maximum potential of a dual-core device. To support independent code development for each core, MCC can be started on either the Master Core's MPLAB X IDE Project or the Slave Core's MPLAB X IDE Project.

Hereafter, a Master Core's MPLAB X IDE Project and a Slave Core's MPLAB X IDE Project will be referred to as the Master Project and the Slave Project, respectively.

In a Master Project, Slave Core related fuses need to be configured. This information needs to be shared with the Slave Project and is facilitated by exporting and importing configuration related information using MCC. The sharing of information from Master Project to Slave Project facilitates MCC to display the settings in the Slave Project, which you configure in the Master Project. If this information is not shared, MCC will display the default setting values in the Slave Project. These settings are not editable in the Slave Project and are only shown to help you in independent code development. Any change required in these settings can only be done in the Master Project. Any modification you make to the Slave Core fuses in the Master Project, the settings have to be shared with the Slave Project, and MCC displays these settings in the Slave Project in synchronous with the Master Project.

This document guides you to:

  • Set up the Master Core using MCC
  • Set up the Slave Core using MCC
  • Export the Slave Core related MCC settings from the Master Project
  • Import the Slave Core related MCC settings done in the Master Project to the Slave Project

For more information on dual-core devices visit the dsPIC33CH family page.
For more information on getting started with dual-core devices, refer to Application Note AN2721.

Setting up the Master Project

Setting up the Master Core involves selecting the Slave Core and configuring it. The following sections explain the steps involved in setting up the Master Core.

ConfiguringMasterCore.png

Slave Core Selection and Configurations

To select the Slave Core for configuration:

  • Create an MPLAB X IDE project or open an already existing MPLAB X IDE project with the Master device selected from the dsPIC33CH family.
  • Launch MCC by
    • Clicking on the MCC icon in MPLAB X IDE, or
    • Navigating to Tools > Embedded > MPLAB Code Configurator v3: Open/Close.
  • Slave Core appears as a module in the device resource area of MCC in a Master Project.
SettingUpMasterProject1.png
  • Double-click on the Slave Core's instance to add it to the project resource area.
SettingUpMasterProject2.png

Configuring the Slave Core

In order to set up the Slave Core, configure the following modules.

  • MSI
  • Slave's ICD
  • Slave's Internal oscillator
  • Slave's Watchdog
SettingUpMasterProject3.png

Configuring MSI

The MSI is the data gateway between the Master Core and the Slave Core, each of which operates within independent clock domains. The MSI module is primarily intended to move data between the cores.

The Mailbox Configuration table provided in MCC allows you to:

  • Configure handshake protocols by selecting the buffer size. Based on the selected buffer size, MCC allocates a set of mailbox registers to the specific protocol.
  • Define the direction of data flow, whether from M → S (Master to Slave) or S → M (Slave to Master).
  • Optionally, assign a custom name to each protocol. This custom name is used as part of API signatures for the protocol in the generated MCC code.
SettingUpMasterProject4.png

Configuring Slave In-Circuit Debugging (ICD)

These settings in MCC allow you to select pins used for in-circuit debugging of the Slave Core. You must select Programming Clock (PGC) and Programming Data (PGD) pins based on the hardware used.

SettingUpMasterProject5.png

Configuring Slave Internal Oscillator

These settings in MCC allow you to configure the required clock source, FRC Postscaler, PLL, Clock switching and Fail-Safe monitor for the Slave Core.

Clock Source This allows you to select the required clock source such as FRC Oscillator, Primary Oscillator, External Clock, LPRC Oscillator, Secondary Oscillator, and Digitally Controlled Oscillator depending on the application. The clock source options may vary with the device used.
Enable FRC Postscaler This allows you to enable the FRC clock divider for the Slave Core and is available only when FRC is selected as the clock source.
PLL Enable The control allows you to select the PLL as the clock source for the Slave Core.
Clock output pin configuration This allows you to configure the OSC2 pin as either clock output or general purpose digital IO in the Slave Core.
Enable Clock Switching This allows your to enable the clock switching feature.
Enable Fail-Safe This allows you to enable or disable the fail-safe monitor feature. When enabled, the fail-safe monitor allows the device to continue to operate even in the event of an oscillator failure.
SettingUpMasterProject6.png

Configuring Slave Watchdog

These settings allow you to configure the Slave Core's watchdog timer.

SettingUpMasterProject7.png

Assigning Pin ownership to the Slave Core

Master Core and Slave Core share the IO ports on the device. The input feature is available to both the cores, whereas the output feature is decided as per the ownership fuses. By default, the output ownership of a pin resides with the Master Core. If the Slave Core needs the output ownership of a particular pin, the ownership configurations have to be changed. Both the Master Core and the Slave Core(s) can monitor a pin as an input as long as the monitoring is of the same type—digital or analog.
The output ownership can be modified in the 'Pin Manager: Grid View' or the register view under 'System Module'.

The following figures illustrate an example pin assignment procedure.

SettingUpMasterProject8.png
SettingUpMasterProject9.png

Naming the Slave Project

The Master Core is programmed with both Master Code and Slave Code. It is required to include the Slave project image header as a part of the Master Code. During execution, the Master Core is initialized first, and the Master Core transfers the Slave Code onto the Slave PRAM.
MCC expects the Slave Core project name to be mentioned in the UI. You need to provide the Slave Core MPLAB X IDE project name in the text box. The Slave Core MPLAB X IDE project name provided is used to include a Slave project image header in the Master project generated code.

The Slave project name you entered in the MCC of the Master Project should exactly match the Slave project created. Failing to do so, the generated code may not compile.

SettingUpMasterProject10.png

Exporting Slave Core Settings

In a Master Project, the configuration fuses related to Slave Core are configured. This setting information needs to be communicated to the Slave Project and is facilitated by exporting and importing the settings.

To export the settings, click on the Save Master Settings button. The settings are saved in the master_config.mc3 file, which resides in the Master Project directory. The created file can also be viewed under the "Important Files" section of MPLABX IDE.

SettingUpMasterProject11.png
SettingUpMasterProject12.png

Setting up the Slave Project

Setting up the Slave Core in a Slave Project involves importing the settings for the Slave Core, which are configured in the Master Project. The settings imported are grouped under the Master Core section in the System resources of MCC. The following sections explain the procedures involved in setting up the Slave Core.

Configuring Master Core

  • Create an MPLAB X IDE project or open an already existing MPLAB X IDE project with the Slave device selected from the dsPIC33CH family.
  • Launch MCC by:
    • Clicking on the MCC icon in MPLAB X IDE, or
    • Navigating to Tools > Embedded > MPLAB Code Configurator v3: Open/Close.
  • Master Core appears as a system resource in the Slave Project.

The Master Core contains the configuration fuses of the Slave Core (MSI, Slave ICD, Slave Internal oscillator and Slave Watchdog), which are configured in the Master Project. To display the settings selected in the Master Project, the settings need to be imported from the Master Project. The procedure to import the settings is explained in the "Importing Slave Core Settings" section.

SettingUpSlaveProject1.png

Configuring MSI

The MSI controls are non-editable in the Slave Project. All the settings related to MSI have to be done in the Master Project and must be imported from the Master Project. Interrupts for the protocols can be configured only after importing the settings.

SettingUpSlaveProject2.png

Configuring SLAVE ICD, SLAVE INTERNAL OSCILLATOR and SLAVE WATCHDOG

On the first launch of MCC, the configurations related to Slave ICD, Internal Oscillator, and Watchdog have default values in the Slave Project. You cannot change any of these configurations in the Slave Project. If any change is required, you have to modify these configurations in the Master Project, save the settings and import the modified settings to the Slave Project. After importing the settings, you will see the configurations made in the Master Project, which are applicable to the Slave Project.

SettingUpSlaveProject3.png

Pin Module

All the pins are available for selection in the Slave Core by default. However, by default ownership of output pins lie with the Master Core. For the pins which are being used by the Slave Core, the ownership of those pins has to be assigned to the Slave Core in the Master Project and those settings need to be imported in the Slave Project.

SettingUpSlaveProject4.png

The 'Notifications [MCC]' tab notes of the Slave Project does not possess the ownership of the selected pins.

SettingUpSlaveProject5.png

Importing Slave Core Settings

Fuses related to the Slave Core are configured in the Master Project and MCC facilitates the exporting and importing of these configuration details to the Slave Project. Exporting of settings from the Master Project is explained in section "Exporting Slave Core Settings".

To import the settings, click on the Load Master Settings button. The settings are saved in the master_config.mc3 file, which resides in the Master Project's directory. Select the file for import.

On Import:

  • All settings related to the Slave Core that were configured in the Master Project get updated to the Slave Project.
  • The updated settings can be viewed by clicking on the Master Core under the device resource area.
SettingUpSlaveProject6.png

Conflicts while Importing

Any conflict that arises while importing the settings will be noted and it is up to you to resolve the notifications accordingly.
For example, the ownership of pins RA0, RA1 lie with the Master Core, and the ownership of pins RA2, RA3, RA4 has been assigned to Slave Core in the Master Project. However, you used RA0, RA1 in the Slave Project. While importing the settings from the Master Project, a pop-up appears indicating the conflicts in ownership for RA0, RA1 since the configuration fuses relating to the ownership of these pins are assigned to the Master Core. You can either choose to override the pin settings from the Master Core or retain it by rejecting the changes.

SettingUpSlaveProject7.png

If you choose to override the pin settings, all the pins that are shown as conflicts will be deselected. However, if you choose to ignore the warning, the pin settings will be retained and notifications for the same will be displayed in the 'Notifications [MCC]' tab.

SettingUpSlaveProject8.png

Demo

MSI Demo

This demo illustrates the process involved in using MCC to configure the System, MSI module, I/O ports ownership in a Master Project, and the Slave Project of a dual-core device.

Objective:

  • Start up MCC in the Master Core MPLAB X IDE project for the dsPIC33CH128MP508 device.
  • Setup the configuration for MSI, I/O pin ownership in the Master Project and export the settings.
    • Configure the MSI mailbox to transfer one word of data from the Master Core to the Slave Core.
    • Configure the MSI mailbox to receive one word of data from the Slave Core to the Master Core.
    • Assign an output pin ownership to the Slave Core.
  • Start up MCC in the Slave Project for dsPIC33CH128MP508S1.
  • Import the settings from the Master Project into the Slave Project.
  • Include Slave Project in a Master Project.
  • Generate code to:
    • Transfer data 0xAAAA from the Master Core to the Slave Core using MSI
    • Retransmit the received data at the Slave Core to the Master Core
    • Flash an LED on data match at the Master Core.
    • Flash an LED on valid data reception at the Slave Core.
Demo.png

Hardware Requirements

Tool About Purchase
Explorer1632-50px.png
Explorer 16/32
Development Board
dsPIC33CH128MP508 PIM Purchase Link >

MCC System Requirements

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC16
C Compiler
swtool-28px.png
MPLAB® Code Configurator
Dynamic Code Generation
  • MPLAB X IDE v4.20 or newer
  • XC16 compiler v1.35 or newer
  • MPLAB Code Configurator (MCC) Plugin v3.55.1 or newer
  • MPLAB Code Configurator (MCC) PIC24/dsPIC33/PIC32MM MCUs Library v1.65 or newer

Configuring MCC

The following sections provide procedures to configure the Master Project and the Slave Project using MCC.

Configuring the Master Project

  • Create an MPLAB X IDE project with the dsPIC33CH128MP508 device and name the project Master.
  • To launch MCC, click on the MCC icon in MPLAB X IDE or navigate to Tools > Embedded > MPLAB Code Configurator v3: Open/Close to launch MCC.
  • Under 'Device Resources', select Peripherals > Slave Core > SLAVE1. The SLAVE1 module automatically moves to the Project Resources window.
  • Switch to the SLAVE1 module GUI.
  • Enter the Slave Project Name as Slave.
DemoMaster1.png
  • In the MSI settings:
    • Enable Protocol A and change the direction to 'M->S'.
    • Enable Protocol B.
DemoMaster2.png
  • In the 'Pin Manager: Grid View' tab:
    • Select 'RE0' as GPIO output.
    • Assign ownership of 'RE1' to SLAVE1.
DemoMaster3.png
  • In the 'Project Resources', select 'Pin Module'.
    • Ensure that the pins are configured as explained in the previous step.
    • Enter a custom name to pin RE0 as LED_MASTER.
DemoMaster4.png
  • In the 'Project Resources', select 'SLAVE1'.
    • Click on Save Master Settings to save the SLAVE1 settings.
    • The saved configuration file can found in the Master Project directory as master_config.mc3.
DemoMaster5.png
DemoMaster6.png
  • Check the 'Notifications [MCC]' tab for any warnings.

You should always resolve "severe" type notifications on their respective modules.

  • Next to "Project Resources", click on the Generate button. A confirmation window appears, indicating possible warnings. Continue to generate the code by clicking Yes.
DemoMaster7.png
  • The MCC configuration is now complete. The generated files are now added to the project you created.
DemoMaster8.png

Configuring the Slave Project

  • Create an MPLAB X IDE project with the dsPIC33CH128MP508S1 device and name the project Slave.
  • To launch MCC, click on the MCC icon in MPLAB X IDE or navigate to Tools > Embedded > MPLAB Code Configurator v3: Open/Close.
  • Under "Project Resources", select 'Master Core'.
  • Click Load Master Settings and navigate to the Master Project directory location and select the master_config.mc3 file. Now the settings of Slave1 (Slave Core) configured in the Master Project are imported.
DemoSlave1.png
  • After importing, a pop-up window shows a conflict for pin RB1. The conflict arises since the pin RB1 was assigned for CLKO functionality by default in the Slave Project and the same pin is also assigned for CLKO in the Master Project. Accept to override to retain the Master Project settings.
DemoSlave2.png
  • The MSI settings configured in the Master Project now get reflected in the Slave Project.
DemoSlave3.png
  • In the 'Pin Manager: Grid View' tab:
    • Select RE1 as GPIO output.
DemoSlave4.png
  • In the "Project Resources", select 'Pin Module'.
    • Ensure that the pins are configured as explained in the previous step.
    • Enter the custom name for pin RE0 as LED_SLAVE.
DemoSlave5.png
  • Check the 'Notifications [MCC]' tab for any warnings.

You should always resolve "severe" type notifications on their respective modules.

  • Next to "Project Resources", click on the Generate button.
  • The MCC configuration is now complete. The generated files are now added to the project you created.
DemoSlave6.png

Including the Slave Project in the Master Project

  • In the Master Project, select 'Slaves' in the folder listing. Right-click and select 'Add the Slave Project…'.
DemoInclusion1.png
  • Browse to the Slave Project location and select the Slave.X image.
DemoInclusion2.png
  • In the Master Project, select 'Slaves' in the folders listing. Right-click to change the properties. Select the 'Build' checkbox.
DemoInclusion3.png

Application Code

Master Project

Edit the main.c file as shown in the example.

#include "mcc_generated_files/mcc.h"
 
#define DATA_UNDER_TEST 0xAAAA
 
int main(void)
{
    // initialize the device
    SYSTEM_Initialize();
 
    //Program and enable slave
    SLAVE1_Program();
    SLAVE1_Start();
 
    ProtocolA_DATA dataSend;
    ProtocolB_DATA dataReceive;
 
    dataSend.ProtocolA[0] = DATA_UNDER_TEST;
    dataReceive.ProtocolB[0] = 0;                         //Initializing to known value.
 
    //Mailbox write
    SLAVE1_ProtocolAWrite((ProtocolA_DATA*)&dataSend);
 
    //Issue interrupt to slave
    SLAVE1_InterruptRequestGenerate();
    while(!SLAVE1_IsInterruptRequestAcknowledged());
    SLAVE1_InterruptRequestComplete();
    while(SLAVE1_IsInterruptRequestAcknowledged());
 
    //Wait for interrupt from slave
    while(!SLAVE1_IsInterruptRequested());
    SLAVE1_InterruptRequestAcknowledge();
    while(SLAVE1_IsInterruptRequested());
    SLAVE1_InterruptRequestAcknowledgeComplete();   
 
    //Mailbox read
    SLAVE1_ProtocolBRead((ProtocolB_DATA*)&dataReceive);
 
    //Glow LED on data match
    if(dataReceive.ProtocolB[0] == DATA_UNDER_TEST)
    {
        LED_MASTER_SetHigh();
    }
    else
    {
        LED_MASTER_SetLow();
    }
 
    while (1);
}

Slave Project

Edit the main.c file as shown in the example.

#include "mcc_generated_files/mcc.h"
 
#define DATA_UNDER_TEST 0xAAAA
 
int main(void)
{
    // initialize the device
    SYSTEM_Initialize();
 
    ProtocolA_DATA dataReceive;
    ProtocolB_DATA dataSend;
 
    dataReceive.ProtocolA[0] = 0;                 //Initializing to known value.
    dataSend.ProtocolB[0] = 0;                      //Initializing to known value.
 
    //Wait for interrupt from master    
    while(!MASTER_IsInterruptRequested());
    MASTER_InterruptRequestAcknowledge();
    while(MASTER_IsInterruptRequested());
    MASTER_InterruptRequestAcknowledgeComplete();
 
    //Mailbox read    
    MASTER_ProtocolARead((ProtocolA_DATA*)&dataReceive);
 
    //Copy the received data for retransmission
    dataSend.ProtocolB[0] = dataReceive.ProtocolA[0];
 
    //Mailbox write 
    MASTER_ProtocolBWrite((ProtocolB_DATA*)&dataSend);
 
    //Issue interrupt to master
    MASTER_InterruptRequestGenerate();
    while(!MASTER_IsInterruptRequestAcknowledged());
    MASTER_InterruptRequestComplete();
    while(MASTER_IsInterruptRequestAcknowledged());
 
    //Glow LED on data match
    if(dataReceive.ProtocolA[0] == DATA_UNDER_TEST)
    {
        LED_SLAVE_SetHigh();
    }
    else
    {
        LED_SLAVE_SetLow();
    }
 
    while (1);
}

LEDs Display for Received Messages

  • Select the Master Project as the main project.
  • Make and program the project.

The Master Core is configured to transmit a word of data to the Slave Core and the Slave Core is configured to re-transmit to the Master Core.

In case of a power-on-reset:

  • The Master Core transmits 0xAAAA and issues an interrupt to the Slave Core. The Slave Core acknowledges the interrupt, re-transmits the received data and issues an interrupt back to the Master Core.
  • The Master Core acknowledges the interrupt and receives the data and verifies it.
  • When the transmitted data and received data matches, the Master Core flashes an LED (D3) connected to pin RE0 of the device.
  • Similarly, the received data at the Slave Core is also compared and verified. The Slave Core flashes an LED (D4) connected to pin RE1 of the device to acknowledge a successful reception.
DemoResult1.png
DemoResult2.png
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.