1. Access CTUNE token with Simplicity Commander
Wireless Gecko (EFR32™) portfolio devices support configuring the crystal oscillator load capacitance in software. The crystal oscillator load capacitor tuning (CTUNE) values are tuned during the production test of both Wireless Gecko-based modules and Silicon Labs Wireless Starter Kit (WSTK) radio boards. For Silabs modules, the optimal value for each device is written to the Device Information (DI) page in flash. For Silabs radio boards, the optimal value for each board is written to an EEPROM that is inaccessible to the software running on the target device, but readable by Simplicity Commander.
The CTUNE commands support reading out the stored CTUNE values from these locations, and writing and reading the CTUNE manufacturing token.
How to issue these commands provided by Simplicity Commander to access the CTUNE token?
Firstly, open Command Prompt of Windows (open “Search Windows” at the bottom left of the windows and type “cmd” to search it).
Secondly, move to the installation directory which includes the Simplicity Commander, e.g., in my computer, the path is “C:\SiliconLabs\SimplicityStudio\v4\developer\adapter_packs\commander”.
Thirdly, issue the get command below to get the CTUNE value, e.g., the device I used is EFR32MG12P433F1024GL125 and the serial number is 440033733.
We can see the values from DI (device information) page, EEPROM on the board and MFG token. Since the DI page doesn’t include the CTUNE value, the value is displayed as “Not set”.
Additionally, we can also issue the set command below to set a new value for CTUNE token in the USER DATA page, e.g., the device I used is EFR32MG12P433F1024GL125 and the serial number is 440033733.
See more details about these commands in document UG162: simplicity-commander-reference-guide.
Silicon Labs recommends that User Data and Lock Bits page tokens be written using Simplicity Commander at the same time as programming the main flash. Simplicity Commander also allows for patching and reprogramming the manufacturing blocks as many times as necessary. For the User Data and Lock Bits page tokens, the relevant IC’s Reference Manual or Data Sheet describe the location of each manufacturing token as an offset to the starting address of the relevant block. We can also see document AN961: custom-nodes-efr32 to learn more about this.
2. Access CTUNE token in Connect example
Connect automatically sets the CTUNE from the manufacturing token during initialization.
Some situations may require that a manufacturing token be programmed at runtime from code running on the chip itself. At the proprietary side, in the Connect stack the manufacturing token module of the HAL provides a token API to write the manufacturing tokens. However, this API only writes manufacturing tokens that are in a completely erased state. If a manufacturing token must be reprogrammed, you must use an external utility.
We can use the functions halCommonGetMfgToken()and halCommonSetMfgToken() to access the CTUNE tokens.
See chapter 3 of AN1154-token-for-non-volatile-storage and chapter 3 of AN961-cutomer-nodes-efr32 for more details.
3. Access tokens in Rail example
Rail doesn’t provide the relevant functions to access the manufacturing tokens in User Data page. To get and set the token value in User Data Page, we can use the functions of MSC.
We can use function HalMfgToken_GetTokenValueFromUserPage() below to get the value from User Data page and the function HalMfgToken_SetTokenValueToUserPage() below to set the value into the tokens in User Data page. Note that before writing the manufacturing tokens should be in a completely erased state.
For implement of the functions, see the attached c/h files. When we use the two functions, we should include hal_ctune.h in source code file. For the tune of crystal we can use these functions to get the CTUNE token value from User Data page, and then write it to the CMU->HFXOSTEADYSTATECTRL register, so it can make the tune of crystal effect. Before writing, make sure that the radio state is idle. See the chapter 184.108.40.206 of the document efr32_reference_manual for details about HFXO configuration.
In the test code, we erase the entire page at first, and then write the value at the address offset 0x0100 in User Data page, where the CTUNE value should be stored.
//Test code below is for setting and getting the CTUNE value in the User Data page uint16_t ctuneValueIn= 332, ctuneValueOut = 0; MSC_ErasePage((uint32_t*)USERDATA_BASE); HalMfgToken_SetTokenValueToUserPage(0x0100, (uint8_t*)&ctuneValueIn, 2); HalMfgToken_GetTokenValueFromUserPage(0x0100, (uint8_t*)&ctuneValueOut, 2); //before setting ctune, remove the radio from rx and tx states RAIL_Idle(railHandle, RAIL_IDLE, true); RAIL_SetTune(railHandle, (uint32_t)ctuneValueOut);
4. Access CTUNE with the Railtest example
The Railtest example provides a way to access the CTUNE control registers. The command setCtune can be used to write the value of CTUNE to the CMU->HFXOSTEADYSTATECTRL register. Note that when we intend to set the value of CTUNE, we should make the radio state be idle with command “rx 0”.
The command getCtune allows us to get the value of CTUNE from the CMU->HFXOSTEADYSTATECTRL register.
With Railtest example, we can also use command getmemw to get CTUNE token value stored in the User Data page. The address of CTUNE token is 0x0fe00100. Note that the only 2 low bytes of the word are valid, because it is limited to get a word at a time using this command and the size of CTUNE value is just 2 bytes.