中级
30 分钟

借助 SEC1210 和 PIC32MZ1024EFH064 安全地处理、移动和存储信息

通过智能卡读取提升访问控制:您的安全明天之钥

Smart Card 2 Click with PIC32MZ clicker

已发布 6月 27, 2024

点击板

Smart Card 2 Click

开发板

PIC32MZ clicker

编译器

NECTO Studio

微控制器单元

PIC32MZ1024EFH064

探索市场上最先进的智能卡读卡器,提供无与伦比的保护和易用性。

A

A

硬件概览

它是如何工作的?

Smart Card 2 Click基于Microchip的SEC1210,这是一款高性能单芯片智能卡控制器,具有UART接口。SEC1210由增强型集成8051 CPU控制,所有芯片外围设备通过SFR或XDATA寄存器空间进行访问和管理。此外,它完全符合现行的智能卡标准(ISO7816、EMV和PC/SC),满足所有通信比特率要求,并支持高达826Kbps的提议比特率。SEC1210电源单元在内部调节和切换,支持所有5V、3V和1.8V智能卡(分别为A类、B类和C类)。SEC1210采用

TrustSpan™技术,使数字系统能够安全地通信、处理、传输和存储信息。板载的卡托支持2FF智能卡的数据处理。额外的外部连接器还允许处理标准的1FF卡,使其非常适合电子过程,如个人识别、访问控制(物理和逻辑访问)、认证等。此Click板™通过UART接口与MCU通信,使用常见的UART RX/TX,默认配置下操作速率为115200 bps,以传输和交换数据。激活/停用过程本身可以通过软件实现,但也支持硬件停用,当卡被拔出时,确保所需的序列无论是否参

与软件都能实现。此外,Smart Card 2 Click还具有通用复位功能,连接到mikroBUS™插槽的RST引脚,这使模块进入复位状态,而标记为SRC的黄色LED指示灯代表智能卡状态指示灯。此LED的闪烁表明智能卡数据处理正在进行中。此Click板™可以与3.3V和5V的MCU一起操作,而SEC1210仅使用来自mikroBUS™电源轨的5V作为其主要电源。然而,此Click板™配备了包含函数和示例代码的库,可用作进一步开发的参考。

Smart Card 2 Click hardware overview image

功能概述

开发板

PIC32MZ Clicker 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位带有浮点单元的 Microchip PIC32MZ 微控制器,一个 USB 连接器,LED 指示灯,按钮,一个 mikroProg 连接器,以及一个用于与外部电子设备接口的头部。得益于其紧凑的设计和清晰易识别的丝网标记,它提供了流畅且沉浸式的工作体验,允许在任

何情况下、任何地方都能访问。PIC32MZ Clicker 开 发套件的每个部分都包含了使同一板块运行最高效的必要组件。除了可以选择 PIC32MZ Clicker 的编程方式,使用 USB HID mikroBootloader 或通过外部 mikroProg 连接器为 PIC,dsPIC 或 PIC32 编程外,Clicker 板还包括一个干净且调节过的开发套件电源供应模块。USB Micro-B 连接可以提供多达 500mA 的电流,这足以操作所有板载和附加模块。所有 

mikroBUS™ 本身支持的通信方法都在这块板上,包 括已经建立良好的 mikroBUS™ 插槽、重置按钮以及若干按钮和 LED 指示灯。PIC32MZ Clicker 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

PIC32MZ clicker double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

1024

硅供应商

Microchip

引脚数

64

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
RE5
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
RB2
TX
UART RX
RB0
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Smart Card 2 Click Schematic schematic

一步一步来

项目组装

PIC32MZ clicker front image hardware assembly

从选择您的开发板和Click板™开始。以PIC32MZ clicker作为您的开发板开始。

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product7 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

该库包含 Smart Card 2 Click 驱动程序的 API。

关键功能:

  • smartcard2_send_ccid - 该函数使用UART串行接口发送CCID命令消息

  • smartcard2_read_ccid - 该函数使用UART串行接口读取CCID响应或事件消息

  • smartcard2_icc_power_on - 该函数通过执行ICC上电命令激活卡片。设备将以包含ICC ATR(复位应答)消息的数据块进行响应

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief Smart Card 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of Smart Card 2 Click board by checking
 * the SIM card presence and activating the card on insert. The card should respond
 * with an ATR (Answer to Reset) message.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and enables the device.
 *
 * ## Application Task
 * Reads and parses all CCID messages received from the device. Checks the SIM card presence
 * and activates it if it's inserted. The card should respond with an ATR (Answer to Reset) message.
 * All data is being logged on the USB UART where you can track their changes.
 * 
 * @note
 * This example doesn't parse ATR messages.
 * There are some online ATR parsers which could be used for decoding those messages.
 * For example: https://smartcard-atr.apdu.fr/
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "smartcard2.h"

static smartcard2_t smartcard2;
static log_t logger;
static uint8_t icc_status = SMARTCARD2_ICC_ABSENT;

/**
 * @brief Smart Card 2 display ccid message function.
 * @details This function parses the CCID message and updates the icc_status in the end.
 * The results will be displayed on the USB UART.
 * @param[in] ccid : CCID message to be parsed.
 * See #smartcard2_ccid_t object definition for detailed explanation.
 * @return None.
 * @note None.
 */
static void smartcard2_display_ccid_message ( smartcard2_ccid_t ccid );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    smartcard2_cfg_t smartcard2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    smartcard2_cfg_setup( &smartcard2_cfg );
    SMARTCARD2_MAP_MIKROBUS( smartcard2_cfg, MIKROBUS_1 );
    if ( UART_ERROR == smartcard2_init( &smartcard2, &smartcard2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    smartcard2_ccid_t ccid = { 0 };
    if ( SMARTCARD2_OK == smartcard2_read_ccid ( &smartcard2, &ccid ) )
    {
        smartcard2_display_ccid_message ( ccid );
    }
    if ( SMARTCARD2_ICC_PRESENT == icc_status )
    {
        log_printf( &logger, " Activating card... \r\n" );
        smartcard2_icc_power_on ( &smartcard2, SMARTCARD2_POWER_SEL_3V );
        Delay_ms ( 100 );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

static void smartcard2_display_ccid_message ( smartcard2_ccid_t ccid )
{
    log_printf( &logger, "---------------------------------\r\n" );
    switch ( ccid.type )
    {
        case SMARTCARD2_EVT_NOTIFY_SLOT_CHANGE:
        {
            log_printf( &logger, " Message type: Slot change\r\n" );
            if ( SMARTCARD2_CARD_ABSENT == ccid.payload[ 0 ] )
            {
                icc_status = SMARTCARD2_ICC_ABSENT;
            }
            else if ( SMARTCARD2_CARD_PRESENT == ccid.payload[ 0 ] )
            {
                icc_status = SMARTCARD2_ICC_PRESENT;
            }
            break;
        }
        case SMARTCARD2_CTRL_NACK:
        {
            log_printf( &logger, " Message type: NACK\r\n" );
            log_printf( &logger, " Command not acknowledged\r\n" );
            break;
        }
        case SMARTCARD2_RSP_SLOT_STATUS:
        {
            log_printf( &logger, " Message type: Slot status\r\n" );
            log_printf( &logger, " Slot number: 0x%.2X\r\n", ( uint16_t ) ccid.slot_num );
            log_printf( &logger, " Seq number: 0x%.2X\r\n", ( uint16_t ) ccid.seq_num );
            log_printf( &logger, " Status: 0x%.2X\r\n", ( uint16_t ) ccid.spec_bytes[ 0 ] );
            icc_status = ccid.spec_bytes[ 0 ] & SMARTCARD2_ICC_STATUS_MASK;
            log_printf( &logger, " Error: 0x%.2X\r\n", ( uint16_t ) ccid.spec_bytes[ 1 ] );
            log_printf( &logger, " Clock status: " );
            switch ( ccid.spec_bytes[ 2 ] )
            {
                case SMARTCARD2_CLK_STATUS_RUNNING:
                {
                    log_printf( &logger, "Running\r\n" );
                    break;
                }
                case SMARTCARD2_CLK_STATUS_STATE_L:
                {
                    log_printf( &logger, "Stoped in state L\r\n" );
                    break;
                }
                case SMARTCARD2_CLK_STATUS_STATE_H:
                {
                    log_printf( &logger, "Stoped in state H\r\n" );
                    break;
                }
                default:
                {
                    log_printf( &logger, "Unknown\r\n" );
                    break;
                }
            }
            break;
        }
        case SMARTCARD2_RSP_DATA_BLOCK:
        {
            log_printf( &logger, " Message type: Data Block\r\n" );
            log_printf( &logger, " Payload size: %lu\r\n", ccid.payload_size );
            log_printf( &logger, " Slot number: 0x%.2X\r\n", ( uint16_t ) ccid.slot_num );
            log_printf( &logger, " Seq number: 0x%.2X\r\n", ( uint16_t ) ccid.seq_num );
            log_printf( &logger, " Status: 0x%.2X\r\n", ( uint16_t ) ccid.spec_bytes[ 0 ] );
            icc_status = ccid.spec_bytes[ 0 ] & SMARTCARD2_ICC_STATUS_MASK;
            log_printf( &logger, " Error: 0x%.2X\r\n", ( uint16_t ) ccid.spec_bytes[ 1 ] );
            log_printf( &logger, " Chain parameter: 0x%.2X\r\n", ( uint16_t ) ccid.spec_bytes[ 2 ] );
            if ( ccid.payload_size )
            {
                log_printf( &logger, " Payload (ATR data as response to power on):\r\n" );
                for ( uint32_t cnt = 0; cnt < ccid.payload_size; cnt++ )
                {
                    log_printf( &logger, " %.2X", ( uint16_t ) ccid.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
            }
            break;
        }
        default:
        {
            log_printf( &logger, " Message type: 0x%.2X\r\n", ( uint16_t ) ccid.type );
            log_printf( &logger, " Payload size: %lu\r\n", ccid.payload_size );
            log_printf( &logger, " Slot number: 0x%.2X\r\n", ( uint16_t ) ccid.slot_num );
            log_printf( &logger, " Seq number: 0x%.2X\r\n", ( uint16_t ) ccid.seq_num );
            log_printf( &logger, " Spec bytes: 0x%.2X, 0x%.2X, 0x%.2X\r\n", ( uint16_t ) ccid.spec_bytes[ 0 ], 
                                                                            ( uint16_t ) ccid.spec_bytes[ 1 ], 
                                                                            ( uint16_t ) ccid.spec_bytes[ 2 ] );
            if ( ccid.payload_size )
            {
                log_printf( &logger, " Payload:\r\n" );
                for ( uint32_t cnt = 0; cnt < ccid.payload_size; cnt++ )
                {
                    log_printf( &logger, " 0x%.2X", ( uint16_t ) ccid.payload[ cnt ] );
                    if ( 7 == cnt % 8 )
                    {
                        log_printf( &logger, "\r\n" );
                    }
                }
                log_printf( &logger, "\r\n" );
            }
            break;
        }
    }
    if ( SMARTCARD2_ICC_ABSENT == icc_status )
    {
        log_printf( &logger, " ICC status: ABSENT\r\n" );
    }
    else if ( SMARTCARD2_ICC_PRESENT == icc_status )
    {
        log_printf( &logger, " ICC status: PRESENT\r\n" );
    }
    else if ( SMARTCARD2_ICC_ACTIVE == icc_status )
    {
        log_printf( &logger, " ICC status: ACTIVE\r\n" );
    }
    log_printf( &logger, "---------------------------------\r\n\n" );
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。