I get error value after handshake:
-0x3310 but cannot find definition for such error. Is it a normal error or something different? The lib version is 1.2.12
Error codes have 'multiple levels' and thus can contain low-level and high-level codes at the same time.
The strerror application can help you with that:
~/mbedtls/programs/util$ ./strerror -0x3310 Last error was: -0x3310 - DHM - Calculation of the DHM secret failed : BIGNUM - Memory allocation failed
So a memory allocation issue it seems.