Our WF121 modules come from the factory pre-flashed with a unique MAC address, starting with Bluegiga's OUI ("00:07:80"). This is stored in a small area of flash on the module, specifically in one of the internal PS keys. The Persistent Store (PS) area of flash is not automatically erased during a DFU reflash over UART, USB, or SPI, but it is wiped out --along with everything else on the module-- when you perform a complete reflash using the ICSP interface and PICkit3 programmer. This means that an ICSP reflash operation will necessarily overwrite the old MAC address data.
A module that has its MAC data erased will automatically revert to the firmware image's default address upon its first boot cycle. Unless the hex file is modified with a custom address using the "changemac" utility, this default address will be 00:07:80:FF:FF:FF. The firmware image's MAC can be set to anything with "changemac" utility, but it is primarily useful only if you know the original address. Therefore, it is important to obtain the original MAC before reflashing, so that it can be re-applied correctly.
The factory default firmware enables BGAPI control over the UART2 interface, which is RF4, RF5, RB8, RB14 as RX/TX/CTS/RTS respectively. The UART interface has flow control enabled and operates at 115200, 8/N/1. Using this interface, you can send the "config_get_mac(0)" API command ("[ 08 01 02 00 00 ]" in hex) to easily get the current MAC using WifiGUI or a custom script/application implementation. This is the preferred method for reading the factory-provided MAC.
However, In some cases, especially during initial small-run assembly tests that occur after devkit prototyping but before a full manufacturing run, it is not easily possible to access the UART2 interface for this purpose. For instance, your target firmware may be configured to use only UART1, or a SPI interface, or the USB interface, or no interface at all and operate entirely using on-module BGScript code. In these cases. It is necessary to use the ICSP interface and PICkit3 hardware and software to first read the complete firmware image from the module. Since the MAC address is stored in flash, you can easily get the current MAC from the .hex image read this way, provided you know where to look.
In order to get access to the existing MAC on a module, it is necessary to read the full firmware image from the module using the MPLAB IPE application (IPE stands for Integrated Programming Environment). The MPLAB IPE is installed as part of the MPLAB IDE installation package but you can select to install only the IPE during the installation process. The MPLAB IPE software does not provide a method for reading only a portion of flash, so the complete image must be read. To do this:
Open the MPLAB IPE programming application and it will automatically detect the presence of the PICkit3 programmer.
You now have access to the complete firmware image from the module. This file contains the contents of the PIC32 flash memory, including whatever existing MAC address is on the module.
Once you have the image from the module, you can open the .hex file in any text editor and the MAC will be in one of two lines depending on the WF121 production batch. This line will contain the factory-flashed MAC address, assuming the module has not previously been erased/reflashed. The .hex file represents 512 kBytes of flash memory in Intel HEX format.
In the .hex file jump to line 32266 (or the line immediately nearby which begins with ":10E01000..."). The MAC address starts at the 18th character, and is 12 characters (6 hex bytes) long as shown below, and in this example screenshot the MAC address is 00:07:80:27:0B:5F. (This is only an example, and not a fixed/new address that you should use in production.)
In the .hex file jump to line 32859 (or the line immediately nearby which begins with ":10050000..."). The MAC address starts at the 14th character, and is 12 characters (6 hex bytes) long as shown below, and in this example screenshot the MAC address is 00:07:80:23:02:F8. (This is only an example, and not a fixed/new address that you should use in production.)
Once you know which address you need to write, the easiest way to do so is with the "config_set_mac" API command. This command can be run from BGScript, or externally using BGAPI over UART, SPI, or USB as long as one of those interfaces is configured for BGAPI control. If you have external BGAPI control such as this, or your BGScript application code provides a mechanism for using a streaming endpoint (UART or USB) to send a new MAC which the script will then apply internally using an API command, this method may be preferable.
Assuming you wish to apply the above example MAC of 00:07:80:27:0B:5F, then:
call config_set_mac(0, "\x00\x07\x80\x27\x0b\x5f")
08 07 02 01 00 00 07 80 27 0b 5f
The new MAC will be written to flash and retained indefinitely, unless you specifically rewrite it again, clear all PS keys, or reflash using the PICkit3/ICSP interface again.
If the API method above is not available or does not make sense with your production process, then you can use the "changemac.exe" tool that comes with the latest Wifi SDKs to pre-apply a MAC address to your compiled firmware image prior to reflashing the module. The changemac tool can be found in the /bin subfolder of wherever you have installed the Wifi SDK. Its syntax is simple:
changemac.exe hexfile mac_address
For example, if you want to modify the MAC address of the "wf121" example project from the SDK using the example address above, perform the following steps:
Once this is done, you can flash the modified wifi.hex file using the PICkit3/ICSP interface. Upon first boot, the stack will detect that no MAC address exists in the relevant PS key, and will "revert" to the supplied address given with changemac.