sipeed / MaixPy-v1

MicroPython for K210 RISC-V, let's play with edge AI easier
https://wiki.sipeed.com/maixpy
Other
1.68k stars 439 forks source link

esp32 spi try to read even if len is 0 #138

Closed chegewara closed 4 years ago

chegewara commented 5 years ago

Hi, i am playing with maixduino board and trying to find why i cant run stable read socket on it. To do this i imported whole esp32 library to standalone-sdk and i found small issue in it. When we run socket_read in loop and at some point there is nothing to read from esp32, brcause data buffer is empty, esp32 on this request e0 45 02 00 01 00 00 02 a0 0f ee 00 returns something like that e0 c5 01 00 00 ee and it is valid response, but k210 does not recognize there is empty buffer and is trying to read data which is causing unexpected behavior on esp32.

At first i thought it may be issue in nina-fw, but after further studying code i found the issue here: https://github.com/sipeed/MaixPy/blob/master/components/micropython/port/src/standard_lib/network/esp32/esp32_spi.c#L402

Temporarily i fixed it like this, but maybe there is better way to do it:

void esp32_spi_read_bytes(uint8_t *buffer, uint32_t len)
{
    if(len == 0)
    return;
....

https://github.com/sipeed/MaixPy/blob/master/components/micropython/port/src/standard_lib/network/esp32/esp32_spi.c#L251

junhuanchen commented 4 years ago

fix