Tuesday 11 February 2020

Setting the MAC address on a Texas Instrumens CC26x2

The MAC address of the TI CC2652 can be set as factory configuration or as customer configuration.

In the first case, and as stated in the CC26xx memory map, the address value is stored in the Factory Configuration Area (FCFG1), specifically in the registers MAC_15_4_0 and MAC_15_4_1, corresponding to the addresses  0x500012F0 (address offset 0x02F0) and 0x500012F4 (address offset 0x02F4).

In the second case (address set as customer configuration) the values are stored in the Customer Configuration Area (CCFG), specifically in the registers IEEE_MAC_0 and IEEE_MAC_1, corresponding to the addreses 0x50004FC8 (address offset 0x1FC8) and 0x50004FCC (address offset 0x1FCC).

Though in both cases the values stored in these addresses are read-only at runtime, the values stored in the Customer Configuration Area can be set in the firmware source code. By default, the CCFG IEEE_MAC_0 and IEEE_MAC_1 address values are defined in the Core SDK driverlib startup_files/ccfg.c file, and therefore set for all the developed applications through the macros SET_CCFG_IEEE_MAC_0 and SET_CCFG_IEEE_MAC_1, both set by default to 0xFFFFFFFF.

As the CCFG documentation states, in case of being set to 0xFFFFFFFF, the IEEE_MAC_0 and IEEE_MAC_1 values must be considered invalid and the FCFG1 MAC_15_4_0 and MAC_15_4_1 values must be used. In practice that means that if the user is not setting an specific MAC address, the default, factory MAC address will be used. This behaviour is coded in the main.c of most (fi not all) SDK examples.

Then, how the user can set the MAC address to an specific, user value? To do that, the macros SET_CCFG_IEEE_MAC_0 and SET_CCFG_IEEE_MAC_1 must be re-defined in the application-specific ccfg.c file. This file is empty by default and its purpose is, specifically, redefining CCFG macros with custom-user values. Specifically, SET_CCFG_IEEE_MAC_0 contains bits 31 to 0 of the MAC, whereas SET_CCFG_IEEE_MAC_1 contains bits 63 to 32.

Have in mind that the CCFG area will be only flashed if, apart of stating specific values as previously explained, the debugger flash settings are set to rewrite (not to keep) it. To proceed in that way uncheck the CCFG protection as shown in the image below. Have in mind that, once the user address was writen in CCFG, it is not necessary rewriting it every time the program changes, unless the whole address changed.


Last but not least, it is very important to consider that, in case of defining a user-specific MAC address, it must be considered as local (not universal) and therefore the second-least-significant-bit of the first octet must be set to 1. That means that the least significat byte of SET_CCFG_IEEE_MAC_0 must have its second bit set to 1 (for instance being set to 0x00000002).

If a Texas Instruments reserved universal MAC address is being used (converting it to local according to that explained in the previous paragraph), a list of the TI vendor-specific three first octects can be checked here. Notice that, since they are universal and not local, all the shown values have the second bit of the least significant byte set to 0.

As an example, if the reserved 0xFC0F4B universal address prefix is being used, first it must be converted from universal to local by setting to 1 the second bit of the least significant byte. In that way, the prevouls value would be converted to 0xFE0F4B. Taking it as base, a valid, local MAC address would be FE:0F:4B:00:00:00:00:01. Therefore, the SET_CCFG_IEEE_MAC_0 macro would be set to 0x004B0FFE and SET_CCFG_IEEE_MAC_1 would be set to 0x01000000.