boards/arm/stm32f401rc-rs485: Add support to MAX31855 and MAX6675

This commit adds support for MAX31855 and MAX6675 thermocouple
sensors on the STM32F401RC-RS485 board via SPI1. It also updates
the board documentation accordingly.

Signed-off-by: Rodrigo Sim <rcsim10@gmail.com>
This commit is contained in:
Rodrigo Sim 2025-07-26 12:25:06 -03:00 committed by Alan C. Assis
parent 80e1f70832
commit a8ac255386
4 changed files with 166 additions and 1 deletions

View file

@ -1000,3 +1000,110 @@ Connect the HX711 to the STM32F4 board using the following pins:
10
For more details, refer to the official `HX711 NuttX documentation <https://nuttx.apache.org/docs/latest/components/drivers/character/analog/adc/hx711/index.html>`_.
MAX31855
--------
MAX31855 is a thermocouple-to-digital converter supporting Type-K
thermocouples. It provides 14-bit temperature resolution with cold-junction
compensation and fault detection, interfacing via SPI.
**Enable the following options using ``make menuconfig``:**
::
CONFIG_STM32_SPI1=y
CONFIG_SENSORS=y
CONFIG_SENSORS_MAX31855=y
CONFIG_EXAMPLES_MAX31855=y
**Wiring:**
Connect the MAX31855 to the STM32F4 board using the following pins:
+-------------+------+
| MAX31855 | PIN |
+=============+======+
| SCK | PA5 |
+-------------+------+
| CS | PC4 |
+-------------+------+
| SO (MISO) | PA6 |
+-------------+------+
**NSH usage:**
::
NuttShell (NSH) NuttX-12.10.0
nsh> ls /dev/temp0
/dev/temp0
nsh> max31855
Unable to open file /dev/temp1
Unable to open file /dev/temp2
Unable to open file /dev/temp3
Starting...
Channel SSP0/SPI1 Device 0: Temperature = 24!
Channel SSP0/SPI1 Device 1: Not enabled!
Channel SSP1/SPI2 Device 0: Not enabled!
Channel SSP1/SPI2 Device 1: Not enabled!
Channel SSP0/SPI1 Device 0: Temperature = 25!
Channel SSP0/SPI1 Device 1: Not enabled!
Channel SSP1/SPI2 Device 0: Not enabled!
Channel SSP1/SPI2 Device 1: Not enabled!
MAX6675
-------
MAX6675 is a cold-junction-compensated K-type thermocouple-to-digital
converter with a 12-bit resolution. It communicates via SPI and is
suited for measuring high temperatures in embedded systems.
**Enable the following options using ``make menuconfig``:**
::
CONFIG_STM32_SPI1=y
CONFIG_SENSORS=y
CONFIG_SENSORS_MAX6675=y
CONFIG_EXAMPLES_MAX31855=y (same example works for both)
**Wiring:**
Connect the MAX6675 to the STM32F4 board using the following pins:
+-------------+------+
| MAX6675 | PIN |
+=============+======+
| SCK | PA5 |
+-------------+------+
| CS | PC5 |
+-------------+------+
| SO (MISO) | PA6 |
+-------------+------+
**NSH usage:**
::
NuttShell (NSH) NuttX-12.10.0
nsh> ls /dev/temp0
/dev/temp0
nsh> max31855
Unable to open file /dev/temp1
Unable to open file /dev/temp2
Unable to open file /dev/temp3
Starting...
Channel SSP0/SPI1 Device 0: Temperature = 24!
Channel SSP0/SPI1 Device 1: Not enabled!
Channel SSP1/SPI2 Device 0: Not enabled!
Channel SSP1/SPI2 Device 1: Not enabled!
Channel SSP0/SPI1 Device 0: Temperature = 24!
Channel SSP0/SPI1 Device 1: Not enabled!
Channel SSP1/SPI2 Device 0: Not enabled!
Channel SSP1/SPI2 Device 1: Not enabled!

View file

@ -346,6 +346,16 @@ extern "C"
#define GPIO_RFID_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN5)
/* MAX31855 */
#define GPIO_MAX31855_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN4)
/* MAX6675 */
#define GPIO_MAX6675_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

View file

@ -93,6 +93,14 @@
#include "stm32_bmp180.h"
#endif
#ifdef CONFIG_SENSORS_MAX31855
#include "stm32_max31855.h"
#endif
#ifdef CONFIG_SENSORS_MAX6675
#include "stm32_max6675.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -182,6 +190,24 @@ int stm32_bringup(void)
stm32_i2ctool();
#endif
#ifdef CONFIG_SENSORS_MAX31855
/* Register device 0 on spi channel 1 */
ret = board_max31855_initialize(0, 1);
if (ret < 0)
{
serr("ERROR: stm32_max31855initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_SENSORS_MAX6675
ret = board_max6675_initialize(0, 1);
if (ret < 0)
{
serr("ERROR: stm32_max6675initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_I2C_EE_24XX
ret = stm32_at24_init("/dev/eeprom");
if (ret < 0)

View file

@ -68,6 +68,14 @@ void weak_function stm32_spidev_initialize(void)
#ifdef CONFIG_CL_MFRC522
stm32_configgpio(GPIO_RFID_CS); /* MFRC522 chip select */
#endif
#if defined(CONFIG_STM32_SPI1) && defined(CONFIG_SENSORS_MAX31855)
stm32_configgpio(GPIO_MAX31855_CS); /* MAX31855 chip select */
#endif
#if defined(CONFIG_STM32_SPI1) && defined(CONFIG_SENSORS_MAX66755)
stm32_configgpio(GPIO_MAX6675_CS); /* MAX6675 chip select */
#endif
}
/****************************************************************************
@ -103,7 +111,7 @@ void stm32_spi1select(struct spi_dev_s *dev,
spiinfo("devid: %d CS: %s\n",
(int)devid, selected ? "assert" : "de-assert");
#if defined(CONFIG_LCD_SSD1306) || defined(CONFIG_LCD_ST7735)
#if defined(CONFIG_LCD_SSD1306) || defined(CONFIG_LCD_ST7735)
if (devid == SPIDEV_DISPLAY(0))
{
stm32_gpiowrite(GPIO_LCD_CS, !selected);
@ -123,6 +131,20 @@ void stm32_spi1select(struct spi_dev_s *dev,
stm32_gpiowrite(GPIO_RFID_CS, !selected);
}
#endif
#if defined(CONFIG_SENSORS_MAX31855)
if (devid == SPIDEV_TEMPERATURE(0))
{
stm32_gpiowrite(GPIO_MAX31855_CS, !selected);
}
#endif
#if defined(CONFIG_SENSORS_MAX6675)
if (devid == SPIDEV_TEMPERATURE(0))
{
stm32_gpiowrite(GPIO_MAX6675_CS, !selected);
}
#endif
}
uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid)