123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- #include "imxrt1062_hal.h"
- #include "board.h"
- #include "fsl_dcp.h"
- #include "fsl_lpuart.h"
- #include "fsl_snvs_lp.h"
- #include "pin_mux.h"
- #include "system_MIMXRT1062.h"
- #include "clock_config.h"
- __attribute__ ((weak)) void uart_puts(char * s){
- while(*s){
- putch(*(s++));
- }
- }
- void init_uart(void)
- {
- lpuart_config_t lpuartConfig;
- LPUART_GetDefaultConfig(&lpuartConfig);
- lpuartConfig.baudRate_Bps = 38400U;
- lpuartConfig.enableTx = 1;
- lpuartConfig.enableRx = 1;
- LPUART_Init(LPUART1, &lpuartConfig, 80000000U);
- }
- void putch(char c)
- {
- while (0U == (LPUART1->STAT & LPUART_STAT_TDRE_MASK)){;}
-
- LPUART1->DATA = c;
-
-
-
- }
- char getch(void)
- {
- while (0U == (LPUART1->STAT & LPUART_STAT_RDRF_MASK)){;}
-
- return LPUART1->DATA;
- }
- void trigger_setup(void)
- {
-
- ;
- }
- void trigger_high(void)
- {
- GPIO_PinWrite(GPIO1, (14U), 1U);
- }
- void trigger_low(void)
- {
- GPIO_PinWrite(GPIO1, (14U), 0U);
- }
- #define EXAMPLE_LED_GPIO BOARD_USER_LED_GPIO
- #define EXAMPLE_LED_GPIO_PIN BOARD_USER_LED_PIN
- volatile uint32_t g_systickCounter;
- volatile bool g_pinSet = false;
- void SysTick_Handler(void)
- {
- if (g_systickCounter != 0U)
- {
- g_systickCounter--;
- }
- }
- void SysTick_DelayTicks(uint32_t n)
- {
- g_systickCounter = n;
- while (g_systickCounter != 0U)
- {
- }
- }
- static dcp_handle_t _dcp_handle;
- void HW_AES128_Init(void)
- {
- dcp_config_t config;
- DCP_GetDefaultConfig(&config);
- DCP_Init(DCP, &config);
-
- _dcp_handle.channel = kDCP_Channel0;
- _dcp_handle.keySlot = 0;
- }
- void HW_AES128_LoadKey(uint8_t * key)
- {
- DCP_AES_SetKey(DCP, &_dcp_handle, key, 16);
- }
- void HW_AES128_Enc_pretrigger(uint8_t * pt)
- {
- ;
- }
- void HW_AES128_Enc(uint8_t * pt)
- {
- DCP_AES_EncryptEcb(DCP, &_dcp_handle, pt, pt, 16);
- }
- void HW_AES128_Enc_posttrigger(uint8_t * pt)
- {
- ;
- }
- void platform_init(void)
- {
-
- BOARD_InitPins();
- BOARD_InitBootClocks();
-
-
- SystemCoreClockUpdate();
-
- init_uart();
-
-
- if(hal_glitch_detected()) {
- uart_puts("BOOT-GLITCH\n");
- }
-
-
-
- SNVS_LP_Init(SNVS);
-
- }
- int hal_glitch_detected(void)
- {
- return SNVS->LPSR & SNVS_LPSR_PGD_MASK;
- }
- void hal_glitch_detect_reset(void)
- {
- SNVS->LPSR = SNVS_LPSR_PGD_MASK;
- }
|