中级
30 分钟

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

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

Smart Card 2 Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

Smart Card 2 Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

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

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

功能概述

开发板

Nucleo 32开发板搭载STM32F031K6 MCU,提供了一种经济且灵活的平台,适用于使用32引脚封装的STM32微控制器进行实验。该开发板具有Arduino™ Nano连接性,便于通过专用扩展板进行功能扩展,并且支持mbed,使其能够无缝集成在线资源。板载集成

ST-LINK/V2-1调试器/编程器,支持通过USB重新枚举,提供三种接口:虚拟串口(Virtual Com port)、大容量存储和调试端口。该开发板的电源供应灵活,可通过USB VBUS或外部电源供电。此外,还配备了三个LED指示灯(LD1用于USB通信,LD2用于电源

指示,LD3为用户可控LED)和一个复位按钮。STM32 Nucleo-32开发板支持多种集成开发环境(IDEs),如IAR™、Keil®和基于GCC的IDE(如AC6 SW4STM32),使其成为开发人员的多功能工具。

Nucleo 32 with STM32F031K6 MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

32

硅供应商

STMicroelectronics

引脚数

32

RAM (字节)

4096

你完善了我!

配件

Click Shield for Nucleo-32是扩展您的开发板功能的理想选择,专为STM32 Nucleo-32引脚布局设计。Click Shield for Nucleo-32提供了两个mikroBUS™插座,可以添加来自我们不断增长的Click板™系列中的任何功能。从传感器和WiFi收发器到电机控制和音频放大器,我们应有尽有。Click Shield for Nucleo-32与STM32 Nucleo-32开发板兼容,为用户提供了一种经济且灵活的方式,使用任何STM32微控制器快速创建原型,并尝试各种性能、功耗和功能的组合。STM32 Nucleo-32开发板无需任何独立的探针,因为它集成了ST-LINK/V2-1调试器/编程器,并随附STM32全面的软件HAL库和各种打包的软件示例。这个开发平台为用户提供了一种简便且通用的方式,将STM32 Nucleo-32兼容开发板与他们喜欢的Click板™结合,应用于即将开展的项目中。

Click Shield for Nucleo-32 accessories 1 image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PA11
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
PA10
TX
UART RX
PA9
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Smart Card 2 Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-144 front image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 32 with STM32F031K6 MCU作为您的开发板开始。

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 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
STM32 M4 Clicker HA MCU/Select 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

额外支持

资源

喜欢这个项目吗?

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