From 2192b8df2bf8813bc8d276e492eb26089e8e6821 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Thu, 7 Jul 2022 19:06:22 +0200 Subject: [PATCH] boards: add initial support for stm32g071b-disco board --- boards/Kconfig | 9 + .../arm/stm32f0l0g0/stm32g071b-disco/Kconfig | 8 + .../stm32f0l0g0/stm32g071b-disco/README.txt | 15 + .../stm32g071b-disco/configs/nsh/defconfig | 59 ++++ .../stm32g071b-disco/include/board.h | 178 +++++++++++ .../stm32g071b-disco/scripts/Make.defs | 39 +++ .../stm32g071b-disco/scripts/ld.script | 112 +++++++ .../stm32f0l0g0/stm32g071b-disco/src/Makefile | 38 +++ .../stm32g071b-disco/src/stm32_appinit.c | 71 +++++ .../stm32g071b-disco/src/stm32_boot.c | 83 +++++ .../stm32g071b-disco/src/stm32_bringup.c | 88 ++++++ .../stm32g071b-disco/src/stm32_djoystick.c | 294 ++++++++++++++++++ .../stm32g071b-disco/src/stm32_userleds.c | 90 ++++++ .../stm32g071b-disco/src/stm32g071b-disco.h | 96 ++++++ 14 files changed, 1180 insertions(+) create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/Kconfig create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/README.txt create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/configs/nsh/defconfig create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.h create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/Make.defs create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/ld.script create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/Makefile create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_appinit.c create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_boot.c create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_djoystick.c create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_userleds.c create mode 100644 boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h diff --git a/boards/Kconfig b/boards/Kconfig index ce75222761..e69d9f0888 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -1344,6 +1344,14 @@ config ARCH_BOARD_NUCLEO_F446RE This is a minimal configuration that supports low-level test of the Nucleo F446RE in the NuttX source tree. + +config ARCH_BOARD_STM32G071B_DISCO + bool "STM32G071 STM32G071B-DISO " + depends on ARCH_CHIP_STM32G071RB + select ARCH_HAVE_LEDS + ---help--- + The STM32G071B-DISCO board based on the STM32G071RB MCU + config ARCH_BOARD_NUCLEO_G070RB bool "STM32G070 Nucleo G070RB" depends on ARCH_CHIP_STM32G070RB @@ -2586,6 +2594,7 @@ config ARCH_BOARD default "nucleo-f446re" if ARCH_BOARD_NUCLEO_F446RE default "nucleo-f410rb" if ARCH_BOARD_NUCLEO_F410RB default "nucleo-f412zg" if ARCH_BOARD_NUCLEO_F412ZG + default "stm32g071b-disco" if ARCH_BOARD_STM32G071B_DISCO default "nucleo-g070rb" if ARCH_BOARD_NUCLEO_G070RB default "nucleo-g071rb" if ARCH_BOARD_NUCLEO_G071RB default "nucleo-h743zi" if ARCH_BOARD_NUCLEO_H743ZI diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/Kconfig b/boards/arm/stm32f0l0g0/stm32g071b-disco/Kconfig new file mode 100644 index 0000000000..956053ae2f --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/Kconfig @@ -0,0 +1,8 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_STM32G071B_DISCO + +endif diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/README.txt b/boards/arm/stm32f0l0g0/stm32g071b-disco/README.txt new file mode 100644 index 0000000000..65b4bf12e1 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/README.txt @@ -0,0 +1,15 @@ +README +====== + + This README discusses issues unique to NuttX configurations for the + STMicro STM32G071B-DISCO development board. The STM32G071B-DISCO board + is based on the STM32G071RB MCU (128Kbytes FLASH and 32Kbytes of SRAM). + + The boards features: + + - An ST-LINK/V2-1 embedded debug tool interface, + - 128 x 64 pixels OLED display (SSD1315Z) + - LEDs, + - 4-way joystick + - USB Type-C current sensing based on the INA230 I2C + current-shunt and power monitor diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/configs/nsh/defconfig b/boards/arm/stm32f0l0g0/stm32g071b-disco/configs/nsh/defconfig new file mode 100644 index 0000000000..29ea257999 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/configs/nsh/defconfig @@ -0,0 +1,59 @@ +# +# 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_LIBC_LONG_LONG is not set +# CONFIG_NSH_ARGCAT is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="stm32g071b-disco" +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_DISABLE_ENVIRON=y +CONFIG_DISABLE_MOUNTPOINT=y +CONFIG_DISABLE_MQUEUE=y +CONFIG_DISABLE_POSIX_TIMERS=y +CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y +CONFIG_EXAMPLES_DJOYSTICK=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=1536 +CONFIG_INPUT=y +CONFIG_INPUT_DJOYSTICK=y +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_SMALL=y +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_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_START_DAY=19 +CONFIG_START_MONTH=5 +CONFIG_START_YEAR=2013 +CONFIG_STDIO_DISABLE_BUFFERING=y +CONFIG_STM32F0L0G0_PWR=y +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 new file mode 100644 index 0000000000..092d288eb9 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.h @@ -0,0 +1,178 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/include/board.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_STM32F0L0G0_STM32G071B_DISCO_INCLUDE_BOARD_H +#define __BOARDS_ARM_STM32F0L0G0_STM32G071B_DISCO_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* HSI - Internal 16 MHz RC Oscillator + * LSI - 32 KHz RC + * HSE - 8 MHz from MCO output of ST-LINK + * LSE - 32.768 kHz + */ + +#define STM32_BOARD_XTAL 8000000ul + +#define STM32_HSI_FREQUENCY 16000000ul +#define STM32_LSI_FREQUENCY 32000 /* Between 30kHz and 60kHz */ +#define STM32_HSE_FREQUENCY STM32_BOARD_XTAL +#define STM32_LSE_FREQUENCY 32768 /* X2 on board */ + +/* Main PLL Configuration. + * + * PLL source is HSI = 16,000,000 + * + * PLL_VCOx = (STM32_HSE_FREQUENCY / PLLM) * PLLN + * Subject to: + * + * 1 <= PLLM <= 8 + * 8 <= PLLN <= 86 + * 4 MHz <= PLL_IN <= 16MHz + * 64 MHz <= PLL_VCO <= 344MHz + * SYSCLK = PLLRCLK = PLL_VCO / PLLR + * + */ + +/* PLL source is HSI, PLLN=50, PLLM=4 + * PLLP enable, PLLQ enable, PLLR enable + * + * 2 <= PLLP <= 32 + * 2 <= PLLQ <= 8 + * 2 <= PLLR <= 8 + * + * PLLR <= 64MHz + * PLLQ <= 128MHz + * PLLP <= 128MHz + * + * PLL_VCO = (16,000,000 / 4) * 50 = 200 MHz + * + * PLLP = PLL_VCO/4 = 200 MHz / 4 = 40 MHz + * PLLQ = PLL_VCO/4 = 200 MHz / 4 = 40 MHz + * PLLR = PLL_VCO/4 = 200 MHz / 4 = 40 MHz + */ + +#define STM32_PLLCFG_PLLSRC RCC_PLLCFG_PLLSRC_HSI +#define STM32_PLLCFG_PLLCFG (RCC_PLLCFG_PLLPEN | \ + RCC_PLLCFG_PLLQEN | \ + RCC_PLLCFG_PLLREN) + +#define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(4) +#define STM32_PLLCFG_PLLN RCC_PLLCFG_PLLN(50) +#define STM32_PLLCFG_PLLP RCC_PLLCFG_PLLP(4) +#define STM32_PLLCFG_PLLQ RCC_PLLCFG_PLLQ(4) +#define STM32_PLLCFG_PLLR RCC_PLLCFG_PLLR(4) + +#define STM32_VCO_FREQUENCY ((STM32_HSE_FREQUENCY / 2) * 50) +#define STM32_PLLP_FREQUENCY (STM32_VCO_FREQUENCY / 4) +#define STM32_PLLQ_FREQUENCY (STM32_VCO_FREQUENCY / 4) +#define STM32_PLLR_FREQUENCY (STM32_VCO_FREQUENCY / 4) + +/* Use the PLL and set the SYSCLK source to be the PLLR (40MHz) */ + +#define STM32_SYSCLK_SW RCC_CFGR_SW_PLL +#define STM32_SYSCLK_SWS RCC_CFGR_SWS_PLL +#define STM32_SYSCLK_FREQUENCY (STM32_PLLR_FREQUENCY) +#define STM32_SYSCLK_FREQUENCY (STM32_PLLR_FREQUENCY) + +/* AHB clock (HCLK) is SYSCLK (40MHz) */ + +#define STM32_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK +#define STM32_HCLK_FREQUENCY STM32_SYSCLK_FREQUENCY + +/* APB1 clock (PCLK1) is HCLK/2 (20MHz) */ + +#define STM32_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLKd2 +#define STM32_PCLK1_FREQUENCY (STM32_HCLK_FREQUENCY/2) + +/* LED definitions **********************************************************/ + +/* LED index values for use with board_userled() */ + +#define BOARD_LEDSINK 0 /* LD4: SINK mode LED */ +#define BOARD_LEDSOURCE 1 /* LD5: SOURCE mode LED */ +#define BOARD_LEDSPY 2 /* LD6: SPY mode LED */ +#define BOARD_LEDCC 3 /* LD7: CC mode LED */ +#define BOARD_NLEDS 4 + +/* LED bits for use with board_userled_all() */ + +#define BOARD_LEDSINK_BIT (1 << BOARD_LEDSINK) +#define BOARD_LEDSOURCE_BIT (1 << BOARD_LEDSOURCE) +#define BOARD_LEDSPY_BIT (1 << BOARD_LEDSPY) +#define BOARD_LEDCC_BIT (1 << BOARD_LEDCC) + +/* Button definitions *******************************************************/ + +/* The STM32G071B-DISO supports one buttons: + * + * B1 RESET: push button connected to NRST is used to RESET the + * STM32G071RB. + * + * and a Joystick: + * + * Joystick center - PC0 + * Joystick down - PC2 + * Joystick left - PC1 + * Joystick right - PC3 + * Joystick up - PC4 + */ + +/* Alternate function pin selections ****************************************/ + +/* USART */ + +/* By default the USART3 is connected to STLINK Virtual COM Port: + * USART3_RX - PC11 + * USART3_TX - PC10 + */ + +#define GPIO_USART3_RX GPIO_USART3_RX_6 /* PC11 */ +#define GPIO_USART3_TX GPIO_USART3_TX_6 /* PC10 */ + +/* I2C1 + * I2C1_SCL - PB6 + * I2C1_SDA - PB7 + */ + +#define GPIO_I2C1_SCL GPIO_I2C1_SCL_2 /* PB6 */ +#define GPIO_I2C1_SDA GPIO_I2C1_SDA_2 /* PB7 */ + +/* SPI1 - OLED display + * SPI1_MISO - not used + * SPI1_MOSI - PA2 + * SPI1_SCK - PA1 + */ + +#undef GPIO_SPI1_MISO /* Not used */ +#define GPIO_SPI1_MOSI GPIO_SPI1_MOSI_1 /* PA2 */ +#define GPIO_SPI1_SCK GPIO_SPI1_SCK_1 /* PA1 */ + +#endif /* __BOARDS_ARM_STM32F0L0G0_STM32G071B_DISCO_INCLUDE_BOARD_H */ diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/Make.defs b/boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/Make.defs new file mode 100644 index 0000000000..0d892e32cb --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/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. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/arch/arm/src/armv6-m/Toolchain.defs + +LDSCRIPT = ld.script +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) + +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/ld.script b/boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/ld.script new file mode 100644 index 0000000000..beb5b1237c --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/ld.script @@ -0,0 +1,112 @@ +/**************************************************************************** +* boards/arm/stm32f0l0g0/stm32g071b-disco/scripts/ld.script + * + * 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. + * + ****************************************************************************/ + +/* The STM32GO71RB has 128Kb of FLASH beginning at address 0x0800:0000. + * 32Kb of SRAM + * + * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000 + * where the code expects to begin execution by jumping to the entry point in + * the 0x0800:0000 address range. + */ + +MEMORY +{ + flash (rx) : ORIGIN = 0x08000000, LENGTH = 128K + sram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K +} + +OUTPUT_ARCH(arm) +EXTERN(_vectors) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > flash + + .init_section : ALIGN(4) { + _sinit = ABSOLUTE(.); + *(.init_array .init_array.*) + _einit = ABSOLUTE(.); + } > flash + + .ARM.extab : ALIGN(4) { + *(.ARM.extab*) + } > flash + + .ARM.exidx : ALIGN(4) { + __exidx_start = ABSOLUTE(.); + *(.ARM.exidx*) + __exidx_end = ABSOLUTE(.); + } > flash + + _eronly = ABSOLUTE(.); + + /* The RAM vector table (if present) should lie at the beginning of SRAM */ + + .ram_vectors : { + *(.ram_vectors) + } > sram + + .data : ALIGN(4) { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > sram AT > flash + + .bss : ALIGN(4) { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > sram + + /* Stabs debugging sections. */ + + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } +} diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Makefile b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Makefile new file mode 100644 index 0000000000..76f9124adf --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/Makefile @@ -0,0 +1,38 @@ +############################################################################ +# boards/arm/stm32f0l0g0/stm32g071b-disco/src/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 + +CSRCS = stm32_boot.c stm32_bringup.c + +# no auto leds +ifeq ($(CONFIG_USERLED),y) +CSRCS += stm32_userleds.c +endif + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += stm32_appinit.c +endif + +ifeq ($(CONFIG_INPUT_DJOYSTICK),y) +CSRCS += stm32_djoystick.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_appinit.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_appinit.c new file mode 100644 index 0000000000..f03c6fb054 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_appinit.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_appinit.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 "stm32g071b-disco.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ +#ifdef CONFIG_BOARD_LATE_INITIALIZE + /* Board initialization already performed by board_late_initialize() */ + + return OK; +#else + /* Perform board-specific initialization */ + + return stm32_bringup(); +#endif +} diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_boot.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_boot.c new file mode 100644 index 0000000000..2124827276 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_boot.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_boot.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 "stm32g071b-disco.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_boardinitialize + * + * Description: + * All STM32 architectures must provide the following entry point. This + * entry point is called early in the initialization -- after all memory + * has been configured and mapped but before any devices have been + * initialized. + * + ****************************************************************************/ + +void stm32_boardinitialize(void) +{ +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif + +#ifdef CONFIG_STM32F0L0G0_SPI + /* Configure SPI chip selects */ + + stm32_spidev_initialize(); +#endif +} + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will + * be called immediately after up_initialize() is called and just before + * the initial application is started. This additional initialization + * phase may be used, for example, to initialize board-specific device + * drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board-specific initialization */ + + stm32_bringup(); +} +#endif diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c new file mode 100644 index 0000000000..91787c9f25 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_bringup.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 "stm32g071b-disco.h" + +#ifdef CONFIG_USERLED +# include +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret; + +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize(LED_DRIVER_PATH); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_INPUT_DJOYSTICK + /* Initialize and register the joystick driver */ + + ret = stm32_djoy_initialization(); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the joystick driver: %d\n", ret); + return ret; + } + + syslog(LOG_INFO, "Successfully registered the joystick driver\n"); +#endif + + UNUSED(ret); + return OK; +} diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_djoystick.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_djoystick.c new file mode 100644 index 0000000000..bcfd9455ac --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_djoystick.c @@ -0,0 +1,294 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_djoystick.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 + +#include "stm32_gpio.h" +#include "stm32g071b-disco.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Number of Joystick discretes */ + +#define DJOY_NGPIOS 5 + +/* Bitset of supported Joystick discretes */ + +#define DJOY_SUPPORTED (DJOY_UP_BIT | DJOY_DOWN_BIT | DJOY_LEFT_BIT | \ + DJOY_RIGHT_BIT | DJOY_BUTTON_SELECT_BIT) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static djoy_buttonset_t +djoy_supported(const struct djoy_lowerhalf_s *lower); +static djoy_buttonset_t +djoy_sample(const struct djoy_lowerhalf_s *lower); +static void djoy_enable(const struct djoy_lowerhalf_s *lower, + djoy_buttonset_t press, djoy_buttonset_t release, + djoy_interrupt_t handler, void *arg); + +static void djoy_disable(void); +static int djoy_interrupt(int irq, void *context, void *arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Pin configuration for each stm32g071b-disco joystick "button." + * Index using DJOY_* definitions in include/nuttx/input/djoystick.h. + */ + +static const uint32_t g_joygpio[DJOY_NGPIOS] = +{ + GPIO_JOY_UP, GPIO_JOY_DOWN, GPIO_JOY_LEFT, GPIO_JOY_RIGHT, GPIO_JOY_SEL +}; + +/* Current interrupt handler and argument */ + +static djoy_interrupt_t g_djoyhandler; +static void *g_djoyarg; + +/* This is the discrete joystick lower half driver interface */ + +static const struct djoy_lowerhalf_s g_djoylower = +{ + .dl_supported = djoy_supported, + .dl_sample = djoy_sample, + .dl_enable = djoy_enable, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: djoy_supported + * + * Description: + * Return the set of buttons supported on the discrete joystick device + * + ****************************************************************************/ + +static djoy_buttonset_t +djoy_supported(const struct djoy_lowerhalf_s *lower) +{ + iinfo("Supported: %02x\n", DJOY_SUPPORTED); + return (djoy_buttonset_t)DJOY_SUPPORTED; +} + +/**************************************************************************** + * Name: djoy_sample + * + * Description: + * Return the current state of all discrete joystick buttons + * + ****************************************************************************/ + +static djoy_buttonset_t djoy_sample(const struct djoy_lowerhalf_s *lower) +{ + djoy_buttonset_t ret = 0; + int i; + bool released; + + /* Read each joystick GPIO value */ + + for (i = 0; i < DJOY_NGPIOS; i++) + { + released = stm32_gpioread(g_joygpio[i]); + if (!released) + { + ret |= (1 << i); + } + } + + iinfo("Retuning: %02x\n", DJOY_SUPPORTED); + return ret; +} + +/**************************************************************************** + * Name: djoy_enable + * + * Description: + * Enable interrupts on the selected set of joystick buttons. And empty + * set will disable all interrupts. + * + ****************************************************************************/ + +static void djoy_enable(const struct djoy_lowerhalf_s *lower, + djoy_buttonset_t press, djoy_buttonset_t release, + djoy_interrupt_t handler, void *arg) +{ + irqstate_t flags; + djoy_buttonset_t either = press | release; + djoy_buttonset_t bit; + bool rising; + bool falling; + int i; + + /* Start with all interrupts disabled */ + + flags = enter_critical_section(); + djoy_disable(); + + iinfo("press: %02x release: %02x handler: %p arg: %p\n", + press, release, handler, arg); + + /* If no events are indicated or if no handler is provided, then this + * must really be a request to disable interrupts. + */ + + if (either && handler) + { + /* Save the new the handler and argument */ + + g_djoyhandler = handler; + g_djoyarg = arg; + + /* Check each GPIO. */ + + for (i = 0; i < DJOY_NGPIOS; i++) + { + /* Enable interrupts on each pin that has either a press or + * release event associated with it. + */ + + bit = (1 << i); + if ((either & bit) != 0) + { + /* Active low so a press corresponds to a falling edge and + * a release corresponds to a rising edge. + */ + + falling = ((press & bit) != 0); + rising = ((release & bit) != 0); + + iinfo("GPIO %d: rising: %d falling: %d\n", + i, rising, falling); + + stm32_gpiosetevent(g_joygpio[i], rising, falling, + true, djoy_interrupt, NULL); + } + } + } + + leave_critical_section(flags); +} + +/**************************************************************************** + * Name: djoy_disable + * + * Description: + * Disable all joystick interrupts + * + ****************************************************************************/ + +static void djoy_disable(void) +{ + irqstate_t flags; + int i; + + /* Disable each joystick interrupt */ + + flags = enter_critical_section(); + for (i = 0; i < DJOY_NGPIOS; i++) + { + stm32_gpiosetevent(g_joygpio[i], false, false, false, NULL, NULL); + } + + leave_critical_section(flags); + + /* Nullify the handler and argument */ + + g_djoyhandler = NULL; + g_djoyarg = NULL; +} + +/**************************************************************************** + * Name: djoy_interrupt + * + * Description: + * Discrete joystick interrupt handler + * + ****************************************************************************/ + +static int djoy_interrupt(int irq, void *context, void *arg) +{ + DEBUGASSERT(g_djoyhandler); + if (g_djoyhandler) + { + g_djoyhandler(&g_djoylower, g_djoyarg); + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_djoy_initialization + * + * Description: + * Initialize and register the discrete joystick driver + * + ****************************************************************************/ + +int stm32_djoy_initialization(void) +{ + int i; + + /* Configure the GPIO pins as inputs. NOTE: This is unnecessary for + * interrupting pins since it will also be done by stm32_gpiosetevent(). + */ + + for (i = 0; i < DJOY_NGPIOS; i++) + { + stm32_configgpio(g_joygpio[i]); + } + + /* Make sure that all interrupts are disabled */ + + djoy_disable(); + + /* Register the joystick device as /dev/djoy0 */ + + return djoy_register("/dev/djoy0", &g_djoylower); +} diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_userleds.c b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_userleds.c new file mode 100644 index 0000000000..d97bb11a00 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_userleds.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32_userleds.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 "stm32_gpio.h" +#include "stm32g071b-disco.h" + +#include + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration */ + +static uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LEDSINK, GPIO_LEDSOURCE, GPIO_LEDSPY, GPIO_LEDCC +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + /* Configure LED GPIOs for output */ + + stm32_configgpio(GPIO_LEDSINK); + stm32_configgpio(GPIO_LEDSOURCE); + stm32_configgpio(GPIO_LEDSPY); + stm32_configgpio(GPIO_LEDCC); + + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < BOARD_NLEDS) + { + stm32_gpiowrite(g_ledcfg[led], !ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + stm32_gpiowrite(GPIO_LEDSINK, (ledset & BOARD_LEDSINK_BIT) != 0); + stm32_gpiowrite(GPIO_LEDSOURCE, (ledset & BOARD_LEDSOURCE_BIT) != 0); + stm32_gpiowrite(GPIO_LEDSPY, (ledset & BOARD_LEDSPY_BIT) != 0); + stm32_gpiowrite(GPIO_LEDCC, (ledset & BOARD_LEDCC_BIT) != 0); +} diff --git a/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h new file mode 100644 index 0000000000..f3ee8e7680 --- /dev/null +++ b/boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.h @@ -0,0 +1,96 @@ +/**************************************************************************** + * boards/arm/stm32f0l0g0/stm32g071b-disco/src/stm32g071b-disco.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_STM32F0L0G0_STM32G071B_DISCO_SRC_STM32G071B_DISCO_H +#define __BOARDS_ARM_STM32F0L0G0_STM32G071B_DISCO_SRC_STM32G071B_DISCO_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* LED definitions **********************************************************/ + +#define GPIO_LEDSINK (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTD | GPIO_PIN9) +#define GPIO_LEDSOURCE (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTD | GPIO_PIN8) +#define GPIO_LEDSPY (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTC | GPIO_PIN12) +#define GPIO_LEDCC (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_HIGH | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTD | GPIO_PIN5) + +#define LED_DRIVER_PATH "/dev/userleds" + +/* Joystic definitions ******************************************************/ + +#define GPIO_JOY_SEL (GPIO_INPUT | GPIO_PULLDOWN | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN0) +#define GPIO_JOY_DOWN (GPIO_INPUT | GPIO_PULLDOWN | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN2) +#define GPIO_JOY_LEFT (GPIO_INPUT | GPIO_PULLDOWN | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN1) +#define GPIO_JOY_RIGHT (GPIO_INPUT | GPIO_PULLDOWN | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN3) +#define GPIO_JOY_UP (GPIO_INPUT | GPIO_PULLDOWN | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN4) + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void); + +/**************************************************************************** + * Name: stm32_djoy_initialization + * + * Description: + * Initialize and register the discrete joystick driver + * + ****************************************************************************/ + +#ifdef CONFIG_INPUT_DJOYSTICK +int stm32_djoy_initialization(void); +#endif + +#endif /* __BOARDS_ARM_STM32F0L0G0_STM32G071B_DISCO_SRC_STM32G071B_DISCO_H */