diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/configs/oled/defconfig b/boards/arm/stm32f0l0g0/stm32g071b-disco/configs/oled/defconfig new file mode 100644 index 00000000000..4b287ddfd7c --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/configs/oled/defconfig @@ -0,0 +1,82 @@ +# +# 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_LEDS is not set +# CONFIG_EXAMPLES_NXLINES_DEFAULT_COLORS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NX_DISABLE_1BPP is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="stm32g071b-disco" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_STM32G071B_DISCO=y +CONFIG_ARCH_CHIP="stm32f0l0g0" +CONFIG_ARCH_CHIP_STM32G071RB=y +CONFIG_ARCH_CHIP_STM32G0=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=2796 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DISABLE_ENVIRON=y +CONFIG_DISABLE_MOUNTPOINT=y +CONFIG_DISABLE_POSIX_TIMERS=y +CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y +CONFIG_EXAMPLES_DJOYSTICK=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_NXHELLO=y +CONFIG_EXAMPLES_NXHELLO_BPP=1 +CONFIG_EXAMPLES_NXLINES=y +CONFIG_EXAMPLES_NXLINES_BORDERWIDTH=1 +CONFIG_EXAMPLES_NXLINES_BPP=1 +CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xff +CONFIG_EXAMPLES_NXLINES_LINEWIDTH=1 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=1536 +CONFIG_INPUT=y +CONFIG_INPUT_DJOYSTICK=y +CONFIG_INTELHEX_BINARY=y +CONFIG_LCD=y +CONFIG_LCD_MAXCONTRAST=255 +CONFIG_LCD_RLANDSCAPE=y +CONFIG_LCD_SSD1306_CUSTOM=y +CONFIG_MM_SMALL=y +CONFIG_MQ_MAXMSGSIZE=64 +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_NUNGET_CHARS=0 +CONFIG_NX=y +CONFIG_NXFONTS_DISABLE_1BPP=y +CONFIG_NXFONT_MONO5X8=y +CONFIG_NX_BLOCKING=y +CONFIG_PREALLOC_TIMERS=0 +CONFIG_PTHREAD_MUTEX_UNSAFE=y +CONFIG_PTHREAD_STACK_DEFAULT=1536 +CONFIG_RAM_SIZE=32760 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SPI_CMDDATA=y +CONFIG_START_DAY=19 +CONFIG_START_MONTH=5 +CONFIG_START_YEAR=2013 +CONFIG_STDIO_DISABLE_BUFFERING=y +CONFIG_STM32F0L0G0_PWR=y +CONFIG_STM32F0L0G0_SPI1=y +CONFIG_STM32F0L0G0_SPI1_COMMTYPE=1 +CONFIG_STM32F0L0G0_USART3=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536 +CONFIG_TLS_NELEM=0 +CONFIG_USART3_SERIAL_CONSOLE=y +CONFIG_USERLED=y +CONFIG_USERLED_LOWER=y diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.h b/boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.h index 092d288eb9e..266184c7029 100644 --- a/boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.h +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.h @@ -171,7 +171,7 @@ * SPI1_SCK - PA1 */ -#undef GPIO_SPI1_MISO /* Not used */ +#define GPIO_SPI1_MISO 0 /* Not used - simplex tx */ #define GPIO_SPI1_MOSI GPIO_SPI1_MOSI_1 /* PA2 */ #define GPIO_SPI1_SCK GPIO_SPI1_SCK_1 /* PA1 */ diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Make.defs b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Make.defs index 248e31ba27f..3a39020afa8 100644 --- a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Make.defs +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Make.defs @@ -31,10 +31,18 @@ ifeq ($(CONFIG_BOARDCTL),y) CSRCS += stm32_appinit.c endif +ifeq ($(CONFIG_SPI),y) +CSRCS += stm32_spi.c +endif + ifeq ($(CONFIG_INPUT_DJOYSTICK),y) CSRCS += stm32_djoystick.c endif +ifeq ($(CONFIG_LCD_SSD1306),y) +CSRCS += stm32_lcd_ssd1306.c +endif + 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/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c index 91787c9f251..9c7a0777b89 100644 --- a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c @@ -83,6 +83,12 @@ int stm32_bringup(void) syslog(LOG_INFO, "Successfully registered the joystick driver\n"); #endif +#ifdef CONFIG_LCD_SSD1306_SPI + /* NOTE: SSD1315Z is compatible with the SSD1306 driver */ + + board_lcd_initialize(); +#endif + UNUSED(ret); return OK; } diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_lcd_ssd1306.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_lcd_ssd1306.c new file mode 100644 index 00000000000..49a041c85c3 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_lcd_ssd1306.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_lcd_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 "stm32_gpio.h" + +#include "stm32g071b-disco.h" + +#include "stm32_ssd1306.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define OLED_SPI_PORT 1 /* OLED display connected to SPI1 */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_lcd_initialize + ****************************************************************************/ + +int board_lcd_initialize(void) +{ + int ret; + + /* Configure the OLED GPIOs. This initial configuration is RESET low, + * putting the OLED into reset state. + */ + + stm32_configgpio(GPIO_SSD1306_RST); + stm32_gpiowrite(GPIO_SSD1306_RST, 0); + + /* Wait a bit then release the OLED from the reset state */ + + up_mdelay(20); + stm32_gpiowrite(GPIO_SSD1306_RST, 1); + + /* Initialize OLED */ + + ret = board_ssd1306_initialize(OLED_SPI_PORT); + if (ret < 0) + { + lcderr("ERROR: Failed to initialize SSD1306\n"); + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: board_lcd_getdev + ****************************************************************************/ + +struct lcd_dev_s *board_lcd_getdev(int devno) +{ + return board_ssd1306_getdev(); +} + +/**************************************************************************** + * Name: board_lcd_uninitialize + ****************************************************************************/ + +void board_lcd_uninitialize(void) +{ + /* TO-FIX */ +} diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_spi.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_spi.c new file mode 100644 index 00000000000..4b6a1c64e84 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_spi.c @@ -0,0 +1,211 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_spi.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 "stm32_gpio.h" +#include "stm32_spi.h" + +#include + +#include "stm32g071b-disco.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Global driver instances */ + +#ifdef CONFIG_STM32F0L0G0_SPI1 +struct spi_dev_s *g_spi1; +#endif +#ifdef CONFIG_STM32F0L0G0_SPI2 +struct spi_dev_s *g_spi2; +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the Nucleo-F401RE and + * Nucleo-F411RE boards. + * + ****************************************************************************/ + +void weak_function stm32_spidev_initialize(void) +{ +#ifdef CONFIG_STM32F0L0G0_SPI1 + /* Configure SPI-based devices */ + + g_spi1 = stm32_spibus_initialize(1); + if (!g_spi1) + { + spierr("ERROR: FAILED to initialize SPI port 1\n"); + } +#endif + +#ifdef CONFIG_LCD_SSD1306_SPI + stm32_configgpio(GPIO_SSD1306_CS); /* SSD1306 chip select */ + stm32_configgpio(GPIO_SSD1306_CMD); /* SSD1306 data/!command */ +#endif +} + +/**************************************************************************** + * Name: stm32_spi1/2/3select and stm32_spi1/2/3status + * + * Description: + * The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status + * must be provided by board-specific logic. They are implementations of + * the select and status methods of the SPI interface defined by struct + * spi_ops_s (see include/nuttx/spi/spi.h). All other methods (including + * stm32_spibus_initialize()) are provided by common STM32 logic. To use + * this common SPI logic on your board: + * + * 1. Provide logic in stm32_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions + * in your board-specific logic. These functions will perform chip + * selection and status operations using GPIOs in the way your board is + * configured. + * 3. Add a calls to stm32_spibus_initialize() in your low level + * application initialization logic + * 4. The handle returned by stm32_spibus_initialize() may then be used to + * bind the SPI driver to higher level logic (e.g., calling + * mmcsd_spislotinitialize(), for example, will bind the SPI driver to + * the SPI MMC/SD driver). + * + ****************************************************************************/ + +#ifdef CONFIG_STM32F0L0G0_SPI1 +void stm32_spi1select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : + "de-assert"); + +#if defined(CONFIG_LCD_SSD1306_SPI) + if (devid == SPIDEV_DISPLAY(0)) + { + stm32_gpiowrite(GPIO_SSD1306_CS, !selected); + } +#endif +} + +uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_STM32F0L0G0_SPI2 +void stm32_spi2select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : + "de-assert"); +} + +uint8_t stm32_spi2status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_STM32F0L0G0_SPI3 +void stm32_spi3select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : + "de-assert"); +} + +uint8_t stm32_spi3status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +/**************************************************************************** + * Name: stm32_spi1cmddata + * + * Description: + * Set or clear the SD1306 D/C n bit to select data (true) or command + * (false). This function must be provided by platform-specific + * logic. This is an implementation of the cmddata method of the SPI + * interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h). + * + * Input Parameters: + * + * spi - SPI device that controls the bus the device that requires the CMD/ + * DATA selection. + * devid - If there are multiple devices on the bus, this selects which one + * to select cmd or data. NOTE: This design restricts, for example, + * one one SPI display per SPI bus. + * cmd - true: select command; false: select data + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_CMDDATA +#ifdef CONFIG_STM32F0L0G0_SPI1 +int stm32_spi1cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ +#if defined(CONFIG_LCD_SSD1306_SPI) + if (devid == SPIDEV_DISPLAY(0)) + { + stm32_gpiowrite(GPIO_SSD1306_CMD, !cmd); + } +#endif + + return OK; +} +#endif + +#ifdef CONFIG_STM32F0L0G0_SPI2 +int stm32_spi2cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return OK; +} +#endif + +#ifdef CONFIG_STM32F0L0G0_SPI3 +int stm32_spi3cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return OK; +} +#endif +#endif /* CONFIG_SPI_CMDDATA */ diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h index f3ee8e76806..5c0c2e1306e 100644 --- a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h @@ -57,6 +57,17 @@ #define GPIO_JOY_UP (GPIO_INPUT | GPIO_PULLDOWN | GPIO_EXTI | \ GPIO_PORTC | GPIO_PIN4) +/* OLED definitions *********************************************************/ + +#define GPIO_SSD1306_CS (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN3) + +#define GPIO_SSD1306_CMD (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN7) + +#define GPIO_SSD1306_RST (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN6) + /**************************************************************************** * Public Data ****************************************************************************/ @@ -81,6 +92,16 @@ int stm32_bringup(void); +/**************************************************************************** + * Name: stm32_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins. + * + ****************************************************************************/ + +void stm32_spidev_initialize(void); + /**************************************************************************** * Name: stm32_djoy_initialization *