#include #include #include #include "aurix_hal_sys.h" #include "IfxScu_reg.h" #include "IfxScu_bf.h" #include "IfxCpu_reg.h" #include "IfxCpu_bf.h" #include "IfxStm_reg.h" #include "IfxStm_bf.h" #include "IfxQspi_reg.h" # define BOARD_NAME "TriBoard-TC233A" # define BOARD_TITLE "TC233A TriBoard" # define MCU_NAME "TC233A" #include "IfxPort_reg.h" #include "IfxPort_bf.h" #include "IfxAsclin_reg.h" #include "IfxAsclin_bf.h" #define USE_DISABLE_EXT_WDT 1 typedef struct _PllInitValue_t { unsigned int valOSCCON; unsigned int valPLLCON0; unsigned int valPLLCON1; /* first step K dividers */ unsigned int valCCUCON0; unsigned int valCCUCON1; unsigned int valCCUCON2; unsigned int finalK; /* final K2DIV value */ } PllInitValue_t; static const PllInitValue_t g_PllInitValue_200_100; #define PLL_VALUE_200_100 ((const PllInitValue_t *)(&g_PllInitValue_200_100)) static const PllInitValue_t g_PllInitValue_100_50; #define PLL_VALUE_100_50 ((const PllInitValue_t *)(&g_PllInitValue_100_50)) static const PllInitValue_t g_PllInitValue_7_37; #define PLL_VALUE_20_10 ((const PllInitValue_t *)(&g_PllInitValue_20_10)) #define DEFAULT_PLL_VALUE PLL_VALUE_20_10 #ifndef DEFAULT_PLL_VALUE # define DEFAULT_PLL_VALUE PLL_VALUE_200_100 #endif #ifndef EXTCLK # define EXTCLK (20000000) /* external oscillator clock (20MHz) */ #endif #pragma section ".rodata" /* PLL settings for 20MHz ext. clock */ static const PllInitValue_t g_PllInitValue_20_10 = { 0x0007001C, 0x01017600, 0x00022020, 0x12120118, 0x10012242, 0x00000002, 29 }; /* 200/100 MHz @ 20MHz ext. clock */ static const PllInitValue_t g_PllInitValue_200_100 = { /* OSCCON, PLLCON0, PLLCON1, CCUCON0, CCUCON1, CCUCON2, finalK */ 0x0007001C, 0x01017600, 0x00020505, 0x12120118, 0x10012242, 0x00000002, 2 }; /* 100/50 MHz @ 20MHz ext. clock */ static const PllInitValue_t g_PllInitValue_100_50 = { /* OSCCON, PLLCON0, PLLCON1, CCUCON0, CCUCON1, CCUCON2, finalK */ 0x0007001C, 0x01018a00, 0x00020606, 0x12120118, 0x10012241, 0x00000002, 6 }; #pragma section static Ifx_SCU * const pSCU = (Ifx_SCU *)&MODULE_SCU; #if (USE_DISABLE_EXT_WDT == 1) /* for serving A-step and B-step (+ newer) TLF devices: use both commands for err pin monitor */ #define WDT_CMD_SIZE (10 + 1) static void disable_external_watchdog(void) { int i; /* command sequence for disabling external watchdog */ const unsigned short wdtdiscmd[WDT_CMD_SIZE] = { 0x8756, 0x87de, 0x86ad, 0x8625, /* unprotect register (PROTCFG) */ 0x8d27, /* disable window watchdog */ 0x8811, /* disable err pin monitor (A-step) */ 0x8A01, /* disable err pin monitor (not A-step) */ 0x87be, 0x8668, 0x877d, 0x8795 /* protect register (PROTCFG) */ }; /* check that this disabling has not been already done (e.g. by the debugger) */ if (QSPI2_GLOBALCON.B.EN) { /* don't do it again */ return; } /* initialise QSPI2 interface */ unlock_wdtcon(); /* remove ENDINIT protection */ QSPI2_CLC.U = 0x8; /* activate module, disable sleep mode */ (void)QSPI2_CLC.U; /* read back to get effective */ P15_PDR0.U = 0x00000000; /* fast speed (all pins) */ P14_PDR0.U = 0x00000000; /* fast speed (all pins) */ QSPI2_PISEL.U = 1; /* MRIS=1 ==> use MRST2B pin */ lock_wdtcon(); /* re-enable ENDINIT protection */ /* configure port pins */ P14_IOCR0.B.PC2 = 0x13; /* SLSO21 */ P15_IOCR0.B.PC3 = 0x13; /* SCLK2 */ #if (APPKIT_TC2X7 == 1) P15_IOCR4.B.PC6 = 0x13; /* MTSR2 */ #else P15_IOCR4.B.PC5 = 0x13; /* MTSR2 */ #endif /* APPKIT_TC2X7 */ P15_IOCR4.B.PC7 = 0x02; /* MRST2B */ /* program QSPI2 parameters */ QSPI2_GLOBALCON.U = 0x00003C04; /* EXPECT=15,SI=0, TQ=4 */ QSPI2_GLOBALCON1.U = 0x14000000;/* RXFM=1,TXFM=1 (Single Move Mode for RX/TX) */ QSPI2_SSOC.U = 0x00020000; /* enable SLSO21, low active */ QSPI2_ECON1.U = 0x501; /* Q=1,A=0,B=1,C=1 */ do { QSPI2_FLAGSCLEAR.U = 0xFFF; /* PT2F,PT1F,RXF,TXF,ERRORFLAGS */ } while (QSPI2_STATUS.U & 0xFFF); /* prepare data transfer format */ QSPI2_BACONENTRY.U = 0x17A10001; /* CS=1,DL=15,MSB=1,TRAIL=1,LAST=1 */ QSPI2_GLOBALCON.B.EN = 1; /* ... and enable the module */ /* transfer all data */ for (i = 0; i < WDT_CMD_SIZE; ++i) { QSPI2_DATAENTRY0.U = (unsigned int)wdtdiscmd[i]; /* wait until transfer is complete */ while (!QSPI2_STATUS.B.TXF) ; /* clear TX flag */ QSPI2_FLAGSCLEAR.U = 1 << 9; /* wait for receive is finished */ while (!QSPI2_STATUS.B.RXF) ; /* clear RX flag */ QSPI2_FLAGSCLEAR.U = 1 << 10; /* read and discard value */ (void)QSPI2_RXEXIT.U; } } #endif /* USE_DISABLE_EXT_WDT */ #ifndef SYSTEM_DONT_SET_PLL /* STM time scaling (for avoiding overflow) */ #define TIME_SCALE_DN 100 #define TIME_SCALE_UP (1000000 / TIME_SCALE_DN) /* wait for