Modus Toolbox FreeRTOS UART

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

cross mob
mikl_1530731
Level 1
Level 1
First like received First like given

Howdy all!

I was using PSoC Creator 4.x and followed Allan's videos to create a FreeRTOS task that allowed me to write to and read from the KitProg UART on SCB5.  It worked well and I allowed the User I/O task to pend until I got an Rx Interrupt from the UART.  We've switched over to Modus Toolbox v1.1 and I'm trying to recreate that functionality.  The transmits work great but for the life of me I can't figure out how to set up the UART Rx interrupt.  The code I used in PSoC Creator doesn't seem to work and Allan's new videos don't show the UART Rx Receive interrupt.  Any clues?

Thanks,

Michael

In PSoC Creator I did the following:

In main before starting the User_IO_Task:

    __enable_irq(); /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    UART_DGB_Init( );

And then in the task:

void UART_DGB_Init( void )

{

    UART_DBG_Start();

    setvbuf( stdin, NULL, _IONBF, 0 );

}

static void UART_Isr()

{

    //Disable & clear the interupt

    Cy_SCB_SetRxInterruptMask( UART_DBG_HW, 0 );

    Cy_SCB_ClearRxInterrupt( UART_DBG_HW, CY_SCB_RX_INTR_NOT_EMPTY);

    NVIC_ClearPendingIRQ( (IRQn_Type) UART_DBG_SCB_IRQ_cfg.intrSrc);

   

    // if the semaphore causes a task switch you should yield to the task

    BaseType_t xHigherPriorityTaskWoken;

    xHigherPriorityTaskWoken = pdFALSE;

    xSemaphoreGiveFromISR( uartSemaphore, &xHigherPriorityTaskWoken ); // Tell the UART thread

    if (xHigherPriorityTaskWoken != pdFALSE)

    {

        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );

    }

}

void User_IO_Task( void *arg)

{

    (void)arg;

           

    uartSemaphore = xSemaphoreCreateBinary( );

   

    // Configure the interuppt handler

    (void) Cy_SysInt_Init( &UART_DBG_SCB_IRQ_cfg, &UART_Isr );

    NVIC_EnableIRQ((IRQn_Type) UART_DBG_SCB_IRQ_cfg.intrSrc);

    Cy_SCB_SetRxInterruptMask( UART_DBG_HW, CY_SCB_RX_INTR_NOT_EMPTY);

       

    while (1)

    {

        xSemaphoreTake(uartSemaphore, portMAX_DELAY);

       

        while (Cy_SCB_UART_GetNumInRxFifo(UART_DBG_HW))

        {

            char c = getchar();

            ...

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

To make it work in ModusToolbox you need to make some more changes as PSoC Creator wrapper APIs like UART_Start() won't work here. Please find attached the files with the modifications. You only need to make changes in these two files (main.c and uartTask.c). Comments have been added to highlight the changes. I have named my UART block as UART in the device configurator.

Entire project is also attached for reference. It has been tested and it is working. Let me know how it goes

Regards,

Dheeraj

View solution in original post

3 Replies
lock attach
Attachments are accessible only for community members.
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

To make it work in ModusToolbox you need to make some more changes as PSoC Creator wrapper APIs like UART_Start() won't work here. Please find attached the files with the modifications. You only need to make changes in these two files (main.c and uartTask.c). Comments have been added to highlight the changes. I have named my UART block as UART in the device configurator.

Entire project is also attached for reference. It has been tested and it is working. Let me know how it goes

Regards,

Dheeraj

That worked!

Now I have to go find out why my printf() and putchar() don't put out the last character.  I used to use UART_PutString() to get around the problem but that isn't defined in Modus Toolbox either.  Off to do some searching...

Thanks,

Michael

0 Likes

I found this page very helpful:  Re: Cyble-212006-01 printf issue

I added this, "setvbuf(stdout, NULL, _IONBF, 0);" to my code and all is working.

Thanks,

Michael