- /****************************************************************************
- * [url=home.php?mod=space&uid=288409]@file[/url] main.c
- * [url=home.php?mod=space&uid=895143]@version[/url] V1.0
- * $Date: 16/09/02 10:04a $
- * @brief
- * Display how to insert OTP signature and Version number into SPI Flash.
- *
- * @note
- * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
- *
- ******************************************************************************/
- #include <stdio.h>
- #include <string.h>
- #include "NUC505Series.h"
- /* If you want to encrypt binary firmware, you can enable
- the session code and assign signature and offset here */
- #define OTP_SIG1 (0x20040929)
- #define OTP_OFFSET (0x130)
- #define Version (0xabcd0001)
- #define V_OFFSET (0x100)
- //#define IAR
- #ifdef IAR
- /* IAR */
- static const uint32_t gu32OtpAddr[1] [url=home.php?mod=space&uid=72445]@[/url] OTP_OFFSET = {OTP_SIG1};
- static const uint32_t gu32VAddr[1] @ V_OFFSET = {Version};
- #else
- /* Keil */
- __attribute__((at(OTP_OFFSET))) static const unsigned int gu32OtpAddr[1] = {OTP_SIG1};
- __attribute__((at(V_OFFSET))) static const unsigned int gu32VAddr[1] = {Version};
- #endif
- /*---------------------------------------------------------------------------------------------------------*/
- /* Global variables */
- /*---------------------------------------------------------------------------------------------------------*/
- uint32_t g_au32BufS[1],g_au32BufV[1];;
- void SYS_Init(void)
- {
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init System Clock */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Enable XTAL */
- CLK->PWRCTL |= CLK_PWRCTL_HXTEN_Msk;
- CLK_SetCoreClock(96000000);
-
- /* Set PCLK divider */
- CLK_SetModuleClock(PCLK_MODULE, NULL, 1);
- /* Update System Core Clock */
- SystemCoreClockUpdate();
- /* Enable IP clock */
- CLK_EnableModuleClock(UART0_MODULE);
- /* Select IP clock source */
- CLK_SetModuleClock(UART0_MODULE, CLK_UART0_SRC_EXT, 0);
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init I/O Multi-function */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Configure multi-function pins for UART0 RXD and TXD */
- SYS->GPB_MFPL = (SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB0MFP_Msk) ) | SYS_GPB_MFPL_PB0MFP_UART0_TXD;
- SYS->GPB_MFPL = (SYS->GPB_MFPL & (~SYS_GPB_MFPL_PB1MFP_Msk) ) | SYS_GPB_MFPL_PB1MFP_UART0_RXD;
- }
- void UART0_Init()
- {
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init UART */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Reset UART module */
- SYS_ResetModule(UART0_RST);
- /* Configure UART0 and set UART0 baud rate */
- UART_Open(UART0, 115200);
- }
- /*---------------------------------------------------------------------------------------------------------*/
- /* MAIN function */
- /*---------------------------------------------------------------------------------------------------------*/
- int32_t main(void)
- {
-
- SYS_Init();
- UART0_Init();
- printf("+-------------------------------------+ \n");
- printf("| NUC505 Cipher Signature Sample Code | \n");
- printf("+-------------------------------------+ \n");
- /* Set OTP */
- #ifdef IAR
- if (0)
- {
- uint32_t s;
- s = gu32OtpAddr[0]+1;
- }
- if (0)
- {
- uint32_t s;
- s = gu32VAddr[0]+1;
- }
- #endif
-
- printf("The signature is 0x20040929\n");
- printf("The Version is 0xabcd0001\n");
-
- memset((char *)g_au32BufS, 0, 32);
- memset((char *)g_au32BufV, 0, 32);
-
- /* Load signature from SPI Flash 0x130 */
- memcpy(g_au32BufS,(void *)304 , sizeof(uint32_t)*1);
- /* Load Version from SPI Flash 0x100 */
- memcpy(g_au32BufV,(void *)256 , sizeof(uint32_t)*1);
-
- if((g_au32BufS[0]==OTP_SIG1)&&(g_au32BufV[0]==Version)){
- printf("Verify the Data is correct\n");
- printf("Demo complete\n");
- }
- else{
- printf("Data validation error\n");
- }
- while(1);
- }
- /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
|