diff --git a/Documentation/platforms/arm/stm32u0/boards/nucleo-u083rc/index.rst b/Documentation/platforms/arm/stm32u0/boards/nucleo-u083rc/index.rst new file mode 100644 index 00000000000..f686bc162f9 --- /dev/null +++ b/Documentation/platforms/arm/stm32u0/boards/nucleo-u083rc/index.rst @@ -0,0 +1,56 @@ +================ +ST Nucleo U083RC +================ + +.. tags:: chip:stm32, chip:stm32u0, chip:stm32u083 + +The Nucleo U083RC is a member of the Nucleo-64 board family. + +USB not supported yet. + +Buttons +======= + +B1 USER: the user button is connected to the I/O PC13 of the STM32 +microcontroller. + +Serial Console +============== + +At default USART2 connected to "Virtual COM Port" is used as serial console. + +Configurations +============== + +nsh +--- + +Configures the NuttShell (nsh) located at apps/examples/nsh. The +Configuration enables the serial interfaces on USART2. Support for +builtin applications is disabled. + +jumbo +----- + +This configuration enables many Apache NuttX features. This is +mostly to help provide additional code coverage in CI, but also +allows for a users to see a wide range of features that are +supported by the OS. + +Enabled features: + +- NSH with builtin applications + +- OS test (ostest) + +- ADC with DMA enabled using A0-A3 pins + +- PWM on TIM1 CH1 (PA8, D7) + +- Quadrature encoder on TIM3 (PA6/PA7, D12/D11) + +- Timer driver on TIM6 (/dev/timer0) + +- IWDG and WWDG watchdogs + +- button with software debouncing enabled (no RC filter on the board) diff --git a/boards/Kconfig b/boards/Kconfig index b53f5edac94..d05381e3843 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -3054,6 +3054,15 @@ config ARCH_BOARD_NUCLEO_C092RC ---help--- STMicro NUCLEO C092RC board based on the STMicro STM32C092RC MCU. +config ARCH_BOARD_NUCLEO_U083RC + bool "STMicro Nucleo U083RC board" + depends on ARCH_CHIP_STM32U083RC + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS + ---help--- + STMicro NUCLEO U083RC board based on the STMicro STM32U083RC MCU. + config ARCH_BOARD_STM32F3_DISCOVERY bool "STMicro STM32F3-Discovery board" depends on ARCH_CHIP_STM32F303VC @@ -4060,6 +4069,7 @@ config ARCH_BOARD default "stm32f072-discovery" if ARCH_BOARD_STM32F072_DISCOVERY default "nucleo-c071rb" if ARCH_BOARD_NUCLEO_C071RB default "nucleo-c092rc" if ARCH_BOARD_NUCLEO_C092RC + default "nucleo-u083rc" if ARCH_BOARD_NUCLEO_U083RC default "stm32f103-minimum" if ARCH_BOARD_STM32F103_MINIMUM default "stm32f411-minimum" if ARCH_BOARD_STM32F411_MINIMUM default "stm3210e-eval" if ARCH_BOARD_STM3210E_EVAL @@ -4665,6 +4675,9 @@ endif if ARCH_BOARD_NUCLEO_C092RC source "boards/arm/stm32c0/nucleo-c092rc/Kconfig" endif +if ARCH_BOARD_NUCLEO_U083RC +source "boards/arm/stm32u0/nucleo-u083rc/Kconfig" +endif if ARCH_BOARD_NUCLEO_F722ZE source "boards/arm/stm32f7/nucleo-f722ze/Kconfig" endif @@ -5350,7 +5363,7 @@ endif if ARCH_CHIP_SAMV7 source "boards/arm/samv7/common/Kconfig" endif -if ARCH_CHIP_STM32C0 || ARCH_CHIP_STM32F0 || ARCH_CHIP_STM32F1 || ARCH_CHIP_STM32F2 || ARCH_CHIP_STM32F3 || ARCH_CHIP_STM32F4 || ARCH_CHIP_STM32F7 || ARCH_CHIP_STM32G0 || ARCH_CHIP_STM32G4 || ARCH_CHIP_STM32L0 || ARCH_CHIP_STM32L1 || ARCH_CHIP_STM32H7 || ARCH_CHIP_STM32H5 || ARCH_CHIP_STM32L5 || ARCH_CHIP_STM32U5 || ARCH_CHIP_STM32WB || ARCH_CHIP_STM32WL5 || ARCH_CHIP_STM32N6 +if ARCH_CHIP_STM32C0 || ARCH_CHIP_STM32F0 || ARCH_CHIP_STM32F1 || ARCH_CHIP_STM32F2 || ARCH_CHIP_STM32F3 || ARCH_CHIP_STM32F4 || ARCH_CHIP_STM32F7 || ARCH_CHIP_STM32G0 || ARCH_CHIP_STM32G4 || ARCH_CHIP_STM32L0 || ARCH_CHIP_STM32L1 || ARCH_CHIP_STM32H7 || ARCH_CHIP_STM32H5 || ARCH_CHIP_STM32L5 || ARCH_CHIP_STM32U0 || ARCH_CHIP_STM32U5 || ARCH_CHIP_STM32WB || ARCH_CHIP_STM32WL5 || ARCH_CHIP_STM32N6 source "boards/arm/common/stm32/Kconfig" endif if ARCH_CHIP_RP2040 diff --git a/boards/arm/stm32u0/common/CMakeLists.txt b/boards/arm/stm32u0/common/CMakeLists.txt new file mode 100644 index 00000000000..14156a4ba83 --- /dev/null +++ b/boards/arm/stm32u0/common/CMakeLists.txt @@ -0,0 +1,25 @@ +# ############################################################################## +# boards/arm/stm32u0/common/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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. +# +# ############################################################################## + +if(CONFIG_ARCH_BOARD_COMMON) + add_subdirectory(${NUTTX_DIR}/boards/arm/common/stm32 stm32_common) +endif() diff --git a/boards/arm/stm32u0/common/Kconfig b/boards/arm/stm32u0/common/Kconfig new file mode 100644 index 00000000000..5c48f62a025 --- /dev/null +++ b/boards/arm/stm32u0/common/Kconfig @@ -0,0 +1,6 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +source "boards/arm/common/stm32/Kconfig" diff --git a/boards/arm/stm32u0/common/Makefile b/boards/arm/stm32u0/common/Makefile new file mode 100644 index 00000000000..4b4f416d9be --- /dev/null +++ b/boards/arm/stm32u0/common/Makefile @@ -0,0 +1,38 @@ +############################################################################# +# boards/arm/stm32u0/common/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 + +STM32_BOARD_COMMON_DIR := $(TOPDIR)$(DELIM)boards$(DELIM)arm$(DELIM)common$(DELIM)stm32 +STM32_COMMON_SRCDIR := $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)common$(DELIM)stm32 + +include board/Make.defs +include $(STM32_BOARD_COMMON_DIR)$(DELIM)src$(DELIM)Make.defs + +DEPPATH += --dep-path board + +include $(TOPDIR)/boards/Board.mk + +ARCHSRCDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src +BOARDDIR = $(ARCHSRCDIR)$(DELIM)board +CFLAGS += ${INCDIR_PREFIX}$(BOARDDIR)$(DELIM)include +CFLAGS += ${INCDIR_PREFIX}$(STM32_COMMON_SRCDIR) diff --git a/boards/arm/stm32u0/nucleo-u083rc/CMakeLists.txt b/boards/arm/stm32u0/nucleo-u083rc/CMakeLists.txt new file mode 100644 index 00000000000..e9d15dd95de --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/CMakeLists.txt @@ -0,0 +1,23 @@ +# ############################################################################## +# boards/arm/stm32u0/nucleo-u083rc/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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. +# +# ############################################################################## + +add_subdirectory(src) diff --git a/boards/arm/stm32u0/nucleo-u083rc/Kconfig b/boards/arm/stm32u0/nucleo-u083rc/Kconfig new file mode 100644 index 00000000000..1a6d9ae73e4 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/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_NUCLEO_U083RC + +endif diff --git a/boards/arm/stm32u0/nucleo-u083rc/configs/jumbo/defconfig b/boards/arm/stm32u0/nucleo-u083rc/configs/jumbo/defconfig new file mode 100644 index 00000000000..84ec84ee4d6 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/configs/jumbo/defconfig @@ -0,0 +1,90 @@ +# +# 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_ADC=y +CONFIG_ANALOG=y +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="nucleo-u083rc" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_NUCLEO_U083RC=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="stm32u0" +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32U083RC=y +CONFIG_ARCH_CHIP_STM32U0=y +CONFIG_ARCH_IRQBUTTONS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL=y +CONFIG_BOARD_LOOPSPERMSEC=4663 +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_MQUEUE=y +CONFIG_DISABLE_POSIX_TIMERS=y +CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y +CONFIG_EXAMPLES_ADC=y +CONFIG_EXAMPLES_ADC_GROUPSIZE=2 +CONFIG_EXAMPLES_ADC_SWTRIG=y +CONFIG_EXAMPLES_BUTTONS=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_PWM=y +CONFIG_EXAMPLES_QENCODER=y +CONFIG_EXAMPLES_TIMER=y +CONFIG_EXAMPLES_WATCHDOG=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=1536 +CONFIG_INPUT=y +CONFIG_INPUT_BUTTONS=y +CONFIG_INPUT_BUTTONS_DEBOUNCE_DELAY=10 +CONFIG_INPUT_BUTTONS_LOWER=y +CONFIG_INTELHEX_BINARY=y +CONFIG_LINE_MAX=64 +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_READLINE=y +CONFIG_NUNGET_CHARS=0 +CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=1536 +CONFIG_PTHREAD_MUTEX_UNSAFE=y +CONFIG_PTHREAD_STACK_DEFAULT=1536 +CONFIG_PWM=y +CONFIG_RAM_SIZE=40960 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SENSORS=y +CONFIG_SENSORS_QENCODER=y +CONFIG_SERIAL_TERMIOS=y +CONFIG_START_DAY=19 +CONFIG_START_MONTH=5 +CONFIG_START_YEAR=2013 +CONFIG_STDIO_DISABLE_BUFFERING=y +CONFIG_STM32_ADC1=y +CONFIG_STM32_ADC_MAX_SAMPLES=4 +CONFIG_STM32_DMA1=y +CONFIG_STM32_IWDG=y +CONFIG_STM32_PWM_MULTICHAN=y +CONFIG_STM32_PWR=y +CONFIG_STM32_TIM1=y +CONFIG_STM32_TIM1_CH1OUT=y +CONFIG_STM32_TIM1_CHANNEL1=y +CONFIG_STM32_TIM1_PWM=y +CONFIG_STM32_TIM3=y +CONFIG_STM32_TIM3_QE=y +CONFIG_STM32_TIM6=y +CONFIG_STM32_USART2=y +CONFIG_STM32_WWDG=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_TESTING_OSTEST=y +CONFIG_TESTING_OSTEST_STACKSIZE=3072 +CONFIG_TIMER=y +CONFIG_USART2_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32u0/nucleo-u083rc/configs/nsh/defconfig b/boards/arm/stm32u0/nucleo-u083rc/configs/nsh/defconfig new file mode 100644 index 00000000000..5f6c73b7ac2 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/configs/nsh/defconfig @@ -0,0 +1,45 @@ +# +# 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="arm" +CONFIG_ARCH_BOARD="nucleo-u083rc" +CONFIG_ARCH_BOARD_NUCLEO_U083RC=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="stm32u0" +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32U083RC=y +CONFIG_ARCH_CHIP_STM32U0=y +CONFIG_ARCH_IRQBUTTONS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARD_LOOPSPERMSEC=4663 +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=1536 +CONFIG_INTELHEX_BINARY=y +CONFIG_LINE_MAX=64 +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_FILEIOSIZE=64 +CONFIG_NSH_READLINE=y +CONFIG_NUNGET_CHARS=0 +CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=1536 +CONFIG_PTHREAD_MUTEX_UNSAFE=y +CONFIG_PTHREAD_STACK_DEFAULT=1536 +CONFIG_RAM_SIZE=40960 +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_STM32_PWR=y +CONFIG_STM32_USART2=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART2_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32u0/nucleo-u083rc/include/board.h b/boards/arm/stm32u0/nucleo-u083rc/include/board.h new file mode 100644 index 00000000000..6ebea33bd51 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/include/board.h @@ -0,0 +1,209 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/include/board.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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_STM32U0_NUCLEO_U083RC_INCLUDE_BOARD_H +#define __BOARDS_ARM_STM32U0_NUCLEO_U083RC_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* HSI - Internal 16 MHz RC Oscillator + * MSI - Internal multispeed RC Oscillator (100 kHz - 48 MHz) + * LSI - 32 kHz RC + * HSE - 8 MHz from MCO output of ST-LINK (not fitted by default) + * LSE - 32.768 kHz + */ + +#define STM32_BOARD_XTAL 8000000ul /* 8MHz */ + +#define STM32_HSI_FREQUENCY 16000000ul /* 16MHz */ +#define STM32_LSI_FREQUENCY 32000 /* Between 30kHz and 60kHz */ +#define STM32_HSE_FREQUENCY STM32_BOARD_XTAL +#define STM32_LSE_FREQUENCY 32768 /* X2 on board */ + +/* PLL configuration + * + * PLL source is HSI16 + * VCO input frequency = 16 MHz / PLLM = 16 MHz (must be 2.66 - 16 MHz) + * VCO output frequency = 16 MHz * PLLN = 112 MHz (must be 96 - 344 MHz) + * PLLP output = 112 MHz / PLLP = 56 MHz + * PLLQ output = 112 MHz / PLLQ = 56 MHz + * PLLR output (SYSCLK) = 112 MHz / PLLR = 56 MHz + */ + +#define STM32_PLLCFG_PLLSRC RCC_PLLCFG_PLLSRC_HSI +#define STM32_PLLCFG_PLLCFG (RCC_PLLCFG_PLLPEN | RCC_PLLCFG_PLLREN) + +#define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(1) +#define STM32_PLLCFG_PLLN RCC_PLLCFG_PLLN(7) +#define STM32_PLLCFG_PLLP RCC_PLLCFG_PLLP(2) +#define STM32_PLLCFG_PLLQ RCC_PLLCFG_PLLQ(2) +#define STM32_PLLCFG_PLLR RCC_PLLCFG_PLLR(2) + +#define STM32_VCO_FREQUENCY ((STM32_HSI_FREQUENCY / 1) * 7) +#define STM32_PLLP_FREQUENCY (STM32_VCO_FREQUENCY / 2) +#define STM32_PLLQ_FREQUENCY (STM32_VCO_FREQUENCY / 2) +#define STM32_PLLR_FREQUENCY (STM32_VCO_FREQUENCY / 2) + +/* Use the PLL as SYSCLK source (56 MHz) */ + +#define STM32_SYSCLK_SW RCC_CFGR_SW_PLL +#define STM32_SYSCLK_SWS RCC_CFGR_SWS_PLL +#define STM32_SYSCLK_FREQUENCY STM32_PLLR_FREQUENCY + +/* AHB clock (HCLK) is SYSCLK (56 MHz) */ + +#define STM32_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK +#define STM32_HCLK_FREQUENCY STM32_SYSCLK_FREQUENCY + +/* APB clock (PCLK) is HCLK (56 MHz) */ + +#define STM32_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK +#define STM32_PCLK1_FREQUENCY STM32_HCLK_FREQUENCY +#define STM32_PCLK2_FREQUENCY STM32_PCLK1_FREQUENCY + +/* All timers on PCLK x1 (56 MHz) */ + +#define STM32_TIM1_CLKIN STM32_PCLK1_FREQUENCY +#define STM32_TIM2_CLKIN STM32_PCLK1_FREQUENCY +#define STM32_TIM3_CLKIN STM32_PCLK1_FREQUENCY +#define STM32_TIM6_CLKIN STM32_PCLK1_FREQUENCY +#define STM32_TIM7_CLKIN STM32_PCLK1_FREQUENCY +#define STM32_TIM15_CLKIN STM32_PCLK1_FREQUENCY +#define STM32_TIM16_CLKIN STM32_PCLK1_FREQUENCY + +/* LED definitions **********************************************************/ + +/* The Nucleo U083RC board has three LEDs. Two of these are controlled by + * logic on the board and are not available for software control: + * + * LD1 COM: LD1 is yellow-green and controlled by the ST-LINK. + * LD3 PWR: red LED indicates that the board is powered. + * + * And one can be controlled by software: + * + * User LD4: green LED is a user LED connected to the I/O PA5. + */ + +/* LED index values for use with board_userled() */ + +#define BOARD_LED1 0 /* User LD4 */ +#define BOARD_NLEDS 1 + +/* LED bits for use with board_userled_all() */ + +#define BOARD_LED1_BIT (1 << BOARD_LED1) + +/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on the + * board. The following definitions describe how NuttX controls + * the LED: + * + * SYMBOL Meaning LED1 state + * ------------------ ----------------------- ---------- + * LED_STARTED NuttX has been started OFF + * LED_HEAPALLOCATE Heap has been allocated OFF + * LED_IRQSENABLED Interrupts enabled OFF + * LED_STACKCREATED Idle stack created ON + * LED_INIRQ In an interrupt No change + * LED_SIGNAL In a signal handler No change + * LED_ASSERTION An assertion failed No change + * LED_PANIC The system has crashed Blinking + * LED_IDLE STM32 is in sleep mode Not used + */ + +#define LED_STARTED 0 +#define LED_HEAPALLOCATE 0 +#define LED_IRQSENABLED 0 +#define LED_STACKCREATED 1 +#define LED_INIRQ 2 +#define LED_SIGNAL 2 +#define LED_ASSERTION 2 +#define LED_PANIC 1 + +/* Button definitions *******************************************************/ + +/* Nucleo U083RC board supports two buttons; only one button is controllable + * by software: + * + * B1 USER: user button connected to STM32 I/O PC13. + * B2 RESET: push button connected to NRST; used to RESET the MCU. + */ + +#define BUTTON_USER 0 /* User B1 */ +#define NUM_BUTTONS 1 + +#define BUTTON_USER_BIT (1 << BUTTON_USER) + +/* Alternate function pin selections ****************************************/ + +/* USART */ + +/* USART1 at arduino D0/D1: + * USART1_RX - PB7 + * USART1_TX - PB6 + */ + +#define GPIO_USART1_RX (GPIO_USART1_RX_2|GPIO_SPEED_HIGH) /* PB7 */ +#define GPIO_USART1_TX (GPIO_USART1_TX_2|GPIO_SPEED_HIGH) /* PB6 */ + +/* By default the USART2 is connected to STLINK Virtual COM Port: + * USART2_RX - PA3 + * USART2_TX - PA2 + */ + +#define GPIO_USART2_RX (GPIO_USART2_RX_1|GPIO_SPEED_HIGH) /* PA3 */ +#define GPIO_USART2_TX (GPIO_USART2_TX_1|GPIO_SPEED_HIGH) /* PA2 */ + +/* PWM on TIM1: + * TIM1_CH1 - PA8 (D7) + */ + +#define GPIO_TIM1_CH1OUT (GPIO_TIM1_CH1OUT_1|GPIO_SPEED_HIGH) /* PA8 */ + +/* Qencoder on TIM3: + * TIM3_CH1IN - PA6 (D12) + * TIM3_CH2IN - PA7 (D11) + */ + +#define GPIO_TIM3_CH1IN (GPIO_TIM3_CH1IN_1|GPIO_SPEED_HIGH) /* PA6 */ +#define GPIO_TIM3_CH2IN (GPIO_TIM3_CH2IN_1|GPIO_SPEED_HIGH) /* PA7 */ + +/* DMA channels *************************************************************/ + +/* ADC */ + +#define ADC1_DMA_CHAN DMAMAP_DMA1_ADC1 /* DMA1 */ + +#endif /* __BOARDS_ARM_STM32U0_NUCLEO_U083RC_INCLUDE_BOARD_H */ diff --git a/boards/arm/stm32u0/nucleo-u083rc/scripts/Make.defs b/boards/arm/stm32u0/nucleo-u083rc/scripts/Make.defs new file mode 100644 index 00000000000..814e9dae238 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/scripts/Make.defs @@ -0,0 +1,37 @@ +############################################################################ +# boards/arm/stm32u0/nucleo-u083rc/scripts/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 = flash.ld +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +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/stm32u0/nucleo-u083rc/scripts/flash.ld b/boards/arm/stm32u0/nucleo-u083rc/scripts/flash.ld new file mode 100644 index 00000000000..5bf02e498f8 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/scripts/flash.ld @@ -0,0 +1,111 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/scripts/flash.ld + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 STM32U083RCT6 has 256KB of FLASH beginning at address 0x0800:0000 and + * 40Kb of SRAM at address 0x20000000 (32Kb SRAM1 + 8Kb backup SRAM2). + * + * 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 = 256K + sram (rwx) : ORIGIN = 0x20000000, LENGTH = 40K +} + +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(.); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors)) + _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(.); + + .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(8); + _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/stm32u0/nucleo-u083rc/src/CMakeLists.txt b/boards/arm/stm32u0/nucleo-u083rc/src/CMakeLists.txt new file mode 100644 index 00000000000..c9d04cf601e --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/CMakeLists.txt @@ -0,0 +1,41 @@ +# ############################################################################## +# boards/arm/stm32u0/nucleo-u083rc/src/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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. +# +# ############################################################################## + +set(SRCS stm32_boot.c stm32_bringup.c) + +if(CONFIG_ARCH_LEDS) + list(APPEND SRCS stm32_autoleds.c) +else() + list(APPEND SRCS stm32_userleds.c) +endif() + +if(CONFIG_ARCH_BUTTONS) + list(APPEND SRCS stm32_buttons.c) +endif() + +if(CONFIG_ADC) + list(APPEND SRCS stm32_adc.c) +endif() + +target_sources(board PRIVATE ${SRCS}) + +set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld") diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/Make.defs b/boards/arm/stm32u0/nucleo-u083rc/src/Make.defs new file mode 100644 index 00000000000..4d854dfee66 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/Make.defs @@ -0,0 +1,43 @@ +############################################################################ +# boards/arm/stm32u0/nucleo-u083rc/src/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 + +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += stm32_autoleds.c +else +CSRCS += stm32_userleds.c +endif + +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += stm32_buttons.c +endif + +ifeq ($(CONFIG_ADC),y) +CSRCS += stm32_adc.c +endif + +DEPPATH += --dep-path board +VPATH += :board +CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/nucleo-u083rc.h b/boards/arm/stm32u0/nucleo-u083rc/src/nucleo-u083rc.h new file mode 100644 index 00000000000..a0196d7ade4 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/nucleo-u083rc.h @@ -0,0 +1,104 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/nucleo-u083rc.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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_STM32U0_NUCLEO_U083RC_SRC_NUCLEO_U083RC_H +#define __BOARDS_ARM_STM32U0_NUCLEO_U083RC_SRC_NUCLEO_U083RC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "stm32_gpio.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Nucleo-U083RC GPIOs ******************************************************/ + +/* User LED: + * LD4 - PA5 + */ + +#define GPIO_LD4 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_MEDIUM | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN5) + +#define LED_DRIVER_PATH "/dev/userleds" + +/* Button definitions *******************************************************/ + +/* B1 USER: the user button is connected to the I/O PC13 (pin 2) of the + * STM32 microcontroller. + */ + +#define MIN_IRQBUTTON BUTTON_USER +#define MAX_IRQBUTTON BUTTON_USER +#define NUM_IRQBUTTONS 1 + +#define GPIO_BTN_USER (GPIO_INPUT | GPIO_PULLUP | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN13) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Functions Definitions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + ****************************************************************************/ + +int stm32_bringup(void); + +/**************************************************************************** + * Name: stm32_adc_setup + * + * Description: + * Initialize ADC and register the ADC driver. + * + ****************************************************************************/ + +#ifdef CONFIG_ADC +int stm32_adc_setup(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_STM32U0_NUCLEO_U083RC_SRC_NUCLEO_U083RC_H */ diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/stm32_adc.c b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_adc.c new file mode 100644 index 00000000000..df993ff445b --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_adc.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/stm32_adc.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* The number of ADC channels in the conversion list */ + +#define ADC1_NCHANNELS 4 + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Identifying number of each ADC channel (even if NCHANNELS is less ) */ + +static const uint8_t g_chanlist1[ADC1_NCHANNELS] = +{ + 4, + 5, + 8, + 17, +}; + +/* Configurations of pins used by each ADC channel */ + +static const uint32_t g_pinlist1[ADC1_NCHANNELS] = +{ + GPIO_ADC1_IN4_1, /* PA0/A0 */ + GPIO_ADC1_IN5_1, /* PA1/A1 */ + GPIO_ADC1_IN8_1, /* PA4/A2 */ + GPIO_ADC1_IN17_1, /* PB0/A3 */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_adc_setup + * + * Description: + * Initialize ADC and register the ADC driver. + * + ****************************************************************************/ + +int stm32_adc_setup(void) +{ + static bool initialized = false; + struct adc_dev_s *adc; + int ret; + int i; + + /* Check if we have already initialized */ + + if (!initialized) + { + /* Configure the pins as analog inputs for the selected channels */ + + for (i = 0; i < ADC1_NCHANNELS; i++) + { + stm32_configgpio(g_pinlist1[i]); + } + + /* Call stm32_adcinitialize() to get an instance of the ADC interface */ + + adc = stm32_adcinitialize(1, g_chanlist1, ADC1_NCHANNELS); + if (adc == NULL) + { + aerr("ERROR: Failed to get ADC interface 1\n"); + return -ENODEV; + } + + /* Register the ADC driver at "/dev/adc0" */ + + ret = adc_register("/dev/adc0", adc); + if (ret < 0) + { + aerr("ERROR: adc_register /dev/adc0 failed: %d\n", ret); + return ret; + } + + initialized = true; + } + + return OK; +} diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/stm32_autoleds.c b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_autoleds.c new file mode 100644 index 00000000000..3b97c0e07ef --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_autoleds.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/stm32_autoleds.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 "chip.h" +#include "arm_internal.h" +#include "stm32_gpio.h" +#include "nucleo-u083rc.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure LD4 GPIO for output */ + + stm32_configgpio(GPIO_LD4); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + if (led == BOARD_LED1) + { + stm32_gpiowrite(GPIO_LD4, true); + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + if (led == BOARD_LED1) + { + stm32_gpiowrite(GPIO_LD4, false); + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/stm32_boot.c b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_boot.c new file mode 100644 index 00000000000..162bbbcd321 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_boot.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/stm32_boot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 "nucleo-u083rc.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_STM32_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) +{ + stm32_bringup(); +} +#endif diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/stm32_bringup.c b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_bringup.c new file mode 100644 index 00000000000..b51ab8a172d --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_bringup.c @@ -0,0 +1,156 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/stm32_bringup.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + +#ifdef CONFIG_USERLED +# include +#endif + +#ifdef CONFIG_STM32_IWDG +# include +#endif + +#ifdef CONFIG_TIMER +# include +#endif + +#ifdef CONFIG_SENSORS_QENCODER +# include "board_qencoder.h" +#endif + +#ifdef CONFIG_PWM +# include "board_pwm.h" +#endif + +#include + +#include "nucleo-u083rc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret; + +#ifdef CONFIG_STM32_IWDG + /* Initialize the watchdog timer */ + + stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); +#endif + +#if defined(CONFIG_TIMER) && defined(CONFIG_STM32_TIM6) + /* Initialize and register the timer driver - TIM6 */ + + ret = stm32_timer_initialize("/dev/timer0", 6); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_timer_initialize failed: %d\n", ret); + } +#endif + +#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER) + /* 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_BUTTONS + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_ADC + /* Initialize ADC and register the ADC driver. */ + + ret = stm32_adc_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_adc_setup failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_PWM + /* Initialize PWM and register the PWM device. */ + + ret = stm32_pwm_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_pwm_setup failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_QENCODER + /* Initialize and register the qencoder driver - TIM3 */ + + ret = board_qencoder_initialize(0, 3); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the qencoder: %d\n", + ret); + return ret; + } +#endif + + UNUSED(ret); + return OK; +} diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/stm32_buttons.c b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_buttons.c new file mode 100644 index 00000000000..4a61b2da2c2 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_buttons.c @@ -0,0 +1,117 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/stm32_buttons.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 "nucleo-u083rc.h" + +#ifdef CONFIG_ARCH_BUTTONS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + /* Configure the single button as an input. NOTE that EXTI interrupts are + * also configured for the pin. + */ + + stm32_configgpio(GPIO_BTN_USER); + return NUM_BUTTONS; +} + +/**************************************************************************** + * Name: board_buttons + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + /* Check that state of each USER button. A LOW value means that the key is + * pressed. + */ + + bool released = stm32_gpioread(GPIO_BTN_USER); + return !released; +} + +/**************************************************************************** + * Button support. + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + * After board_button_initialize() has been called, board_buttons() may be + * called to collect the state of all buttons. board_buttons() returns an + * 32-bit bit set with each bit associated with a button. See the + * BUTTON_*_BIT definitions in board.h for the meaning of each bit. + * + * board_button_irq() may be called to register an interrupt handler that + * will be called when a button is depressed or released. The ID value is a + * button enumeration value that uniquely identifies a button resource. See + * the BUTTON_* definitions in board.h for the meaning of enumeration + * value. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, void *arg) +{ + int ret = -EINVAL; + + if (id == BUTTON_USER) + { + ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, + irqhandler, arg); + } + + return ret; +} +#endif +#endif /* CONFIG_ARCH_BUTTONS */ diff --git a/boards/arm/stm32u0/nucleo-u083rc/src/stm32_userleds.c b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_userleds.c new file mode 100644 index 00000000000..d5c63599612 --- /dev/null +++ b/boards/arm/stm32u0/nucleo-u083rc/src/stm32_userleds.c @@ -0,0 +1,165 @@ +/**************************************************************************** + * boards/arm/stm32u0/nucleo-u083rc/src/stm32_userleds.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 "chip.h" +#include "arm_internal.h" +#include "stm32_gpio.h" +#include "nucleo-u083rc.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* LED Power Management */ + +#ifdef CONFIG_PM +static void led_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +static int led_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_PM +static struct pm_callback_s g_ledscb = +{ + .notify = led_pm_notify, + .prepare = led_pm_prepare, +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: led_pm_notify + * + * Description: + * Notify the driver of new power state. This callback is called after + * all drivers have had the opportunity to prepare for the new power state. + * + ****************************************************************************/ + +#ifdef CONFIG_PM +static void led_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ +} +#endif + +/**************************************************************************** + * Name: led_pm_prepare + * + * Description: + * Request the driver to prepare for a new power state. This is a warning + * that the system is about to enter into a new power state. The driver + * should begin whatever operations that may be required to enter power + * state. The driver may abort the state change mode by returning a + * non-zero value from the callback function. + * + ****************************************************************************/ + +#ifdef CONFIG_PM +static int led_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + /* No preparation to change power modes is required by the LEDs driver. + * We always accept the state change by returning OK. + */ + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + /* Configure LD4 GPIO for output */ + + stm32_configgpio(GPIO_LD4); + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if (led == BOARD_LED1) + { + stm32_gpiowrite(GPIO_LD4, ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + stm32_gpiowrite(GPIO_LD4, (ledset & BOARD_LED1_BIT) != 0); +} + +/**************************************************************************** + * Name: stm32_led_pminitialize + ****************************************************************************/ + +#ifdef CONFIG_PM +void stm32_led_pminitialize(void) +{ + /* Register to receive power management callbacks */ + + int ret = pm_register(&g_ledscb); + DEBUGASSERT(ret == OK); + UNUSED(ret); +} +#endif /* CONFIG_PM */ + +#endif /* !CONFIG_ARCH_LEDS */