[Wi-Fi/蓝牙/Zigbee…] 【WFI32E04分享】②依照国际惯例先来点个灯

[复制链接]
212|3
cc1989summer 发表于 2025-11-5 17:01 | 显示全部楼层 |阅读模式
GPIO, pi, IO, AC, 国际, pi, IO, AC
本帖最后由 cc1989summer 于 2025-11-6 09:55 编辑

【WFI32E04分享】①开箱及官方例程初体验 - Microchip
https://bbs.21ic.com/icview-3494056-1-1.html


书接上回。
开箱并跑了下出厂官方例程,就想着:依照国际惯例先来点个灯吧!


这里,先抛出一个疑惑。

咱们这个活动是说:WFI32E04 高引脚数(HPC)Curiosity开发板限量赠送
WFI32E04模块的主控是 PIC32MZ2051W104 :2MB Flash +640 KB RAM





但实际到手的板子,模块上丝印是:WFI32E02

WFI32E02模块的主控是 PIC32MZ1025W104 :1MB Flash + 320 KB RAM

如图





不过仅仅是存储的差异,其他都没有差别,开发流程也相似






注意WFI32E02,WFI32E04都是模组的名称
实际主控芯片是PIC32MZ1025W104,PIC32MZ2051W104


模组就是在芯片的基础上搭载了天线前端模块、晶振、以及 Trust&GO模块

Trust&GO 安全元件属于 Microchip 通用配置安全器件系列。器
件配置旨在使安全元件适用于 IoT 市场中的一些最常见用例,同时最大程度地减少与安全器件相关的学习和入门准备。






WFI32E02:



PIC32MZ1025W104芯片




PIC32MZ1025W104架构



下面就开始点灯吧!


首先是安装官方开发软件,都是最新版


IDE:MPLABX-v6.25-windows-installer

编译器:xc32-v4.60-full-install-windows-x64-installer




安装目录选择默认。







1.新建工程



选择Tool WFI32-IoT Board (这是系统自动识别的),然后Device也就自动填入:PIC32MZ1025W104132



选择编译器



输入项目名:注意下面的open MCC on finish


2. MCC配置

我们看下MCC的介绍,他是MPLAB Harmony 3的一个组件,用于提供图形化配置界面和官方库函数(Plib),熟悉STM32的可能就明白,其实类似CubeMX/CubeIDE及HAL库。



MPLAB代码配置器(MCC)是集成在MPLAB X IDE里具有友好图形用户界面的免费插件工具,该工具可用于配置单片机。 在这节课,您将学习MCC的主要功能,了解如何使用MCC工具配置外设,包括独立于内核的外设。 MCC 将根据您的要求生成优化的驱动程序代码,该代码会自动集成到新的或现有的嵌入式项目中,学习如何利用 MCC 快速开发嵌入式应用程序,并在最短的时间内完成您的项目!






Microchip会自动下载对应的DFP(器件包)
[color=rgba(0, 0, 0, 0.8)]**Microchip的器件系列包(DFP)**是用于支持Microchip设备的开发工具,主要用于在MPLAB X IDE中管理和更新所使用的器件。DFP提供了与特定器件相关的驱动程序、库和示例代码,使开发者能够更轻松地进行开发和调试。


MCC启动速度比较慢……

另外,我们在左下角 项目环境,可以看到本项目信息,以及Flash及RAM使用率。





这就是MCC的界面






可以看到常见的外设,都可以在此处配置:



本例仅点个灯用不到
进入MCC 的pin configuration页面




回顾下WFI32E02的用户手册,2个LED分别对应 MCU的RK1和RK3引脚。








找到RK1,RK3,分别设置为GPIO,方向OUT,初始高电平,Mode:Digital,上拉下拉不用管



设置好后,回到MCC页面,点击“Generate” 就自动生成了相关代码,包括最重要的main.c
以及相关库函数代码(plib)







这里补充一点:在项目属性里,如果下载了多个DFP(器件包),1.11目前看起来编译会报错,选择1.10就没事了。






3.编写点灯代码

在main.c中添加点灯程序,主要调用了自动生成的#include "peripheral/gpio/plib_gpio.h"中的函数

peripheral/gpio/plib_gpio.h(自动生成)
  1. #ifndef PLIB_GPIO_H
  2. #define PLIB_GPIO_H

  3. #include <device.h>
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #include <stddef.h>

  7. // DOM-IGNORE-BEGIN
  8. #ifdef __cplusplus  // Provide C++ Compatibility

  9.     extern "C" {

  10. #endif
  11. // DOM-IGNORE-END

  12. // *****************************************************************************
  13. // *****************************************************************************
  14. // Section: Data types and constants
  15. // *****************************************************************************
  16. // *****************************************************************************


  17. /*** Macros for GPIO_RK1 pin ***/
  18. #define GPIO_RK1_Set()               (LATKSET = (1U<<1))
  19. #define GPIO_RK1_Clear()             (LATKCLR = (1U<<1))
  20. #define GPIO_RK1_Toggle()            (LATKINV= (1U<<1))
  21. #define GPIO_RK1_OutputEnable()      (TRISKCLR = (1U<<1))
  22. #define GPIO_RK1_InputEnable()       (TRISKSET = (1U<<1))
  23. #define GPIO_RK1_Get()               ((PORTK >> 1) & 0x1U)
  24. #define GPIO_RK1_GetLatch()          ((LATK >> 1) & 0x1U)
  25. #define GPIO_RK1_PIN                  GPIO_PIN_RK1

  26. /*** Macros for GPIO_RK3 pin ***/
  27. #define GPIO_RK3_Set()               (LATKSET = (1U<<3))
  28. #define GPIO_RK3_Clear()             (LATKCLR = (1U<<3))
  29. #define GPIO_RK3_Toggle()            (LATKINV= (1U<<3))
  30. #define GPIO_RK3_OutputEnable()      (TRISKCLR = (1U<<3))
  31. #define GPIO_RK3_InputEnable()       (TRISKSET = (1U<<3))
  32. #define GPIO_RK3_Get()               ((PORTK >> 3) & 0x1U)
  33. #define GPIO_RK3_GetLatch()          ((LATK >> 3) & 0x1U)
  34. #define GPIO_RK3_PIN                  GPIO_PIN_RK3


  35. // *****************************************************************************
  36. /* GPIO Port

  37.   Summary:
  38.     Identifies the available GPIO Ports.

  39.   Description:
  40.     This enumeration identifies the available GPIO Ports.

  41.   Remarks:
  42.     The caller should not rely on the specific numbers assigned to any of
  43.     these values as they may change from one processor to the next.

  44.     Not all ports are available on all devices.  Refer to the specific
  45.     device data sheet to determine which ports are supported.
  46. */


  47. #define    GPIO_PORT_A  (0)
  48. #define    GPIO_PORT_B  (1)
  49. #define    GPIO_PORT_C  (2)
  50. #define    GPIO_PORT_K  (3)
  51. typedef uint32_t GPIO_PORT;

  52. typedef enum
  53. {
  54.     GPIO_INTERRUPT_ON_MISMATCH,
  55.     GPIO_INTERRUPT_ON_RISING_EDGE,
  56.     GPIO_INTERRUPT_ON_FALLING_EDGE,
  57.     GPIO_INTERRUPT_ON_BOTH_EDGES,
  58. }GPIO_INTERRUPT_STYLE;

  59. // *****************************************************************************
  60. /* GPIO Port Pins

  61.   Summary:
  62.     Identifies the available GPIO port pins.

  63.   Description:
  64.     This enumeration identifies the available GPIO port pins.

  65.   Remarks:
  66.     The caller should not rely on the specific numbers assigned to any of
  67.     these values as they may change from one processor to the next.

  68.     Not all pins are available on all devices.  Refer to the specific
  69.     device data sheet to determine which pins are supported.
  70. */


  71. #define     GPIO_PIN_RA0  (0U)
  72. #define     GPIO_PIN_RA1  (1U)
  73. #define     GPIO_PIN_RA2  (2U)
  74. #define     GPIO_PIN_RA3  (3U)
  75. #define     GPIO_PIN_RA4  (4U)
  76. #define     GPIO_PIN_RA5  (5U)
  77. #define     GPIO_PIN_RA6  (6U)
  78. #define     GPIO_PIN_RA7  (7U)
  79. #define     GPIO_PIN_RA8  (8U)
  80. #define     GPIO_PIN_RA9  (9U)
  81. #define     GPIO_PIN_RA10  (10U)
  82. #define     GPIO_PIN_RA11  (11U)
  83. #define     GPIO_PIN_RA12  (12U)
  84. #define     GPIO_PIN_RA13  (13U)
  85. #define     GPIO_PIN_RA14  (14U)
  86. #define     GPIO_PIN_RA15  (15U)
  87. #define     GPIO_PIN_RB0  (16U)
  88. #define     GPIO_PIN_RB1  (17U)
  89. #define     GPIO_PIN_RB2  (18U)
  90. #define     GPIO_PIN_RB3  (19U)
  91. #define     GPIO_PIN_RB4  (20U)
  92. #define     GPIO_PIN_RB5  (21U)
  93. #define     GPIO_PIN_RB6  (22U)
  94. #define     GPIO_PIN_RB7  (23U)
  95. #define     GPIO_PIN_RB8  (24U)
  96. #define     GPIO_PIN_RB9  (25U)
  97. #define     GPIO_PIN_RB10  (26U)
  98. #define     GPIO_PIN_RB11  (27U)
  99. #define     GPIO_PIN_RB12  (28U)
  100. #define     GPIO_PIN_RB13  (29U)
  101. #define     GPIO_PIN_RB14  (30U)
  102. #define     GPIO_PIN_RC0  (32U)
  103. #define     GPIO_PIN_RC1  (33U)
  104. #define     GPIO_PIN_RC2  (34U)
  105. #define     GPIO_PIN_RC3  (35U)
  106. #define     GPIO_PIN_RC4  (36U)
  107. #define     GPIO_PIN_RC5  (37U)
  108. #define     GPIO_PIN_RC6  (38U)
  109. #define     GPIO_PIN_RC7  (39U)
  110. #define     GPIO_PIN_RC8  (40U)
  111. #define     GPIO_PIN_RC9  (41U)
  112. #define     GPIO_PIN_RC10  (42U)
  113. #define     GPIO_PIN_RC11  (43U)
  114. #define     GPIO_PIN_RC12  (44U)
  115. #define     GPIO_PIN_RC13  (45U)
  116. #define     GPIO_PIN_RC14  (46U)
  117. #define     GPIO_PIN_RC15  (47U)
  118. #define     GPIO_PIN_RK0  (48U)
  119. #define     GPIO_PIN_RK1  (49U)
  120. #define     GPIO_PIN_RK2  (50U)
  121. #define     GPIO_PIN_RK3  (51U)
  122. #define     GPIO_PIN_RK4  (52U)
  123. #define     GPIO_PIN_RK5  (53U)
  124. #define     GPIO_PIN_RK6  (54U)
  125. #define     GPIO_PIN_RK7  (55U)
  126. #define     GPIO_PIN_RK8  (56U)
  127. #define     GPIO_PIN_RK9  (57U)
  128. #define     GPIO_PIN_RK10  (58U)
  129. #define     GPIO_PIN_RK11  (59U)
  130. #define     GPIO_PIN_RK12  (60U)
  131. #define     GPIO_PIN_RK13  (61U)
  132. #define     GPIO_PIN_RK14  (62U)

  133.     /* This element should not be used in any of the GPIO APIs.
  134.        It will be used by other modules or application to denote that none of the GPIO Pin is used */
  135. #define    GPIO_PIN_NONE   (-1)

  136. typedef uint32_t GPIO_PIN;


  137. void GPIO_Initialize(void);

  138. // *****************************************************************************
  139. // *****************************************************************************
  140. // Section: GPIO Functions which operates on multiple pins of a port
  141. // *****************************************************************************
  142. // *****************************************************************************

  143. uint32_t GPIO_PortRead(GPIO_PORT port);

  144. void GPIO_PortWrite(GPIO_PORT port, uint32_t mask, uint32_t value);

  145. uint32_t GPIO_PortLatchRead ( GPIO_PORT port );

  146. void GPIO_PortSet(GPIO_PORT port, uint32_t mask);

  147. void GPIO_PortClear(GPIO_PORT port, uint32_t mask);

  148. void GPIO_PortToggle(GPIO_PORT port, uint32_t mask);

  149. void GPIO_PortInputEnable(GPIO_PORT port, uint32_t mask);

  150. void GPIO_PortOutputEnable(GPIO_PORT port, uint32_t mask);

  151. // *****************************************************************************
  152. // *****************************************************************************
  153. // Section: GPIO Functions which operates on one pin at a time
  154. // *****************************************************************************
  155. // *****************************************************************************

  156. static inline void GPIO_PinWrite(GPIO_PIN pin, bool value)
  157. {
  158.      uint32_t xvalue = (uint32_t)value;
  159.     GPIO_PortWrite((pin>>4U), (uint32_t)(0x1U) << (pin & 0xFU), (xvalue) << (pin & 0xFU));
  160. }

  161. static inline bool GPIO_PinRead(GPIO_PIN pin)
  162. {
  163.     return ((((GPIO_PortRead((GPIO_PORT)(pin>>4U))) >> (pin & 0xFU)) & 0x1U) != 0U);
  164. }

  165. static inline bool GPIO_PinLatchRead(GPIO_PIN pin)
  166. {
  167.     return (((GPIO_PortLatchRead((GPIO_PORT)(pin>>4U)) >> (pin & 0xFU)) & 0x1U) != 0U);
  168. }

  169. static inline void GPIO_PinToggle(GPIO_PIN pin)
  170. {
  171.     GPIO_PortToggle((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
  172. }

  173. static inline void GPIO_PinSet(GPIO_PIN pin)
  174. {
  175.     GPIO_PortSet((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
  176. }

  177. static inline void GPIO_PinClear(GPIO_PIN pin)
  178. {
  179.     GPIO_PortClear((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
  180. }

  181. static inline void GPIO_PinInputEnable(GPIO_PIN pin)
  182. {
  183.     GPIO_PortInputEnable((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
  184. }

  185. static inline void GPIO_PinOutputEnable(GPIO_PIN pin)
  186. {
  187.     GPIO_PortOutputEnable((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
  188. }





main.c
  1. int main ( void )
  2. {
  3.     /* Initialize all modules */
  4.     SYS_Initialize ( NULL );
  5.    

  6.     /* Maintain state machines of all polled MPLAB Harmony modules. */

  7.       while(1)
  8.       {
  9.         for(i=0;i<100000000;i++);
  10.         GPIO_RK1_Toggle();
  11.         GPIO_RK3_Toggle();

  12.       }



  13.     /* Execution should not come here during normal operation */

  14.     //return ( EXIT_FAILURE );
  15. }

点击编译及运行按钮,就可以看到开发板上的LED(D300,D301)闪烁了。















本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
xinmeng_wit 发表于 2025-11-6 13:20 | 显示全部楼层
还真没注意是WFI32E04还是WFI32E02
 楼主| cc1989summer 发表于 2025-11-6 20:22 | 显示全部楼层
xinmeng_wit 发表于 2025-11-6 13:20
还真没注意是WFI32E04还是WFI32E02

可以看丝印,估计都是WFI32E02[em:3:]
xinmeng_wit 发表于 2025-11-6 20:34 | 显示全部楼层
cc1989summer 发表于 2025-11-6 20:22
可以看丝印,估计都是WFI32E02

确实是E02
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

32

帖子

0

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