Re: GPIO drivers
Hello Bowen, Thank you for you help. I am not sure if this question is for you or is more architecture specific? I am looking at implementing the the relay ops (set()/get()) functions within the drivers/power/relay/relay.c file. I can see how to implement this based on the drivers/power/relay/relay_gpio.c file. However I think that for control of a processor GPIO (rather than a GPIO controlled by an IO expander) I will need to use the gpiowrite & gpioread functions (rather than the IOEXP_WRITEPIN & IOEXP_READPIN functions used by the relay_gpio.c file). Do you think this is correct, or am I missing something? If the relay.c file is modified to implement the relay ops (set()/get()) functions and uses the gpiowrite & gpioread functions then it becomes board/processor specific (e.g. will need the stm32l4_gpiowrite & stm32l4_gpioread functions for the nucleo-l432kc board I am working with). For my relay driver that doesn't matter (if I don't export it back to github as a patch), but to make the relay driver more generic does this mean the relay.c file should be within the arch/arm/src/ directory? Kind regards Stewart On 17/01/2024 06:49, Stewart Charnell wrote: Hello Bowen, Thank you for responding to my question. Yes I think the relay framework will do what I want, I will try it out. Kind regards Stewart Charnell On 17/01/2024 03:23, 汪博文 wrote: Hello, I'm Bowen Wang and nice to answer your question. Please correct me If I understand wrong. I think you want to use the relay framework in nuttx/drivers/power/relay/relay.c and relay_gpio.c, which are added by me in PR: power/relay: add relay driver framework for NuttX by CV-Bowen · Pull Request #7954 · apache/nuttx (github.com) <https://github.com/apache/nuttx/pull/7954>. The realy framework has two part: 1. The first part is relay.c, relay.c did a very simple thing: convert user ioctl(RELAYIOC_SET/GET) to the relay driver implemented dev->ops->set()/get(), and you can follow the following steps to implement a relay driver: a. implement the relay ops (set()/get()); b. call relay_register() to register your relay driver (just like relay_gpio.c does); 2. The second part is relay_gpio.c, relay_gpio.c base on the *alreay implemented* gpio driver (ioexpander) to resigter a relay driver, so if you has implemented a ioexpander driver, you can enable config: CONFIG_RELAY_GPIO and then call relay_gpio_register() to register a driver, a simple example in sim is: ```c diff --git a/boards/sim/sim/sim/src/sim_ioexpander.c b/boards/sim/sim/sim/src/sim_ioexpander.c index 599ac68743..9397967a24 100644 --- a/boards/sim/sim/sim/src/sim_ioexpander.c +++ b/boards/sim/sim/sim/src/sim_ioexpander.c @@ -29,6 +29,7 @@ #include #include +#include #include "sim.h" @@ -76,6 +77,11 @@ int sim_gpio_initialize(void) IOEXP_SETOPTION(ioe, 1, IOEXPANDER_OPTION_INTCFG, (void *)IOEXPANDER_VAL_DISABLE); gpio_lower_half(ioe, 1, GPIO_OUTPUT_PIN, 1); + int ret = relay_gpio_register(ioe, 1, false, "/dev/relay0"); + if (ret < 0) + { + _err("relay register error\n"); + } /* Pin 2: an non-inverted, edge interrupting pin */ ``` And I'm sorry that I missed the docs and examples about the new added relay framework, I will add this later. Kind regards Bowen Wang -------- Bowen Wang, wangbow...@xiaomi.com *From:* Stewart Charnell <mailto:nu...@charnell.plus.com> *Date:* 2024-01-17 04:33 *To:* dev@nuttx.apache.org *Subject:* [External Mail][Quarantine]GPIO drivers Hello, I have a processor board with GPIO ports which I would like to use to control such things as relays and PSU enable pins. Do I need to write a GPIO driver? There is an I/O expander driver. Is the I/O expander driver specific to expanders or can it be used for GPIO control? Kind regards Stewart Charnell #/**本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!**/#
Re: GPIO drivers
Hello Bowen, Thank you for responding to my question. Yes I think the relay framework will do what I want, I will try it out. Kind regards Stewart Charnell On 17/01/2024 03:23, 汪博文 wrote: Hello, I'm Bowen Wang and nice to answer your question. Please correct me If I understand wrong. I think you want to use the relay framework in nuttx/drivers/power/relay/relay.c and relay_gpio.c, which are added by me in PR: power/relay: add relay driver framework for NuttX by CV-Bowen · Pull Request #7954 · apache/nuttx (github.com) <https://github.com/apache/nuttx/pull/7954>. The realy framework has two part: 1. The first part is relay.c, relay.c did a very simple thing: convert user ioctl(RELAYIOC_SET/GET) to the relay driver implemented dev->ops->set()/get(), and you can follow the following steps to implement a relay driver: a. implement the relay ops (set()/get()); b. call relay_register() to register your relay driver (just like relay_gpio.c does); 2. The second part is relay_gpio.c, relay_gpio.c base on the *alreay implemented* gpio driver (ioexpander) to resigter a relay driver, so if you has implemented a ioexpander driver, you can enable config: CONFIG_RELAY_GPIO and then call relay_gpio_register() to register a driver, a simple example in sim is: ```c diff --git a/boards/sim/sim/sim/src/sim_ioexpander.c b/boards/sim/sim/sim/src/sim_ioexpander.c index 599ac68743..9397967a24 100644 --- a/boards/sim/sim/sim/src/sim_ioexpander.c +++ b/boards/sim/sim/sim/src/sim_ioexpander.c @@ -29,6 +29,7 @@ #include #include +#include #include "sim.h" @@ -76,6 +77,11 @@ int sim_gpio_initialize(void) IOEXP_SETOPTION(ioe, 1, IOEXPANDER_OPTION_INTCFG, (void *)IOEXPANDER_VAL_DISABLE); gpio_lower_half(ioe, 1, GPIO_OUTPUT_PIN, 1); + int ret = relay_gpio_register(ioe, 1, false, "/dev/relay0"); + if (ret < 0) + { + _err("relay register error\n"); + } /* Pin 2: an non-inverted, edge interrupting pin */ ``` And I'm sorry that I missed the docs and examples about the new added relay framework, I will add this later. Kind regards Bowen Wang Bowen Wang, wangbow...@xiaomi.com *From:* Stewart Charnell <mailto:nu...@charnell.plus.com> *Date:* 2024-01-17 04:33 *To:* dev@nuttx.apache.org *Subject:* [External Mail][Quarantine]GPIO drivers Hello, I have a processor board with GPIO ports which I would like to use to control such things as relays and PSU enable pins. Do I need to write a GPIO driver? There is an I/O expander driver. Is the I/O expander driver specific to expanders or can it be used for GPIO control? Kind regards Stewart Charnell #/**本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!**/#
GPIO drivers
Hello, I have a processor board with GPIO ports which I would like to use to control such things as relays and PSU enable pins. Do I need to write a GPIO driver? There is an I/O expander driver. Is the I/O expander driver specific to expanders or can it be used for GPIO control? Kind regards Stewart Charnell
Problems adding a New Board Configuration
Hi, I am working with a nucleo-l432kc board and need to add multiple occurrences of identical peripherals (INA260 current sensor). I thought I would create a new board configuration, based on the nucleo-l432kc to make the any changes in. I used the NUTTX Porting Guide webpage to see what I needed to do (https://cwiki.apache.org/confluence/display/NUTTX/Porting+Guide#newboardconfig). The changes I made were: In file nuttx/boards/Kconfig: 1 - Added section: config ARCH_BOARD_NUCLEO_L432KC_CUST bool "STM32L432 Nucleo-32 L432KC Custom" depends on ARCH_CHIP_STM32L432KC select ARCH_HAVE_LEDS select ARCH_HAVE_BUTTONS select ARCH_HAVE_IRQBUTTONS ---help--- STMicro Nucleo-32 L432KC custom board based on the STMicro STM32L432KCU6 MCU. 2 - Added: default "nucleo-l432kc-custom" if ARCH_BOARD_NUCLEO_L432KC_CUST 3 - Added towards the end of the file: if ARCH_BOARD_NUCLEO_L432KC_CUST source "boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig" endif I Copied nuttx/boards/arm/stm32l4/nucleo-l432kc directory to nuttx/boards/arm/stm32l4/nucleo-l432kc-custom In file boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig: 1 - Changed: if ARCH_BOARD_NUCLEO_L432KC to: if ARCH_BOARD_NUCLEO_L432KC_CUST 2 - Changed: endif # ARCH_BOARD_NUCLEO_L432KC to: endif # ARCH_BOARD_NUCLEO_L432KC_CUST I then ran the following: stewart@stewart-HP-250-G6-Notebook-PC:/data/Nuttx/nuttx$ make distclean stewart@stewart-HP-250-G6-Notebook-PC:/data/Nuttx/nuttx$ tools/configure.sh -l nucleo-l432kc-custom:nsh Copy files Select CONFIG_HOST_LINUX=y Refreshing... CP: arch/dummy/Kconfig to /data/Nuttx/nuttx/arch/dummy/dummy_kconfig CP: boards/dummy/Kconfig to /data/Nuttx/nuttx/boards/dummy/dummy_kconfig LN: platform/board to /data/Nuttx/apps/platform/dummy LN: include/arch to arch/arm/include LN: include/arch/board to /data/Nuttx/nuttx/boards/arm/stm32l4/nucleo-l432kc-custom/include LN: drivers/platform to /data/Nuttx/nuttx/drivers/dummy LN: include/arch/chip to /data/Nuttx/nuttx/arch/arm/include/stm32l4 LN: arch/arm/src/chip to /data/Nuttx/nuttx/arch/arm/src/stm32l4 LN: arch/arm/src/board to /data/Nuttx/nuttx/boards/arm/stm32l4/nucleo-l432kc-custom/src mkkconfig in /data/Nuttx/apps/audioutils mkkconfig in /data/Nuttx/apps/benchmarks mkkconfig in /data/Nuttx/apps/boot mkkconfig in /data/Nuttx/apps/canutils mkkconfig in /data/Nuttx/apps/crypto mkkconfig in /data/Nuttx/apps/examples/mcuboot mkkconfig in /data/Nuttx/apps/examples mkkconfig in /data/Nuttx/apps/fsutils mkkconfig in /data/Nuttx/apps/games mkkconfig in /data/Nuttx/apps/graphics mkkconfig in /data/Nuttx/apps/industry mkkconfig in /data/Nuttx/apps/interpreters/luamodules mkkconfig in /data/Nuttx/apps/interpreters mkkconfig in /data/Nuttx/apps/logging mkkconfig in /data/Nuttx/apps/lte mkkconfig in /data/Nuttx/apps/math mkkconfig in /data/Nuttx/apps/mlearning mkkconfig in /data/Nuttx/apps/netutils mkkconfig in /data/Nuttx/apps/sdr mkkconfig in /data/Nuttx/apps/system mkkconfig in /data/Nuttx/apps/testing mkkconfig in /data/Nuttx/apps/wireless/bluetooth mkkconfig in /data/Nuttx/apps/wireless/ieee802154 mkkconfig in /data/Nuttx/apps/wireless mkkconfig in /data/Nuttx/apps boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:24:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:27:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:41:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:44:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:61:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:64:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:77:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:92:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:104:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:126:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:129:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:144:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:147:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:150:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:165:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:168:warning: choice value used outside its choice group boards/arm/stm32l4/nucleo-l432kc-custom/Kconfig:171:warning: choice value used outside its choice group
Re: STM Nucleo-32 board - I2C functionality
Hi Daniel, Thanks for PR #10753, yes that fixed the problem for me. I am using a PCB with the ina260 sensor in place of the ina226, similar functionality and I2C address. I am working on a driver for the ina260 which I can submit once I have completed more tests. Kind regards Stewart On 25/09/2023 21:52, Stewart Charnell wrote: Hi Daniel, Sorry for not replying earlier, I was away for the weekend. I will test out PR #10753 tomorrow. Kind regards Stewart On 21/09/2023 15:13, Daniel Pereira Carvalho wrote: Hi Stewart, You are right, there is a mistake regarding pin definitions in the file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c. I tried to fix these pin definitions on PR #10753 but I can't test them. Are you able to test it? Thanks Daniel Pereira de Carvalho Em qua., 20 de set. de 2023 às 13:42, Stewart Charnell < nu...@charnell.plus.com> escreveu: Hi, Has anyone used the I2C functionality on the STM Nucleo-32 board (it uses the STM32L432 processor)? I think there is an issue with the file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c. This board can support Arduino NANO pinout compatibility by using links on the PCB. Section '6.10 Solder bridges' of doc. 'UM1956 User manual STM32 Nucleo-32 boards (MB1180)' details these links. One option for the I2C1 interface is to use STM32L432 pins PB_7 (function I2C1_SDA, PCB pin D4) & PA_6 (function I2C1_SCL, PCB pin D5), which are linked by solder bridges on the PCB to STM32L432 pins PA_6 (PCB pin A5) & PA_5 (PCB pin A4) to maintain Arduino NANO pinout compatibility. The webpage os.mbed.com/platforms/ST-Nucleo-L432KC has a picture of the PCB showing the pinout options, and this Information: By default the PA_5 (A4) and PA_6 (A5) pins can only be used as Input floating (ADC function). Remove SB16 and SB18 solder bridges in order to use these pins as Digital output and have access to other functions (DigitalOut, SPI, PWM, etc...). The file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c contains these lines: /* Configure D4(PA5) and D5(PA6) as input floating */ stm32l4_configgpio(GPIO_I2C1_D4); stm32l4_configgpio(GPIO_I2C1_D5); Where GPIO_I2C1_D4 & GPIO_I2C1_D5 are defined in boards/arm/stm32l4/nucleo-l432kc/include/board.h However the device pins PA5 and PA6 correspond to PCB pins A4 and A5 respectively, not PCB pins D4 and D5. These calls to the stm32l4_configgpio functions cause the I2C1 lines to be disabled. Kind regards Stewart Charnell
Re: STM Nucleo-32 board - I2C functionality
Hi Daniel, Sorry for not replying earlier, I was away for the weekend. I will test out PR #10753 tomorrow. Kind regards Stewart On 21/09/2023 15:13, Daniel Pereira Carvalho wrote: Hi Stewart, You are right, there is a mistake regarding pin definitions in the file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c. I tried to fix these pin definitions on PR #10753 but I can't test them. Are you able to test it? Thanks Daniel Pereira de Carvalho Em qua., 20 de set. de 2023 às 13:42, Stewart Charnell < nu...@charnell.plus.com> escreveu: Hi, Has anyone used the I2C functionality on the STM Nucleo-32 board (it uses the STM32L432 processor)? I think there is an issue with the file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c. This board can support Arduino NANO pinout compatibility by using links on the PCB. Section '6.10 Solder bridges' of doc. 'UM1956 User manual STM32 Nucleo-32 boards (MB1180)' details these links. One option for the I2C1 interface is to use STM32L432 pins PB_7 (function I2C1_SDA, PCB pin D4) & PA_6 (function I2C1_SCL, PCB pin D5), which are linked by solder bridges on the PCB to STM32L432 pins PA_6 (PCB pin A5) & PA_5 (PCB pin A4) to maintain Arduino NANO pinout compatibility. The webpage os.mbed.com/platforms/ST-Nucleo-L432KC has a picture of the PCB showing the pinout options, and this Information: By default the PA_5 (A4) and PA_6 (A5) pins can only be used as Input floating (ADC function). Remove SB16 and SB18 solder bridges in order to use these pins as Digital output and have access to other functions (DigitalOut, SPI, PWM, etc...). The file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c contains these lines: /* Configure D4(PA5) and D5(PA6) as input floating */ stm32l4_configgpio(GPIO_I2C1_D4); stm32l4_configgpio(GPIO_I2C1_D5); Where GPIO_I2C1_D4 & GPIO_I2C1_D5 are defined in boards/arm/stm32l4/nucleo-l432kc/include/board.h However the device pins PA5 and PA6 correspond to PCB pins A4 and A5 respectively, not PCB pins D4 and D5. These calls to the stm32l4_configgpio functions cause the I2C1 lines to be disabled. Kind regards Stewart Charnell
STM Nucleo-32 board - I2C functionality
Hi, Has anyone used the I2C functionality on the STM Nucleo-32 board (it uses the STM32L432 processor)? I think there is an issue with the file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c. This board can support Arduino NANO pinout compatibility by using links on the PCB. Section '6.10 Solder bridges' of doc. 'UM1956 User manual STM32 Nucleo-32 boards (MB1180)' details these links. One option for the I2C1 interface is to use STM32L432 pins PB_7 (function I2C1_SDA, PCB pin D4) & PA_6 (function I2C1_SCL, PCB pin D5), which are linked by solder bridges on the PCB to STM32L432 pins PA_6 (PCB pin A5) & PA_5 (PCB pin A4) to maintain Arduino NANO pinout compatibility. The webpage os.mbed.com/platforms/ST-Nucleo-L432KC has a picture of the PCB showing the pinout options, and this Information: By default the PA_5 (A4) and PA_6 (A5) pins can only be used as Input floating (ADC function). Remove SB16 and SB18 solder bridges in order to use these pins as Digital output and have access to other functions (DigitalOut, SPI, PWM, etc...). The file boards/arm/stm32l4/nucleo-l432kc/src/stm32_ina226.c contains these lines: /* Configure D4(PA5) and D5(PA6) as input floating */ stm32l4_configgpio(GPIO_I2C1_D4); stm32l4_configgpio(GPIO_I2C1_D5); Where GPIO_I2C1_D4 & GPIO_I2C1_D5 are defined in boards/arm/stm32l4/nucleo-l432kc/include/board.h However the device pins PA5 and PA6 correspond to PCB pins A4 and A5 respectively, not PCB pins D4 and D5. These calls to the stm32l4_configgpio functions cause the I2C1 lines to be disabled. Kind regards Stewart Charnell