Two sockets usage / Erase of internal flash hangs processor/ Problems with SPI transfers during wifi_connect

Dear Realtek Team,

Right now there are 3 open issues which we can’t resolve ourselves.

(1) Two sockets usage

Latest SDK we received 230613_306b109f broke two concurrent TLS sockets usage (mbedTLS 2.4.0), so we had to stay on the previous one (we used was 221206_bf3b2a72) - that was was broken as well, but we implemented a workaround (patch already sent to realtek). Is there a new SDK that fixes this?
We still see [MODULE_IPSEC-LEVEL_ERROR]:Wait Timeout sometimes (twice per day), so it looks like there is still some concurrency issue there.
More often (~25 per day) we see recv returning no data which causes http connection failure which might be related (but without any special log message).

(2) Erase of internal flash hangs processor

Erasing of the internal flash (more sectors == bigger chance to hang) sometimes hangs the whole processor, it seems to be related with wifi driver, our current fix is to disable wifi before erase, but it’s suboptimal.
Exact function which hands is FLASH_Erase(EraseSector, sec_addr); We call it after we lock the access from the km4 as well as after stopping km0 with device_mutex_lock(RT_DEV_LOCK_FLASH); FLASH_Write_Lock();.

(3) Problems with SPI transfers during wifi_connect

RTL is SPI master, it sends 1,5kB xfers to the slave (another processor we’re using on this board), we can see that during wifi_connect the spi transfers are either completely missing or corrupt.

In the provodied logs (bad-spi-frames.log), have a look at "incomplete frames" messages: we're missing the beginning of the frames for some transfers. Our format for a message trailer is always word (4B aligned) with last bytes being 0x0d0a (\r\n). On those logs we can see that SPI peer received some corrupt frame,

failed to properly parse it (since it was missing the beginning), and responded with the exact bytes it received. Those bytes are not only NOT word-aligned, but all of the bytes in transfer were moved by a nibble (half-byte)!

Logs with [bt-drv] [BB:MSG_HANDLER] are coming from the peer.

Any help with the aforementioned issues would be much appreciated.

I did not see any PR at Pull requests · ambiot/ambd_arduino · GitHub

Hello @M-ichae-l ,

Kat was writing in my name, those are our (kontakt.io) issues.

We are using normal SDK, downloaded directly from Realtek (through anchor).
Patch mentioned is here: 0001-mbedtls-fix-concurrent-access-to-hw-in-mbedtls_gcm_c.zip (1.4 KB)

We have one more issue,
(4) wifi_scan blocks sending data to already connected network
if we’re already connected to wifi, wifi_scan blocks the connection from sending data (we’re connected to fallback network and scanning if “proper one” have appeared).

Also, (2) is becoming a big issue because we observed it hang the processor during OTA procedure!

Kind Regards,
Radek