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.

CC2540: Using Frequency Tuning Commands

Part Number: CC2540

The following info may be helpful to others doing frequency tuning of the 32 MHz crystal for adjusting the CC2540 BLE frequencies.

1) In spite of the TI header files saying that the HCI_EXT_SetFreqTuneCmd and HCI_EXT_SaveFreqTuneCmd "Note: This is a Production Test Mode only command!", this is not true.  These commands both also work in normal mode.  That is, one does not need to use HCI_EXT_EnablePTMCmd first and if one did then the USART 0 is taken over as a serial port.

2) The HCI_EXT_SaveFreqTuneCmd writes to a "ptmFreqTune" variable but does not just write the frequency tuning value.  Since this is a code segment and since they do not support modify which would require erasing a 2 KB Flash page (copying the page to SRAM, writing the byte, erasing the page in Flash, writing back the page from SRAM to Flash), one might think that one could do a save so long as one was writing additional 0 bits.  This does not work because the save command also writes elsewhere to indicate that a save was done.  So only one HCI_EXT_SaveFreqTuneCmd can be done regardless of the specific frequency tuning parameter being saved.

3) An erasure of code memory such as when doing a chip erase or loading new code (which erases Flash pages) even OTA (unless TI is preserving this -- haven't checked for that), the ptmFreqTune variable will be reset to 0xFF (the tuning parameter is just 4 bits of this so 0x0F).

So to do frequency tuning without having to use PTM and the USART 0 serial port and instead using application code, say over SPI to call HCI commands (assuming you write such code to do so on the CC2540), you can erase the chip and/or load new firmware and then do HCI_EXT_SetFreqTuneCmd commands to tune down (or back up after going down) and then do a HCI_EXT_SaveFreqTuneCmd to save.

If you want to preserve this frequency tuning across new code installs, you can read the ptmFreqTune variable to save it elsewhere before erasing/writing new firmware to Flash and then do the HCI_EXT_SetFreqTuneCmd commands to tune down to the saved value and then do a HCI_EXT_SaveFreqTuneCmd to save.

  • The "ptmFreqTune" variable is in code Flash so isn't easy to access given code banks (it can be accessed via the selectable 32 KB Flash bank area known as XBANK). One can instead access the FREQTUNE register (0x618E) XOSC32M_TUNE[3:0] since that gets set at startup from the ptmFreqTune variable and is accessible as XDATA.

  • Correction: FREQTUNE address for CC2540/2541 is 0x6185.  The 0x618E was for the 253x so is not correct.

  • Hi Richard,

    Thanks for sharing your findings!

    FREQTUNE is not a feature that is much used on the CC254x devices. The reason is that individual tuning of the crystal oscillator frequency is typically not required. It is simpler to just use a crystal with performance within the required accuracy for BLE and do a one-time tuning in the design phase by properly dimensioning the external load capacitors. FREQTUNE also has the caveat that it is only possible to add capacitance, and it is thus only possible to shift the frequency downwards.

    More information about FREQTUNE is found in the CC253x/4x User´s Guide, and here: www.ti.com/.../swra372

    It is also possible to bypass the HCI calls completely and write directly to the register. SNV can be used to retain the value through resets and power downs.

    Regards,
    Fredrik