This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430FR5969: Buffer not working properly

Part Number: MSP430FR5969

Tool/software: TI C/C++ Compiler

I was running an encryption function and utilizing a buffer to  hold the generated cipher text. However, when I run it in CCS with the MSP-FET430UIF debugger, the buffer is not being filled with what I would expect it to. If I define the size and call the buffer at the beginning of the code the buffer is just filled with zeroes throughout the code. When I call the buffer right before the encryption function, I find that the buffer is filled with zeroes and then some random hex digits as well. I am not able to find where the problem is :( I am using CCS v8. 

Was wondering if anyone had any suggestions as to why this would be happening? 

The attached image shows what happens when the buffer is called and define right before the function. When placed at the beginning it is completely filled with zeroes.

  • Is buffer a global variable?  

    I'm not sure what you mean when you say "call the buffer".  Only functions are called.  Data variables are used, set, cleared, referenced, and other similar terms.  I'm also confused on what you mean by calling the buffer "at the beginning of the code" or "right before the encryption function".

    Thanks and regards,

    -George

  • Sorry for the confusion let me clarify. Here is the code:

    
    

    I was utilizing and implementation of ascon within it (

    When I call the encryption function:

    crypto_aead_encrypt(

    buffer, &clen, 

    m, sizeof m, 

    ad, sizeof ad, 

    NULL, 

    nonce, 

    key); 

    I utilize a buffer to place the cipher text but it is not properly working within the code. I am wondering why I am facing issues with it. The crypto code produces the correct result when on its own. 

  • When I defined the buffer outside of the main function the buffer was filled with zeroes. When called within the main function random wrong digits filled the buffer
  • In the source code you show, this is the only buffer I see ...

    Susan Joseph26 said:
    // Initialize BlockWrite data buffer.
    uint16_t bwr_array[6] = {0};
    RWData.bwrBufPtr = bwr_array;

    But this buffer is not used anywhere else.  So, it can't be the problem.  

    Unfortunately, I'm so lost, I don't know what question to ask you next.

    Thanks and regards,

    -George

  • I did notice that when I initialized the array with straight fives, the function just replaced some of them with zero, but I am uncertain as to why the encrypt function would do this :( 

  • I did also realize the fact that int is a 16 bit but the code expect a 32 bit. When I tried to change the code I received an error:

    error #10099-D: program will not fit into available memory. placement with alignment fails for section "ALL_FRAM" size 0x11dd3 . Available memory ranges:

    is there a way around assigning a long int without this memory error?
  • This array ...

    Susan Joseph26 said:
    unsigned char cipher[BUFFER_SIZE];

    ... is local to the function main.  Like all other local variables, it is allocated on the stack.  By default, it can contain anything when the function starts.  If any initialization is required, your code must explicitly perform it.  

    Global or static variables are different.  The standard for C requires those variables be initialized to 0 before main begins.

    Thanks and regards,

    -George