initial working (stm32f4-discovery)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
---
|
||||
name: 'Issue report'
|
||||
about: 'Create a report to help us improve the quality of our software'
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
**Caution**
|
||||
|
||||
The Issues are strictly limited for the reporting of problem encountered with the software provided in this project.
|
||||
For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post your report to the **ST Community** in the STM32 MCUs dedicated [page](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus).
|
||||
|
||||
**Describe the set-up**
|
||||
|
||||
* The board (either ST RPN reference or your custom board)
|
||||
* IDE or at least the compiler and its version
|
||||
|
||||
**Describe the bug (skip if none)**
|
||||
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**How to reproduce the bug (skip if none)**
|
||||
|
||||
1. Indicate the global behavior of your application project
|
||||
2. List the modules that you suspect to be the cause of the problem (Drivers, BSP, MW...)
|
||||
3. Describe the use case that generates the problem
|
||||
4. How we can reproduce the problem
|
||||
|
||||
|
||||
**Additional context**
|
||||
|
||||
If you have a first analysis, an enhancement, a fix or a patch, thank you to share your proposal.
|
||||
|
||||
**Screenshots**
|
||||
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
@@ -0,0 +1,5 @@
|
||||
## IMPORTANT INFORMATION
|
||||
|
||||
### Contributor License Agreement (CLA)
|
||||
* The Pull Request feature will be considered by STMicroelectronics after the signature of a **Contributor License Agreement (CLA)** by the submitter.
|
||||
* If you did not sign such agreement, please follow the steps mentioned in the [CONTRIBUTING.md](https://github.com/STMicroelectronics/stm32f4-discovery/blob/main/CONTRIBUTING.md) file.
|
||||
@@ -0,0 +1,73 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team via this [link](https://www.st.com/content/st_com/en/contact-us.html).
|
||||
All complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4,
|
||||
available [here](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html).
|
||||
|
||||
For answers to common questions about this code of conduct, see the [FAQ section](https://www.contributor-covenant.org/faq).
|
||||
@@ -0,0 +1,38 @@
|
||||
## Contributing guide
|
||||
|
||||
This document serves as a checklist before contributing to this repository.
|
||||
It includes links to read up on if topics are unclear to you.
|
||||
|
||||
This guide mainly focuses on steps to be followed to submit an issue or a pull-request.
|
||||
|
||||
### 1. Before opening an issue
|
||||
|
||||
To report a bug or a request please file an issue in the right repository
|
||||
(example for [stm32f4-discovery](https://github.com/STMicroelectronics/stm32f4-discovery/issues/new/choose)).
|
||||
|
||||
Please check the following boxes before posting an issue:
|
||||
- [ ] `Make sure you are using the latest commit (major releases are tagged, but corrections are available as new commits).`
|
||||
- [ ] `Make sure your issue is a question/feedback/suggestions RELATED TO the software provided in this repository.` Otherwise, it should be submitted to the **ST Community** on the appropriate topic [page](https://community.st.com/s/topiccatalog).
|
||||
- [ ] `Make sure your issue is not already reported/fixed on GitHub or discussed on a previous issue.` Please refer to this [dashboard](https://github.com/orgs/STMicroelectronics/projects/2) for the list of issues and pull-requests. Do not forget to browse into the **closed** issues.
|
||||
|
||||
### 2. Posting the issue
|
||||
|
||||
When you have checked the previous boxes, create a new report from the **Issues** tab of the repository. A template is available to help you report the issue you are facing or the enhancement you would like to propose.
|
||||
|
||||
### 3. Pull Requests
|
||||
|
||||
STMicrolectronics is happy to receive contributions from the community, based on an initial Contributor License Agreement (CLA) procedure.
|
||||
|
||||
* If you are an individual writing original source code and you are sure **you own the intellectual property**, then you need to sign an Individual [CLA](https://cla.st.com).
|
||||
* If you work for a company that wants also to allow you to contribute with your work, your company needs to provide a Corporate [CLA](https://cla.st.com) mentioning your GitHub account name.
|
||||
* If you are not sure that a CLA (Individual or Corporate) has been signed for your GitHub account you can check the [CLA](https://cla.st.com) dedicated page.
|
||||
|
||||
Please note that:
|
||||
* The Corporate CLA will always take precedence over the Individual CLA.
|
||||
* One CLA submission is sufficient, for any project proposed by STMicroelectronics.
|
||||
|
||||
### 4. How to proceed
|
||||
|
||||
* We recommend to engage first a communication thru an issue, in order to present your proposal, just to confirm that it corresponds to STMicroelectronics' domain or scope.
|
||||
* Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version.
|
||||
* Please, submit one pull-request per new feature or proposal. This will ease the analysis and the final merge if accepted.
|
||||
@@ -0,0 +1,27 @@
|
||||
Copyright 2017 STMicroelectronics.
|
||||
All rights reserved.
|
||||
|
||||
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 of the copyright holder 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 HOLDER 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.
|
||||
@@ -0,0 +1,39 @@
|
||||
# BSP STM32F4-DISCOVERY Component
|
||||
|
||||

|
||||
|
||||
## Overview
|
||||
|
||||
**STM32Cube** is an STMicroelectronics original initiative to ease developers' life by reducing efforts, time and cost.
|
||||
|
||||
**STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform delivered for each STM32 series.
|
||||
* The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product.
|
||||
* The STM32 HAL-LL drivers, an abstraction layer offering a set of APIs ensuring maximized portability across the STM32 portfolio.
|
||||
* The BSP drivers of each evaluation, demonstration or nucleo board provided for this STM32 series.
|
||||
* A consistent set of middleware libraries such as RTOS, USB, FatFS, graphics, touch sensing library...
|
||||
* A full set of software projects (basic examples, applications, and demonstrations) for each board provided for this STM32 series.
|
||||
|
||||
Two models of publication are proposed for the STM32Cube embedded software:
|
||||
* The monolithic **MCU Package**: all STM32Cube software modules of one STM32 series are present (Drivers, Middleware, Projects, Utilities) in the repository (usual name **STM32Cubexx**, xx corresponding to the STM32 series).
|
||||
* The **MCU component**: each STM32Cube software module being part of the STM32Cube MCU Package, is delivered as an individual repository, allowing the user to select and get only the required software functions.
|
||||
|
||||
## Description
|
||||
|
||||
This **stm32f4-discovery** MCU component repository is one element of the **STM32CubeF4** MCU embedded software package, providing the **STM32F4-DISCOVERY** BSP BOARD component part.
|
||||
|
||||
## Release note
|
||||
|
||||
Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/stm32f4-discovery/blob/main/Release_Notes.html).
|
||||
|
||||
## Compatibility information
|
||||
|
||||
Below is the list of the BSP *component* drivers to be used with this BSP *board* driver. It is **crucial** that you use a consistent set of CMSIS - HAL - BSP versions, as mentioned in [this](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Release_Notes.html) release note.
|
||||
|
||||
* [stm32-bsp-common](https://github.com/STMicroelectronics/stm32-bsp-common)
|
||||
* [stm32-cs43l22](https://github.com/STMicroelectronics/stm32-cs43l22)
|
||||
* [stm32-lis302dl](https://github.com/STMicroelectronics/stm32-lis302dl)
|
||||
* [stm32-lis3dsh](https://github.com/STMicroelectronics/stm32-lis3dsh)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) guide.
|
||||
@@ -0,0 +1,31 @@
|
||||
# Report potential product security vulnerabilities
|
||||
|
||||
ST places a high priority on security, and our Product Security Incident
|
||||
Response Team (PSIRT) is committed to rapidly addressing potential security
|
||||
vulnerabilities affecting our products. PSIRT's long history and vast experience
|
||||
in security allows ST to perform clear analyses and provide appropriate guidance
|
||||
on mitigations and solutions when applicable.
|
||||
|
||||
If you wish to report potential security vulnerabilities regarding our products,
|
||||
**please do not report them through public GitHub issues.** Instead, we
|
||||
encourage you to report them to our ST PSIRT following the process described at:
|
||||
**https://www.st.com/content/st_com/en/security/report-vulnerabilities.html**
|
||||
|
||||
### IMPORTANT - READ CAREFULLY:
|
||||
|
||||
STMicroelectronics International N.V., on behalf of itself, its affiliates and
|
||||
subsidiaries, (collectively “ST”) takes all potential security vulnerability
|
||||
reports or other related communications (“Report(s)”) seriously. In order to
|
||||
review Your Report (the terms “You” and “Yours” include your employer, and all
|
||||
affiliates, subsidiaries and related persons or entities) and take actions as
|
||||
deemed appropriate, ST requires that we have the rights and Your permission to
|
||||
do so.
|
||||
|
||||
As such, by submitting Your Report to ST, You agree that You have the right to
|
||||
do so, and You grant to ST the rights to use the Report for purposes related to
|
||||
security vulnerability analysis, testing, correction, patching, reporting and
|
||||
any other related purpose or function.
|
||||
|
||||
By submitting Your Report, You agree that ST’s
|
||||
[Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html)
|
||||
applies to all related communications.
|
||||
@@ -0,0 +1,682 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4_discovery.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides set of firmware functions to manage Leds and
|
||||
* push-button available on STM32F4-Discovery Kit from STMicroelectronics.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4_discovery.h"
|
||||
|
||||
/** @defgroup BSP BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY STM32F4 DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL STM32F4 DISCOVERY LOW LEVEL
|
||||
* @brief This file provides set of firmware functions to manage Leds and push-button
|
||||
* available on STM32F4-Discovery Kit from STMicroelectronics.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F4 DISCOVERY LOW LEVEL Private TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Defines STM32F4 DISCOVERY LOW LEVEL Private Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief STM32F4 DISCO BSP Driver version number V2.1.5
|
||||
*/
|
||||
#define __STM32F4_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */
|
||||
#define __STM32F4_DISCO_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */
|
||||
#define __STM32F4_DISCO_BSP_VERSION_SUB2 (0x05) /*!< [15:8] sub2 version */
|
||||
#define __STM32F4_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
|
||||
#define __STM32F4_DISCO_BSP_VERSION ((__STM32F4_DISCO_BSP_VERSION_MAIN << 24)\
|
||||
|(__STM32F4_DISCO_BSP_VERSION_SUB1 << 16)\
|
||||
|(__STM32F4_DISCO_BSP_VERSION_SUB2 << 8 )\
|
||||
|(__STM32F4_DISCO_BSP_VERSION_RC))
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Macros STM32F4 DISCOVERY LOW LEVEL Private Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Variables STM32F4 DISCOVERY LOW LEVEL Private Variables
|
||||
* @{
|
||||
*/
|
||||
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED4_GPIO_PORT,
|
||||
LED3_GPIO_PORT,
|
||||
LED5_GPIO_PORT,
|
||||
LED6_GPIO_PORT};
|
||||
const uint16_t GPIO_PIN[LEDn] = {LED4_PIN,
|
||||
LED3_PIN,
|
||||
LED5_PIN,
|
||||
LED6_PIN};
|
||||
|
||||
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT};
|
||||
const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN};
|
||||
const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn};
|
||||
|
||||
uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */
|
||||
uint32_t SpixTimeout = SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
|
||||
|
||||
static SPI_HandleTypeDef SpiHandle;
|
||||
static I2C_HandleTypeDef I2cHandle;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32F4 DISCOVERY LOW LEVEL Private FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Functions STM32F4 DISCOVERY LOW LEVEL Private Functions
|
||||
* @{
|
||||
*/
|
||||
static void I2Cx_Init(void);
|
||||
static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg);
|
||||
static void I2Cx_MspInit(void);
|
||||
static void I2Cx_Error(uint8_t Addr);
|
||||
|
||||
static void SPIx_Init(void);
|
||||
static void SPIx_MspInit(void);
|
||||
static uint8_t SPIx_WriteRead(uint8_t Byte);
|
||||
static void SPIx_Error(void);
|
||||
|
||||
/* Link functions for Accelerometer peripheral */
|
||||
void ACCELERO_IO_Init(void);
|
||||
void ACCELERO_IO_ITConfig(void);
|
||||
void ACCELERO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
|
||||
void ACCELERO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
|
||||
|
||||
/* Link functions for Audio peripheral */
|
||||
void AUDIO_IO_Init(void);
|
||||
void AUDIO_IO_DeInit(void);
|
||||
void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_LED_Functions STM32F4 DISCOVERY LOW LEVEL LED Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This method returns the STM32F4 DISCO BSP Driver revision
|
||||
* @retval version : 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
uint32_t BSP_GetVersion(void)
|
||||
{
|
||||
return __STM32F4_DISCO_BSP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures LED GPIO.
|
||||
* @param Led: Specifies the Led to be configured.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED4
|
||||
* @arg LED3
|
||||
* @arg LED5
|
||||
* @arg LED6
|
||||
*/
|
||||
void BSP_LED_Init(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable the GPIO_LED Clock */
|
||||
LEDx_GPIO_CLK_ENABLE(Led);
|
||||
|
||||
/* Configure the GPIO_LED pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN[Led];
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
|
||||
HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
|
||||
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED On.
|
||||
* @param Led: Specifies the Led to be set on.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED4
|
||||
* @arg LED3
|
||||
* @arg LED5
|
||||
* @arg LED6
|
||||
*/
|
||||
void BSP_LED_On(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED Off.
|
||||
* @param Led: Specifies the Led to be set off.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED4
|
||||
* @arg LED3
|
||||
* @arg LED5
|
||||
* @arg LED6
|
||||
*/
|
||||
void BSP_LED_Off(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the selected LED.
|
||||
* @param Led: Specifies the Led to be toggled.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED4
|
||||
* @arg LED3
|
||||
* @arg LED5
|
||||
* @arg LED6
|
||||
*/
|
||||
void BSP_LED_Toggle(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUTTON_Functions STM32F4 DISCOVERY LOW LEVEL BUTTON Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configures Button GPIO and EXTI Line.
|
||||
* @param Button: Specifies the Button to be configured.
|
||||
* This parameter should be: BUTTON_KEY
|
||||
* @param Mode: Specifies Button mode.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
||||
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
|
||||
* generation capability
|
||||
*/
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Mode)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable the BUTTON Clock */
|
||||
BUTTONx_GPIO_CLK_ENABLE(Button);
|
||||
|
||||
if (Mode == BUTTON_MODE_GPIO)
|
||||
{
|
||||
/* Configure Button pin as input */
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
if (Mode == BUTTON_MODE_EXTI)
|
||||
{
|
||||
/* Configure Button pin as input with External interrupt */
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
|
||||
|
||||
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the selected Button state.
|
||||
* @param Button: Specifies the Button to be checked.
|
||||
* This parameter should be: BUTTON_KEY
|
||||
* @retval The Button GPIO pin value.
|
||||
*/
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
||||
{
|
||||
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUS_Functions STM32F4 DISCOVERY LOW LEVEL BUS Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
BUS OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************* SPI Routines *********************************/
|
||||
|
||||
/**
|
||||
* @brief SPIx Bus initialization
|
||||
*/
|
||||
static void SPIx_Init(void)
|
||||
{
|
||||
if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
|
||||
{
|
||||
/* SPI configuration -----------------------------------------------------*/
|
||||
SpiHandle.Instance = DISCOVERY_SPIx;
|
||||
SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
|
||||
SpiHandle.Init.CRCPolynomial = 7;
|
||||
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
SpiHandle.Init.NSS = SPI_NSS_SOFT;
|
||||
SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
|
||||
SpiHandle.Init.Mode = SPI_MODE_MASTER;
|
||||
|
||||
SPIx_MspInit();
|
||||
HAL_SPI_Init(&SpiHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sends a Byte through the SPI interface and return the Byte received
|
||||
* from the SPI bus.
|
||||
* @param Byte: Byte send.
|
||||
* @retval The received byte value
|
||||
*/
|
||||
static uint8_t SPIx_WriteRead(uint8_t Byte)
|
||||
{
|
||||
uint8_t receivedbyte = 0;
|
||||
|
||||
/* Send a Byte through the SPI peripheral */
|
||||
/* Read byte from the SPI bus */
|
||||
if(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*) &Byte, (uint8_t*) &receivedbyte, 1, SpixTimeout) != HAL_OK)
|
||||
{
|
||||
SPIx_Error();
|
||||
}
|
||||
|
||||
return receivedbyte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPIx error treatment function.
|
||||
*/
|
||||
static void SPIx_Error(void)
|
||||
{
|
||||
/* De-initialize the SPI communication bus */
|
||||
HAL_SPI_DeInit(&SpiHandle);
|
||||
|
||||
/* Re-Initialize the SPI communication bus */
|
||||
SPIx_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP Init.
|
||||
*/
|
||||
static void SPIx_MspInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* Enable the SPI peripheral */
|
||||
DISCOVERY_SPIx_CLK_ENABLE();
|
||||
|
||||
/* Enable SCK, MOSI and MISO GPIO clocks */
|
||||
DISCOVERY_SPIx_GPIO_CLK_ENABLE();
|
||||
|
||||
/* SPI SCK, MOSI, MISO pin configuration */
|
||||
GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MISO_PIN | DISCOVERY_SPIx_MOSI_PIN);
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
|
||||
GPIO_InitStructure.Alternate = DISCOVERY_SPIx_AF;
|
||||
HAL_GPIO_Init(DISCOVERY_SPIx_GPIO_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/******************************* I2C Routines**********************************/
|
||||
/**
|
||||
* @brief Configures I2C interface.
|
||||
*/
|
||||
static void I2Cx_Init(void)
|
||||
{
|
||||
if(HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
|
||||
{
|
||||
/* DISCOVERY_I2Cx peripheral configuration */
|
||||
I2cHandle.Init.ClockSpeed = BSP_I2C_SPEED;
|
||||
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
I2cHandle.Init.OwnAddress1 = 0x33;
|
||||
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
I2cHandle.Instance = DISCOVERY_I2Cx;
|
||||
|
||||
/* Init the I2C */
|
||||
I2Cx_MspInit();
|
||||
HAL_I2C_Init(&I2cHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a value in a register of the device through BUS.
|
||||
* @param Addr: Device address on BUS Bus.
|
||||
* @param Reg: The target register address to write
|
||||
* @param Value: The target register value to be written
|
||||
* @retval HAL status
|
||||
*/
|
||||
static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
status = HAL_I2C_Mem_Write(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Execute user timeout callback */
|
||||
I2Cx_Error(Addr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read a register of the device through BUS
|
||||
* @param Addr: Device address on BUS
|
||||
* @param Reg: The target register address to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint8_t value = 0;
|
||||
|
||||
status = HAL_I2C_Mem_Read(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &value, 1,I2cxTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Execute user timeout callback */
|
||||
I2Cx_Error(Addr);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages error callback by re-initializing I2C.
|
||||
* @param Addr: I2C Address
|
||||
*/
|
||||
static void I2Cx_Error(uint8_t Addr)
|
||||
{
|
||||
/* De-initialize the I2C communication bus */
|
||||
HAL_I2C_DeInit(&I2cHandle);
|
||||
|
||||
/* Re-Initialize the I2C communication bus */
|
||||
I2Cx_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C MSP Initialization
|
||||
*/
|
||||
static void I2Cx_MspInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable I2C GPIO clocks */
|
||||
DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
|
||||
|
||||
/* DISCOVERY_I2Cx SCL and SDA pins configuration ---------------------------*/
|
||||
GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
|
||||
HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* Enable the DISCOVERY_I2Cx peripheral clock */
|
||||
DISCOVERY_I2Cx_CLK_ENABLE();
|
||||
|
||||
/* Force the I2C peripheral clock reset */
|
||||
DISCOVERY_I2Cx_FORCE_RESET();
|
||||
|
||||
/* Release the I2C peripheral clock reset */
|
||||
DISCOVERY_I2Cx_RELEASE_RESET();
|
||||
|
||||
/* Enable and set I2Cx Interrupt to the highest priority */
|
||||
HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
|
||||
|
||||
/* Enable and set I2Cx Interrupt to the highest priority */
|
||||
HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
LINK OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/***************************** LINK ACCELEROMETER *****************************/
|
||||
|
||||
/**
|
||||
* @brief Configures the Accelerometer SPI interface.
|
||||
*/
|
||||
void ACCELERO_IO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* Configure the Accelerometer Control pins --------------------------------*/
|
||||
/* Enable CS GPIO clock and configure GPIO pin for Accelerometer Chip select */
|
||||
ACCELERO_CS_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure GPIO PIN for LIS Chip select */
|
||||
GPIO_InitStructure.Pin = ACCELERO_CS_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
|
||||
HAL_GPIO_Init(ACCELERO_CS_GPIO_PORT, &GPIO_InitStructure);
|
||||
|
||||
/* Deselect: Chip Select high */
|
||||
ACCELERO_CS_HIGH();
|
||||
|
||||
SPIx_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the Accelerometer INT2.
|
||||
* EXTI0 is already used by user button so INT1 is not configured here.
|
||||
*/
|
||||
void ACCELERO_IO_ITConfig(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* Enable INT2 GPIO clock and configure GPIO PINs to detect Interrupts */
|
||||
ACCELERO_INT_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure GPIO PINs to detect Interrupts */
|
||||
GPIO_InitStructure.Pin = ACCELERO_INT2_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(ACCELERO_INT_GPIO_PORT, &GPIO_InitStructure);
|
||||
|
||||
/* Enable and set Accelerometer INT2 to the lowest priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)ACCELERO_INT2_EXTI_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)ACCELERO_INT2_EXTI_IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes one byte to the Accelerometer.
|
||||
* @param pBuffer: pointer to the buffer containing the data to be written to the Accelerometer.
|
||||
* @param WriteAddr: Accelerometer's internal address to write to.
|
||||
* @param NumByteToWrite: Number of bytes to write.
|
||||
*/
|
||||
void ACCELERO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite)
|
||||
{
|
||||
/* Configure the MS bit:
|
||||
- When 0, the address will remain unchanged in multiple read/write commands.
|
||||
- When 1, the address will be auto incremented in multiple read/write commands.
|
||||
*/
|
||||
if(NumByteToWrite > 0x01)
|
||||
{
|
||||
WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD;
|
||||
}
|
||||
/* Set chip select Low at the start of the transmission */
|
||||
ACCELERO_CS_LOW();
|
||||
|
||||
/* Send the Address of the indexed register */
|
||||
SPIx_WriteRead(WriteAddr);
|
||||
|
||||
/* Send the data that will be written into the device (MSB First) */
|
||||
while(NumByteToWrite >= 0x01)
|
||||
{
|
||||
SPIx_WriteRead(*pBuffer);
|
||||
NumByteToWrite--;
|
||||
pBuffer++;
|
||||
}
|
||||
|
||||
/* Set chip select High at the end of the transmission */
|
||||
ACCELERO_CS_HIGH();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a block of data from the Accelerometer.
|
||||
* @param pBuffer: pointer to the buffer that receives the data read from the Accelerometer.
|
||||
* @param ReadAddr: Accelerometer's internal address to read from.
|
||||
* @param NumByteToRead: number of bytes to read from the Accelerometer.
|
||||
*/
|
||||
void ACCELERO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead)
|
||||
{
|
||||
if(NumByteToRead > 0x01)
|
||||
{
|
||||
ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadAddr |= (uint8_t)READWRITE_CMD;
|
||||
}
|
||||
/* Set chip select Low at the start of the transmission */
|
||||
ACCELERO_CS_LOW();
|
||||
|
||||
/* Send the Address of the indexed register */
|
||||
SPIx_WriteRead(ReadAddr);
|
||||
|
||||
/* Receive the data that will be read from the device (MSB First) */
|
||||
while(NumByteToRead > 0x00)
|
||||
{
|
||||
/* Send dummy byte (0x00) to generate the SPI clock to ACCELEROMETER (Slave device) */
|
||||
*pBuffer = SPIx_WriteRead(DUMMY_BYTE);
|
||||
NumByteToRead--;
|
||||
pBuffer++;
|
||||
}
|
||||
|
||||
/* Set chip select High at the end of the transmission */
|
||||
ACCELERO_CS_HIGH();
|
||||
}
|
||||
|
||||
/********************************* LINK AUDIO *********************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes Audio low level.
|
||||
*/
|
||||
void AUDIO_IO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable Reset GPIO Clock */
|
||||
AUDIO_RESET_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Audio reset pin configuration */
|
||||
GPIO_InitStruct.Pin = AUDIO_RESET_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStruct);
|
||||
|
||||
I2Cx_Init();
|
||||
|
||||
/* Power Down the codec */
|
||||
HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_RESET);
|
||||
|
||||
/* Wait for a delay to insure registers erasing */
|
||||
HAL_Delay(5);
|
||||
|
||||
/* Power on the codec */
|
||||
HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_SET);
|
||||
|
||||
/* Wait for a delay to insure registers erasing */
|
||||
HAL_Delay(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes Audio low level.
|
||||
*/
|
||||
void AUDIO_IO_DeInit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param Value: Data to be written
|
||||
*/
|
||||
void AUDIO_IO_Write (uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
I2Cx_WriteData(Addr, Reg, Value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @retval Data to be read
|
||||
*/
|
||||
uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg)
|
||||
{
|
||||
return I2Cx_ReadData(Addr, Reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,282 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4_discovery.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains definitions for STM32F4-Discovery Kit's Leds and
|
||||
* push-button hardware resources.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F4_DISCOVERY_H
|
||||
#define __STM32F4_DISCOVERY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY_LOW_LEVEL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Types STM32F4 DISCOVERY LOW LEVEL_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LED4 = 0,
|
||||
LED3 = 1,
|
||||
LED5 = 2,
|
||||
LED6 = 3
|
||||
} Led_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_KEY = 0,
|
||||
} Button_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_MODE_GPIO = 0,
|
||||
BUTTON_MODE_EXTI = 1
|
||||
} ButtonMode_TypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Constants STM32F4 DISCOVERY LOW LEVEL Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define for STM32F4_DISCOVERY board
|
||||
*/
|
||||
#if !defined (USE_STM32F4_DISCO)
|
||||
#define USE_STM32F4_DISCO
|
||||
#endif
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_LED STM32F4 DISCOVERY LOW LEVEL LED
|
||||
* @{
|
||||
*/
|
||||
#define LEDn 4
|
||||
|
||||
#define LED4_PIN GPIO_PIN_12
|
||||
#define LED4_GPIO_PORT GPIOD
|
||||
#define LED4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define LED4_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
|
||||
|
||||
#define LED3_PIN GPIO_PIN_13
|
||||
#define LED3_GPIO_PORT GPIOD
|
||||
#define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
|
||||
|
||||
#define LED5_PIN GPIO_PIN_14
|
||||
#define LED5_GPIO_PORT GPIOD
|
||||
#define LED5_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define LED5_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
|
||||
|
||||
#define LED6_PIN GPIO_PIN_15
|
||||
#define LED6_GPIO_PORT GPIOD
|
||||
#define LED6_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define LED6_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
|
||||
|
||||
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) do{if((__INDEX__) == 0) LED4_GPIO_CLK_ENABLE(); else \
|
||||
if((__INDEX__) == 1) LED3_GPIO_CLK_ENABLE(); else \
|
||||
if((__INDEX__) == 2) LED5_GPIO_CLK_ENABLE(); else \
|
||||
if((__INDEX__) == 3) LED6_GPIO_CLK_ENABLE(); \
|
||||
}while(0)
|
||||
|
||||
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) do{if((__INDEX__) == 0) LED4_GPIO_CLK_DISABLE(); else \
|
||||
if((__INDEX__) == 1) LED3_GPIO_CLK_DISABLE(); else \
|
||||
if((__INDEX__) == 2) LED5_GPIO_CLK_DISABLE(); else \
|
||||
if((__INDEX__) == 3) LED6_GPIO_CLK_DISABLE(); \
|
||||
}while(0)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUTTON STM32F4 DISCOVERY LOW LEVEL BUTTON
|
||||
* @{
|
||||
*/
|
||||
#define BUTTONn 1
|
||||
|
||||
/**
|
||||
* @brief Wakeup push-button
|
||||
*/
|
||||
#define KEY_BUTTON_PIN GPIO_PIN_0
|
||||
#define KEY_BUTTON_GPIO_PORT GPIOA
|
||||
#define KEY_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define KEY_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define KEY_BUTTON_EXTI_IRQn EXTI0_IRQn
|
||||
|
||||
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do{if((__INDEX__) == 0) KEY_BUTTON_GPIO_CLK_ENABLE(); \
|
||||
}while(0)
|
||||
|
||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) do{if((__INDEX__) == 0) KEY_BUTTON_GPIO_CLK_DISABLE(); \
|
||||
}while(0)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUS STM32F4 DISCOVERY LOW LEVEL BUS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*############################### SPI1 #######################################*/
|
||||
#define DISCOVERY_SPIx SPI1
|
||||
#define DISCOVERY_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
|
||||
#define DISCOVERY_SPIx_GPIO_PORT GPIOA /* GPIOA */
|
||||
#define DISCOVERY_SPIx_AF GPIO_AF5_SPI1
|
||||
#define DISCOVERY_SPIx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define DISCOVERY_SPIx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define DISCOVERY_SPIx_SCK_PIN GPIO_PIN_5 /* PA.05 */
|
||||
#define DISCOVERY_SPIx_MISO_PIN GPIO_PIN_6 /* PA.06 */
|
||||
#define DISCOVERY_SPIx_MOSI_PIN GPIO_PIN_7 /* PA.07 */
|
||||
|
||||
/* Maximum Timeout values for flags waiting loops. These timeouts are not based
|
||||
on accurate values, they just guarantee that the application will not remain
|
||||
stuck if the SPI communication is corrupted.
|
||||
You may modify these timeout values depending on CPU frequency and application
|
||||
conditions (interrupts routines ...). */
|
||||
#define SPIx_TIMEOUT_MAX 0x1000 /*<! The value of the maximal timeout for BUS waiting loops */
|
||||
|
||||
|
||||
/*############################# I2C1 #########################################*/
|
||||
/* I2C clock speed configuration (in Hz) */
|
||||
#ifndef BSP_I2C_SPEED
|
||||
#define BSP_I2C_SPEED 100000
|
||||
#endif /* BSP_I2C_SPEED */
|
||||
|
||||
/* I2C peripheral configuration defines (control interface of the audio codec) */
|
||||
#define DISCOVERY_I2Cx I2C1
|
||||
#define DISCOVERY_I2Cx_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()
|
||||
#define DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define DISCOVERY_I2Cx_SCL_SDA_AF GPIO_AF4_I2C1
|
||||
#define DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT GPIOB
|
||||
#define DISCOVERY_I2Cx_SCL_PIN GPIO_PIN_6
|
||||
#define DISCOVERY_I2Cx_SDA_PIN GPIO_PIN_9
|
||||
|
||||
#define DISCOVERY_I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET()
|
||||
#define DISCOVERY_I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET()
|
||||
|
||||
/* I2C interrupt requests */
|
||||
#define DISCOVERY_I2Cx_EV_IRQn I2C1_EV_IRQn
|
||||
#define DISCOVERY_I2Cx_ER_IRQn I2C1_ER_IRQn
|
||||
|
||||
/* Maximum Timeout values for flags waiting loops. These timeouts are not based
|
||||
on accurate values, they just guarantee that the application will not remain
|
||||
stuck if the SPI communication is corrupted.
|
||||
You may modify these timeout values depending on CPU frequency and application
|
||||
conditions (interrupts routines ...). */
|
||||
#define I2Cx_TIMEOUT_MAX 0x1000 /*<! The value of the maximal timeout for BUS waiting loops */
|
||||
|
||||
|
||||
/*############################# ACCELEROMETER ################################*/
|
||||
/* Read/Write command */
|
||||
#define READWRITE_CMD ((uint8_t)0x80)
|
||||
/* Multiple byte read/write command */
|
||||
#define MULTIPLEBYTE_CMD ((uint8_t)0x40)
|
||||
/* Dummy Byte Send by the SPI Master device in order to generate the Clock to the Slave device */
|
||||
#define DUMMY_BYTE ((uint8_t)0x00)
|
||||
|
||||
/* Chip Select macro definition */
|
||||
#define ACCELERO_CS_LOW() HAL_GPIO_WritePin(ACCELERO_CS_GPIO_PORT, ACCELERO_CS_PIN, GPIO_PIN_RESET)
|
||||
#define ACCELERO_CS_HIGH() HAL_GPIO_WritePin(ACCELERO_CS_GPIO_PORT, ACCELERO_CS_PIN, GPIO_PIN_SET)
|
||||
|
||||
/**
|
||||
* @brief ACCELEROMETER Interface pins
|
||||
*/
|
||||
#define ACCELERO_CS_PIN GPIO_PIN_3 /* PE.03 */
|
||||
#define ACCELERO_CS_GPIO_PORT GPIOE /* GPIOE */
|
||||
#define ACCELERO_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
|
||||
#define ACCELERO_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
|
||||
#define ACCELERO_INT_GPIO_PORT GPIOE /* GPIOE */
|
||||
#define ACCELERO_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
|
||||
#define ACCELERO_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
|
||||
#define ACCELERO_INT1_PIN GPIO_PIN_0 /* PE.00 */
|
||||
#define ACCELERO_INT1_EXTI_IRQn EXTI0_IRQn
|
||||
#define ACCELERO_INT2_PIN GPIO_PIN_1 /* PE.01 */
|
||||
#define ACCELERO_INT2_EXTI_IRQn EXTI1_IRQn
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/*############################### AUDIO ######################################*/
|
||||
/**
|
||||
* @brief AUDIO I2C Interface pins
|
||||
*/
|
||||
#define AUDIO_I2C_ADDRESS 0x94
|
||||
|
||||
/* Audio Reset Pin definition */
|
||||
#define AUDIO_RESET_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define AUDIO_RESET_PIN GPIO_PIN_4
|
||||
#define AUDIO_RESET_GPIO GPIOD
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Macros STM32F4 DISCOVERY LOW LEVEL Exported Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Exported_Functions STM32F4 DISCOVERY LOW LEVEL Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint32_t BSP_GetVersion(void);
|
||||
void BSP_LED_Init(Led_TypeDef Led);
|
||||
void BSP_LED_On(Led_TypeDef Led);
|
||||
void BSP_LED_Off(Led_TypeDef Led);
|
||||
void BSP_LED_Toggle(Led_TypeDef Led);
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Mode);
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4_DISCOVERY_H */
|
||||
@@ -0,0 +1,246 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4_discovery_accelerometer.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides a set of functions needed to manage the
|
||||
* MEMS accelerometers available on STM32F4-Discovery Kit.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4_discovery_accelerometer.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER STM32F4 DISCOVERY ACCELEROMETER
|
||||
* @brief This file includes the motion sensor driver for ACCELEROMETER motion sensor
|
||||
* devices.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Private_TypesDefinitions STM32F4 DISCOVERY ACCELEROMETER Private TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Private_Defines STM32F4 DISCOVERY ACCELEROMETER Private Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Private_Macros STM32F4 DISCOVERY ACCELEROMETER Private Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Private_Variables STM32F4 DISCOVERY ACCELEROMETER Private Variables
|
||||
* @{
|
||||
*/
|
||||
static ACCELERO_DrvTypeDef *AcceleroDrv;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Private_FunctionPrototypes STM32F4 DISCOVERY ACCELEROMETER Private FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Private_Functions STM32F4 DISCOVERY ACCELEROMETER Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setx Accelerometer Initialization.
|
||||
* @retval ACCELERO_OK if no problem during initialization
|
||||
*/
|
||||
uint8_t BSP_ACCELERO_Init(void)
|
||||
{
|
||||
uint8_t ret = ACCELERO_ERROR;
|
||||
uint16_t ctrl = 0x0000;
|
||||
LIS302DL_InitTypeDef lis302dl_initstruct;
|
||||
LIS302DL_FilterConfigTypeDef lis302dl_filter = {0,0,0};
|
||||
LIS3DSH_InitTypeDef l1s3dsh_InitStruct;
|
||||
|
||||
if(Lis302dlDrv.ReadID() == I_AM_LIS302DL)
|
||||
{
|
||||
/* Initialize the accelerometer driver structure */
|
||||
AcceleroDrv = &Lis302dlDrv;
|
||||
|
||||
/* Set configuration of LIS302DL MEMS Accelerometer *********************/
|
||||
lis302dl_initstruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
|
||||
lis302dl_initstruct.Output_DataRate = LIS302DL_DATARATE_100;
|
||||
lis302dl_initstruct.Axes_Enable = LIS302DL_XYZ_ENABLE;
|
||||
lis302dl_initstruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
|
||||
lis302dl_initstruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
|
||||
|
||||
/* Configure MEMS: data rate, power mode, full scale, self test and axes */
|
||||
ctrl = (uint16_t) (lis302dl_initstruct.Output_DataRate | lis302dl_initstruct.Power_Mode | \
|
||||
lis302dl_initstruct.Full_Scale | lis302dl_initstruct.Self_Test | \
|
||||
lis302dl_initstruct.Axes_Enable);
|
||||
|
||||
/* Configure the accelerometer main parameters */
|
||||
AcceleroDrv->Init(ctrl);
|
||||
|
||||
/* MEMS High Pass Filter configuration */
|
||||
lis302dl_filter.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER;
|
||||
lis302dl_filter.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1;
|
||||
lis302dl_filter.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2;
|
||||
|
||||
/* Configure MEMS high pass filter cut-off level, interrupt and data selection bits */
|
||||
ctrl = (uint8_t)(lis302dl_filter.HighPassFilter_Data_Selection | \
|
||||
lis302dl_filter.HighPassFilter_CutOff_Frequency | \
|
||||
lis302dl_filter.HighPassFilter_Interrupt);
|
||||
|
||||
/* Configure the accelerometer LPF main parameters */
|
||||
AcceleroDrv->FilterConfig(ctrl);
|
||||
|
||||
ret = ACCELERO_OK;
|
||||
}
|
||||
else if(Lis3dshDrv.ReadID() == I_AM_LIS3DSH)
|
||||
{
|
||||
/* Initialize the accelerometer driver structure */
|
||||
AcceleroDrv = &Lis3dshDrv;
|
||||
|
||||
/* Set configuration of LIS3DSH MEMS Accelerometer **********************/
|
||||
l1s3dsh_InitStruct.Output_DataRate = LIS3DSH_DATARATE_100;
|
||||
l1s3dsh_InitStruct.Axes_Enable = LIS3DSH_XYZ_ENABLE;
|
||||
l1s3dsh_InitStruct.SPI_Wire = LIS3DSH_SERIALINTERFACE_4WIRE;
|
||||
l1s3dsh_InitStruct.Self_Test = LIS3DSH_SELFTEST_NORMAL;
|
||||
l1s3dsh_InitStruct.Full_Scale = LIS3DSH_FULLSCALE_2;
|
||||
l1s3dsh_InitStruct.Filter_BW = LIS3DSH_FILTER_BW_800;
|
||||
|
||||
/* Configure MEMS: power mode(ODR) and axes enable */
|
||||
ctrl = (uint16_t) (l1s3dsh_InitStruct.Output_DataRate | \
|
||||
l1s3dsh_InitStruct.Axes_Enable);
|
||||
|
||||
/* Configure MEMS: full scale and self test */
|
||||
ctrl |= (uint16_t) ((l1s3dsh_InitStruct.SPI_Wire | \
|
||||
l1s3dsh_InitStruct.Self_Test | \
|
||||
l1s3dsh_InitStruct.Full_Scale | \
|
||||
l1s3dsh_InitStruct.Filter_BW) << 8);
|
||||
|
||||
/* Configure the accelerometer main parameters */
|
||||
AcceleroDrv->Init(ctrl);
|
||||
|
||||
ret = ACCELERO_OK;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
ret = ACCELERO_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read ID of Accelerometer component.
|
||||
* @retval ID
|
||||
*/
|
||||
uint8_t BSP_ACCELERO_ReadID(void)
|
||||
{
|
||||
uint8_t id = 0x00;
|
||||
|
||||
if(AcceleroDrv->ReadID != NULL)
|
||||
{
|
||||
id = AcceleroDrv->ReadID();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reboot memory content of Accelerometer.
|
||||
*/
|
||||
void BSP_ACCELERO_Reset(void)
|
||||
{
|
||||
if(AcceleroDrv->Reset != NULL)
|
||||
{
|
||||
AcceleroDrv->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure Accelerometer click IT.
|
||||
*/
|
||||
void BSP_ACCELERO_Click_ITConfig(void)
|
||||
{
|
||||
if(AcceleroDrv->ConfigIT != NULL)
|
||||
{
|
||||
AcceleroDrv->ConfigIT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear Accelerometer click IT.
|
||||
*/
|
||||
void BSP_ACCELERO_Click_ITClear(void)
|
||||
{
|
||||
if(AcceleroDrv->ClearIT != NULL)
|
||||
{
|
||||
AcceleroDrv->ClearIT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get XYZ axes acceleration.
|
||||
* @param pDataXYZ: Pointer to 3 angular acceleration axes.
|
||||
* pDataXYZ[0] = X axis, pDataXYZ[1] = Y axis, pDataXYZ[2] = Z axis
|
||||
*/
|
||||
void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ)
|
||||
{
|
||||
int16_t SwitchXY = 0;
|
||||
|
||||
if(AcceleroDrv->GetXYZ != NULL)
|
||||
{
|
||||
AcceleroDrv->GetXYZ(pDataXYZ);
|
||||
|
||||
/* Switch X and Y Axes in case of LIS302DL MEMS */
|
||||
if(AcceleroDrv == &Lis302dlDrv)
|
||||
{
|
||||
SwitchXY = pDataXYZ[0];
|
||||
pDataXYZ[0] = pDataXYZ[1];
|
||||
/* Invert Y Axis to be compliant with LIS3DSH MEMS */
|
||||
pDataXYZ[1] = -SwitchXY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4_discovery_accelerometer.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the
|
||||
* stm32f4_discovery_accelerometer.c firmware driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F4_DISCOVERY_ACCELEROMETER_H
|
||||
#define __STM32F4_DISCOVERY_ACCELEROMETER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4_discovery.h"
|
||||
|
||||
/* Include Accelerometer component drivers */
|
||||
#include "../Components/lis302dl/lis302dl.h"
|
||||
#include "../Components/lis3dsh/lis3dsh.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY_ACCELEROMETER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Exported_Types STM32F4 DISCOVERY ACCELEROMETER Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACCELERO_OK = 0,
|
||||
ACCELERO_ERROR = 1,
|
||||
ACCELERO_TIMEOUT = 2
|
||||
}ACCELERO_StatusTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_ACCELEROMETER_Exported_Functions STM32F4 DISCOVERY ACCELEROMETER Exported Functions
|
||||
* @{
|
||||
*/
|
||||
/* Accelerometer functions */
|
||||
uint8_t BSP_ACCELERO_Init(void);
|
||||
uint8_t BSP_ACCELERO_ReadID(void);
|
||||
void BSP_ACCELERO_Reset(void);
|
||||
void BSP_ACCELERO_Click_ITConfig(void);
|
||||
void BSP_ACCELERO_Click_ITClear(void);
|
||||
void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4_DISCOVERY_ACCELEROMETER_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4_discovery_audio.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* stm32f4_discovery_audio.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F4_DISCOVERY_AUDIO_H
|
||||
#define __STM32F4_DISCOVERY_AUDIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Include audio component Driver */
|
||||
#include "../Components/cs43l22/cs43l22.h"
|
||||
|
||||
#include "stm32f4_discovery.h"
|
||||
#include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/Inc/pdm2pcm_glo.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4_DISCOVERY_AUDIO
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_AUDIO_Exported_Types STM32F4 DISCOVERY AUDIO Exported Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_AUDIO_OUT_Exported_Constants STM32F4 DISCOVERY AUDIO OUT Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
AUDIO OUT CONFIGURATION
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* I2S peripheral configuration defines */
|
||||
#define I2S3 SPI3
|
||||
#define I2S3_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE()
|
||||
#define I2S3_CLK_DISABLE() __HAL_RCC_SPI3_CLK_DISABLE()
|
||||
#define I2S3_SCK_SD_WS_AF GPIO_AF6_SPI3
|
||||
#define I2S3_SCK_SD_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define I2S3_MCK_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define I2S3_WS_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define I2S3_WS_PIN GPIO_PIN_4
|
||||
#define I2S3_SCK_PIN GPIO_PIN_10
|
||||
#define I2S3_SD_PIN GPIO_PIN_12
|
||||
#define I2S3_MCK_PIN GPIO_PIN_7
|
||||
#define I2S3_SCK_SD_GPIO_PORT GPIOC
|
||||
#define I2S3_WS_GPIO_PORT GPIOA
|
||||
#define I2S3_MCK_GPIO_PORT GPIOC
|
||||
|
||||
/* I2S DMA Stream definitions */
|
||||
#define I2S3_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define I2S3_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE()
|
||||
#define I2S3_DMAx_STREAM DMA1_Stream7
|
||||
#define I2S3_DMAx_CHANNEL DMA_CHANNEL_0
|
||||
#define I2S3_DMAx_IRQ DMA1_Stream7_IRQn
|
||||
#define I2S3_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
|
||||
#define I2S3_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
|
||||
#define DMA_MAX_SZE 0xFFFF
|
||||
|
||||
#define I2S3_IRQHandler DMA1_Stream7_IRQHandler
|
||||
|
||||
/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
|
||||
#define AUDIO_OUT_IRQ_PREPRIO 0x0E /* Select the preemption priority level(0 is the highest) */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
AUDIO IN CONFIGURATION
|
||||
------------------------------------------------------------------------------*/
|
||||
/* SPI Configuration defines */
|
||||
#define I2S2 SPI2
|
||||
#define I2S2_CLK_ENABLE() __HAL_RCC_SPI2_CLK_ENABLE()
|
||||
#define I2S2_CLK_DISABLE() __HAL_RCC_SPI2_CLK_DISABLE()
|
||||
#define I2S2_SCK_PIN GPIO_PIN_10
|
||||
#define I2S2_SCK_GPIO_PORT GPIOB
|
||||
#define I2S2_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define I2S2_SCK_AF GPIO_AF5_SPI2
|
||||
|
||||
#define I2S2_MOSI_PIN GPIO_PIN_3
|
||||
#define I2S2_MOSI_GPIO_PORT GPIOC
|
||||
#define I2S2_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define I2S2_MOSI_AF GPIO_AF5_SPI2
|
||||
|
||||
/* I2S DMA Stream Rx definitions */
|
||||
#define I2S2_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define I2S2_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE()
|
||||
#define I2S2_DMAx_STREAM DMA1_Stream3
|
||||
#define I2S2_DMAx_CHANNEL DMA_CHANNEL_0
|
||||
#define I2S2_DMAx_IRQ DMA1_Stream3_IRQn
|
||||
#define I2S2_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
|
||||
#define I2S2_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
|
||||
|
||||
#define I2S2_IRQHandler DMA1_Stream3_IRQHandler
|
||||
|
||||
/* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */
|
||||
#define AUDIO_IN_IRQ_PREPRIO 0x0F /* Select the preemption priority level(0 is the highest) */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
CONFIGURATION: Audio Driver Configuration parameters
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#define AUDIODATA_SIZE 2 /* 16-bits audio data size */
|
||||
|
||||
/* Audio status definition */
|
||||
#define AUDIO_OK 0
|
||||
#define AUDIO_ERROR 1
|
||||
#define AUDIO_TIMEOUT 2
|
||||
|
||||
/* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */
|
||||
#define DEFAULT_AUDIO_IN_FREQ I2S_AUDIOFREQ_16K
|
||||
#define DEFAULT_AUDIO_IN_BIT_RESOLUTION 16
|
||||
#define DEFAULT_AUDIO_IN_CHANNEL_NBR 1 /* Mono = 1, Stereo = 2 */
|
||||
#define DEFAULT_AUDIO_IN_VOLUME 64
|
||||
|
||||
/* PDM buffer input size */
|
||||
#define INTERNAL_BUFF_SIZE 128*DEFAULT_AUDIO_IN_FREQ/16000*DEFAULT_AUDIO_IN_CHANNEL_NBR
|
||||
/* PCM buffer output size */
|
||||
#define PCM_OUT_SIZE DEFAULT_AUDIO_IN_FREQ/1000
|
||||
#define CHANNEL_DEMUX_MASK 0x55
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
OPTIONAL Configuration defines parameters
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_AUDIO_Exported_Variables STM32F4 DISCOVERY AUDIO Exported Variables
|
||||
* @{
|
||||
*/
|
||||
extern __IO uint16_t AudioInVolume;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_AUDIO_Exported_Macros STM32F4 DISCOVERY AUDIO Exported Macros
|
||||
* @{
|
||||
*/
|
||||
#define DMA_MAX(_X_) (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE)
|
||||
#define HTONS(A) ((((uint16_t)(A) & 0xff00) >> 8) | (((uint16_t)(A) & 0x00ff) << 8))
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_AUDIO_OUT_Exported_Functions STM32F4 DISCOVERY AUDIO OUT Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
|
||||
uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size);
|
||||
void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
|
||||
uint8_t BSP_AUDIO_OUT_Pause(void);
|
||||
uint8_t BSP_AUDIO_OUT_Resume(void);
|
||||
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
|
||||
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
|
||||
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
|
||||
uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
|
||||
uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
|
||||
|
||||
/* User Callbacks: user has to implement these functions in his code if they are needed. */
|
||||
/* This function is called when the requested data has been completely transferred. */
|
||||
void BSP_AUDIO_OUT_TransferComplete_CallBack(void);
|
||||
|
||||
/* This function is called when half of the requested buffer has been transferred. */
|
||||
void BSP_AUDIO_OUT_HalfTransfer_CallBack(void);
|
||||
|
||||
/* This function is called when an Interrupt due to transfer error on or peripheral
|
||||
error occurs. */
|
||||
void BSP_AUDIO_OUT_Error_CallBack(void);
|
||||
|
||||
/* These function can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */
|
||||
void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params);
|
||||
void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
|
||||
void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4_DISCOVERY_AUDIO_IN_Exported_Functions STM32F4 DISCOVERY AUDIO IN Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
|
||||
uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size);
|
||||
uint8_t BSP_AUDIO_IN_Stop(void);
|
||||
uint8_t BSP_AUDIO_IN_Pause(void);
|
||||
uint8_t BSP_AUDIO_IN_Resume(void);
|
||||
uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume);
|
||||
uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf);
|
||||
/* User Callbacks: user has to implement these functions in his code if they are needed. */
|
||||
/* This function should be implemented by the user application.
|
||||
It is called into this driver when the current buffer is filled to prepare the next
|
||||
buffer pointer and its size. */
|
||||
void BSP_AUDIO_IN_TransferComplete_CallBack(void);
|
||||
void BSP_AUDIO_IN_HalfTransfer_CallBack(void);
|
||||
|
||||
/* This function is called when an Interrupt due to transfer error on or peripheral
|
||||
error occurs. */
|
||||
void BSP_AUDIO_IN_Error_Callback(void);
|
||||
|
||||
/* These function can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */
|
||||
void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params);
|
||||
void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
|
||||
void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4_DISCOVERY_AUDIO_H */
|
||||
Reference in New Issue
Block a user