ARMmbed / wifi-ism43362

ISM43362 WiFi driver
17 stars 22 forks source link

Adding thread safety to the driver. #37

Closed ithinuel closed 5 years ago

ithinuel commented 5 years ago

What ?

When using an SDCard over the same spi interface things go wrong.

Why ?

Both drivers are conflicting when accessing the bus. The bufferedspi should use locks before asserting nss and unlock after releasing nss in order to keep it thread safe.

How is this fixed ?

Adding a lock()/unlock() in enable_nss()/disable_nss() should fix the issue.

jeromecoutant commented 5 years ago

Hi

It makes tests failed:

[1548339801.38][CONN][RXD] ++ MbedOS Error Info ++
[1548339801.43][CONN][RXD] Error Status: 0x80020117 Code: 279 Module: 2
[1548339801.47][CONN][RXD] Error Message: Mutex unlock failed
[1548339801.49][CONN][RXD] Location: 0x80085C3
[1548339801.52][CONN][RXD] Error Value: 0xFFFFFFFD
[1548339801.63][CONN][RXD] Current Thread: main  Id: 0x20002B60 Entry: 0x8008943 StackSize: 0x1000 StackMem: 0x20003A70 SP: 0x200047E0
[1548339801.72][CONN][RXD] For more info, visit: https://mbed.com/s/error?error=0x80020117&tgt=DISCO_L475VG_IOT01A
[1548339801.76][CONN][RXD] -- MbedOS Error Info -

@LMESTM

ithinuel commented 5 years ago

@jeromecoutant I suppect it comes from this disable() that do not have a preceding enable_nss().

Is it safe to remove it ? (and eventually adding nss = 1 in the constructor).

jeromecoutant commented 5 years ago

Is it safe to remove it ?

We agree you could/should remove this disable_nss()

ithinuel commented 5 years ago

I updated the commit. I will be able to test this fix as soon as I can get a hand on a DISCO-F413ZH.

ithinuel commented 5 years ago

Tested against : https://github.com/ARMmbed/simple-mbed-cloud-client/tree/master/TESTS/basic/stress-net-fs

All passed :

mbedgt: test on hardware with target id: 07430221062167143965F16A
mbedgt: test suite 'simple-mbed-cloud-client-tests-basic-stress-net-fs' .............................. OK in 82.01 sec
    test case: 'SD+FAT format' ................................................................... OK in 10.50 sec
    test case: 'SD+FAT+WiFi 1 thread, dl, file seq.' ............................................. OK in 8.62 sec
    test case: 'SD+FAT+WiFi 2 threads, dl, 1kb' .................................................. OK in 14.62 sec
    test case: 'SD+FAT+WiFi 3 threads, dl, 256b, 1kb' ............................................ OK in 23.18 sec
    test case: 'WiFi network setup' .............................................................. OK in 3.97 sec
mbedgt: test case summary: 5 passes, 0 failures
mbedgt: all tests finished!
mbedgt: shuffle seed: 0.0901273327
mbedgt: test suite report:
| target               | platform_name | test suite                                         | result | elapsed_time (sec) | copy_method |
|----------------------|---------------|----------------------------------------------------|--------|--------------------|-------------|
| DISCO_F413ZH-GCC_ARM | DISCO_F413ZH  | simple-mbed-cloud-client-tests-basic-stress-net-fs | OK     | 82.01              | default     |
mbedgt: test suite results: 1 OK
mbedgt: test case report:
| target               | platform_name | test suite                                         | test case                            | passed | failed | result | elapsed_time (sec) |
|----------------------|---------------|----------------------------------------------------|--------------------------------------|--------|--------|--------|--------------------|
| DISCO_F413ZH-GCC_ARM | DISCO_F413ZH  | simple-mbed-cloud-client-tests-basic-stress-net-fs | SD+FAT format                        | 1      | 0      | OK     | 10.5               |
| DISCO_F413ZH-GCC_ARM | DISCO_F413ZH  | simple-mbed-cloud-client-tests-basic-stress-net-fs | SD+FAT+WiFi 1 thread, dl, file seq.  | 1      | 0      | OK     | 8.62               |
| DISCO_F413ZH-GCC_ARM | DISCO_F413ZH  | simple-mbed-cloud-client-tests-basic-stress-net-fs | SD+FAT+WiFi 2 threads, dl, 1kb       | 1      | 0      | OK     | 14.62              |
| DISCO_F413ZH-GCC_ARM | DISCO_F413ZH  | simple-mbed-cloud-client-tests-basic-stress-net-fs | SD+FAT+WiFi 3 threads, dl, 256b, 1kb | 1      | 0      | OK     | 23.18              |
| DISCO_F413ZH-GCC_ARM | DISCO_F413ZH  | simple-mbed-cloud-client-tests-basic-stress-net-fs | WiFi network setup                   | 1      | 0      | OK     | 3.97               |
mbedgt: test case results: 5 OK
mbedgt: completed in 82.94 sec