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.

MSP432E401Y: Passing the address of a CCS variable to inline assembly code

Part Number: MSP432E401Y

Hi,

I want to use some inline assembly code to set the value of a couple of CCS variables (IP address, etc.) so I can set to a value that's in eeprom.

Is there a way to get the address of a CCS variable (uint32_t ui32IPAddr, for example) into a register so I can do this?

Thank you.

  • Hi Brad,

      I'm not an expert in assembly level. Not sure why you want to use assembly to process a C variable. I will suggest you refer to section 6.6.2 and 6.6.3 of the TI Arm Compiler User's Guide for Accessing Assembly Functions/Variables From C/C++. Also refer to section 5.8 for Register Variables and Parameters. Register is a standard C keyword that allows you to force allocate a variable to a register if optimization is not enabled. 

  • Hello Charles,

    I'm using assembly because it's the only way I know to get data out of the eeprom on my board and, as I realized from the last project, I need to set the IP address ui32IPAddr, and Gateway address ui32GWAddr, when I initialize the board to use a static IP address. 

    I'm looking at examples 6.3 and 6.4 and not having much luck. I was able to define the variable, var, as shown in example 6.3 and I was able to declare it to be external as shown in example 6.4, but I don't see any way to use it in an assm command in order to use it to get the data I need.  For example, if I try to use it in this command:

       mov   r1,var

    I get a compilation error "Invalid operand".  Section 5.8 only confused me more.

    Do you see what I'm doing wrong?

    Thank you.

  • I'm using assembly because it's the only way I know to get data out of the eeprom on my board and, as I realized from the last project,

    How did you program EEprom? To read EEprom, it is just a matter of calling EEPROMRead() and the data is saved on a variable.  See below example documented in the Peripheral Driver Library User's Guide. 

    uint32_t ui32EEPROMInit;
    uint32_t pui32Data[2];
    uint32_t pui32Read[2];
    //
    // Enable the EEPROM module.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
    //
    // Wait for the EEPROM module to be ready.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EEPROM0))
    {
    }
    //
    // Wait for the EEPROM Initialization to complete
    //
    ui32EEPROMInit = EEPROMInit();
    //
    // Check if the EEPROM Initialization returned an error
    // and inform the application
    //
    if(ui32EEPROMInit != EEPROM_INIT_OK)
    {
    while(1)
    {
    }
    }
    //
    // Program some data into the EEPROM at address 0x400.
    //
    pui32Data[0] = 0x12345678;
    pui32Data[1] = 0x56789abc;
    EEPROMProgram(pui32Data, 0x400, sizeof(pui32Data));
    //
    // Read it back.
    //
    EEPROMRead(pui32Read, 0x400, sizeof(pui32Read));
    130

  • Hello Charles,

    I got it working with one little problem. The IP address (192.168.1.101) I'm getting in pui32Read[0] is 0x6501A8C0, but I need the bytes reversed to be 0xC0A80165.  I know I can do this with a bunch of instructions, but I'm wondering if there is a simple C/C++ command to do this.

    I'm still interested in any information I can get about how to pass variables back and forth between the C/C++ code and the assembly code because I'm sure I'll run into this problem again some time.

    Thank you

  • Hi Brad,

      I think you want to use htonl and ntohl functions to convert between host byte order and network byte order. Refer to https://linux.die.net/man/3/htonl

      If you refer to the C:\ti\TivaWare_C_Series-2.2.0.295\utils\lwiplib.c file, it uses htonl to translate an unsigned long integer (host byte address) into network byte order. You can first create a simple program and play with these functions before you add into your application.

  • Hello Charles,

    The htonl() function worked, and now the EEPROMRead() function you posted above is working perfectly.

    I really appreciate all the help.

    Thank you so much.