CYW943907AEVAL1F device reboots on AWS thread

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

cross mob
mvpablo
Level 2
Level 2
10 sign-ins 5 replies posted 5 questions asked

Hi.

I'm using the trying to create an RTOS snipet with two threads that runs four very simple steps:

1. (file_a.c) App Main:  initialize the device wiced_init()

2. (file_a.c) Thread 1. Connects to Wifi

3. (file_a.c).Thread 1. Signals that Wifi connection is ready

4. (file_b.c) Thread 2. Recieves the signal that Wifi Connection is ready

5. (file_b.c) Thread 2. Tries to connect to AWS

PROBLEM: the device REBOOTS when reaching the 5 step. I'm not sure if this is because Wifi connection is not in the context of the whole applicacion. and it is REALLY hard to know why cause aws API won't tell much.

ret = wiced_aws_connect(aws_connection) throws an WICED_ERROR #4

Below is the simplified code that I'm testing.

Any guidance is very much appretiated

thanks

file_a.c

#define WIFI_THREAD_PRIORITY     (5)

#define AWS_THREAD_PRIORITY      (8)

#define THREAD_STACK_SIZE        (1024)

wiced_thread_t wifiThreadHandle;  // Handle wifi provisioning

wiced_thread_t awsThreadHandle; // handle AWS connection

wiced_semaphore_t semaphore_signal_wifi; //Signal when WiFi is ready

/*Function that to manage WiFi provisioning */

void wifiProvisioningThread(wiced_thread_arg_t arg) {

    /* Varibles initialization  */

    wiced_result_t ret = WICED_SUCCESS;

    /* Bring up the network interface */

    ret = wiced_network_up( WICED_AWS_DEFAULT_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    if ( ret != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ( "Not able to join the requested AP\n" ) );

        return;

    }

    wiced_rtos_set_semaphore(&semaphore_signal_wifi_connection); // Signal WiFi ready

}

void application_start( ) {

    wiced_init(); /* Initialize the WICED device CYW943907AEVAL1F */

    /* Setup the semaphore to signal when WiFi Connection is established*/

    wiced_rtos_init_semaphore(&semaphore_signal_wifi_connection);

    /* Initialize and start the thread that will handle WiFi connection */

    wiced_rtos_create_thread(&wifiThreadHandle, WIFI_THREAD_PRIORITY, "wifiThread", wifiProvisioningThread, THREAD_STACK_SIZE, NULL);

    /* Initialize and start the thread that will manage AWS */

    wiced_rtos_create_thread(&awsThreadHandle, AWS_THREAD_PRIORITY, "awsThread", awsConnectThread, THREAD_STACK_SIZE, NULL);

}

file_a.h

extern wiced_semaphore_t semaphore_signal_wifi_connection;

extern void awsThreadHandle();

file_b.c

void awsConnectThread()

{

    wiced_aws_handle_t aws_connection = 0;

    wiced_result_t ret = WICED_SUCCESS;

    wiced_rtos_get_semaphore(&semaphore_signal_wifi_connection, WICED_WAIT_FOREVER);

    ret = get_aws_credentials_from_resources();

    if( ret != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("[Application/AWS] Error fetching credentials from resources\n" ) );

        return;

    }

    ret = wiced_aws_init( &my_subscriber_aws_config, my_subscriber_aws_callback );

    if( ret != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ( "[Application/AWS] Failed to Initialize AWS library\n" ) );

        return;

    }

    aws_connection = (wiced_aws_handle_t)wiced_aws_create_endpoint(&my_subscriber_aws_iot_endpoint);

    if( !aws_connection )

    {

        WPRINT_APP_INFO( ( "[Application/AWS] Failed to create AWS connection handle\n" ) );

        return;

    }

    WPRINT_APP_INFO(("[Application/AWS] Opening connection...\n"));

    ret = wiced_aws_connect(aws_connection);  // AT THIS POINT THE DEVICE REBOOTS

    if ( ret != WICED_SUCCESS )

    {

        WPRINT_APP_INFO(("[Application/AWS] Connect Failed\r\n"));

        wiced_rtos_delay_milliseconds( APPLICATION_DELAY_IN_MILLISECONDS * 5 );

        return;

    }

}

0 Likes
1 Solution
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

I have not yet tested your snippet. But the first question that I have is that if you handle the wifi connection in the same main_app thread context (instead of having a separate thread), do you still see the reset?

Since the stack size seems to be 1024 only, did you try to check for stack overflow or increasing the stack size? Can add more comments and questions once I test your application; it would be really helpful if you can add a compile-able zip file.

View solution in original post

0 Likes
2 Replies
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

I have not yet tested your snippet. But the first question that I have is that if you handle the wifi connection in the same main_app thread context (instead of having a separate thread), do you still see the reset?

Since the stack size seems to be 1024 only, did you try to check for stack overflow or increasing the stack size? Can add more comments and questions once I test your application; it would be really helpful if you can add a compile-able zip file.

0 Likes

Thanks for your answer.

Indeed the problem was related to the thread stack size.

I've increased the size from 1024 to (4096) and it solves the problem.

0 Likes