Exemple #1
0
int main(void)
{
    char strClearLine[15] = "ID:            ";
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();     

    /* Init UART0 for printf */
    UART0_Init();   

    printf("CPU @ %dHz\n", SystemCoreClock);

    /* Init SPI0 and LCD */
    LCD_Init();
    LCD_EnableBackLight();
    LCD_ClearScreen();


    LCD_Print(0, "SPI Sample Code ");
    LCD_Print(1, "For Flash Test");
    LCD_Print(2, "Press INT button");

    /* Init P3.2 */
    GPIO_Init();

    SPIFLASH_Init();
    sprintf(g_strBuf, "ID:%x         ", SPIFLASH_ReadId()&0xFFFFUL);
    LCD_Print(3, strClearLine);
    LCD_Print(3, g_strBuf);

    while (!g_isPress);

    SpiTest();

    return 1;
}
Exemple #2
0
/**
  * @brief  Main routine. 
  * @param  None.
  * @return None.
  */
int32_t main(void)                 
{
    SYS_UnlockReg();
    SYS->P5_MFP = (SYS->P5_MFP & 0x00FFFCFC) | 0x03;  /* P5.1 -> XTAL2, P5.0 -> XTAL1 */
    CLK->PWRCON = CLK_PWRCON_XTL12M | 4 | 8 ;

    SYS_Init();
  
    /* SPI test */   
    LCD_Init();   
    LCD_EnableBackLight();
    LCD_ClearScreen();
    LCD_Print(0, "Welcome! Nuvoton");
    LCD_Print(1, "This is LB board");
    LCD_Print(2, "Mini51");
    LCD_Print(3, "TEST"); 
  
    // backlight control pin P5.4
    GPIO_SetMode(P5,1<<4,GPIO_PMD_OUTPUT);
  
    /* INT button triggers P3.2 */
    GPIO_SetMode(P3,(1<<2),GPIO_PMD_OPEN_DRAIN);  
    GPIO_EnableInt(P3, 2, GPIO_INT_FALLING);
    NVIC_EnableIRQ(EINT0_IRQn);
  
    /* Enable interrupt de-bounce function and select de-bounce sampling cycle time */
    GPIO_SET_DEBOUNCE_TIME(GPIO_DBNCECON_DBCLKSRC_HCLK,GPIO_DBNCECON_DBCLKSEL_16);  
    GPIO_ENABLE_DEBOUNCE(P3,1<<2);  

    /* Reset and stop TIMER0, TIMER1 counting first */
    TIMER1->TCSR = TIMER_TCSR_CRST_Msk;
  
    /* Enable TIMER0, TIMER1, NVIC */
    NVIC_EnableIRQ(TMR1_IRQn);
    
    /* To Configure TCMPR values based on Timer clock source and pre-scale value */
    TIMER_SET_PRESCALE_VALUE(TIMER1,0);
  
    
    /* Start TIMER1 counting and setting*/
    TIMER_Open(TIMER1,TIMER_PERIODIC_MODE,SystemCoreClock/1000); 
    
    TIMER_EnableInt(TIMER1);

    while(1) ;    // loop forever
    
}
Exemple #3
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{

    /* Init system, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART0 for printf */
    UART0_Init();

    /* Init GPIO P2.0 (output) and P3.2 (EINT0) */
    GPIO_Init();

    /* Init SPI0 and LCD */
    LCD_Init();
    LCD_EnableBackLight();
    LCD_ClearScreen();

    LCD_Print(0, "Boot from LDROM");
    LCD_Print(1, "Press SW_INT   ");

    while (1)
    {
        if (g_u8IsPress)
        {
            g_u8IsPress = FALSE;
            
            /* Switch to boot from APROM */
            SYS_UnlockReg();
            FMC->ISPCON = FMC_ISPCON_BS_APROM;
            _SYS_RESET_CPU();
            while (1);
        }
        else
        {
            /* LED blanking for 1000ms */
            P2->DOUT ^= 1;
            SYS_SysTickDelay(300000);
            SYS_SysTickDelay(200000);
        }
    }
}
Exemple #4
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
    int32_t  i32Err = 0;
    uint32_t u32Data, u32ImageSize, i, j, *pu32Loader;

    /* Init system, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART0 for printf */
    UART0_Init();

    /* Init GPIO P2.0 (output) and P3.2 (EINT0) */
    GPIO_Init();

    /* Init SPI0 and LCD */
    LCD_Init();
    LCD_EnableBackLight();
    LCD_ClearScreen();


    /* 
        This sample shows how to switch between APROM and LDROM. 
        Target: 
            Smpl_FMC
                Smpl_FMC is the code for APROM. It will program the firmware to LDROM and
                user can press SW_INT to change to boot from LDROM. 
                In APROM, the LED blanking interval is 200ms.
            Smpl_LDROM
                Smpl_LDROM is the code for LDROM. User can press SW_INT to change to boot from APROM.
                In LDROM, the LED blanking interval is 1000ms.
    */
    LCD_Print(0, "Boot from APROM");
    LCD_Print(1, "Press SW_INT   ");
    while (1)
    {
        if(g_u8IsPress)
        {
            g_u8IsPress = FALSE;

            /* Unlock protected registers to write ISP Control Register (ISPCON) */
            SYS_UnlockReg();

            /* Program sample LD code to LDROM */

            /* Enable ISP LDROM update function */
            FMC->ISPCON = FMC_ISPCON_LDUEN_Msk | FMC_ISPCON_ISPEN_Msk;

            /* Page Erase LDROM */
            for (i = 0;i < 4096;i += PAGE_SIZE)
                FMC_Erase(LDROM_BASE + i);


            /* Erase Verify */
            i32Err = 0;
            for (i = LDROM_BASE; i < (LDROM_BASE + 4096); i += 4)
            {
                u32Data = FMC_Read(i);

                if (u32Data != 0xFFFFFFFF)
                {
                    i32Err = 1;
                }
            }


            u32ImageSize = (uint32_t)&g_u32LoaderImageLimit - (uint32_t)&g_u32LoaderImageBase;

            pu32Loader = (uint32_t *)&g_u32LoaderImageBase;
            for (i = 0;i < u32ImageSize;i += PAGE_SIZE)
            {
                FMC_Erase(LDROM_BASE + i);
                for (j = 0;j < PAGE_SIZE;j += 4)
                {
                    FMC_Write(LDROM_BASE + i + j, pu32Loader[(i + j) / 4]);
                }
            }

            /* Verify loader */
            i32Err = 0;
            for (i = 0;i < u32ImageSize;i += PAGE_SIZE)
            {
                for (j = 0;j < PAGE_SIZE;j += 4)
                {
                    u32Data = FMC_Read(LDROM_BASE + i + j);
                    if (u32Data != pu32Loader[(i+j)/4])
                        i32Err = 1;

                    if (i + j >= u32ImageSize)
                        break;
                }


            }

            if(i32Err)
            {
                LCD_ClearScreen();
                LCD_Print(0,"LDROM write fail");
            }
            else
            {
                /* Switch to boot from LDROM */
                FMC->ISPCON = FMC_ISPCON_BS_LDROM;
                _SYS_RESET_CPU();
            }

            while (1);
        }
        else
        {
            /* LED blanking for 200ms */
            P2->DOUT ^= 1;
            SYS_SysTickDelay(100000);
        }

        

    }
}
Exemple #5
0
int main(void)
{
    uint32_t u32Cnt;

    /* Init system, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART for printf */
    UART_Init();

    /* Init SPI and LCD */
    LCD_Init();
    LCD_EnableBackLight();
    LCD_ClearScreen();
    
    printf("CPU @ %d Hz\n", SystemCoreClock);

    LCD_Print(0, "Smpl_DeepSleep");

    /*Initialize external interrupt*/
    GPIO_Init();

    /* 
        P3.2 is used as EINT0 for deep sleep (power down) control.
        Press P3.2 will toggle power down/wakeup state to show how to enter power down.
    */
    LCD_Print(1, "Press INT ");

    while (1)
    {
        char strClearVal[15] = "Count:         ";
        /* Enter power when key change from low to high */
        u32Cnt = 0;
        while (gi8Key == 1)
        {
            sprintf(g_strBuf, "Count:%d", u32Cnt++);
            LCD_Print(3, strClearVal);
            LCD_Print(3, g_strBuf);
        }
        while(gi8Key == 0)
        {
            sprintf(g_strBuf, "Count:%d", u32Cnt++);
            LCD_Print(3, strClearVal);
            LCD_Print(3, g_strBuf);
        }

        LCD_Print(2, "Deep Sleeping...");
        
        /* Unlock protected registers */
        SYS_UnlockReg();

        /* Lock protected registers */
        SYS_LockReg();

        /* We need to disable debounce function before power down, otherwise, there would be twice interrupt when
           wakeup */
        P3->DBEN = 0;

        /* enter power down */;
        CLK_PowerDown();

        /* Re-enable debounce function if necessary */
        P3->DBEN = (1 << 2);

        LCD_Print(2, "Working...      ");
        printf("\nWorking... \n");

        /* Make sure the key is return to high before next key action */
        while (gi8Key == 0);
        
        gi8Key = 0;
    }
}