[APM32F4] 【APM32F411V Tiny Board测评】+点灯和串口printf打印输出测试

[复制链接]
 楼主| WoodData 发表于 2024-5-17 11:48 | 显示全部楼层 |阅读模式
  很高兴又可以参与极海MCU的评测了。收到这个APM32F411开发板有些天了,这几天了解了一下这款MCU,顺便下载了相关资料。在极海官网下载资料挺方便的。主要下载了APM32F4的SDK开发包和芯片用户手册和数据手册,开发板原理图。
APM32F411性能还是很不错的。
1.jpg
下面是开发板原理。接下来准备点个灯和串口输出测试一下。
2.jpg

在sdk中包含KEIL的pack包,安装之后就可以在keil中选择MCU型号了。

下面就是我重新创建的工程,参考SDK例子。实现了LED,按键和串口驱动。
3.jpg

  1. /** @addtogroup Examples
  2.   @{
  3.   */
  4. void APM_TINY_LEDInit(GPIO_T* port, uint32_t pin)
  5. {
  6.     GPIO_Config_T  configStruct;

  7.     /* Enable the GPIO_LED Clock */
  8.     RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOE);

  9.     /* Configure the GPIO_LED pin */
  10.     GPIO_ConfigStructInit(&configStruct);
  11.     configStruct.pin = pin;
  12.     configStruct.mode = GPIO_MODE_OUT;
  13.     configStruct.speed = GPIO_SPEED_50MHz;

  14.     GPIO_Config(port, &configStruct);
  15. }

  16. void APM_TINY_PBInit(GPIO_T* port, uint32_t pin, uint32_t Button_Mode)
  17. {
  18.     GPIO_Config_T     GPIO_configStruct;
  19.     EINT_Config_T     EINT_configStruct;

  20.     /* Enable the BUTTON Clock */
  21.     RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOA);

  22.     /* Configure Button pin as input floating */
  23.     GPIO_ConfigStructInit(&GPIO_configStruct);
  24.     GPIO_configStruct.mode = GPIO_MODE_IN;
  25.     GPIO_configStruct.pin = pin;
  26.     GPIO_configStruct.pupd  = GPIO_PUPD_UP;
  27.     GPIO_Config(port, &GPIO_configStruct);

  28.     if (Button_Mode == 1)
  29.     {
  30.         /* Enable the SYSCFG Clock */
  31.         RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_SYSCFG);
  32.         
  33.         /* Connect Button EINT Line to Button GPIO Pin */
  34.         SYSCFG_ConfigEINTLine(SYSCFG_PORT_GPIOA, SYSCFG_PIN_0);
  35.         /* Configure Button EINT line */
  36.         EINT_configStruct.line = EINT_LINE_0;
  37.         EINT_configStruct.mode = EINT_MODE_INTERRUPT;
  38.         EINT_configStruct.trigger = EINT_TRIGGER_FALLING;
  39.         EINT_configStruct.lineCmd = ENABLE;
  40.         EINT_Config(&EINT_configStruct);
  41.         /* Enable and set Button EINT Interrupt to the lowest priority */
  42.         NVIC_EnableIRQRequest(EINT0_IRQn, 0x0f, 0x0f);
  43.         
  44.         /* Connect Button EINT Line to Button GPIO Pin */
  45.         SYSCFG_ConfigEINTLine(SYSCFG_PORT_GPIOA, SYSCFG_PIN_1);
  46.         /* Configure Button EINT line */
  47.         EINT_configStruct.line = EINT_LINE_1;
  48.         EINT_configStruct.mode = EINT_MODE_INTERRUPT;
  49.         EINT_configStruct.trigger = EINT_TRIGGER_FALLING;
  50.         EINT_configStruct.lineCmd = ENABLE;
  51.         EINT_Config(&EINT_configStruct);
  52.         /* Enable and set Button EINT Interrupt to the lowest priority */
  53.         NVIC_EnableIRQRequest(EINT1_IRQn, 0x0f, 0x0f);
  54.     }
  55. }

  56. void APM_TINY_COMInit(USART_T * com, uint32_t baud)
  57. {
  58.     GPIO_Config_T GPIO_configStruct;
  59.     USART_Config_T usartConfigStruct;

  60.     GPIO_ConfigStructInit(&GPIO_configStruct);
  61.     if (USART1 == com)
  62.     {
  63.         /* Enable GPIO clock */
  64.         RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOA);
  65.         RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_USART1);
  66.         
  67.         /* Connect PXx to USARTx_Tx */
  68.         GPIO_ConfigPinAF(GPIOA, GPIO_PIN_SOURCE_9, GPIO_AF_USART1);
  69.         /* Connect PXx to USARTx_Rx */
  70.         GPIO_ConfigPinAF(GPIOA, GPIO_PIN_SOURCE_10, GPIO_AF_USART1);
  71.         /* Configure USART Tx as alternate function push-pull */
  72.         GPIO_configStruct.mode = GPIO_MODE_AF;
  73.         GPIO_configStruct.pin  = GPIO_PIN_9;
  74.         GPIO_configStruct.speed = GPIO_SPEED_50MHz;
  75.         GPIO_Config(GPIOA, &GPIO_configStruct);
  76.         /* Configure USART Rx as input floating */
  77.         GPIO_configStruct.mode = GPIO_MODE_AF;
  78.         GPIO_configStruct.pin  = GPIO_PIN_10;
  79.         GPIO_Config(GPIOA, &GPIO_configStruct);
  80.     }
  81.     else if (USART2 == com)
  82.     {
  83.         RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOA);
  84.         RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_USART2);
  85.         
  86.         /* Connect PXx to USARTx_Tx */
  87.         GPIO_ConfigPinAF(GPIOA, GPIO_PIN_SOURCE_2, GPIO_AF_USART2);
  88.         /* Connect PXx to USARTx_Rx */
  89.         GPIO_ConfigPinAF(GPIOA, GPIO_PIN_SOURCE_3, GPIO_AF_USART2);
  90.         /* Configure USART Tx as alternate function push-pull */
  91.         GPIO_configStruct.mode = GPIO_MODE_AF;
  92.         GPIO_configStruct.pin  = GPIO_PIN_2;
  93.         GPIO_configStruct.speed = GPIO_SPEED_50MHz;
  94.         GPIO_Config(GPIOA, &GPIO_configStruct);
  95.         /* Configure USART Rx as input floating */
  96.         GPIO_configStruct.mode = GPIO_MODE_AF;
  97.         GPIO_configStruct.pin  = GPIO_PIN_3;
  98.         GPIO_Config(GPIOA, &GPIO_configStruct);
  99.     }
  100.    
  101.     /* USART1 configuration */
  102.     usartConfigStruct.baudRate = baud;
  103.     usartConfigStruct.hardwareFlow = USART_HARDWARE_FLOW_NONE;
  104.     usartConfigStruct.mode = USART_MODE_TX_RX;
  105.     usartConfigStruct.parity = USART_PARITY_NONE;
  106.     usartConfigStruct.stopBits = USART_STOP_BIT_1;
  107.     usartConfigStruct.wordLength = USART_WORD_LEN_8B;
  108.    
  109.     /* USART configuration */
  110.     USART_Config(com, &usartConfigStruct);
  111.     /* Enable USART */
  112.     USART_Enable(com);
  113. }
下面是实现串口printf输出方法。根据如下方法可以快速实现串口重定向到printf.
11.png
接下来只要实现一个int stdout_putchar(int ch)函数即可。
  1. int stdout_putchar(int ch)
  2. {
  3.     /* send a byte of data to the serial port */
  4.     USART_TxData(USART1, (uint8_t)ch);
  5.     /* wait for the data to be send */
  6.     while (USART_ReadStatusFlag(USART1, USART_FLAG_TXBE) == RESET);

  7.     return (ch);
  8. }
下面是main测试代码:
  1. int main(void)
  2. {
  3.     SystemCoreClockUpdate();
  4.     SysTick_Config(SystemCoreClock / 1000); //1ms
  5.    
  6.     APM_TINY_LEDInit(LED2_GPIO_PORT,LED2_PIN);
  7.     APM_TINY_LEDInit(LED3_GPIO_PORT,LED3_PIN);
  8.    
  9.     APM_TINY_PBInit(KEY1_BUTTON_GPIO_PORT, KEY1_BUTTON_PIN,0);
  10.     APM_TINY_PBInit(KEY2_BUTTON_GPIO_PORT, KEY2_BUTTON_PIN,0);
  11.    
  12.     APM_TINY_COMInit(USART1,115200);
  13.    
  14.     printf("APM32F411 TEST.\r\n");
  15.     while (1)
  16.     {
  17.         APM_DelayMs(200);
  18.         GPIO_ToggleBit(LED2_GPIO_PORT,LED2_PIN);
  19.         APM_DelayMs(200);
  20.         GPIO_ToggleBit(LED3_GPIO_PORT,LED3_PIN);
  21.         
  22.         if(GPIO_ReadInputBit(KEY1_BUTTON_GPIO_PORT, KEY1_BUTTON_PIN) == BIT_RESET)
  23.         {
  24.             printf("APM32F411 Key1 Press.\r\n");
  25.         }
  26.         
  27.         if(GPIO_ReadInputBit(KEY2_BUTTON_GPIO_PORT, KEY2_BUTTON_PIN) == BIT_RESET)
  28.         {
  29.             printf("APM32F411 Key2 Press.\r\n");
  30.         }
  31.     }
  32. }
然后设置keil优化等级和头文件路径。
13.png

串口输出效果:
12.png

4.jpg

HXM1593 发表于 2024-5-18 16:34 | 显示全部楼层
能否提供个完整工程试试
szt1993 发表于 2024-5-23 17:16 | 显示全部楼层
楼主是用的自带的例程进行的测试嘛?
 楼主| WoodData 发表于 2024-5-23 17:35 | 显示全部楼层
szt1993 发表于 2024-5-23 17:16
楼主是用的自带的例程进行的测试嘛?

自己修改一下的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

127

主题

4778

帖子

28

粉丝
快速回复 在线客服 返回列表 返回顶部

127

主题

4778

帖子

28

粉丝
快速回复 在线客服 返回列表 返回顶部