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

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

commit d805ea1b15fbc2c387226881331b7be10f39bb9c
Author: raiden00pl <[email protected]>
AuthorDate: Mon Oct 12 09:51:21 2026 +0200

    boards/arm/common/stm32: make the MFRC522 SPI bus and reset configurable
    
    A board can select the MFRC522 SPI bus with BOARD_MFRC522_SPI (SPI1 by
    default) and a reset pin with BOARD_MFRC522_GPIO_RESET in board.h, so
    boards with a different wiring can use the common driver setup.
    
    Signed-off-by: raiden00pl <[email protected]>
    Assisted-by: Claude Code
---
 boards/arm/common/stm32/src/stm32_mfrc522.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/boards/arm/common/stm32/src/stm32_mfrc522.c 
b/boards/arm/common/stm32/src/stm32_mfrc522.c
index 0da85237c69..9ab46e04809 100644
--- a/boards/arm/common/stm32/src/stm32_mfrc522.c
+++ b/boards/arm/common/stm32/src/stm32_mfrc522.c
@@ -33,16 +33,24 @@
 #include <nuttx/spi/spi.h>
 #include <nuttx/contactless/mfrc522.h>
 
+#include <arch/board/board.h>
+
 #include "stm32.h"
 #include "stm32_spi.h"
 
-#if defined(CONFIG_SPI) && defined(CONFIG_STM32_SPI1) && 
defined(CONFIG_CL_MFRC522)
+#if defined(CONFIG_SPI) && defined(CONFIG_CL_MFRC522)
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define MFRC522_SPI_PORTNO 1   /* On SPI1 */
+/* The board can select the SPI bus with BOARD_MFRC522_SPI, SPI1 by default */
+
+#ifdef BOARD_MFRC522_SPI
+#  define MFRC522_SPI_PORTNO BOARD_MFRC522_SPI
+#else
+#  define MFRC522_SPI_PORTNO 1
+#endif
 
 /****************************************************************************
  * Public Functions
@@ -66,6 +74,14 @@ int stm32_mfrc522initialize(const char *devpath)
 {
   struct spi_dev_s *spi;
   int ret;
+
+#ifdef BOARD_MFRC522_GPIO_RESET
+  /* MFRC522 hardware reset on rising edge */
+
+  stm32_configgpio(BOARD_MFRC522_GPIO_RESET);
+  stm32_gpiowrite(BOARD_MFRC522_GPIO_RESET, true);
+#endif
+
   spi = stm32_spibus_initialize(MFRC522_SPI_PORTNO);
   if (!spi)
     {

Reply via email to