UART to output with printf() function - A simple program for beginners using Modus Toolbox2.1 with PSoC6(M4)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi all,

I am making some programs for beginners using Modus ToolBox 2.1. When migrating the development environment from PSoc Creator to Modus, I had a hard time creating a simple program.

Here, a simple program for the M4 core of PSoC 6 using  Modus Toolbox2.1 is introduced here.

The environment is as follows.

ModusToolbox2.1

CY8CKIT-062-BLE

Last time, I used UART by setting SCB with the Device Configuration tool, but there is a library that can use the printf() function more easily. It's also used in the "Hello World" example, but here's an extract of only the UART output settings using printf () with Retarget IO Library.

Select the CY8CKIT-062-BLE kit from the New Application tool in the Quick Panel and use it based on what was created in the empty PSoC 6 app.

The Device Configuration tool in the IDE of Modus Toolbox2.1 is not used for Pin and UART related component settings.

Launch the Library Manager from the Quick Panel to add the Retarget IO Lib to your project as follows.

1.png

Go to the “Libraries” tab in the Library Manager and check retarget-io.

After checking, click the “Apply” button at the bottom right to close the Library Manager.

Then all you have to do is write the program.

The program is as follows.

#include "cy_pdl.h"

#include "cyhal.h"

#include "cybsp.h"

#include "cy_retarget_io.h"

int main(void)

{

    cy_rslt_t result;

    /* Initialize the device and board peripherals */

    result = cybsp_init() ;

    if (result != CY_RSLT_SUCCESS)

    {

        CY_ASSERT(0);

    }

    result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);

    if (result != CY_RSLT_SUCCESS)

    {

        CY_ASSERT(0);

    }

    __enable_irq();

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

    printf("\x1b[2J\x1b[;H");

    printf("PSoC 6 MCU: Hello World! Example \r\n\n");

    for (;;)

    {

    }

}

Since I used TeraTerm as a terminal, the setting is described below.

2.png

Note: “Port” is depending on the PC environment.

It's very easy. Please use it for debugging in the Modus Toolbox environment.

Thanks,

Kenshow

3 Replies
Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Dear Kenshow-san,

Thank you very much for your sharing this CE.

Best regards.

0 Likes
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hello everyone,

The program was changed more simply.

I deleted an unnecessary object call declaration.

Thanks,

Kenshow

Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

I changed the order in which API functions are called and updated the program.

Thanks,

Kenshow

18-June-2020

0 Likes