Interrupt based Button doesn't work with CYW943907AEVAL1F board

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

cross mob
Anonymous
Not applicable

Hi,

I am using CYW943907AEVAL1F development board. I am using GPIO buttons 1 and 2 in interrupt mode. I am facing an issue that when I press the button, the registered handler is not called and the application gets crashed. However, the polling mode is wotking fine, so there is no problem with the hardware I guess. Can you please let me know what I am missing?

Below is my application code. Whenever I press Button 2, the application crashes.

#include "wiced.h"

wiced_semaphore_t semaphore;

void _SwitchHandler(void* arg) {

    if (wiced_rtos_set_semaphore(&semaphore) != WICED_SUCCESS) {

        return;

    }

}

void application_start( )

{

    /* Initialise the WICED device */

    wiced_init();

    if (wiced_rtos_init_semaphore(&semaphore) != WICED_SUCCESS)

    {

        return;

    }

    wiced_gpio_init(WICED_BUTTON2, INPUT_PULL_UP);

    if (WICED_SUCCESS != wiced_gpio_input_irq_enable(WICED_BUTTON2, IRQ_TRIGGER_RISING_EDGE,

            _SwitchHandler, NULL)) {

        WPRINT_APP_INFO(("Failed to register handler\n"));

        return;

    }

    while (wiced_rtos_get_semaphore(semaphore, 100) != WICED_SUCCESS) {

        wiced_rtos_delay_milliseconds(100);

    }

    WPRINT_APP_INFO(("Button pressed.\n"));

}

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Naman,

Kindly try the attached application

Press a USER_1 and you should see LED_1 glow.

This is using isr.

View solution in original post

10 Replies
lock attach
Attachments are accessible only for community members.
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hi Naman,

You need to create a thread to set semaphore so that it can be acquired by the isr to perform some action. Without a thread, your program will be stuck at the while loop

while (wiced_rtos_get_semaphore(semaphore, 100) != WICED_SUCCESS)

{

     wiced_rtos_delay_milliseconds(100);

}

You can refer to apps>semaphore for better understanding of thread and handling through semaphore. You can also refer to the attached code for your reference. I have included both the buttons for generating interrupt and togglling a LED.

Regards,

Priya Mourya

Anonymous
Not applicable

Hi riya

Thanks for response. I tried to run the application that you have attached but I faced the same issue that the application crashed and restarts when I press a button. Below is the screenshot of the console logs.

wiced_button_crash.JPG

Below are the steps I have followed:

  1. Copied the sample application to main.c file and created makefile as below.

     NAME := temp

     $(NAME)_SOURCES  := main.c

     # These do not have any LEDs/Buttons

     INVALID_PLATFORMS := BCM943909* BCM943907* FM4_176L_S6E2GM.BCM943438WLPTH_2

   2. Added make target: "temp-CYW943907AEVAL1F-FreeRTOS-LwIP download run"

    3. Run the application and press either SW1 or SW3 on the board.

Also, I didn't find any apps -> semaphore application in WICED-Studio-5.0/43xxx_Wi-Fi directory. Please let me know if I am missing something.

0 Likes
lock attach
Attachments are accessible only for community members.

Naman,

Kindly try the attached application

Press a USER_1 and you should see LED_1 glow.

This is using isr.

PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Naman,

The example provided by vikr​ will solve your problem.

Besides if you want to use semaphore in ISR, you have to use different APIs for setting and releasing the semaphore. Also if you use the make target as "temp-CYW943907AEVAL1F download run", the application will run fine. Here it will use NetX Duo as the network stack.

Anonymous
Not applicable

HI Riya,

I want to use Freertos with LwIP and want to use semaphore in ISR. I tried with Freertos call (xSemaphoreGiveFromISR) and this works fine. Is there any WICED Api wrapper (like wiced_rtos_set_semaphore or wiced_rtos_get_semaphore) for using semaphore in ISR?

Thanks.

0 Likes

naman.trivedi_2654081 wrote:

HI Riya,

I want to use Freertos with LwIP and want to use semaphore in ISR. I tried with Freertos call (xSemaphoreGiveFromISR) and this works fine. Is there any WICED Api wrapper (like wiced_rtos_set_semaphore or wiced_rtos_get_semaphore) for using semaphore in ISR?

Thanks.

host_rtos_set_semaphore() pass WICED_TRUE to called_from_ISR parameter.

Currently there is no WICED API wrapper that can do that.

0 Likes

Hi,

Passing WICED_TRUE in host_rtos_set_semaphore() will not solve the problem entirely because setting it to WICED_TRUE will result in calling xSemaphoreGiveFromISR() in ISR and this function requires that the semaphore must have previously been created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting(). So you also need to create the semaphore through xSemaphoreCreateBinary() or xSemaphoreCreateCounting().

Thanks

0 Likes

No matter pass WICED_TRUE or WICED_FALSE to host_rtos_set_semaphore(),

the semaphore must be inited first before using host_rtos_set_semaphore()/host_rtos_set_semaphore().

That's common sense. A host_rtos_init_semaphore() call should work.

0 Likes

Hi natrc_2654081,

I am facing some similar issue with FreeRTOS in WICED. Did you find any solution to the above mentioned problem?

Thanks.

0 Likes