diff --git a/boards/arm/rp2040/common/Makefile b/boards/arm/rp2040/common/Makefile new file mode 100644 index 00000000000..44a345c756f --- /dev/null +++ b/boards/arm/rp2040/common/Makefile @@ -0,0 +1,34 @@ +############################################################################# +# boards/arm/rp2040/common/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################# + +include $(TOPDIR)/Make.defs + +include board/Make.defs +include src/Make.defs + +DEPPATH += --dep-path board +DEPPATH += --dep-path src + +include $(TOPDIR)/boards/Board.mk + +ARCHSRCDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src +BOARDDIR = $(ARCHSRCDIR)$(DELIM)board +CFLAGS += $(shell $(INCDIR) "$(CC)" $(BOARDDIR)$(DELIM)include) + diff --git a/boards/arm/rp2040/common/src/Make.defs b/boards/arm/rp2040/common/src/Make.defs new file mode 100644 index 00000000000..89d4a940c87 --- /dev/null +++ b/boards/arm/rp2040/common/src/Make.defs @@ -0,0 +1,31 @@ +############################################################################# +# boards/arm/rp2040/common/src/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################# + +ifeq ($(CONFIG_RP2040_I2C_DRIVER),y) +CSRCS += rp2040_i2cdev.c +endif + +ifeq ($(CONFIG_LCD_SSD1306),y) +CSRCS += rp2040_ssd1306.c +endif + +DEPPATH += --dep-path src +VPATH += :src +CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src) diff --git a/boards/arm/rp2040/common/src/rp2040_i2cdev.c b/boards/arm/rp2040/common/src/rp2040_i2cdev.c new file mode 100644 index 00000000000..d233f20b952 --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_i2cdev.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_i2cdev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "rp2040_i2c.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_i2cdev_initialize + * + * Description: + * Initialize and register i2c driver for the specified i2c port + * + ****************************************************************************/ + +int board_i2cdev_initialize(int port) +{ + int ret; + FAR struct i2c_master_s *i2c; + + i2cinfo("Initializing /dev/i2c%d..\n", port); + + /* Initialize i2c device */ + + i2c = rp2040_i2cbus_initialize(port); + if (!i2c) + { + i2cerr("ERROR: Failed to initialize i2c%d.\n", port); + return -ENODEV; + } + + ret = i2c_register(i2c, port); + if (ret < 0) + { + i2cerr("ERROR: Failed to register i2c%d: %d\n", port, ret); + } + + return ret; +} diff --git a/boards/arm/rp2040/common/src/rp2040_ssd1306.c b/boards/arm/rp2040/common/src/rp2040_ssd1306.c new file mode 100644 index 00000000000..441b478665d --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_ssd1306.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_ssd1306.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include + +#include "rp2040_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define OLED_I2C_PORT 0 /* OLED display connected to I2C0 */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static FAR struct lcd_dev_s *g_lcddev; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_lcd_initialize + ****************************************************************************/ + +int board_lcd_initialize(void) +{ + FAR struct i2c_master_s *i2c; + const int busno = OLED_I2C_PORT; + const int devno = 0; + + /* Initialize I2C */ + + i2c = rp2040_i2cbus_initialize(busno); + if (!i2c) + { + lcderr("ERROR: Failed to initialize I2C port %d\n", busno); + return -ENODEV; + } + + /* Bind the I2C port to the OLED */ + + g_lcddev = ssd1306_initialize(i2c, NULL, devno); + if (!g_lcddev) + { + lcderr("ERROR: Failed to bind I2C port %d to OLED %d\n", busno, devno); + return -ENODEV; + } + else + { + lcdinfo("Bound I2C port %d to OLED %d\n", busno, devno); + + /* And turn the OLED on */ + + g_lcddev->setpower(g_lcddev, CONFIG_LCD_MAXPOWER); + return OK; + } +} + +/**************************************************************************** + * Name: board_lcd_getdev + ****************************************************************************/ + +FAR struct lcd_dev_s *board_lcd_getdev(int lcddev) +{ + if (lcddev == 0) + { + return g_lcddev; + } + + return NULL; +} + +/**************************************************************************** + * Name: board_lcd_uninitialize + ****************************************************************************/ + +void board_lcd_uninitialize(void) +{ +} diff --git a/boards/arm/rp2040/raspberrypi-pico/Kconfig b/boards/arm/rp2040/raspberrypi-pico/Kconfig index 6ddc2c9963d..e77f724b220 100644 --- a/boards/arm/rp2040/raspberrypi-pico/Kconfig +++ b/boards/arm/rp2040/raspberrypi-pico/Kconfig @@ -26,4 +26,29 @@ config RP2040_UF2_BINARY ---help--- Create nuttx.uf2 binary format used on RP2040 based arch. + +config RP2040_UART0_GPIO + int "UART0 GPIO pin assign (0,12,16,28 or -1:no assign)" + default 0 + range -1 29 + depends on RP2040_UART0 + +config RP2040_UART1_GPIO + int "UART1 GPIO pin assign (4,8,20,24 or -1:no assign)" + default -1 + range -1 29 + depends on RP2040_UART1 + +config RP2040_I2C0_GPIO + int "I2C0 GPIO pin assign (0,4,8,12,16,20,24,28 or -1:no assign)" + default -1 + range -1 29 + depends on RP2040_I2C0 + +config RP2040_I2C1_GPIO + int "I2C1 GPIO pin assign (2,6,10,14,18,22,26 or -1:no assign)" + default -1 + range -1 29 + depends on RP2040_I2C1 + endif diff --git a/boards/arm/rp2040/raspberrypi-pico/README.txt b/boards/arm/rp2040/raspberrypi-pico/README.txt index be2f4cada76..9262d937d5e 100644 --- a/boards/arm/rp2040/raspberrypi-pico/README.txt +++ b/boards/arm/rp2040/raspberrypi-pico/README.txt @@ -10,6 +10,7 @@ Currently only the following devices are suppored. Supported: - UART (console port) - GPIO 0 (UART0 TX) and GPIO 1 (UART0 RX) are used for the console. + - I2C - Flash ROM Boot - SRAM Boot - If Pico SDK is available, nuttx.uf2 file which can be used in @@ -46,6 +47,27 @@ Installation 5. To access the console, GPIO 0 and 1 pins must be connected to the device such as USB-serial converter. +Defconfigs +========== + +- nsh + Minimum configuration with NutShell + +- nshsram + Load NuttX binary to SRAM + +- smp + Enable SMP mode. Both Core 0 and Core 1 are used by NuttX. + +- ssd1306 + SSD1306 OLED display (I2C) test configuration + Connection: + SSD1306 Raspberry Pi Pico + GND ----- GND (Pin 3 or 38 or ...) + VCC ----- 3V3 OUT (Pin 36) + SDA ----- GP4 (I2C0 SDA) (Pin 6) + SCL ----- GP5 (I2C0 SCL) (Pin 7) + License exceptions ================== diff --git a/boards/arm/rp2040/raspberrypi-pico/include/board.h b/boards/arm/rp2040/raspberrypi-pico/include/board.h index 3735b9f8caf..31e26e921d6 100644 --- a/boards/arm/rp2040/raspberrypi-pico/include/board.h +++ b/boards/arm/rp2040/raspberrypi-pico/include/board.h @@ -27,6 +27,8 @@ #include +#include "rp2040_i2cdev.h" + #ifndef __ASSEMBLY__ # include #endif @@ -56,7 +58,6 @@ /* GPIO definitions *********************************************************/ -#define BOARD_GPIO_UART_PIN 0 #define BOARD_GPIO_LED_PIN 25 /**************************************************************************** diff --git a/boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2cdev.h b/boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2cdev.h new file mode 100644 index 00000000000..fc1bd1770ba --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2cdev.h @@ -0,0 +1,72 @@ +/**************************************************************************** + * boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2cdev.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_RP2040_I2CDEV_H +#define __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_RP2040_I2CDEV_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_i2cdev_initialize + * + * Description: + * Initialize i2c driver and register the /dev/i2c device. + * + ****************************************************************************/ + +#ifdef CONFIG_RP2040_I2C_DRIVER +int board_i2cdev_initialize(int bus); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_RP2040_I2CDEV_H */ diff --git a/boards/arm/rp2040/raspberrypi-pico/src/Makefile b/boards/arm/rp2040/raspberrypi-pico/src/Make.defs similarity index 84% rename from boards/arm/rp2040/raspberrypi-pico/src/Makefile rename to boards/arm/rp2040/raspberrypi-pico/src/Make.defs index 8791c6873a2..64de118796f 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/Makefile +++ b/boards/arm/rp2040/raspberrypi-pico/src/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# boards/arm/rp2040/raspberrypi-pico/src/Makefile +# boards/arm/rp2040/raspberrypi-pico/src/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -28,4 +28,6 @@ ifeq ($(CONFIG_BOARDCTL_RESET),y) CSRCS += rp2040_reset.c endif -include $(TOPDIR)/boards/Board.mk +DEPPATH += --dep-path board +VPATH += :board +CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board) diff --git a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_boardinitialize.c b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_boardinitialize.c index 106d6409561..1f7da1522ae 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_boardinitialize.c +++ b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_boardinitialize.c @@ -65,13 +65,6 @@ void rp2040_boardearlyinitialize(void) clrbits_reg32(RP2040_PADS_BANK0_GPIO_IE, RP2040_PADS_BANK0_GPIO(28)); clrbits_reg32(RP2040_PADS_BANK0_GPIO_IE, RP2040_PADS_BANK0_GPIO(29)); - /* Set default UART TX,RX pin */ - - rp2040_gpio_set_function(BOARD_GPIO_UART_PIN, - RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); - rp2040_gpio_set_function(BOARD_GPIO_UART_PIN + 1, - RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); - /* Set board LED pin */ rp2040_gpio_set_function(BOARD_GPIO_LED_PIN, @@ -79,6 +72,60 @@ void rp2040_boardearlyinitialize(void) putreg32(1 << BOARD_GPIO_LED_PIN, RP2040_SIO_GPIO_OE_SET); putreg32(1 << BOARD_GPIO_LED_PIN, RP2040_SIO_GPIO_OUT_SET); + + /* Set default UART pin */ + +#if defined(CONFIG_RP2040_UART0) && CONFIG_RP2040_UART0_GPIO >= 0 + rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* TX */ + rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO + 1, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* RX */ +#ifdef CONFIG_SERIAL_OFLOWCONTROL + rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO + 2, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* CTS */ +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO + 3, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* RTS */ +#endif +#endif + +#if defined(CONFIG_RP2040_UART1) && CONFIG_RP2040_UART1_GPIO >= 0 + rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* TX */ + rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO + 1, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* RX */ +#ifdef CONFIG_SERIAL_OFLOWCONTROL + rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO + 2, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* CTS */ +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO + 3, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_UART); /* RTS */ +#endif +#endif + + /* Set default I2C pin */ + +#if defined(CONFIG_RP2040_I2C0) && CONFIG_RP2040_I2C0_GPIO >= 0 + rp2040_gpio_set_function(CONFIG_RP2040_I2C0_GPIO, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_I2C); /* SDA */ + rp2040_gpio_set_function(CONFIG_RP2040_I2C0_GPIO + 1, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_I2C); /* SCL */ + + rp2040_gpio_set_pulls(CONFIG_RP2040_I2C0_GPIO, false, true); /* Pull down */ + rp2040_gpio_set_pulls(CONFIG_RP2040_I2C0_GPIO + 1, false, true); +#endif + +#if defined(CONFIG_RP2040_I2C1) && CONFIG_RP2040_I2C1_GPIO >= 0 + rp2040_gpio_set_function(CONFIG_RP2040_I2C1_GPIO, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_I2C); /* SDA */ + rp2040_gpio_set_function(CONFIG_RP2040_I2C1_GPIO + 1, + RP2040_IO_BANK0_GPIO_CTRL_FUNCSEL_I2C); /* SCL */ + + rp2040_gpio_set_pulls(CONFIG_RP2040_I2C1_GPIO, false, true); /* Pull down */ + rp2040_gpio_set_pulls(CONFIG_RP2040_I2C1_GPIO + 1, false, true); +#endif } /**************************************************************************** diff --git a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c index 0f1002d9366..68e78268da0 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c +++ b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c @@ -29,6 +29,8 @@ #include +#include + #include "rp2040_pico.h" /**************************************************************************** @@ -43,6 +45,24 @@ int rp2040_bringup(void) { int ret = 0; +#ifdef CONFIG_RP2040_I2C_DRIVER + #ifdef CONFIG_RP2040_I2C0 + ret = board_i2cdev_initialize(0); + if (ret < 0) + { + _err("ERROR: Failed to initialize I2C0.\n"); + } + #endif + + #ifdef CONFIG_RP2040_I2C1 + ret = board_i2cdev_initialize(1); + if (ret < 0) + { + _err("ERROR: Failed to initialize I2C1.\n"); + } + #endif +#endif + #ifdef CONFIG_FS_PROCFS /* Mount the procfs file system */