本帖最后由 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(自动生成)
- #ifndef PLIB_GPIO_H
- #define PLIB_GPIO_H
- #include <device.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include <stddef.h>
- // DOM-IGNORE-BEGIN
- #ifdef __cplusplus // Provide C++ Compatibility
- extern "C" {
- #endif
- // DOM-IGNORE-END
- // *****************************************************************************
- // *****************************************************************************
- // Section: Data types and constants
- // *****************************************************************************
- // *****************************************************************************
- /*** Macros for GPIO_RK1 pin ***/
- #define GPIO_RK1_Set() (LATKSET = (1U<<1))
- #define GPIO_RK1_Clear() (LATKCLR = (1U<<1))
- #define GPIO_RK1_Toggle() (LATKINV= (1U<<1))
- #define GPIO_RK1_OutputEnable() (TRISKCLR = (1U<<1))
- #define GPIO_RK1_InputEnable() (TRISKSET = (1U<<1))
- #define GPIO_RK1_Get() ((PORTK >> 1) & 0x1U)
- #define GPIO_RK1_GetLatch() ((LATK >> 1) & 0x1U)
- #define GPIO_RK1_PIN GPIO_PIN_RK1
- /*** Macros for GPIO_RK3 pin ***/
- #define GPIO_RK3_Set() (LATKSET = (1U<<3))
- #define GPIO_RK3_Clear() (LATKCLR = (1U<<3))
- #define GPIO_RK3_Toggle() (LATKINV= (1U<<3))
- #define GPIO_RK3_OutputEnable() (TRISKCLR = (1U<<3))
- #define GPIO_RK3_InputEnable() (TRISKSET = (1U<<3))
- #define GPIO_RK3_Get() ((PORTK >> 3) & 0x1U)
- #define GPIO_RK3_GetLatch() ((LATK >> 3) & 0x1U)
- #define GPIO_RK3_PIN GPIO_PIN_RK3
- // *****************************************************************************
- /* GPIO Port
- Summary:
- Identifies the available GPIO Ports.
- Description:
- This enumeration identifies the available GPIO Ports.
- Remarks:
- The caller should not rely on the specific numbers assigned to any of
- these values as they may change from one processor to the next.
- Not all ports are available on all devices. Refer to the specific
- device data sheet to determine which ports are supported.
- */
- #define GPIO_PORT_A (0)
- #define GPIO_PORT_B (1)
- #define GPIO_PORT_C (2)
- #define GPIO_PORT_K (3)
- typedef uint32_t GPIO_PORT;
- typedef enum
- {
- GPIO_INTERRUPT_ON_MISMATCH,
- GPIO_INTERRUPT_ON_RISING_EDGE,
- GPIO_INTERRUPT_ON_FALLING_EDGE,
- GPIO_INTERRUPT_ON_BOTH_EDGES,
- }GPIO_INTERRUPT_STYLE;
- // *****************************************************************************
- /* GPIO Port Pins
- Summary:
- Identifies the available GPIO port pins.
- Description:
- This enumeration identifies the available GPIO port pins.
- Remarks:
- The caller should not rely on the specific numbers assigned to any of
- these values as they may change from one processor to the next.
- Not all pins are available on all devices. Refer to the specific
- device data sheet to determine which pins are supported.
- */
- #define GPIO_PIN_RA0 (0U)
- #define GPIO_PIN_RA1 (1U)
- #define GPIO_PIN_RA2 (2U)
- #define GPIO_PIN_RA3 (3U)
- #define GPIO_PIN_RA4 (4U)
- #define GPIO_PIN_RA5 (5U)
- #define GPIO_PIN_RA6 (6U)
- #define GPIO_PIN_RA7 (7U)
- #define GPIO_PIN_RA8 (8U)
- #define GPIO_PIN_RA9 (9U)
- #define GPIO_PIN_RA10 (10U)
- #define GPIO_PIN_RA11 (11U)
- #define GPIO_PIN_RA12 (12U)
- #define GPIO_PIN_RA13 (13U)
- #define GPIO_PIN_RA14 (14U)
- #define GPIO_PIN_RA15 (15U)
- #define GPIO_PIN_RB0 (16U)
- #define GPIO_PIN_RB1 (17U)
- #define GPIO_PIN_RB2 (18U)
- #define GPIO_PIN_RB3 (19U)
- #define GPIO_PIN_RB4 (20U)
- #define GPIO_PIN_RB5 (21U)
- #define GPIO_PIN_RB6 (22U)
- #define GPIO_PIN_RB7 (23U)
- #define GPIO_PIN_RB8 (24U)
- #define GPIO_PIN_RB9 (25U)
- #define GPIO_PIN_RB10 (26U)
- #define GPIO_PIN_RB11 (27U)
- #define GPIO_PIN_RB12 (28U)
- #define GPIO_PIN_RB13 (29U)
- #define GPIO_PIN_RB14 (30U)
- #define GPIO_PIN_RC0 (32U)
- #define GPIO_PIN_RC1 (33U)
- #define GPIO_PIN_RC2 (34U)
- #define GPIO_PIN_RC3 (35U)
- #define GPIO_PIN_RC4 (36U)
- #define GPIO_PIN_RC5 (37U)
- #define GPIO_PIN_RC6 (38U)
- #define GPIO_PIN_RC7 (39U)
- #define GPIO_PIN_RC8 (40U)
- #define GPIO_PIN_RC9 (41U)
- #define GPIO_PIN_RC10 (42U)
- #define GPIO_PIN_RC11 (43U)
- #define GPIO_PIN_RC12 (44U)
- #define GPIO_PIN_RC13 (45U)
- #define GPIO_PIN_RC14 (46U)
- #define GPIO_PIN_RC15 (47U)
- #define GPIO_PIN_RK0 (48U)
- #define GPIO_PIN_RK1 (49U)
- #define GPIO_PIN_RK2 (50U)
- #define GPIO_PIN_RK3 (51U)
- #define GPIO_PIN_RK4 (52U)
- #define GPIO_PIN_RK5 (53U)
- #define GPIO_PIN_RK6 (54U)
- #define GPIO_PIN_RK7 (55U)
- #define GPIO_PIN_RK8 (56U)
- #define GPIO_PIN_RK9 (57U)
- #define GPIO_PIN_RK10 (58U)
- #define GPIO_PIN_RK11 (59U)
- #define GPIO_PIN_RK12 (60U)
- #define GPIO_PIN_RK13 (61U)
- #define GPIO_PIN_RK14 (62U)
- /* This element should not be used in any of the GPIO APIs.
- It will be used by other modules or application to denote that none of the GPIO Pin is used */
- #define GPIO_PIN_NONE (-1)
- typedef uint32_t GPIO_PIN;
- void GPIO_Initialize(void);
- // *****************************************************************************
- // *****************************************************************************
- // Section: GPIO Functions which operates on multiple pins of a port
- // *****************************************************************************
- // *****************************************************************************
- uint32_t GPIO_PortRead(GPIO_PORT port);
- void GPIO_PortWrite(GPIO_PORT port, uint32_t mask, uint32_t value);
- uint32_t GPIO_PortLatchRead ( GPIO_PORT port );
- void GPIO_PortSet(GPIO_PORT port, uint32_t mask);
- void GPIO_PortClear(GPIO_PORT port, uint32_t mask);
- void GPIO_PortToggle(GPIO_PORT port, uint32_t mask);
- void GPIO_PortInputEnable(GPIO_PORT port, uint32_t mask);
- void GPIO_PortOutputEnable(GPIO_PORT port, uint32_t mask);
- // *****************************************************************************
- // *****************************************************************************
- // Section: GPIO Functions which operates on one pin at a time
- // *****************************************************************************
- // *****************************************************************************
- static inline void GPIO_PinWrite(GPIO_PIN pin, bool value)
- {
- uint32_t xvalue = (uint32_t)value;
- GPIO_PortWrite((pin>>4U), (uint32_t)(0x1U) << (pin & 0xFU), (xvalue) << (pin & 0xFU));
- }
- static inline bool GPIO_PinRead(GPIO_PIN pin)
- {
- return ((((GPIO_PortRead((GPIO_PORT)(pin>>4U))) >> (pin & 0xFU)) & 0x1U) != 0U);
- }
- static inline bool GPIO_PinLatchRead(GPIO_PIN pin)
- {
- return (((GPIO_PortLatchRead((GPIO_PORT)(pin>>4U)) >> (pin & 0xFU)) & 0x1U) != 0U);
- }
- static inline void GPIO_PinToggle(GPIO_PIN pin)
- {
- GPIO_PortToggle((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
- }
- static inline void GPIO_PinSet(GPIO_PIN pin)
- {
- GPIO_PortSet((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
- }
- static inline void GPIO_PinClear(GPIO_PIN pin)
- {
- GPIO_PortClear((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
- }
- static inline void GPIO_PinInputEnable(GPIO_PIN pin)
- {
- GPIO_PortInputEnable((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
- }
- static inline void GPIO_PinOutputEnable(GPIO_PIN pin)
- {
- GPIO_PortOutputEnable((pin>>4U), (uint32_t)0x1U << (pin & 0xFU));
- }
main.c
- int main ( void )
- {
- /* Initialize all modules */
- SYS_Initialize ( NULL );
-
-
- /* Maintain state machines of all polled MPLAB Harmony modules. */
- while(1)
- {
- for(i=0;i<100000000;i++);
- GPIO_RK1_Toggle();
- GPIO_RK3_Toggle();
-
- }
- /* Execution should not come here during normal operation */
- //return ( EXIT_FAILURE );
- }
点击编译及运行按钮,就可以看到开发板上的LED(D300,D301)闪烁了。
|