打印
[活动专区]

【N32G430开发板试用】串口Printf系统时钟测试

[复制链接]
1985|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
      国民MCU最具有性价比的N32G430开发板:开发板自带下载器,所有GPIO引出,可以做芯片所有功能测评。     本次测评主要是基础时钟分析,串口配置,printf打印函数使用,





芯片介绍:
― ―32 位 ARM Cortex-M4 内核+ FPU,支持 DSP 指令和 MPU
― ― 内置 1KB 指令 Cache 缓存,支持 Flash 加速单元执行程序 0 等待
― ― 最高主频 128MHz,160DMIPS





时钟树:



下面进行时钟测试:
上代码:
#include <stdio.h>
#include "main.h"



USART_InitType USART_InitStructure;


void delay_us(uint32_t delay_us)
{   
  volatile unsigned int num;
  volatile unsigned int t;

  
  for (num = 0; num < delay_us; num++)
  {
    t = 11;
    while (t != 0)
    {
      t--;
    }
  }
}

void delay_ms(uint16_t delay_ms)
{   
  volatile unsigned int num;
  for (num = 0; num < delay_ms; num++)
  {
    delay_us(1000);
  }
}

int main(void)
{
    RCC_ClocksType RCC_ClocksStatus;
   
    /* System Clocks Configuration */
    RCC_Configuration();

    /* Configure the GPIO ports */
    GPIO_Configuration();

    RCC_Clocks_Frequencies_Value_Get(&RCC_ClocksStatus);

    /* USARTy and USARTz configuration ------------------------------------------------------*/
    USART_InitStructure.BaudRate            = 115200;
    USART_InitStructure.WordLength          = USART_WL_8B;
    USART_InitStructure.StopBits            = USART_STPB_1;
    USART_InitStructure.Parity              = USART_PE_NO;
    USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
    USART_InitStructure.Mode                = USART_MODE_RX | USART_MODE_TX;

    /* Configure USARTx */
    USART_Initializes(USARTx, &USART_InitStructure);
    /* Enable the USARTx */
    USART_Enable(USARTx);

    /* Output a message on Hyperterminal using printf function */
//    printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");

    while (1)
    {

                       printf("SysclkFreq_Frequency %d \r\n",RCC_ClocksStatus.SysclkFreq);
                                   printf("HclkFreq_Frequency %d \r\n",RCC_ClocksStatus.HclkFreq);
                                   printf("Pclk1Freq_Frequency %d \r\n",RCC_ClocksStatus.Pclk1Freq);
                                   printf("Pclk2Freq_Frequency %d \r\n",RCC_ClocksStatus.Pclk2Freq);
                                   printf("AdcPllClkFreq_Frequency %d \r\n",RCC_ClocksStatus.AdcPllClkFreq);
                                   printf("AdcHclkFreq_Frequency %d \r\n",RCC_ClocksStatus.AdcHclkFreq);

                              printf("\r\n");         printf("\r\n");         printf("\r\n");
                       
                        delay_ms(5000);
                       
    }
}

/**
*\*\name    RCC_Configuration.
*\*\fun     Configures the different system clocks.
*\*\param   none
*\*\return  none
**/
void RCC_Configuration(void)
{
    /* Enable GPIO clock */
    GPIO_AHBClkCmd(USARTx_GPIO_CLK);
    /* Enable USARTx Clock */
    USART_APBxClkCmd(USARTx_CLK);
}

/**
*\*\name    GPIO_Configuration.
*\*\fun     Configures the different GPIO ports.
*\*\param   none
*\*\return  none
**/
void GPIO_Configuration(void)
{
    GPIO_InitType GPIO_InitStructure;

    /* Initialize GPIO_InitStructure */
    GPIO_Structure_Initialize(&GPIO_InitStructure);   

    /* Configure USARTx Tx as alternate function push-pull */
    GPIO_InitStructure.Pin            = USARTx_TxPin;
    GPIO_InitStructure.GPIO_Mode      = GPIO_MODE_AF_PP;
    GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF;
    GPIO_Peripheral_Initialize(USARTx_GPIO, &GPIO_InitStructure);   

    /* Configure USARTx Rx as alternate function push-pull */
    GPIO_InitStructure.Pin            = USARTx_RxPin;
    GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF;
    GPIO_Peripheral_Initialize(USARTx_GPIO, &GPIO_InitStructure);
}


/**
*\*\name    fputc.
*\*\fun     retarget the C library printf function to the USART
*\*\param   ch
*\*\param   f
*\*\return  none
**/
int fputc(int ch, FILE* f)
{
    USART_Data_Send(USARTx, (uint8_t)ch);
    while (USART_Flag_Status_Get(USARTx, USART_FLAG_TXDE) == RESET)
        ;

    return (ch);
}

#ifdef USE_FULL_ASSERT

/**
*\*\name    assert_failed.
*\*\fun     Reports the name of the source file and the source line number
*\*\        where the assert_param error has occurred.
*\*\param   file pointer to the source file name
*\*\param   line assert_param error line source number
*\*\return  none
**/
void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
{
    /* User can add his own implementation to report the file name and line number,
       ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

    /* Infinite loop */
    while (1)
    {
    }
}

#endif
   
  结构体:
typedef struct
{
    uint32_t SysclkFreq;    /* returns SYSCLK clock frequency expressed in Hz */
    uint32_t HclkFreq;      /* returns HCLK clock frequency expressed in Hz */
    uint32_t Pclk1Freq;     /* returns PCLK1 clock frequency expressed in Hz */
    uint32_t Pclk2Freq;     /* returns PCLK2 clock frequency expressed in Hz */
    uint32_t AdcPllClkFreq; /* returns ADCPLLCLK clock frequency expressed in Hz */
    uint32_t AdcHclkFreq;   /* returns ADCHCLK clock frequency expressed in Hz */
} RCC_ClocksType;


keil下寄存器查看



打印测试:





使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:项目经理
简介:资深嵌入式开发工程师

83

主题

154

帖子

3

粉丝