diff --git a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst index 1371b309211..38d9c014af0 100644 --- a/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst +++ b/Documentation/platforms/arm/stm32f4/boards/stm32f401rc-rs485/index.rst @@ -69,31 +69,32 @@ User Buttons The STM32F4-RS485 has 4 user switches. -======= ===== -SWITCH PINS -======= ===== -SWIO_1 PB13 -SWIO_2 PB14 -SWIO_3 PB15 -SWIO_4 PC6 -======= ===== +======= ===== ====== +SWITCH PINS LABEL +======= ===== ====== +SWIO_1 PB13 SW3 +SWIO_2 PB14 SW4 +SWIO_3 PB15 SW5 +SWIO_4 PC6 SW6[1] +======= ===== ====== + +[1] The switch SWIO_4 (SW6) is disabled due a conflict with PIN +PC6 when using USART6. UARTs ===== The STM32F4-RS485 has 1 USART available for user. -USART2 +USART6 ------ ========== ======= UART/USART PINS ========== ======= -CTS PA0 -RTS PA1 -TX PA2 [1] -RX PA3 -CK PA4 +TX PC6 [1] +RX PC7 +CK PA8 ========== ======= [1] Warning you make need to reverse RX/TX on some RS-232 converters @@ -174,7 +175,7 @@ USART2 PINS ========== ===== USART2_RX RO USART2_RTS DE, /RE -SART2_RX DI +USART2_RX DI ========== ===== A/D Converter @@ -221,7 +222,7 @@ nsh --- Configures the NuttShell (nsh) located at apps/examples/nsh. This -configuration enables a serial console on UART2. +configuration enables a serial console on USART6. sdcard ------ @@ -235,3 +236,81 @@ NSH commands:: nsh> mount -t procfs /proc nsh> mount -t vfat /dev/mmcsd0 /mnt +modbus_slave +------------ + +Configures the NuttShell (nsh) and enables modbus in slave mode. This +configuration enables a serial console on USART6. The RS-485 is connected +to USART2. Follow below precedure to use modbus test aplication, you will +need a USB to RS-485 converter to connect the board to a PC via RS-485. + +NuttShell configuration: + +Run modbus application at NSH:: + + nsh> modbus -help + USAGE: modbus [-d|e|s|q|h] + + Where: + -d : Disable protocol stack + -e : Enable the protocol stack + -s : Show current status + -q : Quit application + -h : Show this information + + nsh> modbus -e + +PC Configuration: + +Download and install mbpoll aplication:: + + sudo apt install mbpoll + +Check which TTY USB port is being used by you USB to RS-485 converter:: + + sudo dmesg + [99846.668209] usb 1-1.3: Product: USB Serial + [99846.676313] ch341 1-1.3:1.0: ch341-uart converter detected + [99846.677454] usb 1-1.3: ch341-uart converter now attached to ttyUSB1 + +Run the mbpoll as below:: + + mbpoll -a 10 -b 38400 -t 3 -r 1000 -c 4 /dev/ttyUSB1 -R + + +At PC terminal you will see the mbpoll application receiving the random values +generated by STM32F401RC-RS485 and transmitted over RS-485:: + + mbpoll 1.0-0 - FieldTalk(tm) Modbus(R) Master Simulator + Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll + This program comes with ABSOLUTELY NO WARRANTY. + This is free software, and you are welcome to redistribute it + under certain conditions; type 'mbpoll -w' for details. + + Protocol configuration: Modbus RTU + Slave configuration...: address = [10] + start reference = 1000, count = 4 + Communication.........: /dev/ttyUSB1, 38400-8E1 + t/o 1.00 s, poll rate 1000 ms + Data type.............: 16-bit register, input register table + -- Polling slave 10... Ctrl-C to stop) + [1000]: 58080 (-7456) + [1001]: 0 + [1002]: 0 + [1003]: 0 + -- Polling slave 10... Ctrl-C to stop) + [1000]: 6100 + [1001]: 0 + [1002]: 0 + [1003]: 0 + -- Polling slave 10... Ctrl-C to stop) + [1000]: 51010 (-14526) + [1001]: 0 + [1002]: 0 + [1003]: 0 + -- Polling slave 10... Ctrl-C to stop) + [1000]: 12528 + [1001]: 0 + [1002]: 0 + [1003]: 0 + diff --git a/arch/arm/include/stm32/chip.h b/arch/arm/include/stm32/chip.h index f155df64d23..00855956cb1 100644 --- a/arch/arm/include/stm32/chip.h +++ b/arch/arm/include/stm32/chip.h @@ -1587,7 +1587,7 @@ # define STM32_NDMA 2 /* DMA1-2 with 8 streams each*/ # define STM32_NSPI 3 /* SPI1-3 */ # define STM32_NI2S 2 /* I2S2-3 (multiplexed with SPI2-3) */ -# define STM32_NUSART 3 /* USART1, 2 and 6 */ +# define STM32_NUSART 6 /* Actually only 3: USART1, 2 and 6 */ # define STM32_NI2C 3 /* I2C1-3 */ # define STM32_NCAN 0 /* No CAN */ # if defined(CONFIG_ARCH_CHIP_STM32F401CB) || defined(CONFIG_ARCH_CHIP_STM32F401CC) diff --git a/boards/arm/stm32/stm32f401rc-rs485/configs/modbus_slave/defconfig b/boards/arm/stm32/stm32f401rc-rs485/configs/modbus_slave/defconfig new file mode 100644 index 00000000000..6c78a8ca9a0 --- /dev/null +++ b/boards/arm/stm32/stm32f401rc-rs485/configs/modbus_slave/defconfig @@ -0,0 +1,70 @@ +# +# 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_MB_ASCII_ENABLED is not set +# CONFIG_MB_TCP_ENABLED 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_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_BOARD_LOOPSPERMSEC=8499 +CONFIG_BUILTIN=y +CONFIG_EXAMPLES_BUTTONS=y +CONFIG_EXAMPLES_BUTTONS_NAME0="SW3" +CONFIG_EXAMPLES_BUTTONS_NAME1="SW4" +CONFIG_EXAMPLES_BUTTONS_NAME2="SW5" +CONFIG_EXAMPLES_BUTTONS_NAME3="SW6" +CONFIG_EXAMPLES_BUTTONS_NAMES=y +CONFIG_EXAMPLES_BUTTONS_QTD=4 +CONFIG_EXAMPLES_MODBUS=y +CONFIG_EXAMPLES_MODBUS_PORT=1 +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_MODBUS=y +CONFIG_MODBUS_SLAVE=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_SPI=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_USART2=y +CONFIG_STM32_USART6=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART2_BAUD=38400 +CONFIG_USART2_PARITY=2 +CONFIG_USART2_RS485=y +CONFIG_USART6_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32/stm32f401rc-rs485/configs/nsh/defconfig b/boards/arm/stm32/stm32f401rc-rs485/configs/nsh/defconfig index d9fb2d4370b..fed70c4f38c 100644 --- a/boards/arm/stm32/stm32f401rc-rs485/configs/nsh/defconfig +++ b/boards/arm/stm32/stm32f401rc-rs485/configs/nsh/defconfig @@ -26,9 +26,8 @@ CONFIG_EXAMPLES_BUTTONS=y CONFIG_EXAMPLES_BUTTONS_NAME0="SW3" CONFIG_EXAMPLES_BUTTONS_NAME1="SW4" CONFIG_EXAMPLES_BUTTONS_NAME2="SW5" -CONFIG_EXAMPLES_BUTTONS_NAME3="SW6" CONFIG_EXAMPLES_BUTTONS_NAMES=y -CONFIG_EXAMPLES_BUTTONS_QTD=4 +CONFIG_EXAMPLES_BUTTONS_QTD=3 CONFIG_HAVE_CXX=y CONFIG_HAVE_CXXINITIALIZE=y CONFIG_INIT_ENTRYPOINT="nsh_main" @@ -54,7 +53,7 @@ CONFIG_START_YEAR=2014 CONFIG_STM32_JTAG_SW_ENABLE=y CONFIG_STM32_OTGFS=y CONFIG_STM32_PWR=y -CONFIG_STM32_USART2=y +CONFIG_STM32_USART6=y CONFIG_SYSTEM_NSH=y CONFIG_TASK_NAME_SIZE=0 -CONFIG_USART2_SERIAL_CONSOLE=y +CONFIG_USART6_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32/stm32f401rc-rs485/configs/sdcard/defconfig b/boards/arm/stm32/stm32f401rc-rs485/configs/sdcard/defconfig index 5c50b8bacc8..0bac727099e 100644 --- a/boards/arm/stm32/stm32f401rc-rs485/configs/sdcard/defconfig +++ b/boards/arm/stm32/stm32f401rc-rs485/configs/sdcard/defconfig @@ -64,7 +64,7 @@ CONFIG_STM32_OTGFS=y CONFIG_STM32_PWR=y CONFIG_STM32_SDIO=y CONFIG_STM32_SDIO_CARD=y -CONFIG_STM32_USART2=y +CONFIG_STM32_USART6=y CONFIG_SYSTEM_NSH=y CONFIG_TASK_NAME_SIZE=0 -CONFIG_USART2_SERIAL_CONSOLE=y +CONFIG_USART6_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32/stm32f401rc-rs485/include/board.h b/boards/arm/stm32/stm32f401rc-rs485/include/board.h index 76400eae09a..016ce5a8409 100644 --- a/boards/arm/stm32/stm32f401rc-rs485/include/board.h +++ b/boards/arm/stm32/stm32f401rc-rs485/include/board.h @@ -256,48 +256,32 @@ extern "C" /* Alternate function pin selections ****************************************/ -/* USART1: - * RXD: PA10 CN9 pin 3, CN10 pin 33 - * PB7 CN7 pin 21 - * TXD: PA9 CN5 pin 1, CN10 pin 21 - * PB6 CN5 pin 3, CN10 pin 17 +/* USART2: + * RXD: PA3 CN4 pin 20 + * TXD: PA2 CN4 pin 18 */ -#if 1 -# define GPIO_USART1_RX GPIO_USART1_RX_1 /* PA10 */ -# define GPIO_USART1_TX GPIO_USART1_TX_1 /* PA9 */ -#else -# define GPIO_USART1_RX GPIO_USART1_RX_2 /* PB7 */ -# define GPIO_USART1_TX GPIO_USART1_TX_2 /* PB6 */ +#ifdef CONFIG_USART2_RS485 + /* Lets use for RS485 */ + +# define GPIO_USART2_TX GPIO_USART2_TX_1 /* PA2 */ +# define GPIO_USART2_RX GPIO_USART2_RX_1 /* PA3 */ + + /* RS485 DIR pin: PA1 */ + +# define GPIO_USART2_RS485_DIR (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_50MHz |\ + GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN1) + #endif -/* USART2: - * RXD: PA3 CN9 pin 1 (See SB13, 14, 62, 63). CN10 pin 37 - * PD6 - * TXD: PA2 CN9 pin 2(See SB13, 14, 62, 63). CN10 pin 35 - * PD5 - */ - -#define GPIO_USART2_RX GPIO_USART2_RX_1 /* PA3 */ -#define GPIO_USART2_TX GPIO_USART2_TX_1 /* PA2 */ -#define GPIO_USART2_RTS GPIO_USART2_RTS_2 -#define GPIO_USART2_CTS GPIO_USART2_CTS_2 - /* USART6: - * RXD: PC7 CN5 pin2, CN10 pin 19 - * PA12 CN10, pin 12 - * TXD: PC6 CN10, pin 4 - * PA11 CN10, pin 14 + * RXD: PC7 CN2 pin 15 + * TXD: PC6 CN2 pin 17 */ #define GPIO_USART6_RX GPIO_USART6_RX_1 /* PC7 */ #define GPIO_USART6_TX GPIO_USART6_TX_1 /* PC6 */ -/* UART RX DMA configurations */ - -#define DMAMAP_USART1_RX DMAMAP_USART1_RX_2 -#define DMAMAP_USART6_RX DMAMAP_USART6_RX_2 - /* I2C * * The optional _GPIO configurations allow the I2C driver to manually @@ -379,20 +363,18 @@ extern "C" #define LED_PANIC 1 /* Buttons - * The STM32F401RC-RS485 has 4 user buttons: SW3, SW4, SW5 and - * SW6. They are connected to PB13, PB14, PB15 and PC6 respectively. + * The STM32F401RC-RS485 has 3 user buttons: SW3, SW4, and SW5. + * They are connected to PB13, PB14, and PB15 respectively. */ #define BUTTON_SW3 0 #define BUTTON_SW4 1 #define BUTTON_SW5 2 -#define BUTTON_SW6 3 -#define NUM_BUTTONS 4 +#define NUM_BUTTONS 3 #define BUTTON_SW3_BIT (1 << BUTTON_SW3) #define BUTTON_SW4_BIT (1 << BUTTON_SW4) #define BUTTON_SW5_BIT (1 << BUTTON_SW5) -#define BUTTON_SW6_BIT (1 << BUTTON_SW6) #define GPIO_TIM2_CH1IN (GPIO_TIM2_CH1IN_1 | GPIO_PULLUP) #define GPIO_TIM2_CH2IN (GPIO_TIM2_CH2IN_1 | GPIO_PULLUP) diff --git a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_buttons.c b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_buttons.c index 85d2e79a263..8f7dfc1aaae 100644 --- a/boards/arm/stm32/stm32f401rc-rs485/src/stm32_buttons.c +++ b/boards/arm/stm32/stm32f401rc-rs485/src/stm32_buttons.c @@ -46,7 +46,7 @@ static const uint32_t g_buttons[NUM_BUTTONS] = { - GPIO_BTN_SW3, GPIO_BTN_SW4, GPIO_BTN_SW5, GPIO_BTN_SW6 + GPIO_BTN_SW3, GPIO_BTN_SW4, GPIO_BTN_SW5 }; /**************************************************************************** diff --git a/boards/arm/stm32/stm32f401rc-rs485/src/stm32f401rc-rs485.h b/boards/arm/stm32/stm32f401rc-rs485/src/stm32f401rc-rs485.h index 261d533b62a..0e0141ca515 100644 --- a/boards/arm/stm32/stm32f401rc-rs485/src/stm32f401rc-rs485.h +++ b/boards/arm/stm32/stm32f401rc-rs485/src/stm32f401rc-rs485.h @@ -75,16 +75,15 @@ GPIO_SPEED_50MHz) /* Buttons - * The STM32F401RC-RS485 has 4 user buttons. + * The STM32F401RC-RS485 has 3 user buttons. * - SW3 is connected to the GPIO PB13. * - SW4 is connected to the GPIO PB14. * - SW5 is connected to the GPIO PB15. - * - SW6 is connected to the GPIO PC6. */ #define MIN_IRQBUTTON BUTTON_SW3 -#define MAX_IRQBUTTON BUTTON_SW6 -#define NUM_IRQBUTTONS 4 +#define MAX_IRQBUTTON BUTTON_SW5 +#define NUM_IRQBUTTONS 3 #define GPIO_BTN_SW3 \ (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTB | GPIO_PIN13) @@ -92,29 +91,6 @@ (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTB | GPIO_PIN14) #define GPIO_BTN_SW5 \ (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTB | GPIO_PIN15) -#define GPIO_BTN_SW6 \ - (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTC | GPIO_PIN6) - -/* The shield uses the following pins: - * - * +5V - * GND - * SERIAL_TX=PA_2 USER_BUTTON=PC_13 - * SERIAL_RX=PA_3 LD2=PA_5 - * - * Analog Digital - * A0=PA_0 USART2RX D0=PA_3 D8 =PA_9 - * A1=PA_1 USART2TX D1=PA_2 D9 =PC_7 - * A2=PA_4 D2=PA_10 WIFI_CS=D10=PB_6 SPI_CS - * A3=PB_0 WIFI_INT=D3=PB_3 D11=PA_7 SPI_MOSI - * A4=PC_1 SD_CS=D4=PB_5 D12=PA_6 SPI_MISO - * A5=PC_0 WIFI_EN=D5=PB_4 LD2=D13=PA_5 SPI_SCK - * LED2=D6=PB_10 I2C1_SDA=D14=PB_9 WIFI Probe - * D7=PA_8 I2C1_SCL=D15=PB_8 WIFI Probe - * - * mostly from: https://mbed.org/platforms/ST-Nucleo-F401RE/ - * - */ /* SPI1 off */