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.

Error in memcpy() function for uart_echo.c



Hi All,

I am trying to use the memcpy() function to copy RXed data over UART to SRAM for the Stellaris LM4F120 board. I keep getting the error "uart_echo.c(100): error:  #167: argument of type "int" is incompatible with parameter of type "void *restrict" and "uart_echo.c(96): error:  #29: expected an expression". 

I am using the uart_echo.c code from Stellarisware and added the following lines:

char mycharacter[];

while(ROM_UARTCharGetNonBlocking(UART0_BASE))
{
mycharacter = ROM_UARTCharGetNonBlocking(UART0_BASE);
memcpy(SRAM_BASE, mycharacter, sizeof(char)*8);              // I am now trying to copy the first 16 bytes only
}

Please let me know what the issue is. Keep getting errors like "uart_echo.c(99): error:  #167: argument of type "int" is incompatible with parameter of type "void *restrict" and "uart_echo.c(98): error:  #513: a value of type "long" cannot be assigned to an entity of type "void *"

Thanks!

BR,

\Kashif

  • Hi,

    Try changing to:

    unsigned char mycharacter;

    And casting SRAM_BASE in memcpy

  • Hi Kashif,

        See, the memcpy API at your IDE, so you would know how to assign parameters to it. This is memcpy below from the internet.

       http://www.tutorialspoint.com/c_standard_library/c_function_memcpy.htm

    -kel

  • Kashif Nawaz said:

    char mycharacter[];

    You need to allocate storage

    Kashif Nawaz said:
    mycharacter = ROM_UARTCharGetNonBlocking(UART0_BASE);

    You are attempting to change the address of the storage location. 

    Kashif Nawaz said:
    memcpy(SRAM_BASE, mycharacter, sizeof(char)*8);              // I am now trying to copy the first 16 bytes only

    What's the definition of SRAM_BASE?  It would appear to be an integer type from the error message. 

    mycharacter is just fine as the second argument.

    Comment and third argument disagree

    Given that you have only read a single character the size of memcpy is suspect.

    Suggest you get a copy of PC-Lint.  It's error messages can often be clearer and it will help produce better, more consistent code if you use it regularly as part of your build.  My own build process will only compile after lint is successful

     

    Robert

  • Just as an example I wrapped this up a bit

    #include <string.h>
    
    char ROM_UARTCharGetNonBlocking(int port);
    
    #define UART0_BASE 12
    #define SRAM_BASE 140
    
    char mycharacter[];
    
    main()
    {
    while(ROM_UARTCharGetNonBlocking(UART0_BASE))
      {
      mycharacter = ROM_UARTCharGetNonBlocking(UART0_BASE);
      memcpy(SRAM_BASE, mycharacter, sizeof(char)*8);              // I am now trying to copy the first 16 bytes only
      }
    }
    

    and ran it through PC-Lint's public facility

    FlexeLint for C/C++ (Unix) Vers. 9.00k, Copyright Gimpel Software 1985-2013
    --- Module: diy.c (C)

         1  #include <string.h>
         2  
         3  char ROM_UARTCharGetNonBlocking(int port);
         4  
         5  #define UART0_BASE 12
         6  #define SRAM_BASE 140
         7  
                              _
         8  char mycharacter[];
    diy.c  8  Error 85:  Array 'mycharacter' has dimension 0
         9  
        10  main()
        11  {
        12  while(ROM_UARTCharGetNonBlocking(UART0_BASE))
        13    {
                                                                  _
        14    mycharacter = ROM_UARTCharGetNonBlocking(UART0_BASE);
    diy.c  14  Error 64:  Type mismatch (assignment) (char [] = char)
                     _
        15    memcpy(SRAM_BASE, mycharacter, sizeof(char)*8);              // I am now trying to copy the first 16 bytes only
    diy.c  15  Error 64:  Type mismatch (arg. no. 1) (void * = int)
    diy.c  15  Warning 419:  Apparent data overrun for function 'memcpy(void *, const void *, unsigned int)', argument 3 (size=8) exceeds argument 1 (size=-140) [Reference: file diy.c: line 15]
        16    }
        17  }

  • @Markel : Yeps I have seen this tutorial and executed a simple memcpy program myself for C using GCC compiler.

    Hiwever, I think for ARM eabi its definition is a bit different 

    extern _ARMABI void *memcpy(void * __restrict /*s1*/,
    const void * __restrict /*s2*/, size_t /*n*/) __attribute__((__nonnull__(1,2)));

    this leads to uart_echo.c(99): error:  #167: argument of type "unsigned char" is incompatible with parameter of type "const void *restrict" and uart_echo.c(99): error:  #167: argument of type "int" is incompatible with parameter of type "void *restrict"

  • @Robert: #define SRAM_BASE               0x20000000  // SRAM memory 

    this is the bare SRAM of the device.I am not sure how this can be typecasted. It looks a simple pointer to a location in memory.

  • Kashif Nawaz said:

    Hiwever, I think for ARM eabi its definition is a bit different 

    It is only different in terms of somebody adding _ARMABI and __attribute__ extensions which are compiler specific.

     

    As far as your use of it is concerned they are identical.

     

    Robert

  • @Johannes: yes the unsigned does reduce 1 error. however, what do you mean by casting SRAM_BASE in memcpy? Can you suggest an example?

  • Kashif Nawaz said:
    It looks a simple pointer to a location in memory.

    That is not a pointer

    Note: copying to a random place in memory is going to cause a problem in any case.  Don't do it.

     

    Robert