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

PSoC™ 6 Forum Discussions

PrGa_4700211
Level 2
Level 2
First like given

Hi,

In the below code I have tried to trigger an interrupt when the GPIO pin goes to low. I have understood that all the interrupt sources that are available can be found in  the type def IRQn_Type.

1. But where do I get the Interrupt Priority ( IntrPriority ). What should be the value of it?

2. I am assuming that this is the flow for programming a interrupt. Please correct me if I am wrong.

    • Initialize interrupt using Cy_SysInt_Int()
    • Enable the interrupt using NVIC_EnableIRQ()
    • Define the Interrupt Sub Routine.

3. Is there any documentation describing how to program and handle different types of interrupts? Example: When a FIFO is full, When ADC has captures a data, etc. It can be generic as well.

4. When I am debugging using the PSOC Creator. If I try to add watch for a variable. The value is not being displayed. It is being displayed as optimized value. Where should I modify the optimization settings to see the value of the variable added to the watch..

pastedImage_0.png

0 Likes
1 Solution

Hi,

> I am still not clear about the interrupt priority.

> In the above case, You are generating the code using PSOC creator and then trying to figure out the intrpriority and intrsrc.

> But I don't want to do it that way.

> I wanted a generic way to figureout them. Its just like a case where I don't have PSOC creator and just have an IAR.

From the information presented in the DWR > Interrupts

we can assign priority from 0 to 7, and if I remember correct, 0 is the highest and 7 is the lowest.

004-dwr-interrupts.JPG

And usually 0 is used for the system critical interrupts, so as a user I would not try to use it.

And if there is no conflict with other interrupts in your design, probably using 7 will be fine.

But if you have multiple interrupts which needs some difference(s) in the priority then you can assign some smaller numbers.

Meantime if you are using some kind of RTOS or system which has priority groups we need to follow its rule.

So in "my" rule of thumb, I would use priority 7 for the beginning and most of the time I can forget about it.

> Also one more question I have is, When we are configuring SW2, We select the interrupt.

> Which part of the code does that in the PSOC creator generated files?

In PSoC Creator we (or I?) use component configuration window,

which we can access by double clicking the component.

So I double clicked SW2 and used following two configuration windows.

Configure 'SW2' > Pins > General

010-SW2-config.JPG

Configure 'SW2' Pins > Input

011-SW2-input-config.JPG

And I checked the GlobalSignal_PORT0 component to generate interrupt for "Port interrupt 0"

012-GlobalSignal_PORT0.JPG

Then clicking the "Generate Application" icon or From Menu: Build > Generate Application

will generate low level drivers and etc. in the Generated_Source.

And in the Generated_Source > PIns and Interrupts

I found cyfitter_sysint_cfg.c and cyfitter_sysint_cfg.h where I could find those definitions and functions.

In my previous reply, one thing I failed to inform you was

for us (users) the final information can be obtained from

     the Architecture Technical Reference Manual (TRM)

and

     the Registers Technical Reference Manual (Register TRM)

Both can be obtained for your device from

https://www.cypress.com/products/32-bit-arm-cortex-m4-cortex-m0-psoc-6

30-May-2020

moto

View solution in original post

3 Replies
MotooTanaka
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi,

As I'm not very familiar with PSoC 6 and its interrupt,

I tried to study it a little this morning.

(So, please note that I am not an authority and can be wrong anywhere.)

> 1. But where do I get the Interrupt Priority ( IntrPriority ). What should be the value of it?

To try your sample, I created a project with CY8CKIT-062-BLE

(1) schematic

Note: The name of the Interrupt Component is "SysInt_1" here.

000-schematic.JPG

(2) pins

001-pins.JPG

(3) SW2 config

002-SW2-config.JPG

002-SW2-input.JPG

(4) LED Config (RED)

003-RED-config.JPG

(5) In the Design Wide Resources > Interrupts

Note: ARM CM4 Priority is set to 7 (by default)

004-dwr-interrupts.JPG

(6) Then by skimming CE219521 and CE220263, I modified your program like below

Note: I have not touched your handler,

and I did not need set priority.

===================

#include "project.h"

void GPIOPortIntHandler(void)

{

    Cy_GPIO_Write(GREEN_PORT, GREEN_NUM, 1) ;

    Cy_GPIO_Write(RED_PORT, RED_NUM, 0) ;

    CyDelay(500) ;

    Cy_GPIO_Write(RED_PORT, RED_NUM, 1) ;

    Cy_GPIO_ClearInterrupt(SW2_PORT, SW2_NUM) ;

}

int main(void)

{

    cy_en_sysint_status_t status ;

  

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

    status = Cy_SysInt_Init(&SysInt_1_cfg, GPIOPortIntHandler);

    NVIC_ClearPendingIRQ(SysInt_1_cfg.intrSrc);

    NVIC_EnableIRQ(SysInt_1_cfg.intrSrc) ;

  

    for(;;)

    {

        Cy_GPIO_Write(GREEN_PORT, GREEN_NUM, 0) ;

    }

}

===================

(7) Then to find the priority, I ran search for SysInt_1_cfg.

I found the following lines in "cyfitter_sysint_cfg.c"

==============

    /* SysInt_1 */

    const cy_stc_sysint_t SysInt_1_cfg = {

        .intrSrc = (IRQn_Type)SysInt_1__INTC_NUMBER,

        .intrPriority = SysInt_1__INTC_CORTEXM4_PRIORITY

    };

==============

And SysInt_1__INTC_CORTEXM4_PRIORITY was defined as 7 in cyfitter_sysint.h

==============

/* SysInt_1 */

#define SysInt_1__INTC_CORTEXM4_ASSIGNED 1

#define SysInt_1__INTC_CORTEXM4_PRIORITY 7u <---- here

#define SysInt_1__INTC_NUMBER 0u

#define SysInt_1_INTC_CORTEXM4_ASSIGNED 1

#define SysInt_1_INTC_CORTEXM4_PRIORITY 7u

#define SysInt_1_INTC_NUMBER 0u

==============

So, so far, I did not have to change/set the priority of this gpio interrupt.

Then I tried to modify the interrupt in DWR > Interrupts

Note: I changed the priority to 6 here

005-sysint_changed_to_6.JPG

Then I regenerate and rebuilt the project. (It was working OK, too)

When I checked the defined value of the priority, it was now 6 in "cyfitter_sysint_cfg.c"

006-priority-changed.JPG

So, could this be an answer to your question No.1 ?

> 2. I am assuming that this is the flow for programming a interrupt. Please correct me if I am wrong.

In the CE219521 sample, initialization was

===========

    /* Enale interrupt */

    __enable_irq();

    /* Initialize and enable GPIO interrupt assigned to CM0+ */

Cy_SysInt_Init(&SysInt_Switch_cfg, Isr_switch);

NVIC_ClearPendingIRQ(SysInt_Switch_cfg.intrSrc);

NVIC_EnableIRQ(SysInt_Switch_cfg.intrSrc);

===========

So the only difference is if you call NVIC_ClearPendingIRQ() before NVIC_EnableIRQ().

I would recommend to call NVIC_ClearPendingIRQ().

> 3. Is there any documentation describing how to program and handle different types of interrupts?

> Example: When a FIFO is full, When ADC has captures a data, etc. It can be generic as well.

Although I don't have a good answer to this.

Usually I would recommend the followings

(1) Read the datasheet of the Component (FIFO, ADC, etc)

(2) Find and refer to the code sample via menu (FILE > Code Example...)

(3) Find and refer to the sample projects in the Cypress Developer Community > Code Examples

Community Code Examples

(4) Just like you did this time, post a question to this Community 😉

> 4. When I am debugging using the PSOC Creator. If I try to add watch for a variable.

> The value is not being displayed. It is being displayed as optimized value.

> Where should I modify the optimization settings to see the value of the variable added to the watch..

Is the variable defined as "volatile"?

May be making the variable volatile helps you to avoid the optimization.

Meantime, From the menu Project > Build Settings...

In the CM0+/CM4 ARM GCC xxx > Compiler > Optimization

There is an option of "Optimization Level"

If you set it to "None", you can avoid optimization.

30-May-2020

moto

0 Likes

Hi,

I am still not clear about the interrupt priority. In the above case, You are generating the code using PSOC creator and then trying to figure out the intrpriority and intrsrc. But I don't want to do it that way. I wanted a generic way to figureout them. Its just like a case where I don't have PSOC creator and just have an IAR.

Also one more question I have is, When we are configuring SW2, We select the interrupt. Which part of the code does that in the PSOC creator generated files?

pastedImage_0.png

0 Likes

Hi,

> I am still not clear about the interrupt priority.

> In the above case, You are generating the code using PSOC creator and then trying to figure out the intrpriority and intrsrc.

> But I don't want to do it that way.

> I wanted a generic way to figureout them. Its just like a case where I don't have PSOC creator and just have an IAR.

From the information presented in the DWR > Interrupts

we can assign priority from 0 to 7, and if I remember correct, 0 is the highest and 7 is the lowest.

004-dwr-interrupts.JPG

And usually 0 is used for the system critical interrupts, so as a user I would not try to use it.

And if there is no conflict with other interrupts in your design, probably using 7 will be fine.

But if you have multiple interrupts which needs some difference(s) in the priority then you can assign some smaller numbers.

Meantime if you are using some kind of RTOS or system which has priority groups we need to follow its rule.

So in "my" rule of thumb, I would use priority 7 for the beginning and most of the time I can forget about it.

> Also one more question I have is, When we are configuring SW2, We select the interrupt.

> Which part of the code does that in the PSOC creator generated files?

In PSoC Creator we (or I?) use component configuration window,

which we can access by double clicking the component.

So I double clicked SW2 and used following two configuration windows.

Configure 'SW2' > Pins > General

010-SW2-config.JPG

Configure 'SW2' Pins > Input

011-SW2-input-config.JPG

And I checked the GlobalSignal_PORT0 component to generate interrupt for "Port interrupt 0"

012-GlobalSignal_PORT0.JPG

Then clicking the "Generate Application" icon or From Menu: Build > Generate Application

will generate low level drivers and etc. in the Generated_Source.

And in the Generated_Source > PIns and Interrupts

I found cyfitter_sysint_cfg.c and cyfitter_sysint_cfg.h where I could find those definitions and functions.

In my previous reply, one thing I failed to inform you was

for us (users) the final information can be obtained from

     the Architecture Technical Reference Manual (TRM)

and

     the Registers Technical Reference Manual (Register TRM)

Both can be obtained for your device from

https://www.cypress.com/products/32-bit-arm-cortex-m4-cortex-m0-psoc-6

30-May-2020

moto