所以对HCLK时钟源要求不高可以直接使用 这一个函数就搞定
#include <stdio.h>
#include "M058S.h"
#define PLLCON_SETTING CLK_PLLCON_50MHz_HXT
#define PLL_CLOCK 50000000
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
CLK_SetCoreClock(FREQ_50MHZ);
CLK_EnableModuleClock(UART0_MODULE);
CLK_SetModuleClock(UART0_MODULE,CLK_CLKSEL1_UART_S_PLL,CLK_CLKDIV_UART(1));
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set P3 multi-function pins for UART0 RXD , TXD and CKO */
SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
SYS->P3_MFP |= (SYS_MFP_P30_RXD | SYS_MFP_P31_TXD);
}
void UART0_Init()
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART */
/*---------------------------------------------------------------------------------------------------------*/
/* Reset UART0 */
SYS->IPRSTC2 |= SYS_IPRSTC2_UART0_RST_Msk;
SYS->IPRSTC2 &= ~SYS_IPRSTC2_UART0_RST_Msk;
/* Configure UART0 and set UART0 Baudrate */
UART0->BAUD = UART_BAUD_MODE2 | UART_BAUD_MODE2_DIVIDER(__HXT, 115200);
UART0->LCR = UART_WORD_LEN_8 | UART_PARITY_NONE | UART_STOP_BIT_1;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Main Function */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
/* Init UART0 for printf */
UART0_Init();
printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);
/*
This sample code will blinking LED on NuTiny EVB board of M058SSAN.
The I/O for LED is P2.3 or P3.6
*/
printf("+---------------------------------------+\n");
printf("| NuTiny EVB LED Sample Code |\n");
printf("+---------------------------------------+\n");
/* Init P3.6 to be output mode */
GPIO_SetMode(P3,BIT6,GPIO_PMD_OUTPUT);
while(1)
{
/* Toggle P3.6 */
P36 ^= 1;
/* Delay 200ms */
CLK_SysTickDelay(200000);
}
}
|