Hi everyone,

We were able to identify the root cause of the issue we were experiencing. The problem was due to a RAM test in our application that, at a certain point during execution, corrupted the memory region where wolfSSL was dynamically allocating its buffers and data structures, leading to transmission issues.

We have now switched from dynamic to static memory allocation, and everything is working correctly.

At this point, we would like to understand if there is a recommended method to determine the required size of the static memory used by wolfSSL for its buffers and data structures.

Currently, we are using a rather memory-intensive configuration:

(Stack max size = 0x4000)

#define WOLFSSL_NO_MALLOC
#define WOLFSSL_STATIC_MEMORY
#undef  WOLFSSL_SMALL_STACK

#define GEN_MEM_SIZE (80 * 1024)
#define IO_MEM_SIZE  (50 * 1024)

unsigned char GEN_MEM[GEN_MEM_SIZE];
unsigned char IO_MEM[IO_MEM_SIZE];

Any guidance on how to properly size these buffers would be greatly appreciated.

Thank you!

wolfSSL_read called from an STM32 microcontroller acting as a Server returns -313 (FATAL ERROR) after many succesfull readings from a CSharp application acting as a Client.

    ret = wolfSSL_read(Pt_ssl, A_prcl_msd_m1_m1s_data_link_rx_buffer, sizeof(A_prcl_msd_m1_m1s_data_link_rx_buffer)-1);
    err = wolfSSL_get_error(Pt_ssl, ret);


Our receive callback is like this and works fine

wolfSSL_CTX_SetIORecv(Pt_ctx, PRCL_MSD_M1_M1S_DLINK_uartIORx);

/*!
* \brief   WolfSSL receive callback
* \dotfile PRCL_MSD_M1_M1S_DLINK_uartIORx.dot
* \ingroup MSD_M1_M1S_PROTOCOL_DATA_LINK
*/
static int PRCL_MSD_M1_M1S_DLINK_uartIORx(WOLFSSL *ssl, char *buf, const int sz, void *ctx)
{
    bool b_message_received;
    static int8_t * p_data_received_buf;
    static int32_t total_amount_data_rcv = 0;
    int32_t bytes_available_fifo = 0;
    int32_t bytes_to_read;
    int32_t bytes_read;

    b_message_received = MDL_USARTS_Check_end_reception(USART_MSD_COMMS);

    if (b_message_received == TRUE)
    {
        total_amount_data_rcv = MDL_USARTS_Get_DMA_amount_of_rx_data(USART_MSD_COMMS);
        MDL_USARTS_Reset_DMA_amount_of_rx_data(USART_MSD_COMMS);

        MDL_USARTS_Start_receive(USART_MSD_COMMS);

        p_data_received_buf = (int8_t*)MDL_USARTS_Get_receive_buffer(USART_MSD_COMMS);
        MDL_CIRC_FIFO_Fifo_push_buf(&T_wolfSSL_rx_fifo, (uint8_t *)p_data_received_buf, total_amount_data_rcv);
    }

    bytes_available_fifo = MDL_CIRC_FIFO_Fifo_used_size(&T_wolfSSL_rx_fifo);

    if (bytes_available_fifo > 0)
    {
        DEBUG_PRINTF("FIFO used: %d, DMA received: %d\r\n", bytes_available_fifo, total_amount_data_rcv);
        bytes_to_read = (bytes_available_fifo < sz) ? bytes_available_fifo : sz;
        bytes_read        = MDL_CIRC_FIFO_Fifo_pop_buf(&T_wolfSSL_rx_fifo, (uint8_t *)buf, bytes_to_read);
        return bytes_read;
    }
    else
    {
        return WOLFSSL_CBIO_ERR_WANT_READ;
    }

}

Does anyone has any suggestion?
Many Thanks,
Edoardo