element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
At The Core Design Challenge
  • Challenges & Projects
  • Design Challenges
  • At The Core Design Challenge
  • More
  • Cancel
At The Core Design Challenge
Blog Tennis Picker@The Core #2 The Mechanism of IPC semaphore
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join At The Core Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 22 Mar 2023 7:54 AM Date Created
  • Views 702 views
  • Likes 8 likes
  • Comments 2 comments
Related
Recommended

Tennis Picker@The Core #2 The Mechanism of IPC semaphore

fyaocn
fyaocn
22 Mar 2023

#2 The Mechanism of IPC semaphore

Table of Contents

  • 1 Rocking the IPC@the Core
  • 2 ModusToolbox  3.0 for IPC project
  • 3 WorkFlow for PSoC 62S4 dual-core IPC Project
  • 4 Create IPC Semapore Project
  • 5 IPC semaphore Build and Run
  • 6 Summary
  • Reference

1 Rocking the IPC@the Core

Themes of At the Core challenge is pushing the limits of Dual Core on the PSoCTm 62S4, to take advantage of the dual core architecture of the PSoC 62 microcontroller. Here is the CPU subsystem with Cortex-M0+ core and Cortex-M4 core.

image

Inter-processor communication (IPC) provides the functionality for multiple processors to communicate and synchronize their activities. IPC hardware is implemented using two register structures.This allows for building varying models of interface,
■ IPC Channel: Communication and synchronization between processors is achieved using this structure.
■ IPC Interrupt: Each interrupt structure configures an interrupt line, which can be triggered by a ‘notify’ or ‘release’ event of any IPC channel.
image

To make it simplified, to understand IPC, one can take IPC channel as kind of LOCK. The IPC channels can be used to implement locks for some form of mutually exclusive access to a shared resource. When multiple processors share a resource, the processors are capable of acquiring and releasing the IPC channel. So the processor can assume an IPC channel as a lock. This IPC mechanism can avoid confict on resource access.

For PSoC 62S4, the shared resource is accessible by two 32-bit register  IPC_STRUCTx_DATA0 and IPC_STRUCTx_DATA1. These registers can be considered as the shared data memory for the channel. Typically, these registers will hold messages that need to be communicated between processors. If the messages are larger than the combined 64-bit size, place pointers in one or both of these registers. It takes some time to understand every details in graph below, 

image

With all the reference files list below, one can get full picture. But just remember, the IPC channel is one LOCK to shared Memery for M0+ core and M4 core to access safely. And Infineon’s ModusToolbox 3.0 is just the perfect software development platform.

2 ModusToolbox  3.0 for IPC project

In addition to Modus Toolbox, PSoC creator is alternative choice for IPC project.

image

But PSoC 62S4 is not supported for now. So use Modus Toolbox IDE instead,

image

3 WorkFlow for PSoC 62S4 dual-core IPC Project

3.1 Startup sequence

After device reset, only CM0+ executes; CM4 is held in a reset state. CM0+ first executes Infineon system and security code. After CM0+ executes the system and security code, it executes the application code. In the application code, CM0+ may release the CM4 reset, causing CM4 to start executing its application code.

3.2 Create a dual-core application

  • Create new application based on an existing dual-CPU code example. Use any code example with a repo name that includes “dual-CPU” as a start point. For most cases, the mtb-example-psoc6-dual-cpu- empty-app is a good choice. That is easy to start but it takes more time to debugg.
  • Or convert single-core application to a dual-core application.

Change Makefile variables – Open the Makefile of the application and modify the variables. The common.mk and common_app.mk Makefiles at the root level of the dual-core application shall be modified as well such as MTB_TYPE, APPNAME, COMPONENTS, and DISABLE_COMPONENTS and add new values for variables such as COMPONENTS and DISABLE_COMPONENTS.

Customizing linker scripts - The CM0+ and CM4 projects each have their own linker scripts supplied by the BSP. By default, the CM0+ CPU consumes only 8192 [0x2000] bytes of flash and 8192 [0x2000] bytes of SRAM. If CM0+ project requiresmore memory, both linker scripts require changes.The CM0+ linker script is located at directory - bsps/TARGET_APP_<BSP_NAME>/COMPONENT_CM0P.

Sharing libraries and peripherals - The deps folder of each project contains the list of libraries used by that project. As described earlier ModusToolbox use Library Manager to manage BSP and libraries.

Create source files - Coding for the customized project. Balance performance and low power status.

4 Create IPC Semapore Project

The sample project share the UART hardware block to send messages to the computer. An IPC semaphore controls access to the UART to avoid situations where both CPUs attempt to send messages at the same time. The same IPC semaphore is also used to synchronize the initialization code between the two CPUs. The example provides an option to disable  semaphore usage to observe how it affects the system. An LED on the kit indicates whether the semaphore is being used.

The main code in M0+ core,

int main(void)
{
    cy_rslt_t result;

    /* Initialize the device and board peripherals */
    result = cybsp_init() ;
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }
    /* Enable global interrupts */
    __enable_irq();

    /* Lock the sempahore to wait for CM4 to be init */
    Cy_IPC_Sema_Set(SEMA_NUM, false);

    /* Enable CM4. CY_CORTEX_M4_APPL_ADDR must be updated if CM4 memory layout is changed. */
    Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR);

    /* Wait till CM4 unlocks the semaphore */
    do
    {
        __WFE();
    }
    while (Cy_IPC_Sema_Status(SEMA_NUM) == CY_IPC_SEMA_STATUS_LOCKED);

    /* Update clock settings */
    SystemCoreClockUpdate();

    for (;;)
    {
        /* Check if the button is pressed */
        if (Cy_GPIO_Read(CYBSP_SW2_PORT, CYBSP_SW2_PIN) == 0)
        {
        #if ENABLE_SEMA
            if (Cy_IPC_Sema_Set(SEMA_NUM, false) == CY_IPC_SEMA_SUCCESS)
        #endif
            {
                /* Print a message to the console */
                Cy_SCB_UART_PutString(CYBSP_UART_HW, "Message sent from CM0+\r\n");

            #if ENABLE_SEMA
                while (CY_IPC_SEMA_SUCCESS != Cy_IPC_Sema_Clear(SEMA_NUM, false));
            #endif
            }
        }
    }
}

The main code in M4 core,

int main(void)
{
    cy_rslt_t result = CY_RSLT_SUCCESS;

    /* Initialize the device and board peripherals */
    result = cybsp_init();
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    /* Enable global interrupts */
    __enable_irq();

    /* Free the hardware instance object iff initialized by other core
     * before initializing the same hardware instance object in this core. */
    cyhal_hwmgr_free(&CYBSP_UART_obj);
    cyhal_hwmgr_free(&CYBSP_DEBUG_UART_RX_obj);
    cyhal_hwmgr_free(&CYBSP_DEBUG_UART_TX_obj);
    cyhal_hwmgr_free(&CYBSP_SW2_obj);

    /* Initialize retarget-io to use the debug UART port. */
    result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX,
            CY_RETARGET_IO_BAUDRATE);
    CY_ASSERT(result == CY_RSLT_SUCCESS);

    /* Initialize the User Button */
    result = cyhal_gpio_init(CYBSP_USER_BTN, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF);
    CY_ASSERT(result == CY_RSLT_SUCCESS);

    /* Initialize the User LED */
    result = cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, LED_STATE);
    CY_ASSERT(result == CY_RSLT_SUCCESS);

    /* Unlock the semaphore and wake-up the CM0+ */
    Cy_IPC_Sema_Clear(SEMA_NUM, false);
    __SEV();

    /* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
    printf("\x1b[2J\x1b[;H");

    printf("******************  IPC Semaphore Example  ****************** \r\n\n");

    printf("<Press the kit's user button to print messages>\r\n\n");

    for (;;)
    {
        if (cyhal_gpio_read(CYBSP_USER_BTN) == CYBSP_BTN_PRESSED)
        {
        #if ENABLE_SEMA
            /* Attempt to lock the semaphore */
            if (Cy_IPC_Sema_Set(SEMA_NUM, false) == CY_IPC_SEMA_SUCCESS)
        #endif
            {
                /* Print a message to the console */
                printf("Message sent from CM4\r\n");

            #if ENABLE_SEMA
                while (CY_IPC_SEMA_SUCCESS != Cy_IPC_Sema_Clear(SEMA_NUM, false));
            #endif
            }
        }
    }

}

Compare the two codes, it can be found that M0+ core start M4 core by release the RESET signal,

 Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR);

Check the IPC semaphore LOCK with the while loop,

  while (Cy_IPC_Sema_Status(SEMA_NUM) == CY_IPC_SEMA_STATUS_LOCKED);

Toggle the LOCK status with

Cy_IPC_Sema_Set(SEMA_NUM, false) == CY_IPC_SEMA_SUCCESS

Thus, semaphore channel start exchange DATA.

5 IPC semaphore Build and Run

Build the dual-core project with one-click, two-stage build. Stage 1, build for Core M0+

image

Stage 2 , build for Core M4, and return with no errors.

image

Program the code

image

Run with information exchange , toggling interlock status  of semaphore channel M0+ core and M4 core

image

6 Summary

This blog gives general work flow for Dual-CPU project, as start point for construting Tennis Picker Project.

Reference

1) Infineon-PSoC_6_MCU_CY8C61x4_CY8C62x4_Architecture_Technical_Reference_Manual_PSoC_61_PSoC_62_MCU-AdditionalTechnicalInformation-v04_00-EN.pdf

2) Infineon-AN215656_PSoC_6_MCU_Dual-CPU_System_Design-ApplicationNotes-v10_00-EN.pdf

3) https://infineon.github.io/mtb-pdl-cat1/pdl_api_reference_manual/html/group__group__ipc.html


#1 The first move

                                                                                                                                                     #3 Rover Platform
  • Sign in to reply

Top Comments

  • skruglewicz
    skruglewicz over 2 years ago +2
    Excellent blog on IPC.. I’ll be using message or command IPC in my design. you educated me on basic IPC concepts.. thank you. … Steve K
  • Digimorf
    Digimorf over 2 years ago +1
    Nice and clean, thanks for the explanation.
  • Digimorf
    Digimorf over 2 years ago

    Nice and clean, thanks for the explanation. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 2 years ago

    Excellent blog on IPC.. I’ll be using message or command IPC in my design. you educated me on basic IPC concepts.. thank you. … Steve K

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube