CC26xx Driver Library
setup.c File Reference
#include "../inc/hw_types.h"
#include "../inc/hw_memmap.h"
#include "../inc/hw_adi.h"
#include "../inc/hw_adi_2_refsys.h"
#include "../inc/hw_adi_3_refsys.h"
#include "../inc/hw_adi_4_aux.h"
#include "../inc/hw_aon_ioc.h"
#include "../inc/hw_aon_pmctl.h"
#include "../inc/hw_aon_rtc.h"
#include "../inc/hw_ddi_0_osc.h"
#include "../inc/hw_ccfg.h"
#include "../inc/hw_fcfg1.h"
#include "../inc/hw_flash.h"
#include "../inc/hw_prcm.h"
#include "../inc/hw_vims.h"
#include "aux_sysif.h"
#include "chipinfo.h"
#include "setup.h"
#include "setup_rom.h"

Macros

#define ADI_4_AUX_O_LPMBIAS   0x0000000E
 
#define ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_M   0x0000003F
 
#define ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_S   0
 
#define ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_M   0x00000038
 
#define ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_S   3
 
#define CPU_DELAY_MICRO_SECONDS(x)   CPUdelay(((uint32_t)((( x ) * 48.0 ) / 5.0 )) - 1 )
 

Functions

static void TrimAfterColdReset (void)
 Trims to be applied when coming from PIN_RESET. More...
 
static void TrimAfterColdResetWakeupFromShutDown (uint32_t ui32Fcfg1Revision)
 Trims to be applied when coming from SHUTDOWN (also called when coming from PIN_RESET). More...
 
static void TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown (void)
 Trims to be applied when coming from POWER_DOWN (also called when coming from SHUTDOWN and PIN_RESET). More...
 
void SetupTrimDevice (void)
 Performs the necessary trim of the device which is not done in boot code. More...
 
static void Step_RCOSCHF_CTRIM (uint32_t toCode)
 
static void Step_VBG (int32_t targetSigned)
 

Macro Definition Documentation

#define ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_M   0x00000038
#define ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_S   3
#define ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_M   0x0000003F
#define ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_S   0
#define ADI_4_AUX_O_LPMBIAS   0x0000000E
#define CPU_DELAY_MICRO_SECONDS (   x)    CPUdelay(((uint32_t)((( x ) * 48.0 ) / 5.0 )) - 1 )

Function Documentation

static void Step_RCOSCHF_CTRIM ( uint32_t  toCode)
static

Referenced by TrimAfterColdResetWakeupFromShutDown().

234 {
235  uint32_t currentRcoscHfCtlReg ;
236  uint32_t currentTrim ;
237 
238  currentRcoscHfCtlReg = HWREGH( AUX_DDI0_OSC_BASE + DDI_0_OSC_O_RCOSCHFCTL );
239  currentTrim = ((( currentRcoscHfCtlReg & DDI_0_OSC_RCOSCHFCTL_RCOSCHF_CTRIM_M ) >>
240  DDI_0_OSC_RCOSCHFCTL_RCOSCHF_CTRIM_S ) ^ 0xC0 );
241 
242  while ( toCode != currentTrim ) {
243  HWREG( AON_RTC_BASE + AON_RTC_O_SYNCLF ); // Wait for next edge on SCLK_LF (positive or negative)
244 
245  if ( toCode > currentTrim ) currentTrim++;
246  else currentTrim--;
247 
248  HWREGH( AUX_DDI0_OSC_BASE + DDI_0_OSC_O_RCOSCHFCTL ) =
249  ( currentRcoscHfCtlReg & ~DDI_0_OSC_RCOSCHFCTL_RCOSCHF_CTRIM_M ) |
250  (( currentTrim ^ 0xC0 ) << DDI_0_OSC_RCOSCHFCTL_RCOSCHF_CTRIM_S );
251  }
252 }
static void Step_VBG ( int32_t  targetSigned)
static

Referenced by TrimAfterColdResetWakeupFromShutDown().

256 {
257  // VBG (ANA_TRIM[5:0]=TRIMTEMP --> ADI_3_REFSYS:REFSYSCTL3.TRIM_VBG)
258  uint32_t refSysCtl3Reg ;
259  int32_t currentSigned ;
260 
261  do {
262  refSysCtl3Reg = HWREGB( ADI3_BASE + ADI_3_REFSYS_O_REFSYSCTL3 );
263  currentSigned =
264  (((int32_t)( refSysCtl3Reg << ( 32 - ADI_3_REFSYS_REFSYSCTL3_TRIM_VBG_W - ADI_3_REFSYS_REFSYSCTL3_TRIM_VBG_S )))
265  >> ( 32 - ADI_3_REFSYS_REFSYSCTL3_TRIM_VBG_W ));
266 
267  HWREG( AON_RTC_BASE + AON_RTC_O_SYNCLF ); // Wait for next edge on SCLK_LF (positive or negative)
268 
269  if ( targetSigned != currentSigned ) {
270  if ( targetSigned > currentSigned ) currentSigned++;
271  else currentSigned--;
272 
273  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_REFSYSCTL3 ) =
274  ( refSysCtl3Reg & ~( ADI_3_REFSYS_REFSYSCTL3_BOD_BG_TRIM_EN | ADI_3_REFSYS_REFSYSCTL3_TRIM_VBG_M )) |
275  ((((uint32_t)currentSigned) << ADI_3_REFSYS_REFSYSCTL3_TRIM_VBG_S ) & ADI_3_REFSYS_REFSYSCTL3_TRIM_VBG_M );
276 
277  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_REFSYSCTL3 ) |= ADI_3_REFSYS_REFSYSCTL3_BOD_BG_TRIM_EN; // Bit set by doing a read modify write
278  }
279  } while ( targetSigned != currentSigned );
280 }
static void TrimAfterColdReset ( void  )
static

Trims to be applied when coming from PIN_RESET.

Returns
None

Referenced by SetupTrimDevice().

468 {
469  // Currently no specific trim for Cold Reset
470 }
static void TrimAfterColdResetWakeupFromShutDown ( uint32_t  ui32Fcfg1Revision)
static

Trims to be applied when coming from SHUTDOWN (also called when coming from PIN_RESET).

Parameters
ui32Fcfg1Revision
Returns
None

Referenced by SetupTrimDevice().

294 {
295  uint32_t ccfg_ModeConfReg ;
296 
297  // Check in CCFG for alternative DCDC setting
298  if (( HWREG( CCFG_BASE + CCFG_O_SIZE_AND_DIS_FLAGS ) & CCFG_SIZE_AND_DIS_FLAGS_DIS_ALT_DCDC_SETTING ) == 0 ) {
299  // ADI_3_REFSYS:DCDCCTL5[3] (=DITHER_EN) = CCFG_MODE_CONF_1[19] (=ALT_DCDC_DITHER_EN)
300  // ADI_3_REFSYS:DCDCCTL5[2:0](=IPEAK ) = CCFG_MODE_CONF_1[18:16](=ALT_DCDC_IPEAK )
301  // Using a single 4-bit masked write since layout is equal for both source and destination
302  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = ( 0xF0 |
303  ( HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 ) >> CCFG_MODE_CONF_1_ALT_DCDC_IPEAK_S ));
304 
305  }
306 
307  // TBD-Agama - Temporarily removed for Agama
308 
309  // read the MODE_CONF register in CCFG
310  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
311 
312  // First part of trim done after cold reset and wakeup from shutdown:
313  // -Adjust the VDDR_TRIM_SLEEP value.
314  // -Configure DCDC.
315  SetupAfterColdResetWakeupFromShutDownCfg1( ccfg_ModeConfReg );
316 
317  // Second part of trim done after cold reset and wakeup from shutdown:
318  // -Configure XOSC.
319 #if ( CCFG_BASE == CCFG_BASE_DEFAULT )
320  SetupAfterColdResetWakeupFromShutDownCfg2( ui32Fcfg1Revision, ccfg_ModeConfReg );
321 #else
322  NOROM_SetupAfterColdResetWakeupFromShutDownCfg2( ui32Fcfg1Revision, ccfg_ModeConfReg );
323 #endif
324 
325  // Special shadow register trim propagation on first batch of devices
326  {
327  uint32_t ui32EfuseData ;
328  uint32_t orgResetCtl ;
329 
330  // Get VTRIM_COARSE and VTRIM_DIG from EFUSE shadow register OSC_BIAS_LDO_TRIM
331  ui32EfuseData = HWREG( FCFG1_BASE + FCFG1_O_SHDW_OSC_BIAS_LDO_TRIM );
332 
333  Step_RCOSCHF_CTRIM(( ui32EfuseData &
334  FCFG1_SHDW_OSC_BIAS_LDO_TRIM_RCOSCHF_CTRIM_M ) >>
335  FCFG1_SHDW_OSC_BIAS_LDO_TRIM_RCOSCHF_CTRIM_S ) ;
336 
337  // Write to register SOCLDO_0_1 (addr offset 3) bits[7:4] (VTRIM_COARSE) and
338  // bits[3:0] (VTRIM_DIG) in ADI_2_REFSYS. Direct write can be used since
339  // all register bit fields are trimmed.
340  HWREGB(ADI2_BASE + ADI_O_DIR + ADI_2_REFSYS_O_SOCLDOCTL1) =
341  ((((ui32EfuseData & FCFG1_SHDW_OSC_BIAS_LDO_TRIM_VTRIM_COARSE_M) >>
342  FCFG1_SHDW_OSC_BIAS_LDO_TRIM_VTRIM_COARSE_S) <<
343  ADI_2_REFSYS_SOCLDOCTL1_VTRIM_COARSE_S) |
344 
345  (((ui32EfuseData & FCFG1_SHDW_OSC_BIAS_LDO_TRIM_VTRIM_DIG_M) >>
346  FCFG1_SHDW_OSC_BIAS_LDO_TRIM_VTRIM_DIG_S) <<
347  ADI_2_REFSYS_SOCLDOCTL1_VTRIM_DIG_S));
348 
349  // Write to register CTLSOCREFSYS0 (addr offset 0) bits[4:0] (TRIMIREF) in
350  // ADI_2_REFSYS. Avoid using masked write access since bit field spans
351  // nibble boundary. Direct write can be used since this is the only defined
352  // bit field in this register.
353  HWREGB(ADI2_BASE + ADI_O_DIR + ADI_2_REFSYS_O_REFSYSCTL0) =
354  (((ui32EfuseData & FCFG1_SHDW_OSC_BIAS_LDO_TRIM_TRIMIREF_M) >>
355  FCFG1_SHDW_OSC_BIAS_LDO_TRIM_TRIMIREF_S) <<
356  ADI_2_REFSYS_REFSYSCTL0_TRIM_IREF_S);
357 
358  // Write to register CTLSOCREFSYS2 (addr offset 4) bits[7:4] (TRIMMAG) in
359  // ADI_3_REFSYS
360  HWREGH(ADI3_BASE + ADI_O_MASK8B + (ADI_3_REFSYS_O_REFSYSCTL2 << 1)) =
361  (ADI_3_REFSYS_REFSYSCTL2_TRIM_VREF_M << 8) |
362  (((ui32EfuseData & FCFG1_SHDW_OSC_BIAS_LDO_TRIM_TRIMMAG_M) >>
363  FCFG1_SHDW_OSC_BIAS_LDO_TRIM_TRIMMAG_S) <<
364  ADI_3_REFSYS_REFSYSCTL2_TRIM_VREF_S);
365 
366  // Get TRIMBOD_EXTMODE or TRIMBOD_INTMODE from EFUSE shadow register in FCFG1
367  ui32EfuseData = HWREG( FCFG1_BASE + FCFG1_O_SHDW_ANA_TRIM );
368 
369  orgResetCtl = ( HWREG( AON_PMCTL_BASE + AON_PMCTL_O_RESETCTL ) & ~AON_PMCTL_RESETCTL_MCU_WARM_RESET_M );
370  HWREG( AON_PMCTL_BASE + AON_PMCTL_O_RESETCTL ) =
371  ( orgResetCtl & ~( AON_PMCTL_RESETCTL_CLK_LOSS_EN |
372  AON_PMCTL_RESETCTL_VDD_LOSS_EN |
373  AON_PMCTL_RESETCTL_VDDR_LOSS_EN |
374  AON_PMCTL_RESETCTL_VDDS_LOSS_EN ));
375  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait for xxx_LOSS_EN setting to propagate
376 
377  // The VDDS_BOD trim and the VDDR trim is already stepped up to max/HH if "CC1352 boost mode" is requested.
378  // See function SetupAfterColdResetWakeupFromShutDownCfg1() in setup_rom.c for details.
379  if ((( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDR_EXT_LOAD ) != 0 ) ||
380  (( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDS_BOD_LEVEL ) == 0 ) )
381  {
382  if(HWREG(AON_PMCTL_BASE + AON_PMCTL_O_PWRCTL) &
383  AON_PMCTL_PWRCTL_EXT_REG_MODE)
384  {
385  // Apply VDDS BOD trim value
386  // Write to register CTLSOCREFSYS1 (addr offset 3) bit[7:3] (TRIMBOD)
387  // in ADI_3_REFSYS
388  HWREGH(ADI3_BASE + ADI_O_MASK8B + (ADI_3_REFSYS_O_REFSYSCTL1 << 1)) =
389  (ADI_3_REFSYS_REFSYSCTL1_TRIM_VDDS_BOD_M << 8) |
390  (((ui32EfuseData & FCFG1_SHDW_ANA_TRIM_TRIMBOD_EXTMODE_M) >>
391  FCFG1_SHDW_ANA_TRIM_TRIMBOD_EXTMODE_S) <<
392  ADI_3_REFSYS_REFSYSCTL1_TRIM_VDDS_BOD_S);
393  }
394  else
395  {
396  // Apply VDDS BOD trim value
397  // Write to register CTLSOCREFSYS1 (addr offset 3) bit[7:3] (TRIMBOD)
398  // in ADI_3_REFSYS
399  HWREGH(ADI3_BASE + ADI_O_MASK8B + (ADI_3_REFSYS_O_REFSYSCTL1 << 1)) =
400  (ADI_3_REFSYS_REFSYSCTL1_TRIM_VDDS_BOD_M << 8) |
401  (((ui32EfuseData & FCFG1_SHDW_ANA_TRIM_TRIMBOD_INTMODE_M) >>
402  FCFG1_SHDW_ANA_TRIM_TRIMBOD_INTMODE_S) <<
403  ADI_3_REFSYS_REFSYSCTL1_TRIM_VDDS_BOD_S);
404  }
405  // Load the new VDDS_BOD setting
406  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_REFSYSCTL3 ) &= ~ADI_3_REFSYS_REFSYSCTL3_BOD_BG_TRIM_EN; // Bit clear by doing a read modify write
407  HWREGB( ADI3_BASE + ADI_3_REFSYS_O_REFSYSCTL3 ) |= ADI_3_REFSYS_REFSYSCTL3_BOD_BG_TRIM_EN; // Bit set by doing a read modify write
408 
409  SetupStepVddrTrimTo(( ui32EfuseData &
410  FCFG1_SHDW_ANA_TRIM_VDDR_TRIM_M ) >>
411  FCFG1_SHDW_ANA_TRIM_VDDR_TRIM_S ) ;
412  }
413 
414  // VBG (ANA_TRIM[5:0]=TRIMTEMP --> ADI_3_REFSYS:REFSYSCTL3.TRIM_VBG)
415  Step_VBG(((int32_t)( ui32EfuseData << ( 32 - FCFG1_SHDW_ANA_TRIM_TRIMTEMP_W - FCFG1_SHDW_ANA_TRIM_TRIMTEMP_S )))
416  >> ( 32 - FCFG1_SHDW_ANA_TRIM_TRIMTEMP_W ));
417 
418  // Wait two more LF edges before restoring xxx_LOSS_EN settings
419  HWREG( AON_RTC_BASE + AON_RTC_O_SYNCLF ); // Wait for next edge on SCLK_LF (positive or negative)
420  HWREG( AON_RTC_BASE + AON_RTC_O_SYNCLF ); // Wait for next edge on SCLK_LF (positive or negative)
421  HWREG( AON_PMCTL_BASE + AON_PMCTL_O_RESETCTL ) = orgResetCtl;
422  HWREG( AON_RTC_BASE + AON_RTC_O_SYNC ); // Wait for xxx_LOSS_EN setting to propagate
423  }
424 
425  {
426  uint32_t trimReg ;
427  uint32_t ui32TrimValue ;
428 
429  //--- Propagate the LPM_BIAS trim ---
430  trimReg = HWREG( FCFG1_BASE + FCFG1_O_DAC_BIAS_CNF );
431  ui32TrimValue = (( trimReg & FCFG1_DAC_BIAS_CNF_LPM_TRIM_IOUT_M ) >>
432  FCFG1_DAC_BIAS_CNF_LPM_TRIM_IOUT_S ) ;
433  HWREGB( AUX_ADI4_BASE + ADI_4_AUX_O_LPMBIAS ) = (( ui32TrimValue << ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_S ) &
435  //--- Set fixed LPM_BIAS values --- LPM_BIAS_BACKUP_EN = 1 and LPM_BIAS_WIDTH_TRIM = 3
436  HWREGB( ADI3_BASE + ADI_O_SET + ADI_3_REFSYS_O_AUX_DEBUG ) = ADI_3_REFSYS_AUX_DEBUG_LPM_BIAS_BACKUP_EN;
437  HWREGH( AUX_ADI4_BASE + ADI_O_MASK8B + ( ADI_4_AUX_O_COMP * 2 )) = // Set LPM_BIAS_WIDTH_TRIM = 3
438  (( ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_M << 8 ) | // Set mask (bits to be written) in [15:8]
439  ( 3 << ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_S ) ); // Set value (in correct bit pos) in [7:0]
440  }
441 
442  // Third part of trim done after cold reset and wakeup from shutdown:
443  // -Configure HPOSC.
444  // -Setup the LF clock.
445 #if ( CCFG_BASE == CCFG_BASE_DEFAULT )
446  SetupAfterColdResetWakeupFromShutDownCfg3( ccfg_ModeConfReg );
447 #else
448  NOROM_SetupAfterColdResetWakeupFromShutDownCfg3( ccfg_ModeConfReg );
449 #endif
450 
451  // Set AUX into power down active mode
453 
454  // Disable EFUSE clock
455  HWREGBITW( FLASH_BASE + FLASH_O_CFG, FLASH_CFG_DIS_EFUSECLK_BITN ) = 1;
456 }
static void Step_VBG(int32_t targetSigned)
Definition: setup.c:255
#define ADI_4_AUX_O_LPMBIAS
Definition: setup.c:47
void SetupAfterColdResetWakeupFromShutDownCfg3(uint32_t ccfg_ModeConfReg)
Third part of configuration required when waking up from shutdown.
Definition: setup_rom.c:324
#define ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_S
Definition: setup.c:51
#define ADI_4_AUX_COMP_LPM_BIAS_WIDTH_TRIM_M
Definition: setup.c:50
#define AUX_SYSIF_OPMODE_TARGET_PDA
Definition: aux_sysif.h:99
void SetupAfterColdResetWakeupFromShutDownCfg1(uint32_t ccfg_ModeConfReg)
First part of configuration required when waking up from shutdown.
Definition: setup_rom.c:167
void AUXSYSIFOpModeChange(uint32_t targetOpMode)
Changes the AUX operational mode to the requested target mode.
Definition: aux_sysif.c:67
#define ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_S
Definition: setup.c:49
static void Step_RCOSCHF_CTRIM(uint32_t toCode)
Definition: setup.c:233
void SetupStepVddrTrimTo(uint32_t toCode)
Set VDDR boost mode (by setting VDDR_TRIM to FCFG1..VDDR_TRIM_HH and setting VDDS_BOD to max) ...
Definition: setup_rom.c:119
void SetupAfterColdResetWakeupFromShutDownCfg2(uint32_t ui32Fcfg1Revision, uint32_t ccfg_ModeConfReg)
Second part of configuration required when waking up from shutdown.
Definition: setup_rom.c:222
#define ADI_4_AUX_LPMBIAS_LPM_TRIM_IOUT_M
Definition: setup.c:48

Here is the call graph for this function:

static void TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown ( void  )
static

Trims to be applied when coming from POWER_DOWN (also called when coming from SHUTDOWN and PIN_RESET).

Returns
None

Referenced by SetupTrimDevice().

226 {
227  // Currently no specific trim for Powerdown
228 }