[活动] 【APM32F107VC MINIBOARD开发板测评】1.开篇基础工程

[复制链接]
 楼主| xld0932 发表于 2023-2-17 22:20 | 显示全部楼层 |阅读模式
首先感谢21ic、感谢极海,有幸参与APM32F107VC MINIBOARD开发板测评活动; 19.jpg



极海半导体作为国内MCU的佼佼者,产品涵盖了Cortex M0+\M3\M4、RISC-V、蓝牙低功耗等,应用领域广泛,更是致力于开发工业级/车规级微控制器,并在不断的开拓创新;通过参与这次测评活动来熟悉极海MCU的开发过程,在基于APM32F107VCT6 MINI开发板的基础上搭建开发环境、完成基于MINI开发板的示例工程、结合项目中常用的外设ADC和DAC进行测试、对保证程序可靠运行的IWDT和WWDT进行熟悉和测试、对MCU内部自带的FLASH读、写、保护等功能进行熟悉和测试、最后完成MCU在实际项目中的IAP功能进行实现和测试。

18.jpg


我们先准备一些资料:
1、APM32F107 MINI开发板使用说明书: APM32F107 MINI开发板使用说明书V1.1.pdf (2.21 MB, 下载次数: 12)
2、KEIL的PACK安装包: Geehy.APM32F1xx_DFP.1.1.0.pack.zip (4.28 MB, 下载次数: 13)
3、SDK底层驱动库程序及示例程序:APM32F10x_SDK_V1.8(官网下载)
4、硬件设计原理图: APM32F107VC MINIBOARD V1.0.SchDoc.pdf (33.61 KB, 下载次数: 6)
上面这些资料也可以登录到极海官网进行下载……


接下来我们使用KEIL的MDK集成开发环境结合官方提供的SDK库来创建一个示例工程:
步骤1、创建工程
1.png 2.png 3.png 4.png 5.png

步骤2、添加程序到工程
6.png 7.png

步骤3、配置工程选项
8.png 9.png 10.png 11.png 12.png 13.png 14.png 15.png 16.png


接下来我们需要参考原理图对LED、KEY和USART进行初始化配置,通过USART和重载fputc函数来实现printf打印的功能;另外再移植两个开源的组件:一个是MultiButton,它是用来实现按键功能处理的;另外一个是MultiTimer,在我们不使用RTOS的情况下,就通过这个组件结合SysTick滴答定时器实现时间片的任务管理和调试……代码如下所示:
LED实现代码:
  1. MultiTimer LED_MultiTimer;

  2. /*!
  3.   * [url=home.php?mod=space&uid=247401]@brief[/url]       LED MultiTimer callback
  4.   *
  5.   * @param       None
  6.   *
  7.   * @retval      None
  8.   *
  9.   */
  10. void LED_MultiTimerCallback(MultiTimer *timer, void *userData)
  11. {
  12.     if (BIT_SET != GPIO_ReadOutputBit(GPIOE, GPIO_PIN_5))
  13.     {
  14.         GPIO_WriteBitValue(GPIOE, GPIO_PIN_5, BIT_SET);
  15.     }
  16.     else
  17.     {
  18.         GPIO_WriteBitValue(GPIOE, GPIO_PIN_5, BIT_RESET);
  19.     }

  20.     if (BIT_SET != GPIO_ReadOutputBit(GPIOE, GPIO_PIN_6))
  21.     {
  22.         GPIO_WriteBitValue(GPIOE, GPIO_PIN_6, BIT_SET);
  23.     }
  24.     else
  25.     {
  26.         GPIO_WriteBitValue(GPIOE, GPIO_PIN_6, BIT_RESET);
  27.     }

  28.     MultiTimerStart(&LED_MultiTimer, 250, LED_MultiTimerCallback, "LED");
  29. }

  30. /*!
  31.   * @brief       LED Init
  32.   *
  33.   * @param       None
  34.   *
  35.   * @retval      None
  36.   *
  37.   */
  38. void LED_Init(void)
  39. {
  40.     GPIO_Config_T  GPIO_ConfigStruct;

  41.     RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOE);

  42.     GPIO_ConfigStructInit(&GPIO_ConfigStruct);
  43.     GPIO_ConfigStruct.pin   = GPIO_PIN_5 | GPIO_PIN_6;
  44.     GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
  45.     GPIO_ConfigStruct.mode  = GPIO_MODE_OUT_PP;
  46.     GPIO_Config(GPIOE, &GPIO_ConfigStruct);

  47.     MultiTimerStart(&LED_MultiTimer, 250, LED_MultiTimerCallback, "LED");
  48. }


KEY实现代码:
  1. MultiTimer KEY_MultiTimer;
  2. struct Button btnKEY1, btnKEY2;

  3. /*!
  4.   * @brief       Read key input level
  5.   *
  6.   * @param       btn
  7.   *
  8.   * @retval      level
  9.   *
  10.   */
  11. uint8_t read_pin_level(uint8_t pin_id)
  12. {
  13.     switch (pin_id)
  14.     {
  15.         case 0:
  16.             return (GPIO_ReadInputBit(GPIOA, GPIO_PIN_0));

  17.         case 1:
  18.             return (GPIO_ReadInputBit(GPIOA, GPIO_PIN_1));

  19.         default:
  20.             return (BIT_SET);
  21.     }
  22. }

  23. /*!
  24.   * @brief       Key handler
  25.   *
  26.   * @param       btn
  27.   *
  28.   * @retval      None
  29.   *
  30.   */
  31. void KEY_Handler(void *btn)
  32. {
  33.     Button *key = btn;
  34.     uint8_t button_id = key->button_id + 1;

  35.     switch (key->event)
  36.     {
  37.         case PRESS_DOWN:
  38.             printf("\r\nKEY%d : PRESS_DOWN", button_id);
  39.             break;

  40.         case PRESS_UP:
  41.             printf("\r\nKEY%d : PRESS_UP", button_id);
  42.             break;

  43.         case SINGLE_CLICK:
  44.             printf("\r\nKEY%d : SINGLE_CLICK", button_id);
  45.             break;

  46.         case DOUBLE_CLICK:
  47.             printf("\r\nKEY%d : DOUBLE_CLICK", button_id);
  48.             break;

  49.         case LONG_PRESS_START:
  50.             printf("\r\nKEY%d : LONG_PRESS_START", button_id);
  51.             break;

  52.         case LONG_PRESS_HOLD:
  53.             printf("\r\nKEY%d : LONG_PRESS_HOLD", button_id);
  54.             break;

  55.         default:
  56.             break;
  57.     }
  58. }

  59. /*!
  60.   * @brief       KEY MultiTimer callback
  61.   *
  62.   * @param       None
  63.   *
  64.   * @retval      None
  65.   *
  66.   */
  67. void KEY_MultiTimerCallback(MultiTimer *timer, void *userData)
  68. {
  69.     button_ticks();

  70.     MultiTimerStart(&KEY_MultiTimer, 5, KEY_MultiTimerCallback, "KEY");
  71. }

  72. /*!
  73.   * @brief       KEY Init
  74.   *
  75.   * @param       None
  76.   *
  77.   * @retval      None
  78.   *
  79.   */
  80. void KEY_Init(void)
  81. {
  82.     GPIO_Config_T  GPIO_ConfigStruct;

  83.     RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOA);

  84.     GPIO_ConfigStructInit(&GPIO_ConfigStruct);
  85.     GPIO_ConfigStruct.pin  = GPIO_PIN_0 | GPIO_PIN_1;
  86.     GPIO_ConfigStruct.mode = GPIO_MODE_IN_PU;
  87.     GPIO_Config(GPIOA, &GPIO_ConfigStruct);

  88.     button_init(&btnKEY1, read_pin_level, BIT_RESET, 0);
  89.     button_attach(&btnKEY1, SINGLE_CLICK, KEY_Handler);
  90.     button_start(&btnKEY1);

  91.     button_init(&btnKEY2, read_pin_level, BIT_RESET, 1);
  92.     button_attach(&btnKEY2, SINGLE_CLICK, KEY_Handler);
  93.     button_start(&btnKEY2);

  94.     MultiTimerStart(&KEY_MultiTimer, 5, KEY_MultiTimerCallback, "KEY");
  95. }


printf实现代码:
  1. /*!
  2.   * @brief       USART1 Init with baudrate
  3.   *
  4.   * @param       None
  5.   *
  6.   * @retval      None
  7.   *
  8.   */
  9. void USART_Init(uint32_t Baudrate)
  10. {
  11.     GPIO_Config_T  GPIO_ConfigStruct;
  12.     USART_Config_T USART_ConfigStruct;

  13.     RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_USART1);

  14.     USART_ConfigStructInit(&USART_ConfigStruct);
  15.     USART_ConfigStruct.baudRate     = 115200;
  16.     USART_ConfigStruct.wordLength   = USART_WORD_LEN_8B;
  17.     USART_ConfigStruct.stopBits     = USART_STOP_BIT_1;
  18.     USART_ConfigStruct.parity       = USART_PARITY_NONE;
  19.     USART_ConfigStruct.mode         = USART_MODE_TX;
  20.     USART_ConfigStruct.hardwareFlow = USART_HARDWARE_FLOW_NONE;
  21.     USART_Config(USART1, &USART_ConfigStruct);

  22.     RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOA);

  23.     GPIO_ConfigStructInit(&GPIO_ConfigStruct);
  24.     GPIO_ConfigStruct.pin   = GPIO_PIN_9;
  25.     GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
  26.     GPIO_ConfigStruct.mode  = GPIO_MODE_AF_PP;
  27.     GPIO_Config(GPIOA, &GPIO_ConfigStruct);

  28.     USART_Enable(USART1);
  29. }

  30. /*!
  31.   * @brief       redefine fputc function
  32.   *
  33.   * @param       ch, *f
  34.   *
  35.   * @retval      ch
  36.   *
  37.   */
  38. int fputc(int ch, FILE *f)
  39. {
  40.     USART_TxData(USART1, (uint8_t)ch);

  41.     while (RESET == USART_ReadStatusFlag(USART1, USART_FLAG_TXBE))
  42.     {
  43.     }

  44.     return (ch);
  45. }


主程序及中断程序:
  1. volatile uint32_t SysTick_Tick = 0;

  2. /*!
  3.   * @brief       Get SysTick tick
  4.   *
  5.   * @param       None
  6.   *
  7.   * @retval      SysTick_Tick
  8.   *
  9.   */
  10. uint64_t SysTick_GetTick(void)
  11. {
  12.     return (SysTick_Tick);
  13. }

  14. /*!
  15.   * @brief       Main program
  16.   *
  17.   * @param       None
  18.   *
  19.   * @retval      None
  20.   *
  21.   */
  22. int main(void)
  23. {
  24.     MultiTimerInstall(SysTick_GetTick);

  25.     SysTick_Config(SystemCoreClock / 1000);

  26.     USART_Init(115200);

  27.     printf("\r\nAPM32F107VC MINIBOARD V1.0 %s %s\r\n", __DATE__, __TIME__);

  28.     KEY_Init();

  29.     LED_Init();

  30.     while (1)
  31.     {
  32.         MultiTimerYield();
  33.     }
  34. }

  35. /*!
  36.   * @brief   This function handles SysTick Handler
  37.   *
  38.   * @param   None
  39.   *
  40.   * @retval  None
  41.   *
  42.   */
  43. void SysTick_Handler(void)
  44. {
  45.     SysTick_Tick++;
  46. }



最后我们将编译无误的程序下载到开发板运行,LED灯间隔在闪烁,当我们按下相应的按键后会有消息打印出来……
17.png


软件工程源代码:
Project_20230217.zip (478.65 KB, 下载次数: 7)
jimmhu 发表于 2023-3-4 20:49 | 显示全部楼层
这个兼容st的芯片吗?              
bestwell 发表于 2023-3-5 10:22 | 显示全部楼层
APM32F107VC 资料在哪里下载
uptown 发表于 2023-3-10 11:44 | 显示全部楼层
这个兼容st的芯片吗?              
youtome 发表于 2023-3-10 14:54 | 显示全部楼层
基础工程文件,入门的好资料。              
hilahope 发表于 2023-3-10 16:46 | 显示全部楼层
APM32F107VC 的性能真是强悍。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:King.Xu

77

主题

3023

帖子

38

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