-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stm32h7/linum-stm32h753bi: add tone support
Signed-off-by: Jorge Guzman <[email protected]>
- Loading branch information
Showing
8 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
boards/arm/stm32h7/linum-stm32h753bi/configs/tone/defconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# | ||
# 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_DEBUG_ERROR is not set | ||
# CONFIG_NSH_ALIAS is not set | ||
# 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_AUDIO_TONE=y | ||
CONFIG_BOARD_LOOPSPERMSEC=43103 | ||
CONFIG_BUILTIN=y | ||
CONFIG_DEBUG_FEATURES=y | ||
CONFIG_DEBUG_PWM=y | ||
CONFIG_DEBUG_SYMBOLS=y | ||
CONFIG_DEBUG_TIMER=y | ||
CONFIG_DRIVERS_AUDIO=y | ||
CONFIG_EXAMPLES_ALARM=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=120 | ||
CONFIG_NSH_READLINE=y | ||
CONFIG_ONESHOT=y | ||
CONFIG_PREALLOC_TIMERS=4 | ||
CONFIG_PWM=y | ||
CONFIG_RAM_SIZE=245760 | ||
CONFIG_RAM_START=0x20010000 | ||
CONFIG_RAW_BINARY=y | ||
CONFIG_READLINE_CMD_HISTORY=y | ||
CONFIG_READLINE_CMD_HISTORY_LINELEN=120 | ||
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_ONESHOT=y | ||
CONFIG_STM32H7_PWR=y | ||
CONFIG_STM32H7_RTC=y | ||
CONFIG_STM32H7_TIM17=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_CLE=y | ||
CONFIG_SYSTEM_NSH=y | ||
CONFIG_TASK_NAME_SIZE=0 | ||
CONFIG_USART1_SERIAL_CONSOLE=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/**************************************************************************** | ||
* boards/arm/stm32h7/linum-stm32h753bi/src/stm32_tone.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 <nuttx/config.h> | ||
#include <nuttx/config.h> | ||
|
||
#include <errno.h> | ||
#include <debug.h> | ||
#include <stdio.h> | ||
#include <fcntl.h> | ||
|
||
#include <nuttx/timers/pwm.h> | ||
#include <nuttx/timers/oneshot.h> | ||
#include <nuttx/audio/tone.h> | ||
#include <arch/board/board.h> | ||
|
||
#include "linum-stm32h753bi.h" | ||
#include "arm_internal.h" | ||
#include "stm32_pwm.h" | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Types | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Function Prototypes | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Data | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: tone_example | ||
* | ||
* Input Parameters: | ||
* devno - The device number, used to build the device path as /dev/toneN | ||
* | ||
* Description: | ||
* Configure and test the tone generator. | ||
* | ||
****************************************************************************/ | ||
|
||
static void tone_example(int devno) | ||
{ | ||
int ret; | ||
int fd; | ||
char devpath[12]; | ||
const char msg[] = "t120o1l16b9n0baan0bn0bn0baaan0b9n0baan0b"; | ||
|
||
snprintf(devpath, 12, "/dev/tone%d", devno); | ||
fd = open(devpath, O_RDWR); | ||
if (fd < 0) | ||
{ | ||
printf("Failed to open device driver at: %s\n", devpath); | ||
return -errno; | ||
} | ||
|
||
ret = write(fd, msg, sizeof(msg)); | ||
if (ret < 0) | ||
{ | ||
printf("Failed to write to device driver at: %s\n", devpath); | ||
return ret; | ||
} | ||
|
||
close(fd); | ||
|
||
return ret; | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: board_tone_initialize | ||
* | ||
* Input Parameters: | ||
* devno - The device number, used to build the device path as /dev/toneN | ||
* | ||
* Description: | ||
* Configure and initialize the tone generator. | ||
* | ||
****************************************************************************/ | ||
|
||
int board_tone_initialize(int devno) | ||
{ | ||
static bool initialized = false; | ||
struct pwm_lowerhalf_s *tone; | ||
struct oneshot_lowerhalf_s *oneshot = NULL; | ||
int ret; | ||
char devpath[12]; | ||
|
||
/* Have we already initialized? */ | ||
|
||
if (!initialized) | ||
{ | ||
/* Call stm32_pwminitialize() to get an instance of the PWM interface */ | ||
|
||
tone = stm32_pwminitialize(BUZZER_PWMTIMER); | ||
if (!tone) | ||
{ | ||
auderr("Failed to get the STM32 PWM lower half to AUDIO TONE\n"); | ||
return -ENODEV; | ||
} | ||
|
||
/* Initialize TONE PWM */ | ||
|
||
tone->ops->setup(tone); | ||
|
||
/* Initialize ONESHOT Timer */ | ||
|
||
oneshot = oneshot_initialize(BOARD_TONE_ONESHOT_TIM, | ||
BOARD_TONE_ONESHOT_TIM_RES); | ||
if (!oneshot) | ||
{ | ||
auderr("Failed to initialize ONESHOT Timer!\n"); | ||
return -ENODEV; | ||
} | ||
|
||
/* Register the Audio Tone driver at "/dev/tone0" */ | ||
|
||
snprintf(devpath, 12, "/dev/tone%d", devno); | ||
ret = tone_register(devpath, tone, oneshot); | ||
if (ret < 0) | ||
{ | ||
auderr("ERROR: tone_register failed: %d\n", ret); | ||
return ret; | ||
} | ||
|
||
/* Now we are initialized */ | ||
|
||
initialized = true; | ||
|
||
/* Play tone example */ | ||
|
||
tone_example(devno); | ||
} | ||
|
||
return OK; | ||
} |