From a5754a2f03bbdba8084f60dfcf235cb823c56d05 Mon Sep 17 00:00:00 2001 From: Rodrigo Sim Date: Sat, 21 Sep 2024 11:25:27 -0300 Subject: [PATCH] arm/stm32f401rc-rs485: Add support to LCD 16x2 with I2C Backpack Signed-off-by: Rodrigo Sim rcsim10@gmail.com --- .../boards/stm32f401rc-rs485/index.rst | 43 +++++++++++- .../configs/lcd1602/defconfig | 68 +++++++++++++++++++ .../stm32f401rc-rs485/src/stm32_bringup.c | 15 ++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 boards/arm/stm32/stm32f401rc-rs485/configs/lcd1602/defconfig diff --git a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst index 20d067d01b..95c1087812 100644 --- a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst +++ b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst @@ -699,6 +699,13 @@ Configures the NuttShell (nsh) over USB Serial (check usbserial configuration) a BMP280 has an I2C address that can be configure by SDO. Connecting SDO to GND results in slave address 0x76, connection it to VDD results in slave address 0x77. This can be configured by enabling BMP280_I2C_ADDR_76 or BMP280_I2C_ADDR_77. This configuration uses I2C1 and slave address 0x77. +======= ===== +SENSOR PINS +======= ===== +SDA PA7 +SCK PB8 +======= ===== + NSH commands:: NuttShell (NSH) NuttX-12.6.0-RC1 @@ -709,4 +716,38 @@ NSH commands:: Absolute pressure [hPa] = 932.650024 Temperature [C] = 24.490000 -There is a known issue where every time the sensor is initialized, the first measurement is wrong, please check https://github.com/apache/nuttx/issues/12421 for the latest updates on this issue. \ No newline at end of file +There is a known issue where every time the sensor is initialized, the first measurement is wrong, please check https://github.com/apache/nuttx/issues/12421 for the latest updates on this issue. + +lcd1602 +------- + +This configuration sets up the NuttShell (NSH) interface over USB Serial (refer to the usbserial +configuration for details). It also enables I2C1 and the driver for an alphanumeric/segment LCD. +Specifically, the setup supports a 16x2 LCD screen based on the HD44780 controller, which is +interfaced using an I2C adapter known as the LCD Backpack, utilizing the PCF8574 chip. + +======= ===== +LCD PINS +======= ===== +SDA PA7 +SCK PB8 +======= ===== + +NSH commands:: + + nsh> slcd "Hello NuttX" + Opening /dev/slcd0 for read/write access + Attributes: + rows: 2 columns: 16 nbars: 0 + max contrast: 0 max brightness: 1 + Clear screen + WRITING: + 0000: 1b5b46 .[F + Set brightness to 1 + Print [Hello NuttX] + WRITING: + 0000: 1b5b471b5b30304c1b5b4548656c6c6f 204e75747458 .[G.[00L.[EHello NuttX + Test complete + nsh> + + diff --git a/boards/arm/stm32/stm32f401rc-rs485/configs/lcd1602/defconfig b/boards/arm/stm32/stm32f401rc-rs485/configs/lcd1602/defconfig new file mode 100644 index 0000000000..a2ecac7598 --- /dev/null +++ b/boards/arm/stm32/stm32f401rc-rs485/configs/lcd1602/defconfig @@ -0,0 +1,68 @@ +# +# 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_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_SLCD=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2C=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INPUT=y +CONFIG_INPUT_BUTTONS=y +CONFIG_INPUT_BUTTONS_LOWER=y +CONFIG_INTELHEX_BINARY=y +CONFIG_LCD_BACKPACK=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_SLCD=y +CONFIG_SPI=y +CONFIG_START_DAY=5 +CONFIG_START_MONTH=5 +CONFIG_START_YEAR=2014 +CONFIG_STM32_I2C1=y +CONFIG_STM32_JTAG_SW_ENABLE=y +CONFIG_STM32_OTGFS=y +CONFIG_STM32_PWR=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/src/stm32_bringup.c b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c index b513580b4f..fb03c70efa 100644 --- a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_bringup.c @@ -79,6 +79,10 @@ #include "stm32_bmp280.h" #endif +#ifdef CONFIG_LCD_BACKPACK +#include "stm32_lcd_backpack.h" +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -313,5 +317,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_LCD_BACKPACK + /* slcd:0, i2c:1, rows=2, cols=16 */ + + ret = board_lcd_backpack_init(0, 1, 2, 16); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret); + return ret; + } +#endif + return ret; }