MPLAB® Code Configurator Support for Dual-Core Devices

Last modified by Microchip on 2024/01/19 22:04

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.

Back to Top

Overview

This article provides information on using MCC to customize Master and Slave cores to leverage the 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 article guides you through:

  • Setting up the Master core using MCC
  • Setting up the Slave core using MCC
  • Exporting the Slave core related MCC settings from the Master Project
  • Importing 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 Dual-Core Digital Signal Controllers" family page.

For more information on getting started with dual-core devices, refer to Application Note AN2721 "Getting Started with Dual Core".

Back to Top

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.

Master/Slave core arangement

Back to Top

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.

The Slave core appears as a module in the device resource area of MCC in a Master Project.

Set slave configuation

Double-click on the Slave core's instance to add it to the Project Resource area.

Double-click on the Slave Core's instance to add it to the Project Resource area

Back to Top

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

configure the slave core

Back to Top

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.

Configuring MSI

Back to Top

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.

Configuring Slave In-Circuit Debugging

Back to Top

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.

Table 1
Clock SourceThis 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 PostscalerThis 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 EnableThe control allows you to select the PLL as the clock source for the Slave core.
Clock output pin configurationThis allows you to configure the OSC2 pin as either clock output or general purpose digital IO in the Slave core.
Enable Clock SwitchingThis allows your to enable the clock switching feature.
Enable Fail-SafeThis 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.

Configuring Slave Internal Oscillator

Back to Top

Configuring Slave Watchdog

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

Configuring Slave Watchdog

Back to Top

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 and 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.

Assigning Pin ownership to the Slave Core

assign pin ownership

Back to Top

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.

Naming the Slave Project

Back to Top

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 MPLAB X IDE.

Exporting Slave Core Settings

File where slave settings are saved

Back to Top

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.

Configuring Master Core

Back to Top

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.

Configuring MSI

Back to Top

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.

Configuring SLAVE ICD, SLAVE INTERNAL OSCILLATOR and SLAVE WATCHDOG

Back to Top

Pin Module

All the pins are available for selection in the Slave core by default. However, by default ownership of output pins lies with the Master core. For the pins that 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.

Pin Module

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

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

Back to Top

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 the "Exporting Slave Core Settings" section.

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 Master Core under the device resource area.

Importing Slave Core Settings

Back to Top

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.

Conflicts while Importing

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.

If you choose to override the pin settings, all the pins that are shown as conflicts will be deselected

Back to Top

Demo

Hardware Tools

  • Explorer 16/32 Development Board
  • dsPIC33CH128MP508 PIM

Software Tools

Minimum Tool Requirements

This demo was created and tested with these tool versions:

  • 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

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.

Master/Slave device diagram

Back to Top

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".

Back to Top


To launch MCC, click on the MCC icon in MPLAB X IDE or navigate to Tools > Embedded > MPLAB Code Configurator v3: Open/Close.

Back to Top


Under Device Resources, select Peripherals > Slave Core > SLAVE1. The SLAVE1 module automatically moves to the Project Resources window.

Back to Top


Switch to the SLAVE1 module GUI.

Back to Top


Enter the Slave Project Name as "Slave".

Configuring the Master project

Back to Top


In the MSI settings:

  • Enable Protocol A and change the direction to M->S.
  • Enable Protocol B.

MSI settings

Back to Top


In the Pin Manager: Grid View tab:

  • Select RE0 as GPIO output.
  • Assign ownership of RE1 to SLAVE1.

Pin Manager: Grid View tab

Back to Top


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".

In Project Resources, select Pin Module

Back to Top


In the Project Resources, select SLAVE1.

Click on Save Master Settings to save the SLAVE1 settings.
In Project Resources, select SLAVE1

The saved configuration file can be found in the Master Project directory as master_config.mc3.

The saved configuration file can found in the Master project directory

Back to Top


Check the Notifications [MCC] tab for any warnings.

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

Back to Top


Next to Project Resources, click on the Generate button. A confirmation window appears, indicating possible warnings. Continue to generate the code by clicking Yes.

click on the Generate button

The MCC configuration is now complete. The generated files are now added to the project you created.

The MCC configuration is now complete.

Back to Top


Configuring the Slave Project
Create an MPLAB X IDE project with the dsPIC33CH128MP508S1 device and name the project "Slave".

Back to Top


To launch MCC, click on the MCC icon in MPLAB X IDE or navigate to Tools > Embedded > MPLAB Code Configurator v3: Open/Close.

Back to Top


Under Project Resources and select Master Core.

Back to Top


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.

Configuring the Slave project

Back to Top


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.

a pop-up window shows a conflict for pin RB1

Back to Top


The MSI settings configured in the Master Project now get reflected in the Slave Project.

The MSI settings configured in the Master project now get reflected in the Slave project.

Back to Top


In the Pin Manager: Grid View tab, select RE1 as GPIO output.

the Pin Manager: Grid View tab

Back to Top


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".

In Project Resources, select Pin Module

Back to Top


Check the Notifications [MCC] tab for any warnings.

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

Back to Top


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.

The MCC configuration is now complete.

Back to Top


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….

In the Master project, select Slaves in the folder listing. Right-click and select Add Slave Project…

Back to Top


Browse to the Slave Project location and select the Slave.X image.

Browse to the Slave project location and select the Slave.X image.

Back to Top


In the Master Project, select Slaves in the folders listing. Right-click to change the properties. Select the Build checkbox.

select Slaves in the folders list

Back to Top


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);
}

Back to Top

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);
}

Back to Top

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.

Leds blinking

HSow which leds will blink

Back to Top