[活动专区] 【N32G430开发板试用】串口Printf系统时钟测试

[复制链接]
 楼主| abner_ma 发表于 2022-7-18 17:47 | 显示全部楼层 |阅读模式
      国民MCU最具有性价比的N32G430开发板:开发板自带下载器,所有GPIO引出,可以做芯片所有功能测评。     本次测评主要是基础时钟分析,串口配置,printf打印函数使用,


QQ截图20220718173045.png


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



1.png

时钟树:

4.png

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



  3. USART_InitType USART_InitStructure;


  4. void delay_us(uint32_t delay_us)
  5. {   
  6.   volatile unsigned int num;
  7.   volatile unsigned int t;

  8.   
  9.   for (num = 0; num < delay_us; num++)
  10.   {
  11.     t = 11;
  12.     while (t != 0)
  13.     {
  14.       t--;
  15.     }
  16.   }
  17. }

  18. void delay_ms(uint16_t delay_ms)
  19. {   
  20.   volatile unsigned int num;
  21.   for (num = 0; num < delay_ms; num++)
  22.   {
  23.     delay_us(1000);
  24.   }
  25. }

  26. int main(void)
  27. {
  28.     RCC_ClocksType RCC_ClocksStatus;
  29.    
  30.     /* System Clocks Configuration */
  31.     RCC_Configuration();

  32.     /* Configure the GPIO ports */
  33.     GPIO_Configuration();

  34.     RCC_Clocks_Frequencies_Value_Get(&RCC_ClocksStatus);

  35.     /* USARTy and USARTz configuration ------------------------------------------------------*/
  36.     USART_InitStructure.BaudRate            = 115200;
  37.     USART_InitStructure.WordLength          = USART_WL_8B;
  38.     USART_InitStructure.StopBits            = USART_STPB_1;
  39.     USART_InitStructure.Parity              = USART_PE_NO;
  40.     USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
  41.     USART_InitStructure.Mode                = USART_MODE_RX | USART_MODE_TX;

  42.     /* Configure USARTx */
  43.     USART_Initializes(USARTx, &USART_InitStructure);
  44.     /* Enable the USARTx */
  45.     USART_Enable(USARTx);

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

  48.     while (1)
  49.     {

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

  56.                               printf("\r\n");         printf("\r\n");         printf("\r\n");
  57.                        
  58.                         delay_ms(5000);
  59.                        
  60.     }
  61. }

  62. /**
  63. *\*\name    RCC_Configuration.
  64. *\*\fun     Configures the different system clocks.
  65. *\*\param   none
  66. *\*\return  none
  67. **/
  68. void RCC_Configuration(void)
  69. {
  70.     /* Enable GPIO clock */
  71.     GPIO_AHBClkCmd(USARTx_GPIO_CLK);
  72.     /* Enable USARTx Clock */
  73.     USART_APBxClkCmd(USARTx_CLK);
  74. }

  75. /**
  76. *\*\name    GPIO_Configuration.
  77. *\*\fun     Configures the different GPIO ports.
  78. *\*\param   none
  79. *\*\return  none
  80. **/
  81. void GPIO_Configuration(void)
  82. {
  83.     GPIO_InitType GPIO_InitStructure;

  84.     /* Initialize GPIO_InitStructure */
  85.     GPIO_Structure_Initialize(&GPIO_InitStructure);   

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

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


  96. /**
  97. *\*\name    fputc.
  98. *\*\fun     retarget the C library printf function to the USART
  99. *\*\param   ch
  100. *\*\param   f
  101. *\*\return  none
  102. **/
  103. int fputc(int ch, FILE* f)
  104. {
  105.     USART_Data_Send(USARTx, (uint8_t)ch);
  106.     while (USART_Flag_Status_Get(USARTx, USART_FLAG_TXDE) == RESET)
  107.         ;

  108.     return (ch);
  109. }

  110. #ifdef USE_FULL_ASSERT

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

  123.     /* Infinite loop */
  124.     while (1)
  125.     {
  126.     }
  127. }

  128. #endif
   
  结构体:
  1. typedef struct
  2. {
  3.     uint32_t SysclkFreq;    /* returns SYSCLK clock frequency expressed in Hz */
  4.     uint32_t HclkFreq;      /* returns HCLK clock frequency expressed in Hz */
  5.     uint32_t Pclk1Freq;     /* returns PCLK1 clock frequency expressed in Hz */
  6.     uint32_t Pclk2Freq;     /* returns PCLK2 clock frequency expressed in Hz */
  7.     uint32_t AdcPllClkFreq; /* returns ADCPLLCLK clock frequency expressed in Hz */
  8.     uint32_t AdcHclkFreq;   /* returns ADCHCLK clock frequency expressed in Hz */
  9. } RCC_ClocksType;


keil下寄存器查看

2.png

打印测试:

3.png



您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

95

主题

181

帖子

3

粉丝
快速回复 返回顶部 返回列表