Topic: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Hello!
I am working on STM32f4 project, in IAR, with my TCP connection with static memory.
1) The first problem - when i tried to build this project with dynamic memory - malloc function was recieving NULL always. I made a big heap, but doesnt work anyway. Can you help me, what is wrong.

Post's attachments

Отладка.jpg
Отладка.jpg 636.87 kb, 1 downloads since 2018-10-04 

You don't have the permssions to download the attachments of this post.

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

2) We decided to use static memory - so now i have some anouther problems.
first of all: How to configure Visual Studio with this ./configure --enable-staticmemory ? (took from here https://www.wolfssl.com/docs/wolfssl-ma … ocation/), cant find where to put this configuring flag.

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

STM32, IAR, STATIC_MEMORY
i have some problems - cant get "method", in function wolfTLSv1_2_client_method  - always getting NULL

this is my user_settnigs.h :

#define SINGLE_THREADED  /* or define RTOS  option */
#define NO_FILESYSTEM
#define NO_ASN_TIME
#define NO_WOLFSSL_SERVER
#define NO_INLINE
#define USER_TIME
#define WOLFSSL_USER_IO
#define SIZEOF_LONG_LONG 8
#define WOLFSSL_STATIC_MEMORY
#define USE_FAST_MATH
#define WOLFSSL_NO_MALLOC

this is my settnigs.h :

 #define WOLFSSL_IAR_ARM 

This is my tls-client function:

#define MAXSZ              1024
#define MAXxxx             256

   
   
   
/*------------------------------------------------------------------------*/
/* TLS CLIENT */
/*------------------------------------------------------------------------*/


int tls_client_func(void)
{

    char reply[MAXSZ];
    int msgSz, error;
    char msg[] = "Hello WolfSSL!\r\n";
    
    
    WOLFSSL_CTX* ctx;
    WOLFSSL* ssl;
    
    int ret;
    int MAX_CONCURRENT_HANDSHAKES = 1024;
    int MAX_CONCURRENT_IO = 1024;
      
    unsigned char memory[MAXxxx];
    int memorySz = MAXxxx;
    unsigned char IO[MAXxxx];
    int IOSz = MAXxxx;
    int flag = WOLFMEM_IO_POOL | WOLFMEM_TRACK_STATS;
    
    // create ctx also using static memory, start with general memory to use
    ctx = NULL;
    
    wolfSSL_Init();
    
[b]   // Here, next function doesnt work, gets not SSL_SUCCESS[/b]

    ret = wolfSSL_CTX_load_static_memory(&ctx, wolfTLSv1_2_client_method_ex, memory, memorySz, 0, MAX_CONCURRENT_HANDSHAKES);
    if (ret != SSL_SUCCESS) {
    // handle error case
      goto fail;
    }
    
    // load in memory for use with IO
    ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag, MAX_CONCURRENT_IO);
    if (ret != SSL_SUCCESS) {
    // handle error case
      goto fail;
    }
    
    
    
    /*------------------------------------------------------------------------*/
    /* ECDHE-ECDSA */
    /*------------------------------------------------------------------------*/
    /*--------------------*/
    /* for peer auth use: */
    /*--------------------*/
    //    wolfSSL_CTX_load_verify_buffer(ctx, rsa_key_der_1024,
    //                                    sizeof_rsa_key_der_1024, SSL_FILETYPE_ASN1);
    //    wolfSSL_CTX_load_verify_buffer(ctx, server_cert_der_1024,
    //                                    sizeof_server_cert_der_1024, SSL_FILETYPE_ASN1);
    /*---------------------*/
    /* for no peer auth:   */
    /*---------------------*/
    wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
    /*---------------------*/
    /* end peer auth option*/
    /*---------------------*/
    if ((ret = wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-ECDSA-AES128-SHA256")) != SSL_SUCCESS) {
        wolfSSL_CTX_free(ctx);
        //printf("CTXset_cipher_list failed, error: %d\n", ret);
        goto fail;
    }
    /*------------------------------------------------------------------------*/
    /* END CIPHER SUITE OPTIONS */
    /*------------------------------------------------------------------------*/
    wolfSSL_CTX_SetIORecv(ctx, CbIORecv);
    wolfSSL_CTX_SetIOSend(ctx, CbIOSend);
    
    /*
    if ((ssl = wolfSSL_new(ctx)) == NULL) {
        error = wolfSSL_get_error(ssl, 0);
        //printf("wolfSSL_new failed %d\n", error);
        wolfSSL_CTX_free(ctx);
        return -1;
    }
    */
    /* non blocking accept and connect */
    
    ret = SSL_FAILURE;

    while (ret != SSL_SUCCESS) {
        /* client connect */
        ret = wolfSSL_connect(ssl);
        error = wolfSSL_get_error(ssl, 0);
        if (ret != SSL_SUCCESS) {
            if (error != SSL_ERROR_WANT_READ && error != SSL_ERROR_WANT_WRITE) {
                /* Fail */
                //printf("wolfSSL connect failed with return code %d\n", error);
                goto fail;
            }
        }
        /* Success */
    }

    /* read and write */
    while (1) {
        /* client send/read */
        msgSz = sizeof(msg);
        ret   = wolfSSL_write(ssl, msg, msgSz);
        error = wolfSSL_get_error(ssl, 0);
        if (ret != msgSz) {
            if (error != SSL_ERROR_WANT_READ && error != SSL_ERROR_WANT_WRITE) {
                /* Write failed */
                goto fail;
            }
        }
        /* Write succeeded */
        break;
    }

    while (1) {
        ret = wolfSSL_read(ssl, reply, sizeof(reply) - 1);
        error = wolfSSL_get_error(ssl, 0);
        if (ret < 0) {
            if (error != SSL_ERROR_WANT_READ && error != SSL_ERROR_WANT_WRITE) {
                /* Can put print here, the server enters a loop waiting to read
                 * a confirmation message at this point */
                // printf("client read failed\n");
                goto fail;
            }
            continue;
        }
        else {
            /* Can put print here, the server enters a loop waiting to read
             * a confirmation message at this point */
            reply[ret] = '\0';
            // printf("Client Received Reply: %s\n", reply);
            break;
        }

    }

    return 0;

fail:
    wolfSSL_shutdown(ssl);
    wolfSSL_free(ssl);
    wolfSSL_CTX_free(ctx);

    return -1;
}
Post's attachments

Отладка.jpg
Отладка.jpg 549.87 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Hi @stanislavirin

Please find attached documentation for static memory solution!

I think this will clear some things up!

Warmest Regards,

K

Post's attachments

Static memory documentation (for public use).pdf 242.47 kb, 1 downloads since 2018-10-08 

You don't have the permssions to download the attachments of this post.

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Hi @stanislavirin,

Can you tell us a little about what it is you are working on and the end goals for the project?

- K

6 (edited by stanislavirin 2018-10-10 00:42:30)

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

There is mistake in description: https://www.wolfssl.com/docs/wolfssl-ma … llocation/

0 - default general memory
WOLFMEM_IO_POOL - used for input/output buffer when sending receiving messages.
        Overrides general memory, so all memory in buffer passed in is used for IO.
WOLFMEM_IO_FIXED - same as WOLFMEM_IO_POOL but each SSL now keeps two
        buffers to themselves for their lifetime.
WOLFMEM_TRACK_STATS - each SSL keeps track of memory stats while running.


while we have such defines in wolfssl-3.15.3/memory.h

    #define WOLFMEM_GENERAL       0x01
    #define WOLFMEM_IO_POOL       0x02
    #define WOLFMEM_IO_POOL_FIXED 0x04
    #define WOLFMEM_TRACK_STATS   0x08

thats why i have problems with static memory - i have used wrong flag.

Post's attachments

Error in description.png
Error in description.png 1.23 mb, 1 downloads since 2018-10-10 

You don't have the permssions to download the attachments of this post.

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Hi @stanislavirin,

Thanks for the catch with documentation! 0 should also work as a general memory flag, but will update the documentation to be consistent. I'm curious if changing the flag resolved your issue?

Regards,
Jacob

Share

8 (edited by stanislavirin 2018-10-14 08:12:48)

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Hi, Jacob!
Changing flag resolved the problem with 2 functions:

 int flag = WOLFMEM_GENERAL;//       0x01
    ret = wolfSSL_CTX_load_static_memory(&ctx, wolfTLSv1_2_client_method_ex, memory, memorySz, 0x01, MAX_CONCURRENT_HANDSHAKES);
    if (ret != SSL_SUCCESS) {
    // handle error case
      goto fail;
    }
    flag = WOLFMEM_IO_POOL;
    // load in memory for use with IO
    ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag, MAX_CONCURRENT_IO);
    if (ret != SSL_SUCCESS) {
    // handle error case
      goto fail;
    }

now they return SSL_SUCCESS.

Next problem - this functions dont return SSL_SUCCESS :

ret = wolfSSL_CTX_load_verify_buffer(ctx, dh_key_der_1024, 
                                         sizeof_dh_key_der_1024, SSL_FILETYPE_ASN1);
    if (ret != SSL_SUCCESS) {
        // error loading key from buffer
        goto fail;
    }

AllocDer() returns MEMORY_E;

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

How large is the memory buffer being passed in? Adding --enable-debug to the wolfSSL build and calling wolfSSL_Debugging_ON() at the beginning of your application will print out debug messages. Can you add in the debugging messages to see if the static memory feature is running out of memory? An error message of "ERROR ran out of static memory" will be printed out if no more memory buckets were available.

Regards,
Jacob

Share

10 (edited by stanislavirin 2018-10-22 03:55:14)

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

I should go anouther way...
The goal - is to launch any working test project, that will be compiled. I go in wolfssl-3.15.3/IDE/IAR-EWARM/Projects/wolfssl :

wolfCrypt-test - Debug.

Error:

Fatal Error[Li001]: could not open file "D:\Stas\wolfssl-3.15.3\wolfssl-3.15.3\IDE\IAR-EWARM\Projects\lib\ewarm\Exe\wolfSSL-Lib.a"

Post's attachments

systeminint.jpg
systeminint.jpg 337.97 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Share

11 (edited by stanislavirin 2018-10-22 03:57:32)

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

wolfCrypt-Lib - Debug.

Error:

Fatal Error[Pe1696]: cannot open source file "D:\Stas\wolfssl-3.15.3\wolfssl-3.15.3\wolfcrypt\src\sp.c"


Can you tell me, what's wrong?

Post's attachments

systeminint.jpg
systeminint.jpg 335.78 kb, 1 downloads since 2018-10-22 

You don't have the permssions to download the attachments of this post.

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Working in IAR 6.5 , trying to open wolfssl 3.15.3

Share

Re: [SOLVED] Stm32, IAR, Own TCP, Static memory.

Case was handled in more detail through support channel.

Updating the version of IAR IDE used and starting with a fresh copy of wolfSSL 3.15.3 helped resolve the issue.

~Jacob

Share