diff --git a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst index 76181522b7b..5b671ace0a7 100644 --- a/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst +++ b/Documentation/platforms/arm/stm32h7/boards/linum-stm32h753bi/index.rst @@ -49,6 +49,8 @@ Expansion connector 2 features. - 6 PWM Channels - 10 ADCs +Board documentation: https://wittetech.com/ + LEDs ==== @@ -301,42 +303,37 @@ LCD ======= The LINUM-STM32H753BI use the LTDC to support one LCD with RGB connection. - =========== ===== - LTDC PINS - =========== ===== - LTDC_B0 PF0 - LTDC_B1 PJ13 - LTDC_B2 PJ14 - LTDC_B3 PJ15 - LTDC_B4 PK3 - LTDC_B5 PK4 - LTDC_B6 PK5 - LTDC_B7 PK6 - LTDC_CLK PI14 - LTDC_DE PK7 - LTDC_G0 PJ7 - LTDC_G1 PJ8 - LTDC_G2 PJ9 - LTDC_G3 PJ10 - LTDC_G4 PJ11 - LTDC_G5 PK0 - LTDC_G6 PK1 - LTDC_G7 PK2 - LTDC_HSYNC PI10 - LTDC_R0 PI15 - LTDC_R1 PJ0 - LTDC_R2 PJ1 - LTDC_R3 PJ2 - LTDC_R4 PJ3 - LTDC_R5 PJ4 - LTDC_R6 PJ5 - LTDC_R7 PJ6 - LTDC_VSYNC PI9 - =========== ===== - ============= ===== - PWM PINS + LTDC PINS ============= ===== + LTDC_B0 PF0 + LTDC_B1 PJ13 + LTDC_B2 PJ14 + LTDC_B3 PJ15 + LTDC_B4 PK3 + LTDC_B5 PK4 + LTDC_B6 PK5 + LTDC_B7 PK6 + LTDC_CLK PI14 + LTDC_DE PK7 + LTDC_G0 PJ7 + LTDC_G1 PJ8 + LTDC_G2 PJ9 + LTDC_G3 PJ10 + LTDC_G4 PJ11 + LTDC_G5 PK0 + LTDC_G6 PK1 + LTDC_G7 PK2 + LTDC_HSYNC PI10 + LTDC_R0 PI15 + LTDC_R1 PJ0 + LTDC_R2 PJ1 + LTDC_R3 PJ2 + LTDC_R4 PJ3 + LTDC_R5 PJ4 + LTDC_R6 PJ5 + LTDC_R7 PJ6 + LTDC_VSYNC PI9 PWM_BACKLIGHT PH6 ============= ===== @@ -352,15 +349,15 @@ The LINUM-STM32H753BI has one I2S output. I2S2_SDO PI3 ======== ===== -BUZZER +PWM ======= -The LINUM-STM32H753BI has a buzzer without internal oscillator +The LINUM-STM32H753BI has a buzzer without internal oscillator connected to PB7 - ======= ===== - GPIO PINS - ======= ===== - BUZZER PC13 - ======= ===== + ========= ===== + GPIO PINS + ========= ===== + BUZZER PB7 + ========= ===== ============== @@ -451,10 +448,29 @@ The SD card can then be mounted by the NSH commands:: eeprom ------ -Use dd command to write and read data from EEPROM as below::: +Use **dd** command to write and read data from EEPROM as below::: nsh> dd if=/dev/console of=/dev/eeprom bs=1 count=35 Witte-Tech Linum-STM32H753BI board nsh> dd if=/dev/eeprom of=/dev/console bs=4 count=35 Witte-Tech Linum-STM32H753BI board - nsh> \ No newline at end of file + nsh> + +buzzer +------ + +This example use the timer 4 with channel 2 to generate a PWM output signal on buzzer pin:: + + nsh> ls /dev + /dev: + console + null + pwm0 + rtc0 + ttyS0 + nsh> pwm -d 75 -t 3 + pwm_main: starting output with frequency: 100 duty: 0000bfff + pwm_main: stopping output + nsh> pwm -f 300 -t 3 + pwm_main: starting output with frequency: 300 duty: 0000bfff + pwm_main: stopping output \ No newline at end of file diff --git a/arch/arm/src/stm32/stm32_pwm.c b/arch/arm/src/stm32/stm32_pwm.c index 8e69373cc51..cc8436fe76f 100644 --- a/arch/arm/src/stm32/stm32_pwm.c +++ b/arch/arm/src/stm32/stm32_pwm.c @@ -247,7 +247,7 @@ # define TIMRST_TIM16 RCC_APB1RSTR_TIM16RST # define TIMCLK_TIM17 STM32_APB1_TIM17_CLKIN # define TIMRCCEN_TIM17 STM32_RCC_APB1ENR -# define TIMEN_TIM17 RCC_APB1ENR_TIM71EN +# define TIMEN_TIM17 RCC_APB1ENR_TIM17EN # define TIMRCCRST_TIM17 STM32_RCC_APB1RSTR # define TIMRST_TIM17 RCC_APB1RSTR_TIM17RST #endif diff --git a/arch/arm/src/stm32h7/stm32_pwm.c b/arch/arm/src/stm32h7/stm32_pwm.c index d6f682ecccb..a208f0cd531 100644 --- a/arch/arm/src/stm32h7/stm32_pwm.c +++ b/arch/arm/src/stm32h7/stm32_pwm.c @@ -145,7 +145,7 @@ #define TIMRST_TIM16 RCC_APB2RSTR_TIM16RST #define TIMCLK_TIM17 STM32_APB2_TIM17_CLKIN #define TIMRCCEN_TIM17 STM32_RCC_APB2ENR -#define TIMEN_TIM17 RCC_APB2ENR_TIM71EN +#define TIMEN_TIM17 RCC_APB2ENR_TIM17EN #define TIMRCCRST_TIM17 STM32_RCC_APB2RSTR #define TIMRST_TIM17 RCC_APB2RSTR_TIM17RST diff --git a/boards/arm/stm32h7/linum-stm32h753bi/configs/buzzer/defconfig b/boards/arm/stm32h7/linum-stm32h753bi/configs/buzzer/defconfig new file mode 100644 index 00000000000..374dbe6f4ff --- /dev/null +++ b/boards/arm/stm32h7/linum-stm32h753bi/configs/buzzer/defconfig @@ -0,0 +1,61 @@ +# +# 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_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_PS is not set +# CONFIG_STANDARD_SERIAL is not set +# CONFIG_STM32H7_USE_LEGACY_PINMAP is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="linum-stm32h753bi" +CONFIG_ARCH_BOARD_LINUM_STM32H753BI=y +CONFIG_ARCH_CHIP="stm32h7" +CONFIG_ARCH_CHIP_STM32H753BI=y +CONFIG_ARCH_CHIP_STM32H7=y +CONFIG_ARCH_CHIP_STM32H7_CORTEXM7=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV7M_DCACHE=y +CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y +CONFIG_ARMV7M_DTCM=y +CONFIG_ARMV7M_ICACHE=y +CONFIG_BOARD_LOOPSPERMSEC=43103 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_ALARM=y +CONFIG_EXAMPLES_PWM=y +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBM=y +CONFIG_MM_REGIONS=4 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PWM=y +CONFIG_RAM_SIZE=245760 +CONFIG_RAM_START=0x20010000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_RTC_ALARM=y +CONFIG_RTC_DATETIME=y +CONFIG_RTC_DRIVER=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_STM32H7_PWR=y +CONFIG_STM32H7_RTC=y +CONFIG_STM32H7_TIM4=y +CONFIG_STM32H7_TIM4_CH2OUT=y +CONFIG_STM32H7_TIM4_CHANNEL=2 +CONFIG_STM32H7_TIM4_PWM=y +CONFIG_STM32H7_USART1=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART1_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h index aef2924950b..3fda56c61f2 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/include/board.h +++ b/boards/arm/stm32h7/linum-stm32h753bi/include/board.h @@ -396,6 +396,11 @@ #define GPIO_I2C3_SCL (GPIO_I2C3_SCL_2 | GPIO_SPEED_100MHz) /* PH7 */ #define GPIO_I2C3_SDA (GPIO_I2C3_SDA_2 | GPIO_SPEED_100MHz) /* PH8 */ +/* PWM - Buzzer */ + +#define GPIO_TIM17_CH1OUT (GPIO_TIM17_CH1NOUT_1) /* PB7 */ +#define GPIO_TIM4_CH2OUT (GPIO_TIM4_CH2OUT_1) /* PB7 */ + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt b/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt index eaf07d1b287..7f8d7d52a01 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt +++ b/boards/arm/stm32h7/linum-stm32h753bi/src/CMakeLists.txt @@ -48,6 +48,10 @@ if(CONFIG_I2C_EE_24XX) list(APPEND SRCS stm32_at24.c) endif() +if(CONFIG_PWM) + list(APPEND SRCS stm32_pwm.c) +endif() + target_sources(board PRIVATE ${SRCS}) set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld") diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile b/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile index e745de7f75f..30d5adc7303 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile +++ b/boards/arm/stm32h7/linum-stm32h753bi/src/Makefile @@ -46,6 +46,10 @@ ifeq ($(CONFIG_I2C_EE_24XX),y) CSRCS += stm32_at24.c endif +ifeq ($(CONFIG_PWM),y) +CSRCS += stm32_pwm.c +endif + ifeq ($(CONFIG_BOARDCTL),y) CSRCS += stm32_appinitialize.c endif diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h b/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h index 697e6c645fe..be4aad48900 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h +++ b/boards/arm/stm32h7/linum-stm32h753bi/src/linum-stm32h753bi.h @@ -99,6 +99,10 @@ #define SDIO_SLOTNO 0 #define SDIO_MINOR 0 +/* PWM */ + +#define BUZZER_PWMTIMER 4 + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -172,4 +176,16 @@ int stm32_sdio_initialize(void); int stm32_at24_init(char *path); #endif +/**************************************************************************** + * Name: stm32_pwm_setup + * + * Description: + * Initialize PWM and register the PWM device. + * + ****************************************************************************/ + +#ifdef CONFIG_PWM +int stm32_pwm_setup(void); +#endif + #endif /* __BOARDS_ARM_STM32H7_LINUM_STM32H753BI_SRC_LINUM_STM32H753BI_H */ diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c index 0fc5f6ee3f0..4604a282945 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c +++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_bringup.c @@ -208,5 +208,15 @@ int stm32_bringup(void) } #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 + return OK; } diff --git a/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_pwm.c b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_pwm.c new file mode 100644 index 00000000000..f9266ccb9d3 --- /dev/null +++ b/boards/arm/stm32h7/linum-stm32h753bi/src/stm32_pwm.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * boards/arm/stm32h7/linum-stm32h753bi/src/stm32_pwm.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 "chip.h" +#include "arm_internal.h" +#include "stm32_pwm.h" +#include "linum-stm32h753bi.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#define HAVE_PWM 1 + +#ifndef CONFIG_PWM +# undef HAVE_PWM +#endif + +#ifndef CONFIG_STM32H7_TIM4 +# undef HAVE_PWM +#endif + +#ifndef CONFIG_STM32H7_TIM4_PWM +# undef HAVE_PWM +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_pwm_setup + * + * Description: + * Initialize PWM and register the PWM device. + * + ****************************************************************************/ + +int stm32_pwm_setup(void) +{ +#ifdef HAVE_PWM + static bool initialized = false; + struct pwm_lowerhalf_s *pwm; + int ret; + + /* Have we already initialized? */ + + if (!initialized) + { + /* Get an instance of the PWM interface */ + + pwm = stm32_pwminitialize(BUZZER_PWMTIMER); + if (!pwm) + { + tmrerr("ERROR: Failed to get the STM32 PWM lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm0" */ + + ret = pwm_register("/dev/pwm0", pwm); + if (ret < 0) + { + tmrerr("ERROR: pwm_register failed: %d\n", ret); + return ret; + } + + /* Now we are initialized */ + + initialized = true; + } + + return OK; +#else + return -ENODEV; +#endif +}