Example application for the STMicroelectronics X-NUCLEO-NFC05A1

Dependencies:   RFAL ST25R3911 BSP05

X-NUCLEO-NFC05A1 NFC Card Reader Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC05A1 NFC Card Reader Expansion Board based on the ST25R3911B.

Example Application

This program gives the user the possibility to read the URI information written on the expansion board. The LEDs will blink for few seconds to indicate that the board is initializing. As soon as it finishes, the device is ready to communicate with external NFC devices. LED6 will blink until an NFC device is close to it and ready to read the URI value.

Tested Platforms

This firmware has been tested on STM32 NUCLEO-F401RE

Committer:
DiegoOstuni
Date:
Thu Nov 14 14:57:00 2019 +0000
Revision:
3:9a152c93d7a2
Parent:
1:86504e1ac6b1
Example application for the STMicroelectronics X-NUCLEO-NFC05A1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 1:86504e1ac6b1 1 /******************************************************************************
DiegoOstuni 1:86504e1ac6b1 2 * @attention
DiegoOstuni 1:86504e1ac6b1 3 *
DiegoOstuni 1:86504e1ac6b1 4 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
DiegoOstuni 1:86504e1ac6b1 5 *
DiegoOstuni 1:86504e1ac6b1 6 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 1:86504e1ac6b1 7 * You may not use this file except in compliance with the License.
DiegoOstuni 1:86504e1ac6b1 8 * You may obtain a copy of the License at:
DiegoOstuni 1:86504e1ac6b1 9 *
DiegoOstuni 1:86504e1ac6b1 10 * http://www.st.com/myliberty
DiegoOstuni 1:86504e1ac6b1 11 *
DiegoOstuni 1:86504e1ac6b1 12 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 1:86504e1ac6b1 13 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 1:86504e1ac6b1 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 1:86504e1ac6b1 15 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 1:86504e1ac6b1 16 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 1:86504e1ac6b1 17 * See the License for the specific language governing permissions and
DiegoOstuni 1:86504e1ac6b1 18 * limitations under the License.
DiegoOstuni 1:86504e1ac6b1 19 *
DiegoOstuni 1:86504e1ac6b1 20 ******************************************************************************/
DiegoOstuni 1:86504e1ac6b1 21 /*
DiegoOstuni 1:86504e1ac6b1 22 * PROJECT:
DiegoOstuni 1:86504e1ac6b1 23 * $Revision: $
DiegoOstuni 1:86504e1ac6b1 24 * LANGUAGE: ANSI C
DiegoOstuni 1:86504e1ac6b1 25 */
DiegoOstuni 1:86504e1ac6b1 26
DiegoOstuni 1:86504e1ac6b1 27 /*! \file
DiegoOstuni 1:86504e1ac6b1 28 *
DiegoOstuni 1:86504e1ac6b1 29 * \author
DiegoOstuni 1:86504e1ac6b1 30 *
DiegoOstuni 1:86504e1ac6b1 31 * \brief Debug log output utility implementation.
DiegoOstuni 1:86504e1ac6b1 32 *
DiegoOstuni 1:86504e1ac6b1 33 */
DiegoOstuni 1:86504e1ac6b1 34
DiegoOstuni 1:86504e1ac6b1 35 /*
DiegoOstuni 1:86504e1ac6b1 36 ******************************************************************************
DiegoOstuni 1:86504e1ac6b1 37 * INCLUDES
DiegoOstuni 1:86504e1ac6b1 38 ******************************************************************************
DiegoOstuni 1:86504e1ac6b1 39 */
DiegoOstuni 1:86504e1ac6b1 40 //#include "usart.h"
DiegoOstuni 1:86504e1ac6b1 41 #include "logger.h"
DiegoOstuni 1:86504e1ac6b1 42 #include "st_errno.h"
DiegoOstuni 1:86504e1ac6b1 43 #include <string.h>
DiegoOstuni 1:86504e1ac6b1 44 #include <stdarg.h>
DiegoOstuni 1:86504e1ac6b1 45
DiegoOstuni 1:86504e1ac6b1 46 /*
DiegoOstuni 1:86504e1ac6b1 47 ******************************************************************************
DiegoOstuni 1:86504e1ac6b1 48 * LOCAL DEFINES
DiegoOstuni 1:86504e1ac6b1 49 ******************************************************************************
DiegoOstuni 1:86504e1ac6b1 50 */
DiegoOstuni 1:86504e1ac6b1 51
DiegoOstuni 1:86504e1ac6b1 52
DiegoOstuni 1:86504e1ac6b1 53 #if (USE_LOGGER == LOGGER_ON)
DiegoOstuni 1:86504e1ac6b1 54
DiegoOstuni 1:86504e1ac6b1 55 #define MAX_HEX_STR 4
DiegoOstuni 1:86504e1ac6b1 56 #define MAX_HEX_STR_LENGTH 128
DiegoOstuni 1:86504e1ac6b1 57 char hexStr[MAX_HEX_STR][MAX_HEX_STR_LENGTH];
DiegoOstuni 1:86504e1ac6b1 58 uint8_t hexStrIdx = 0;
DiegoOstuni 1:86504e1ac6b1 59 #endif /* #if USE_LOGGER == LOGGER_ON */
DiegoOstuni 1:86504e1ac6b1 60
DiegoOstuni 1:86504e1ac6b1 61 #define USART_TIMEOUT 1000
DiegoOstuni 1:86504e1ac6b1 62
DiegoOstuni 1:86504e1ac6b1 63 UART_HandleTypeDef *pLogUsart = 0;
DiegoOstuni 1:86504e1ac6b1 64 uint8_t logUsartTx(uint8_t *data, uint16_t dataLen);
DiegoOstuni 1:86504e1ac6b1 65
DiegoOstuni 1:86504e1ac6b1 66 /**
DiegoOstuni 1:86504e1ac6b1 67 * @brief This function initalize the UART handle.
DiegoOstuni 1:86504e1ac6b1 68 * @param husart : already initalized handle to USART HW
DiegoOstuni 1:86504e1ac6b1 69 * @retval none :
DiegoOstuni 1:86504e1ac6b1 70 */
DiegoOstuni 1:86504e1ac6b1 71 void logUsartInit(UART_HandleTypeDef *husart)
DiegoOstuni 1:86504e1ac6b1 72 {
DiegoOstuni 1:86504e1ac6b1 73 pLogUsart = husart;
DiegoOstuni 1:86504e1ac6b1 74 }
DiegoOstuni 1:86504e1ac6b1 75
DiegoOstuni 1:86504e1ac6b1 76 /**
DiegoOstuni 1:86504e1ac6b1 77 * @brief This function Transmit data via USART
DiegoOstuni 1:86504e1ac6b1 78 * @param data : data to be transmitted
DiegoOstuni 1:86504e1ac6b1 79 * @param dataLen : length of data to be transmitted
DiegoOstuni 1:86504e1ac6b1 80 * @retval ERR_INVALID_HANDLE : in case the SPI HW is not initalized yet
DiegoOstuni 1:86504e1ac6b1 81 * @retval others : HAL status
DiegoOstuni 1:86504e1ac6b1 82 */
DiegoOstuni 1:86504e1ac6b1 83 uint8_t logUsartTx(uint8_t *data, uint16_t dataLen)
DiegoOstuni 1:86504e1ac6b1 84 {
DiegoOstuni 1:86504e1ac6b1 85 if(pLogUsart == 0)
DiegoOstuni 1:86504e1ac6b1 86 return ERR_INVALID_HANDLE;
DiegoOstuni 1:86504e1ac6b1 87
DiegoOstuni 1:86504e1ac6b1 88 return HAL_UART_Transmit(pLogUsart, data, dataLen, USART_TIMEOUT);
DiegoOstuni 1:86504e1ac6b1 89 }
DiegoOstuni 1:86504e1ac6b1 90
DiegoOstuni 1:86504e1ac6b1 91 int logUsart(const char* format, ...)
DiegoOstuni 1:86504e1ac6b1 92 {
DiegoOstuni 1:86504e1ac6b1 93 #if (USE_LOGGER == LOGGER_ON)
DiegoOstuni 1:86504e1ac6b1 94 {
DiegoOstuni 1:86504e1ac6b1 95 #define LOG_BUFFER_SIZE 256
DiegoOstuni 1:86504e1ac6b1 96 char buf[LOG_BUFFER_SIZE];
DiegoOstuni 1:86504e1ac6b1 97 va_list argptr;
DiegoOstuni 1:86504e1ac6b1 98 va_start(argptr, format);
DiegoOstuni 1:86504e1ac6b1 99 int cnt = vsnprintf(buf, LOG_BUFFER_SIZE, format, argptr);
DiegoOstuni 1:86504e1ac6b1 100 va_end(argptr);
DiegoOstuni 1:86504e1ac6b1 101
DiegoOstuni 1:86504e1ac6b1 102 /* */
DiegoOstuni 1:86504e1ac6b1 103 logUsartTx((uint8_t*)buf, strlen(buf));
DiegoOstuni 1:86504e1ac6b1 104 return cnt;
DiegoOstuni 1:86504e1ac6b1 105 }
DiegoOstuni 1:86504e1ac6b1 106 #else
DiegoOstuni 1:86504e1ac6b1 107 {
DiegoOstuni 1:86504e1ac6b1 108 return 0;
DiegoOstuni 1:86504e1ac6b1 109 }
DiegoOstuni 1:86504e1ac6b1 110 #endif /* #if USE_LOGGER == LOGGER_ON */
DiegoOstuni 1:86504e1ac6b1 111 }
DiegoOstuni 1:86504e1ac6b1 112
DiegoOstuni 1:86504e1ac6b1 113 /* */
DiegoOstuni 1:86504e1ac6b1 114
DiegoOstuni 1:86504e1ac6b1 115 char* hex2Str(unsigned char * data, size_t dataLen)
DiegoOstuni 1:86504e1ac6b1 116 {
DiegoOstuni 1:86504e1ac6b1 117 #if (USE_LOGGER == LOGGER_ON)
DiegoOstuni 1:86504e1ac6b1 118 {
DiegoOstuni 1:86504e1ac6b1 119 unsigned char * pin = data;
DiegoOstuni 1:86504e1ac6b1 120 const char * hex = "0123456789ABCDEF";
DiegoOstuni 1:86504e1ac6b1 121 char * pout = hexStr[hexStrIdx];
DiegoOstuni 1:86504e1ac6b1 122 uint8_t i = 0;
DiegoOstuni 1:86504e1ac6b1 123 uint8_t idx = hexStrIdx;
DiegoOstuni 1:86504e1ac6b1 124 if(dataLen == 0)
DiegoOstuni 1:86504e1ac6b1 125 {
DiegoOstuni 1:86504e1ac6b1 126 pout[0] = 0;
DiegoOstuni 1:86504e1ac6b1 127 }
DiegoOstuni 1:86504e1ac6b1 128 else
DiegoOstuni 1:86504e1ac6b1 129 {
DiegoOstuni 1:86504e1ac6b1 130 for(; i < dataLen - 1; ++i)
DiegoOstuni 1:86504e1ac6b1 131 {
DiegoOstuni 1:86504e1ac6b1 132 *pout++ = hex[(*pin>>4)&0xF];
DiegoOstuni 1:86504e1ac6b1 133 *pout++ = hex[(*pin++)&0xF];
DiegoOstuni 1:86504e1ac6b1 134 }
DiegoOstuni 1:86504e1ac6b1 135 *pout++ = hex[(*pin>>4)&0xF];
DiegoOstuni 1:86504e1ac6b1 136 *pout++ = hex[(*pin)&0xF];
DiegoOstuni 1:86504e1ac6b1 137 *pout = 0;
DiegoOstuni 1:86504e1ac6b1 138 }
DiegoOstuni 1:86504e1ac6b1 139
DiegoOstuni 1:86504e1ac6b1 140 hexStrIdx++;
DiegoOstuni 1:86504e1ac6b1 141 hexStrIdx %= MAX_HEX_STR;
DiegoOstuni 1:86504e1ac6b1 142
DiegoOstuni 1:86504e1ac6b1 143 return hexStr[idx];
DiegoOstuni 1:86504e1ac6b1 144 }
DiegoOstuni 1:86504e1ac6b1 145 #else
DiegoOstuni 1:86504e1ac6b1 146 {
DiegoOstuni 1:86504e1ac6b1 147 return NULL;
DiegoOstuni 1:86504e1ac6b1 148 }
DiegoOstuni 1:86504e1ac6b1 149 #endif /* #if USE_LOGGER == LOGGER_ON */
DiegoOstuni 1:86504e1ac6b1 150 }