Application Note
59 of 80
002-26071 Rev. *B
2021-09-07
Clock configuration setup in TRAVEO™ T2G family CYT4D series MCUs
Configuring the internal clock
5.10.3
Sample code for the initial configuration of ECO prescaler settings
show the sample code.
Code Listing 44
General configuration of ECO prescaler settings
#define ECO_PRESCALER_TARGET_FREQ (1234567ul)
#define CLK_FREQ_ECO (16000000ul)
#define PATH_SOURCE_CLOCK_FREQ CLK_FREQ_ECO
/** Wait time definition **/
#define WAIT_FOR_STABILIZATION (10000ul)
int main(void)
{
:
/* Set Clock Configuring registers */
AllClockConfiguration();
:
/* Please check clock output using oscilloscope after CPU reached here. */
for(;;);
}
Code Listing 45
AllClockConfiguration() function
static void AllClockConfiguration(void)
{
/***** ECO prescaler setting ******/
{
:
cy_en_sysclk_status_t ecoPreStatus;
ecoPreStatus = Cy_SysClk_SetEcoPrescale(CLK_FREQ_ECO, ECO_PRESCALER_TARGET_FREQ);
CY_ASSERT(ecoPreStatus == CY_SYSCLK_SUCCESS);
ecoPreStatus = Cy_SysClk_EcoPrescaleEnable(WAIT_FOR_STABILIZATION);
CY_ASSERT(ecoPreStatus == CY_SYSCLK_SUCCESS);
}
return;
}
Code Listing 46
Cy_SysClk_SetEcoPrescale() function
cy_en_sysclk_status_t Cy_SysClk_SetEcoPrescale(uint32_t ecoFreq, uint32_t targetFreq)
{
// Frequency of ECO (4MHz ~ 33.33MHz) might exceed 32bit value if shifted 8 bit.
// So, it uses 64 bit data for fixed point operation.
// Lowest 8 bit are fractional value. Next 10 bit are integer value.
uint64_t fixedPointEcoFreq = ((uint64_t)ecoFreq << 8ull);
uint64_t fixedPointDivNum64;
uint32_t fixedPointDivNum;
// Culculate divider number
fixedPointDivNum64 = fixedPointEcoFreq / (uint64_t)targetFreq;
// Dividing num should be larger 1.0, and smaller than maximum of 10bit number.
if((fixedPointDivNum64 < 0x100ull) && (fixedPointDivNum64 > 0x40000ull))
{
return CY_SYSCLK_BAD_PARAM;
}
fixedPointDivNum = (uint32_t)fixedPointDivNum64;
Cy_SysClk_SetEcoPrescaleManual(
(((fixedPointDivNum & 0x0003FF00ul) >> 8ul) - 1ul),
(fixedPointDivNum & 0x000000FFul)
);
return CY_SYSCLK_SUCCESS;
}
Define the ECO prescaler target frequency.
ECO prescaler setting. See
Define the ECO clock frequency.
Define waiting for stabilization.
ECO prescaler setting. See
ECO prescaler enable. See
Configure the ECO prescaler. See