This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new fddebc267d arm/stm32f401rc-rs485: Add support to RFID MFRC522
fddebc267d is described below

commit fddebc267d73abc930e9465fe451a0a3f635aebe
Author: Rodrigo Sim <[email protected]>
AuthorDate: Sun Aug 4 16:14:55 2024 -0300

    arm/stm32f401rc-rs485: Add support to RFID MFRC522
    
    Signed-off-by: Rodrigo Sim [email protected]
---
 .../arm/stm32f4/boards/stm32f401rc-rs485/index.rst |  27 +++++++
 .../boards/stm32f401rc-rs485/mfrc522_image.jpg     | Bin 0 -> 53856 bytes
 boards/arm/stm32/common/include/stm32_mfrc522.h    |  79 +++++++++++++++++++
 boards/arm/stm32/common/src/CMakeLists.txt         |   4 +
 boards/arm/stm32/common/src/Make.defs              |   4 +
 boards/arm/stm32/common/src/stm32_mfrc522.c        |  84 +++++++++++++++++++++
 .../stm32f401rc-rs485/configs/mfrc522/defconfig    |  66 ++++++++++++++++
 boards/arm/stm32/stm32f401rc-rs485/include/board.h |   4 +
 .../stm32/stm32f401rc-rs485/src/stm32_bringup.c    |  12 +++
 boards/arm/stm32/stm32f401rc-rs485/src/stm32_spi.c |  11 +++
 10 files changed, 291 insertions(+)

diff --git 
a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst 
b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst
index c550958f03..339f5064e7 100644
--- a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst
+++ b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst
@@ -664,3 +664,30 @@ you can configure this using menuconfig::
 
        Number of 8x8 LEDs matrices in the horizontal (width)
        Number of 8x8 LEDs matrices in the vertical (height)
+
+mfrc522
+-------
+
+Configures the NuttShell (nsh) over USB Serial (check usbserial configuration) 
and enables RFID driver with
+MFRC522::
+
+       nsh> rfid_readuid
+       Trying to READ: Card is not present!
+       Trying to READ: Card is not present!
+       Trying to READ: RFID CARD UID = 0x3DB3F169
+
+
+======= ====
+MFRC522 PINS
+======= ====
+SCK     PA5
+MISO    PA6
+MOSI    PA7
+CS      PC5  
+======= ====
+
+The board used is based on MFRC522 NXP IC that supports contactless 
communication
+at 13.56 MHz and ISO/IEC 14443 A/MIFARE and NTAG.
+
+.. figure:: mfrc522_image.jpg
+   :align: center
diff --git 
a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/mfrc522_image.jpg
 
b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/mfrc522_image.jpg
new file mode 100644
index 0000000000..6381a4c3f8
Binary files /dev/null and 
b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/mfrc522_image.jpg
 differ
diff --git a/boards/arm/stm32/common/include/stm32_mfrc522.h 
b/boards/arm/stm32/common/include/stm32_mfrc522.h
new file mode 100644
index 0000000000..75f7266d5f
--- /dev/null
+++ b/boards/arm/stm32/common/include/stm32_mfrc522.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * boards/arm/stm32/common/include/stm32_mfrc522.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_MFRC522_H
+#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_MFRC522_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_mfrc522initialize
+ *
+ * Description:
+ *   Initialize and register the MFRC522 RFID driver.
+ *
+ * Input Parameters:
+ *   devpath - The full path to the driver to register. E.g., "/dev/rfid0"
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int stm32_mfrc522initialize(const char *devpath);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_MFRC522_H */
diff --git a/boards/arm/stm32/common/src/CMakeLists.txt 
b/boards/arm/stm32/common/src/CMakeLists.txt
index cfd9465b74..4c6c4df796 100644
--- a/boards/arm/stm32/common/src/CMakeLists.txt
+++ b/boards/arm/stm32/common/src/CMakeLists.txt
@@ -120,6 +120,10 @@ if(CONFIG_LCD_MAX7219)
   list(APPEND SRCS stm32_max7219_matrix.c)
 endif()
 
+if(CONFIG_CL_MFRC522)
+  list(APPEND SRCS stm32_mfrc522.c)
+endif()
+
 if(CONFIG_LIS3DSH)
   list(APPEND SRCS stm32_lis3dsh.c)
 endif()
diff --git a/boards/arm/stm32/common/src/Make.defs 
b/boards/arm/stm32/common/src/Make.defs
index 324c1e66c2..ddb698c13b 100644
--- a/boards/arm/stm32/common/src/Make.defs
+++ b/boards/arm/stm32/common/src/Make.defs
@@ -128,6 +128,10 @@ ifeq ($(CONFIG_LCD_MAX7219),y)
   CSRCS += stm32_max7219_matrix.c
 endif
 
+ifeq ($(CONFIG_CL_MFRC522),y)
+  CSRCS += stm32_mfrc522.c
+endif
+
 ifeq ($(CONFIG_LIS3DSH),y)
   CSRCS += stm32_lis3dsh.c
 endif
diff --git a/boards/arm/stm32/common/src/stm32_mfrc522.c 
b/boards/arm/stm32/common/src/stm32_mfrc522.c
new file mode 100644
index 0000000000..4fda6901f6
--- /dev/null
+++ b/boards/arm/stm32/common/src/stm32_mfrc522.c
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * boards/arm/stm32/common/src/stm32_mfrc522.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/board.h>
+#include <nuttx/spi/spi.h>
+#include <nuttx/contactless/mfrc522.h>
+
+#include "stm32.h"
+#include "stm32_spi.h"
+
+#if defined(CONFIG_SPI) && defined(CONFIG_STM32_SPI1) && 
defined(CONFIG_CL_MFRC522)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MFRC522_SPI_PORTNO 1   /* On SPI1 */
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_mfrc522initialize
+ *
+ * Description:
+ *   Initialize and register the MFRC522 RFID driver.
+ *
+ * Input Parameters:
+ *   devpath - The full path to the driver to register. E.g., "/dev/rfid0"
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int stm32_mfrc522initialize(const char *devpath)
+{
+  struct spi_dev_s *spi;
+  int ret;
+  spi = stm32_spibus_initialize(MFRC522_SPI_PORTNO);
+  if (!spi)
+    {
+      return -ENODEV;
+    }
+
+  /* Then register the MFRC522 */
+
+  ret = mfrc522_register(devpath, spi);
+  if (ret < 0)
+    {
+      snerr("ERROR: Error registering MFRC522\n");
+    }
+
+  return ret;
+}
+
+#endif /* CONFIG_SPI && CONFIG_MFRC522 */
diff --git a/boards/arm/stm32/stm32f401rc-rs485/configs/mfrc522/defconfig 
b/boards/arm/stm32/stm32f401rc-rs485/configs/mfrc522/defconfig
new file mode 100644
index 0000000000..2f0acaf0e4
--- /dev/null
+++ b/boards/arm/stm32/stm32f401rc-rs485/configs/mfrc522/defconfig
@@ -0,0 +1,66 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed 
.config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that 
includes your
+# modifications.
+#
+# CONFIG_ARCH_FPU is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+# CONFIG_NSH_DISABLE_IFCONFIG is not set
+# CONFIG_NSH_DISABLE_PS is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="stm32f401rc-rs485"
+CONFIG_ARCH_BOARD_COMMON=y
+CONFIG_ARCH_BOARD_STM32F401RC_RS485=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_CHIP="stm32"
+CONFIG_ARCH_CHIP_STM32=y
+CONFIG_ARCH_CHIP_STM32F401RC=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_IRQBUTTONS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARDCTL_USBDEVCTRL=y
+CONFIG_BOARD_LOOPSPERMSEC=8499
+CONFIG_BUILTIN=y
+CONFIG_CDCACM=y
+CONFIG_CDCACM_CONSOLE=y
+CONFIG_CL_MFRC522=y
+CONFIG_DRIVERS_CONTACTLESS=y
+CONFIG_EXAMPLES_BUTTONS=y
+CONFIG_EXAMPLES_BUTTONS_NAME0="SW3"
+CONFIG_EXAMPLES_BUTTONS_NAME1="SW4"
+CONFIG_EXAMPLES_BUTTONS_NAME2="SW5"
+CONFIG_EXAMPLES_BUTTONS_NAMES=y
+CONFIG_EXAMPLES_BUTTONS_QTD=3
+CONFIG_EXAMPLES_RFID_READUID=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INPUT=y
+CONFIG_INPUT_BUTTONS=y
+CONFIG_INPUT_BUTTONS_LOWER=y
+CONFIG_INTELHEX_BINARY=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=98304
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_START_DAY=5
+CONFIG_START_MONTH=5
+CONFIG_START_YEAR=2014
+CONFIG_STM32_JTAG_SW_ENABLE=y
+CONFIG_STM32_OTGFS=y
+CONFIG_STM32_PWR=y
+CONFIG_STM32_SPI1=y
+CONFIG_STM32_USART6=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_USBDEV=y
diff --git a/boards/arm/stm32/stm32f401rc-rs485/include/board.h 
b/boards/arm/stm32/stm32f401rc-rs485/include/board.h
index 706c266a14..1deaf475cd 100644
--- a/boards/arm/stm32/stm32f401rc-rs485/include/board.h
+++ b/boards/arm/stm32/stm32f401rc-rs485/include/board.h
@@ -340,6 +340,10 @@ extern "C"
 #define STM32_LCD_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
                            GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN4)
 
+/* MFRC522 */
+
+#define GPIO_RFID_CS      (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
+                           GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN5)
 /* LEDs
  *
  * The STM32F401RC-RS485 boards provide 4 blue user LEDs. LD1, LD2, LD3
diff --git a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c 
b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c
index d1d0833799..cd8f236be0 100644
--- a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c
+++ b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c
@@ -67,6 +67,10 @@
 #include "stm32_max7219_matrix.h"
 #endif
 
+#ifdef CONFIG_CL_MFRC522
+#include "stm32_mfrc522.h"
+#endif
+
 #ifdef CONFIG_STEPPER_DRV8825
 #include "stm32_drv8266.h"
 #endif
@@ -286,5 +290,13 @@ int stm32_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_CL_MFRC522
+  ret = stm32_mfrc522initialize("/dev/rfid0");
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: stm32_mfrc522initialize() failed: %d\n", ret);
+    }
+#endif
+
   return ret;
 }
diff --git a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_spi.c 
b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_spi.c
index 987e225145..fd7bfeb72b 100644
--- a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_spi.c
+++ b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_spi.c
@@ -62,6 +62,10 @@ void weak_function stm32_spidev_initialize(void)
 #ifdef CONFIG_LCD_MAX7219
   stm32_configgpio(STM32_LCD_CS);    /* MAX7219 chip select */
 #endif
+
+#ifdef CONFIG_CL_MFRC522
+  stm32_configgpio(GPIO_RFID_CS);    /* MFRC522 chip select */
+#endif
 }
 
 /****************************************************************************
@@ -110,6 +114,13 @@ void stm32_spi1select(struct spi_dev_s *dev,
       stm32_gpiowrite(STM32_LCD_CS, !selected);
     }
   #endif
+
+  #if defined(CONFIG_CL_MFRC522)
+  if (devid == SPIDEV_CONTACTLESS(0))
+    {
+      stm32_gpiowrite(GPIO_RFID_CS, !selected);
+    }
+  #endif
 }
 
 uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid)

Reply via email to