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.

RTOS/TM4C129XNCZAD: tı-rtos mac address change problem

Part Number: TM4C129XNCZAD

Tool/software: TI-RTOS

Hi,

In my project, I want to read MAC Adrress from the Eeprom of the device by means of i2 protocol in TI-RTOS.For this purpose, I created a new task that reads the MAC from eeprom registers and write the related registers that are lUser0 and lUser1 like this:

void macInitFxn()
{
    I2C_Handle i2c6Handle;
    I2C_Params i2c6Params;
    uint8_t txBuffer[1];
    /* 48 bits of MAC Addr */
    uint8_t getMacBuffer[6];
    I2C_Transaction i2cTransaction;

    I2C_Params_init(&i2c6Params);
    i2c6Handle = I2C_open(DK_TM4C129X_I2C6, &i2c6Params);

    if(i2c6Handle == NULL)
    {
          LOG("I2C cannot be opened correctly for MAC Address!\n");
          return;
    }

/* Take MAC Address Information */
/* MAC Address start register from 0xFA to 0xFF */
txBuffer[0] = 0xFA;
/* Slave Address for Eeprom */
i2cTransaction.slaveAddress = 0x50;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = getMacBuffer;
i2cTransaction.readCount = 6;

if (I2C_transfer(i2c6Handle, &i2cTransaction))
{
uint32_t hMAC = ( ( getMacBuffer[0] << 16 ) | ( getMacBuffer[1] << 8 ) | ( getMacBuffer[2]) );
uint32_t lMAC = ( ( getMacBuffer[3] << 16 ) | ( getMacBuffer[4] << 8 ) | ( getMacBuffer[5]) );
if(FlashUserSet( hMAC, lMAC ) != SUCCESS)
{
LOGERR("MAC Address could not be programmed successfully");
I2C_close(i2c6Handle);
return;
}
if(FlashUserSave() != SUCCESS)
{
LOGERR("Changing of MAC Address could not be committed");
I2C_close(i2c6Handle);
return;
}
LOG("MAC Address is changed successfully");
I2C_close(i2c6Handle);
return;
}

LOGERR("I2C Bus fault\n");
I2C_close(i2c6Handle);
return;
}

I see that MAC Address from LM Flah programmer is changed succesfully to value which is read from Eeprom even though it could not been as changed when I use "arp -a" command in cmd. I see FF-FF-FF-FF-FF-FF .Is there any problem for changing MAC in my code ? Am I read only register values from LM Flah Porgrammer? Thanks for your answers.

Best Regards,

Cengizhan YAPICIOĞLU 

  • LM Flash programmer can be used to read or program the User 0 and User 1 registers that are often used to store the MAC address. You can only program when the original values are all FF. To actually program, you must select the "Commit MAC Address" check box before you click "Program MAC Address".
  • Thanks for your answer. However, I want to code MAC address from the value that is read from Eeprom by means of i2c protocol. If I use, Board_initEMAC() I can not add I2C_Transfer function to it owing to the fact that Swı/Hwi could not been called at SYS/BIOS functions. How can I modify MAC in code side ? In other words, is there any method in TI-RTOS for tm4c129x to what "Commit MAC Address" do in LM Flash programmer ?  

    Best Regards,
    Cengizhan YAPICIOĞLU

  • Hi Cengizhan,

    First, don't call Board_initEMAC() in main(). Instead call it in a task after you get the MAC address.

    You have a couple options to delay the starting of the NDK stack:
    1. Do not graphically generate it. Instead supply the thread yourself and start it after calling Board_initEMAC().
    2. Add a startup hook function into the stack via the .cfg file. Have that function block on a semaphore. Post the semaphore after you call Board_initEMAC(). The hook is called very early in the stack thread, well before the MAC address is referenced.

    .cfg file
    Global.stackBeginHook = "&myNDKStackBeginHook";

    .c file
    void myNDKStackBeginHook()
    {
    Semaphore_pend(mySem, BIOS_WAIT_FOREVER);
    }


    Todd
  • Hi Todd,

    Initially, the solution was became successful and MAC address is changed.However, I lost the UDP communications which are controlled with the help of Tasks that are called by main() with NDK Open  Hook. How can I solve both of these ? Edit : I noticed that problem is occurred in "akbUdpSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);" that returns invalid socket when I changed the MAC as you mentioned above. What can be a solution for this MAC change problem? 

    King Regards,

    Cengizhan YAPICIOĞLU 

  • Cengizhan,

    You cannot try to use the NDK until it is started. You can use the hook functions in the NDK to start the other tasks (instead of being started in main).

    Todd
  • Hi,

    Sorry but I could not exactly understand what you mention. When I move my Tasks to stack hook or network open hook, network open hook semaphore is crash. Could you please give me some extra information for how can I use both network open hook for UDP and stack open hook for MAC address like where could I call network open hook and related tasks for UDP communication. At the current situation I have a mainTask in main.c and that calls the initialization task in another .c file. From here, I call some basic Task that are necessary for our Project like i2c initialization for sensors, uart communication, UDP initilaization and so on. As I understand, I have only problems with UDP Task with netopenhook and MAC init Task with stackopenhook. Where should I call these tasks exactly ? Sorry, but I could not find any solution for this issue. Thanks for your answer.

    Best Regards,

    Cengizhan Yapıcıoğlu

  • Hi,
    I am so sorry even though MAC address change plays a huge important role in the Project I could send you the code parts of the ndk stacks and main.c if it can be useful but I could not understand where can I call the Tasks.Moreover, I could not find any example about it. Could you please provide me a basic example for how can I change MAC and control UDP with netOpenHook at the same time. When I change the MAC I lost UDP. Thaks for your attention.

    Best Regards,
    Cengizhan Yapıcıoğlu

  • I've attached a modified TCP Echo. I've added the hook and a task that sleep for 5 seconds (to simulate getting the MAC address). It's up to you to not have any task call the NDK before it is up.  So no socket calls, etc.

    delayedNDK.zip

    If you want a running stack and then change the MAC address, you must shutdown the stack  (look at NC_NetStop), change the MAC address and restart it.

    Todd

  • Please note the issues found with the NDK driver for your release here: processors.wiki.ti.com/.../TI-RTOS_Support

    One is related to shutdown and restarting the NDK!

    Todd
  • Hi, with using this example and NC_NetStop(1), I have changed MAC successfully. Thanks for your answers.