- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"));
}
Solved! Go to Solution.
- Labels:
-
GPIO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Naman,
Kindly try the attached application
Press a USER_1 and you should see LED_1 glow.
This is using isr.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Below are the steps I have followed:
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Currently there is no WICED API wrapper that can do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi natrc_2654081,
I am facing some similar issue with FreeRTOS in WICED. Did you find any solution to the above mentioned problem?
Thanks.