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

source/logger.cpp

Committer:
DiegoOstuni
Date:
2019-11-14
Revision:
1:86504e1ac6b1

File content as of revision 1:86504e1ac6b1:

/******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
  *
  * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/myliberty
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
******************************************************************************/
/*
 *      PROJECT:   
 *      $Revision: $
 *      LANGUAGE:  ANSI C
 */

/*! \file
 *
 *  \author 
 *
 *  \brief Debug log output utility implementation.
 *
 */

/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
//#include "usart.h"
#include "logger.h"
#include "st_errno.h"
#include <string.h>
#include <stdarg.h>

/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/

      
#if (USE_LOGGER == LOGGER_ON)

#define MAX_HEX_STR         4
#define MAX_HEX_STR_LENGTH  128
char hexStr[MAX_HEX_STR][MAX_HEX_STR_LENGTH];
uint8_t hexStrIdx = 0;
#endif /* #if USE_LOGGER == LOGGER_ON */

#define USART_TIMEOUT          1000

UART_HandleTypeDef *pLogUsart = 0;
uint8_t logUsartTx(uint8_t *data, uint16_t dataLen);

/**
  * @brief  This function initalize the UART handle.
    * @param    husart : already initalized handle to USART HW
  * @retval none :
  */
void logUsartInit(UART_HandleTypeDef *husart)
{
    pLogUsart = husart;
}

/**
  * @brief  This function Transmit data via USART
    * @param    data : data to be transmitted
    * @param    dataLen : length of data to be transmitted
  * @retval ERR_INVALID_HANDLE : in case the SPI HW is not initalized yet
  * @retval others : HAL status
  */
uint8_t logUsartTx(uint8_t *data, uint16_t dataLen)
{
  if(pLogUsart == 0)
    return ERR_INVALID_HANDLE;

  return HAL_UART_Transmit(pLogUsart, data, dataLen, USART_TIMEOUT);
}

int logUsart(const char* format, ...)
{
  #if (USE_LOGGER == LOGGER_ON)
  {  
    #define LOG_BUFFER_SIZE 256
    char buf[LOG_BUFFER_SIZE];
    va_list argptr;
    va_start(argptr, format);
    int cnt = vsnprintf(buf, LOG_BUFFER_SIZE, format, argptr);
    va_end(argptr);  
      
    /* */
    logUsartTx((uint8_t*)buf, strlen(buf));
    return cnt;
  }
  #else
  {
    return 0;
  }
  #endif /* #if USE_LOGGER == LOGGER_ON */
}

/* */

char* hex2Str(unsigned char * data, size_t dataLen)
{
  #if (USE_LOGGER == LOGGER_ON)
  {
    unsigned char * pin = data;
    const char * hex = "0123456789ABCDEF";
    char * pout = hexStr[hexStrIdx];
    uint8_t i = 0;
    uint8_t idx = hexStrIdx;
    if(dataLen == 0)
    {
      pout[0] = 0;     
    } 
    else     
    {
      for(; i < dataLen - 1; ++i)
      {
          *pout++ = hex[(*pin>>4)&0xF];
          *pout++ = hex[(*pin++)&0xF];
      }
      *pout++ = hex[(*pin>>4)&0xF];
      *pout++ = hex[(*pin)&0xF];
      *pout = 0;
    }    
    
    hexStrIdx++;
    hexStrIdx %= MAX_HEX_STR;
    
    return hexStr[idx];
  }
  #else
  {
    return NULL;
  }
  #endif /* #if USE_LOGGER == LOGGER_ON */
}