Skip to content

Instantiating OdinWiFiInterface seems to be changing Thread behavior with I2C Slave #6122

@dmelo

Description

@dmelo

Note: This is just a template, so feel free to use/remove the unnecessary things

Description

  • Type: Bug
  • Priority: Blocker

Bug

Target
UBLOX_EVK_ODIN_W2

Toolchain:
GCC_ARM

Toolchain version:
arm-none-eabi-g++ (Fedora 7.1.0-2.fc26) 7.1.0

mbed-cli version:
1.4.0

mbed-os sha:
caeaa49 (HEAD, tag: mbed-os-5.7.4, tag: latest) Merge pull request #5954 from ARMmbed/release-candidate

DAPLink version:

Expected behavior
I have two threads, the first runs i2cslave and just prints what it gets from the master and the second thread prints a simple string and then sleeps for 1 second. Both threads are in infinite loop.

Execution 1 - When I run this program, everything runs just fine.

Execution 2 - When I add an global OdinWiFiInterface instance, I expected both thread to keep running and showing the printf results on the serial.

Actual behavior

On execution 2, the i2C slave thread seems to be starving the second thread. I don't see the printf from the second thread anymore.

Steps to reproduce

Run the following code:

#include "mbed.h"
#include "rtos.h"
#include "OdinWiFiInterface.h"

#define I2C_ADDRESS 0x25

Thread t1, thread_i2c_slave;

// To reproduce execution 1, comment the line above.
OdinWiFiInterface wifi; // During execution 2, I have instanced a OdinWiFiInterface object.

void func_t1()
{
    for (int i = 0;; i++) {
        printf("FUNC_T1 ============\n%d\n==============\n\n", i);
        Thread::wait(1000);
    }
}

void i2c_slave()
{
    I2CSlave slave(PF_0, PF_1);
    int count = 0;
    char buf[10];
    char msg[] = "Slave!";

    slave.address(I2C_ADDRESS);
    while (1) {
        int i = slave.receive();
        count++;
        switch (i) {
            case I2CSlave::ReadAddressed:
                slave.write(msg, strlen(msg) + 1); // Includes null char
                break;
            case I2CSlave::WriteGeneral:
                slave.read(buf, 10);
                printf("Read G: %s\n", buf);
                break;
            case I2CSlave::WriteAddressed:
                slave.read(buf, 10);
                printf("Read A: strlen %d. ", strlen(buf));
                for (unsigned int c =0; c < strlen(buf); c++) {
                    printf("%X ", buf[c]);
                }
                printf("\n");
                printf("count: %d\n", count);
                break;
        }
        for(int i = 0; i < 10; i++) buf[i] = 0;    // Clear buffer
    }
}

int main()
{
    printf("BEGIN\n");

    printf("starting threads\n");
    t1.start(func_t1);
    thread_i2c_slave.start(i2c_slave);

    t1.join();
    thread_i2c_slave.join();

    return 0;
}

Output on the execution 1:

BEGIN
starting threads
FUNC_T1 ============
0
==============

Read A: strlen 4. 1 61 62 63 
count: 749070
Read A: strlen 4. 1 61 62 63 
count: 1602034
FUNC_T1 ============
1
==============

Read A: strlen 4. 1 61 62 63 
count: 2386922
Read A: strlen 4. 1 61 62 63 
count: 3237849
FUNC_T1 ============
2
==============

Read A: strlen 4. 1 61 62 63 
count: 4022860
Read A: strlen 4. 1 61 62 63 
count: 4873974
FUNC_T1 ============
3
==============

Read A: strlen 4. 1 61 62 63 
count: 5658975
Read A: strlen 4. 1 61 62 63 
count: 6510014
FUNC_T1 ============
4
==============

Read A: strlen 4. 1 61 62 63 
count: 7294943
Read A: strlen 4. 1 61 62 63 
count: 8145975
FUNC_T1 ============
5
==============

Read A: strlen 4. 1 61 62 63 
count: 8930893
Read A: strlen 4. 1 61 62 63 
count: 9781846

Output on execution 2:

BEGIN
starting threads
FUNC_T1 ============
0
==============

Read A: strlen 4. 1 61 62 63 
count: 139268
Read A: strlen 4. 1 61 62 63 
count: 952623
Read A: strlen 4. 1 61 62 63 
count: 1778385
Read A: strlen 4. 1 61 62 63 
count: 2602818
Read A: strlen 4. 1 61 62 63 
count: 3429469
Read A: strlen 4. 1 61 62 63 
count: 4258486
Read A: strlen 4. 1 61 62 63 
count: 5087584
Read A: strlen 4. 1 61 62 63 
count: 5912158
Read A: strlen 4. 1 61 62 63 
count: 6738882
Read A: strlen 4. 1 61 62 63 
count: 7568029
Read A: strlen 4. 1 61 62 63 
count: 8397041
Read A: strlen 4. 1 61 62 63 
count: 9225966
Read A: strlen 4. 1 61 62 63 
count: 10054951
Read A: strlen 4. 1 61 62 63 
count: 10882079
Read A: strlen 4. 1 61 62 63 
count: 11709333
Read A: strlen 4. 1 61 62 63 
count: 12536402
Read A: strlen 4. 1 61 62 63 
count: 13363531
Read A: strlen 4. 1 61 62 63 
count: 14190524
Read A: strlen 4. 1 61 62 63 
count: 15017642
Read A: strlen 4. 1 61 62 63 
count: 15844821
Read A: strlen 4. 1 61 62 63 
count: 16671864

Question

How can I make the threads work while using OdinWiFiInterface?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions