CC26xx Driver Library
setup.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: setup.c
3 * Revised: 2016-08-10 11:10:10 +0200 (Wed, 10 Aug 2016)
4 * Revision: 46997
5 *
6 * Description: Setup file for CC13xx/CC26xx devices.
7 *
8 * Copyright (c) 2015 - 2016, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 // Hardware headers
40 #include <inc/hw_types.h>
41 #include <inc/hw_memmap.h>
42 #include <inc/hw_adi.h>
43 #include <inc/hw_adi_2_refsys.h>
44 #include <inc/hw_adi_3_refsys.h>
45 #include <inc/hw_aon_ioc.h>
46 #include <inc/hw_aon_sysctl.h>
47 #include <inc/hw_aon_wuc.h>
48 #include <inc/hw_aux_wuc.h>
49 #include <inc/hw_ccfg.h>
50 #include <inc/hw_fcfg1.h>
51 #include <inc/hw_flash.h>
52 #include <inc/hw_prcm.h>
53 #include <inc/hw_vims.h>
54 // Driverlib headers
55 #include <driverlib/aon_wuc.h>
56 #include <driverlib/aux_wuc.h>
57 #include <driverlib/chipinfo.h>
58 #include <driverlib/setup.h>
59 #include <driverlib/setup_rom.h>
60 // ##### INCLUDE IN ROM BEGIN #####
61 // We need intrinsic functions for IAR (if used in source code)
62 #ifdef __IAR_SYSTEMS_ICC__
63 #include <intrinsics.h>
64 #endif
65 // ##### INCLUDE IN ROM END #####
66 
67 //*****************************************************************************
68 //
69 // Handle support for DriverLib in ROM:
70 // This section will undo prototype renaming made in the header file
71 //
72 //*****************************************************************************
73 #if !defined(DOXYGEN)
74  #undef SetupTrimDevice
75  #define SetupTrimDevice NOROM_SetupTrimDevice
76 #endif
77 
78 
79 
80 //*****************************************************************************
81 //
82 // Defined CPU delay macro with microseconds as input
83 // Quick check shows: (To be further investigated)
84 // At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 5 cycles
85 // At 48 MHz RCOSC and VIMS.CONTROL.PREFETCH = 1, there is 4 cycles
86 // At 24 MHz RCOSC and VIMS.CONTROL.PREFETCH = 0, there is 3 cycles
87 //
88 //*****************************************************************************
89 #define CPU_DELAY_MICRO_SECONDS( x ) \
90  CPUdelay(((uint32_t)((( x ) * 48.0 ) / 5.0 )) - 1 )
91 
92 
93 //*****************************************************************************
94 //
95 // Function declarations
96 //
97 //*****************************************************************************
98 static void TrimAfterColdReset( void );
99 static void TrimAfterColdResetWakeupFromShutDown( uint32_t ui32Fcfg1Revision );
101 
102 //*****************************************************************************
103 //
104 // Perform the necessary trim of the device which is not done in boot code
105 //
106 // This function should only execute coming from ROM boot. The current
107 // implementation does not take soft reset into account. However, it does no
108 // damage to execute it again. It only consumes time.
109 //
110 //*****************************************************************************
111 void
113 {
114  uint32_t ui32Fcfg1Revision;
115  uint32_t ui32AonSysResetctl;
116 
117  //
118  // Get layout revision of the factory configuration area
119  // (Handle undefined revision as revision = 0)
120  //
121  ui32Fcfg1Revision = HWREG(FCFG1_BASE + FCFG1_O_FCFG1_REVISION);
122  if ( ui32Fcfg1Revision == 0xFFFFFFFF ) {
123  ui32Fcfg1Revision = 0;
124  }
125 
126  //
127  // This driverlib version and setup file is for CC26xx PG2.2 and later
128  // Halt if violated
129  //
131 
132  //
133  // Enable standby in flash bank
134  //
136 
137  //
138  // Clock must always be enabled for the semaphore module (due to ADI/DDI HW workaround)
139  //
141 
142  //
143  // Warm resets on CC26XX complicates software design as much of our software
144  // expect that initialization is done from a full system reset.
145  // This includes RTC setup, oscillator configuration and AUX setup.
146  // To ensure a full reset of the device is done when customers get e.g. a Watchdog
147  // reset, the following is set here:
148  //
150 
151  //
152  // Select correct CACHE mode and set correct CACHE configuration
153  //
155 
156  // 1. Check for powerdown
157  // 2. Check for shutdown
158  // 3. Assume cold reset if none of the above.
159  //
160  // It is always assumed that the application will freeze the latches in
161  // AON_IOC when going to powerdown in order to retain the values on the IOs.
162  //
163  // NB. If this bit is not cleared before proceeding to powerdown, the IOs
164  // will all default to the reset configuration when restarting.
166  {
167  //
168  // NB. This should be calling a ROM implementation of required trim and
169  // compensation
170  // e.g. TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown()
172  }
173  // Check for shutdown
174  //
175  // When device is going to shutdown the hardware will automatically clear
176  // the SLEEPDIS bit in the SLEEP register in the AON_SYSCTRL12 module.
177  // It is left for the application to assert this bit when waking back up,
178  // but not before the desired IO configuration has been re-established.
180  {
181  //
182  // NB. This should be calling a ROM implementation of required trim and
183  // compensation
184  // e.g. TrimAfterColdResetWakeupFromShutDown() -->
185  // TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown();
186  TrimAfterColdResetWakeupFromShutDown(ui32Fcfg1Revision);
188  }
189  else
190  {
191  // Consider adding a check for soft reset to allow debugging to skip
192  // this section!!!
193  //
194  // NB. This should be calling a ROM implementation of required trim and
195  // compensation
196  // e.g. TrimAfterColdReset() -->
197  // TrimAfterColdResetWakeupFromShutDown() -->
198  // TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown()
200  TrimAfterColdResetWakeupFromShutDown(ui32Fcfg1Revision);
202 
203  }
204 
205  //
206  // Set VIMS power domain control.
207  // PDCTL1VIMS = 0 ==> VIMS power domain is only powered when CPU power domain is powered
208  //
209  HWREG( PRCM_BASE + PRCM_O_PDCTL1VIMS ) = 0;
210 
211  //
212  // Configure optimal wait time for flash FSM in cases where flash pump
213  // wakes up from sleep
214  //
215  HWREG(FLASH_BASE + FLASH_O_FPAC1) = (HWREG(FLASH_BASE + FLASH_O_FPAC1) &
217  (0x139<<FLASH_FPAC1_PSLEEPTDIS_S);
218 
219  //
220  // And finally at the end of the flash boot process:
221  // SET BOOT_DET bits in AON_SYSCTL to 3 if already found to be 1
222  // Note: The BOOT_DET_x_CLR/SET bits must be manually cleared
223  //
224  if ((( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
227  {
228  ui32AonSysResetctl = ( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
232  HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) = ui32AonSysResetctl;
233  }
234 
235  //
236  // Make sure there are no ongoing VIMS mode change when leaving SetupTrimDevice()
237  // (There should typically be no wait time here, but need to be sure)
238  //
239  while ( HWREGBITW( VIMS_BASE + VIMS_O_STAT, VIMS_STAT_MODE_CHANGING_BITN )) {
240  // Do nothing - wait for an eventual ongoing mode change to complete.
241  }
242 }
243 
244 //*****************************************************************************
245 //
250 //
251 //*****************************************************************************
252 static void
254 {
255  //
256  // Currently no specific trim for Powerdown
257  //
258 }
259 
260 //*****************************************************************************
261 //
266 //
267 //*****************************************************************************
268 static void
269 TrimAfterColdResetWakeupFromShutDown(uint32_t ui32Fcfg1Revision)
270 {
271  uint32_t ccfg_ModeConfReg ;
272  uint32_t mp1rev ;
273 
274  //
275  // Force AUX on and enable clocks
276  //
277  // No need to save the current status of the power/clock registers.
278  // At this point both AUX and AON should have been reset to 0x0.
279  //
281 
282  //
283  // Wait for power on on the AUX domain
284  //
286 
287  //
288  // Enable the clocks for AUX_DDI0_OSC and AUX_ADI4
289  //
292 
293  //
294  // It's found to be optimal to override the FCFG1..DCDC_IPEAK setting as follows:
295  // if ( alternative DCDC setting in CCFG is enabled ) ADI3..IPEAK = CCFG..DCDC_IPEAK
296  // else ADI3..IPEAK = 2
297  //
299  //
300  // ADI_3_REFSYS:DCDCCTL5[3] (=DITHER_EN) = CCFG_MODE_CONF_1[19] (=ALT_DCDC_DITHER_EN)
301  // ADI_3_REFSYS:DCDCCTL5[2:0](=IPEAK ) = CCFG_MODE_CONF_1[18:16](=ALT_DCDC_IPEAK )
302  // Using a single 4-bit masked write since layout is equal for both source and destination
303  //
304  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = ( 0xF0 |
306 
307  } else {
308  HWREGB( ADI3_BASE + ADI_O_MASK4B + ( ADI_3_REFSYS_O_DCDCCTL5 * 2 )) = 0x72;
309  }
310 
311  //
312  // Enable for JTAG to be powered down (will still be powered on if debugger is connected)
313  //
315 
316  //
317  // read the MODE_CONF register in CCFG
318  //
319  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
320 
321  //
322  // First part of trim done after cold reset and wakeup from shutdown:
323  // -Adjust the VDDR_TRIM_SLEEP value.
324  // -Configure DCDC.
325  //
326  SetupAfterColdResetWakeupFromShutDownCfg1( ccfg_ModeConfReg );
327 
328  //
329  // Second part of trim done after cold reset and wakeup from shutdown:
330  // -Configure XOSC.
331  //
332  SetupAfterColdResetWakeupFromShutDownCfg2( ui32Fcfg1Revision, ccfg_ModeConfReg );
333 
334  //
335  // Increased margin between digital supply voltage and VDD BOD during standby.
336  // VTRIM_UDIG: signed 4 bits value to be incremented by 2 (max = 7)
337  // VTRIM_BOD: unsigned 4 bits value to be decremented by 1 (min = 0)
338  // This applies to chips with mp1rev < 542 for cc13xx and for mp1rev < 527 for cc26xx
339  //
340  mp1rev = ( HWREG( FCFG1_BASE + 0x00000314 ) & 0x0000FFFF );
341  if ( mp1rev < 527 ) {
342  uint32_t vtrim_bod = (( HWREG( FCFG1_BASE + 0x000002BC ) >> 24 ) & 0xF ); // bit[27:24] unsigned
343  uint32_t vtrim_udig = (( HWREG( FCFG1_BASE + 0x000002BC ) >> 16 ) & 0xF ); // bit[19:16] signed
344  if ( vtrim_bod > 0 ) {
345  vtrim_bod -= 1;
346  }
347  if ( vtrim_udig != 7 ) {
348  if ( vtrim_udig == 6 ) {
349  vtrim_udig = 7;
350  } else {
351  vtrim_udig = (( vtrim_udig + 2 ) & 0xF );
352  }
353  }
355  ( vtrim_udig << ADI_2_REFSYS_SOCLDOCTL0_VTRIM_UDIG_S ) |
356  ( vtrim_bod << ADI_2_REFSYS_SOCLDOCTL0_VTRIM_BOD_S ) ;
357  }
358 
359  //
360  // Third part of trim done after cold reset and wakeup from shutdown:
361  // -Configure HPOSC.
362  // -Setup the LF clock.
363  //
364  SetupAfterColdResetWakeupFromShutDownCfg3( ccfg_ModeConfReg );
365 
366  //
367  // Allow AUX to power down
368  //
370 
371  //
372  // Leaving on AUX and clock for AUX_DDI0_OSC on but turn off clock for AUX_ADI4
373  //
375 
376  // Disable EFUSE clock
378 }
379 
380 
381 //*****************************************************************************
382 //
386 //
387 //*****************************************************************************
388 static void
390 {
391  //
392  // Currently no specific trim for Cold Reset
393  //
394 }
void SetupAfterColdResetWakeupFromShutDownCfg3(uint32_t ccfg_ModeConfReg)
Third part of configuration required when waking up from shutdown.
Definition: setup_rom.c:302
#define AUX_WUC_POWER_DOWN
Definition: aux_wuc.h:95
void AUXWUCPowerCtrl(uint32_t ui32PowerMode)
Control the power to the AUX domain.
Definition: aux_wuc.c:274
void SetupTrimDevice(void)
Performs the necessary trim of the device which is not done in boot code.
Definition: setup.c:112
void ThisCodeIsBuiltForCC26xxHwRev22AndLater_HaltIfViolated(void)
Verifies that current chip is built for CC26xx HwRev 2.2 or later and never returns if violated...
Definition: chipinfo.c:237
void SetupAfterColdResetWakeupFromShutDownCfg1(uint32_t ccfg_ModeConfReg)
First part of configuration required when waking up from shutdown.
Definition: setup_rom.c:123
static void TrimAfterColdResetWakeupFromShutDownWakeupFromPowerDown(void)
Trims to be applied when coming from POWER_DOWN (also called when coming from SHUTDOWN and PIN_RESET)...
Definition: setup.c:253
void SetupSetCacheModeAccordingToCcfgSetting(void)
Set correct VIMS_MODE according to CCFG setting (CACHE or GPRAM)
Definition: setup_rom.c:881
static void TrimAfterColdResetWakeupFromShutDown(uint32_t ui32Fcfg1Revision)
Trims to be applied when coming from SHUTDOWN (also called when coming from PIN_RESET).
Definition: setup.c:269
void SetupAfterColdResetWakeupFromShutDownCfg2(uint32_t ui32Fcfg1Revision, uint32_t ccfg_ModeConfReg)
Second part of configuration required when waking up from shutdown.
Definition: setup_rom.c:186
static void TrimAfterColdReset(void)
Trims to be applied when coming from PIN_RESET.
Definition: setup.c:389
static void AONWUCJtagPowerOff(void)
Request power off of the JTAG domain.
Definition: aon_wuc.h:816