一、硬件接口和连接NFC天线说明:
主板上板载NFC芯片ST25DV04K,该芯片通过CPU的I2C4进行控制,电路图如下:
使用板载NFC功能需要外接天线,接线如图
二、下载和安装测试软件
测试软件下载:
Execution File
下载后测试软解压缩后,里面有 Android和PC 2个文件夹,
说明:
Android文件夹里面是配套使用的APP,需要安装到有NFC功能的手机里面.
PC文件夹里面是在开发板windows下使用的测试软件
测试软件源码下载:
Source Code
Android App Source Code
三、测试NFC功能
3.1 我们提供C#样例程序,演示NFC读写测试,在开发板windows系统下运行下载的测试程序 St25Dv-Test.exe 如图
操作流程:
1)先"连接设备"
2)主要操作:
X1 SBC向手机APP传数据区域:开发版NFC芯片发数据给APP
X1 SBC收到手机NFC的数据区域:根据中断读取来自手机NFC数据。
“写标签:风火轮官网”:通过NDEF把www.youyeetoo.cn写入到芯片中做标签
“写标签:启动微信”:把微信启动方式写入标签.这样安卓NFC手机扫一下就能启动微信
3.2 安卓手机中安装下载的测试程序NFC2023v1.1_20230927_debug.apk
这里用安卓手机为例,如图:测试NFC用安卓APP
上部分:主要是日志,
下部分:手机通过NFC把数据传输到X1 SBC开发版.
四、扩展知识参考(这些已经集成到BIOS和win系统,不需动手操作)
下面是介绍如何给开发板添加NFC设备和配置驱动程序,这些流程,出厂默认已经完成,无需任何操作,可以作为深度二次开发参考用.
驱动程序下载
4.1 在BIOS中添加NFC设备
添加方法:请参考"Windows驱动开发"描述后面部分"新设备加入到系统"流程,这里仅说明需要添加的ASL代码(注意:下面用了中文注解关键信息,根据实际硬件进行修改。需要强调的是正式ASL代码中不能出现中文,使用时候删除掉中文注解或者换成英文注解):
因为ST25DV04K 有2个设备地址,所以这里添加了2个设备.
I2C地址:0X53 允许访问用户存储器、动态寄存器或FTM信箱(快速传输)
I2C地址:0X57 允许访问静态寄存器(系统),和设置I2C访问密码.用户存储器分区等.
Scope (_SB.PC00.I2C4)
{
Device (NFC0)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "25DV0053") // _HID: Hardware ID
Name (_CID, "25DV0053") // _CID: Compatible ID
Name (_S0W, Zero) // _S0W: S0 Device Wake State
Name (_UID, One) // _UID: Unique ID
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
Name (SBFB, ResourceTemplate ()
{
I2cSerialBusV2 (0x0053, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.PC00.I2C4",
0x00, ResourceConsumer, _Y50, Exclusive,
)
})
Name (SBFG, ResourceTemplate ()
{
GpioInt (Edge, ActiveLow, ExclusiveAndWake, PullUp, 0x0000,
"\\_SB.GPI0", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0000
}
})
CreateDWordField (SBFB, \_SB.PC00.I2C4.NFC0._Y50._SPE, SPEX) // _SPE: Speed
CreateWordField (SBFG, 0x17, INT1)
Method (_INI, 0, NotSerialized) // _INI: Initialize
{
//pin-list 0x07010004
INT1 = GNUM (0x07010004)
SHPO (0x07010004, One)
SPEX = 0x00061A80
Return (Zero)
}
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Return (ConcatenateResTemplate (SBFB, SBFG))
}
}
}
Scope (_SB.PC00.I2C4)
{
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "25DV0057") // _HID: Hardware ID
Name (_CID, "25DV0057") // _CID: Compatible ID
Name (_S0W, Zero) // _S0W: S0 Device Wake State
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (RBUF, ResourceTemplate ()
{
I2cSerialBusV2 (0x0057, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.PC00.I2C4",
0x00, ResourceConsumer, , Exclusive,
)
})
Return (RBUF) /* \_SB_.PC00.I2C4.NFC1._CRS.RBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
}
NFC设备添加到BIOS后,可以从设备管理器里面查看到:未知设备,对应的硬件ID和ASL代码中描述_HID (25DV0053) 和_HID (25DV0057) 2个设备
4.2 设备ID和驱动程序关联
我们将提供I2C驱动程序,把硬件ID 25DV0053 25DV0057 添加到驱动安装文件"SpbDriver.inf"中,驱动文件全文如下:
[Version]
Signature = "$WINDOWS NT$"
Class = HIDClass
ClassGuid ={745a17a0-74d3-11d0-b6fe-00a0c90f57da}
Provider = %ProviderName%
DriverVer = 08/13/2023,16.5.5.7
CatalogFile = SpbDriver.cat
PnpLockdown = 1
[DestinationDirs]
DefaultDestDir = 13
[SourceDisksNames]
1 = %DiskId1%,,,""
[SourceDisksFiles]
SpbDriver.sys = 1,,
[Manufacturer]
%StdMfg%=Standard,NTamd64
[Standard.NTamd64]
%SpbDriver.DeviceDesc%=SpbDriver_Device, ACPI\25DV0053
%SpbDriver1.DeviceDesc%=SpbDriver_Device, ACPI\25DV0057
%SpbDriver2.DeviceDesc%=SpbDriver_Device, ACPI\I2C30001
%SpbDriver3.DeviceDesc%=SpbDriver_Device, ACPI\SPI1001
[SpbDriver_Device.NT]
CopyFiles=Drivers_Dir
[SpbDriver_Device.NT.HW]
AddReg=SpbDriver_AddReg
[Drivers_Dir]
SpbDriver.sys
[SpbDriver_AddReg]
HKR,Settings,"ConnectInterrupt",0x00010001,1
[SpbDriver_Device.NT.Services]
AddService = SpbDriver,%SPSVCINST_ASSOCSERVICE%, SpbDriver_Service_Inst
[SpbDriver_Service_Inst]
DisplayName = %SpbDriver.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %13%\SpbDriver.sys
[Strings]
SPSVCINST_ASSOCSERVICE= 0x00000002
ProviderName = "www.youyeetoo.com"
StdMfg = "(Standard system devices)"
DiskId1 = "SPB Driver Peripheral Installation Disk #1"
SpbDriver.DeviceDesc = "25DV0053 NFC I2C4 Address 0X53"
SpbDriver.SVCDESC = "SPB Driver Peripheral desc"
SpbDriver1.DeviceDesc = "25DV0057 NFC I2C4 Address 0X57"
SpbDriver2.DeviceDesc = "I2C30001 Address 0X50"
SpbDriver3.DeviceDesc = "SPI1001 Driver"
ClassName = "I2C"
其中文件中最关键的2行,也是根据实际情况修改的2行,如下:
[Standard.NTamd64]
; 驱动匹配的设备ID为25DV0053和25DV0057
%SpbDriver.DeviceDesc%=SpbDriver_Device, ACPI\25DV0053
%SpbDriver1.DeviceDesc%=SpbDriver_Device, ACPI\25DV0057
[Strings]
; 在设备管理器里面设备显示描述
SpbDriver.DeviceDesc = "25DV0053 NFC I2C4 Address 0X53"
SpbDriver1.DeviceDesc = "25DV0057 NFC I2C4 Address 0X57"
4.3 安装驱动程序
在以上步骤修改好后,在"SpbDriver.inf"文件鼠标右键选"安装",系统弹出提示,选"始终安装驱动程序",过一会就出现安装成功弹窗.在设备管理器中"人机接口设备"中,可以看到已经成功安装该NFC设备驱动程序了