forked from mlyszczek/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stm32f7: Add basic PWM support to nucleo-144 board
More PWMs and multi channels support may be investigated and added later. It was tested on nucleo-f767zi with those features enabled in configuration: ``` CONFIG_EXAMPLES_PWM=y CONFIG_PWM=y CONFIG_STM32F7_TIM1=y CONFIG_STM32F7_TIM1_PWM=y CONFIG_STM32F7_TIM2=y (...) CONFIG_STM32F7_TIM4_PWM=y ``` Change-Id: I08ebd4a538d15661788a0a54c2113ad767f22747 Bug: https://bitbucket.org/nuttx/nuttx/issues/153 Relate-to: rzr/webthing-iotjs#3 Forwarded: https://bitbucket.org/nuttx/nuttx/pull-requests/862 Signed-off-by: Philippe Coval <p.coval@samsung.com>
- Loading branch information
Showing
5 changed files
with
194 additions
and
0 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
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,162 @@ | ||
/************************************************************************************ | ||
* configs/nucleo-144/src/stm32_pwm.c | ||
* | ||
* Copyright (C) 2019 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <gnutt@nuttx.org> | ||
* Author: Philippe Coval <p.coval@samsung.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* 3. Neither the name NuttX nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
************************************************************************************/ | ||
|
||
/************************************************************************************ | ||
* Included Files | ||
************************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <errno.h> | ||
#include <debug.h> | ||
#include <sys/types.h> | ||
|
||
#include <nuttx/board.h> | ||
#include <nuttx/drivers/pwm.h> | ||
#include <arch/board/board.h> | ||
|
||
#include "chip.h" | ||
#include "up_arch.h" | ||
#include "stm32_pwm.h" | ||
#include "nucleo-144.h" | ||
|
||
/************************************************************************************ | ||
* Pre-processor Definitions | ||
************************************************************************************/ | ||
|
||
#define HAVE_PWM 1 | ||
#ifndef CONFIG_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) | ||
{ | ||
/* Call stm32_pwminitialize() to get an instance of the PWM interface */ | ||
|
||
#if defined(CONFIG_STM32F7_TIM1_PWM) | ||
pwm = stm32_pwminitialize(1); | ||
if (!pwm) | ||
{ | ||
aerr("ERROR: Failed to get the STM32F7 PWM lower half\n"); | ||
return -ENODEV; | ||
} | ||
|
||
ret = pwm_register("/dev/pwm0", pwm); | ||
if (ret < 0) | ||
{ | ||
aerr("ERROR: pwm_register failed: %d\n", ret); | ||
return ret; | ||
} | ||
#endif | ||
|
||
#if defined(CONFIG_STM32F7_TIM2_PWM) | ||
pwm = stm32_pwminitialize(2); | ||
if (!pwm) | ||
{ | ||
aerr("ERROR: Failed to get the STM32F7 PWM lower half\n"); | ||
return -ENODEV; | ||
} | ||
|
||
ret = pwm_register("/dev/pwm1", pwm); | ||
if (ret < 0) | ||
{ | ||
aerr("ERROR: pwm_register failed: %d\n", ret); | ||
return ret; | ||
} | ||
#endif | ||
|
||
#if defined(CONFIG_STM32F7_TIM3_PWM) | ||
pwm = stm32_pwminitialize(3); | ||
if (!pwm) | ||
{ | ||
aerr("ERROR: Failed to get the STM32F7 PWM lower half\n"); | ||
return -ENODEV; | ||
} | ||
|
||
ret = pwm_register("/dev/pwm2", pwm); | ||
if (ret < 0) | ||
{ | ||
aerr("ERROR: pwm_register failed: %d\n", ret); | ||
return ret; | ||
} | ||
#endif | ||
|
||
#if defined(CONFIG_STM32F7_TIM4_PWM) | ||
pwm = stm32_pwminitialize(4); | ||
if (!pwm) | ||
{ | ||
aerr("ERROR: Failed to get the STM32F7 PWM lower half\n"); | ||
return -ENODEV; | ||
} | ||
|
||
ret = pwm_register("/dev/pwm3", pwm); | ||
if (ret < 0) | ||
{ | ||
aerr("ERROR: pwm_register failed: %d\n", ret); | ||
return ret; | ||
} | ||
#endif | ||
/* Now we are initialized */ | ||
|
||
initialized = true; | ||
} | ||
|
||
return OK; | ||
#else | ||
return -ENODEV; | ||
#endif | ||
} |