initial working (stm32f4-discovery)

This commit is contained in:
2026-07-31 19:07:15 +03:00
commit ce6632f48c
2214 changed files with 1264937 additions and 0 deletions
@@ -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/stm32f401-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 [stm32f401-discovery](https://github.com/STMicroelectronics/stm32f401-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.
+39
View File
@@ -0,0 +1,39 @@
# BSP STM32F401-DISCOVERY Component
![latest tag](https://img.shields.io/github/v/tag/STMicroelectronics/stm32f401-discovery.svg?color=brightgreen)
## 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 **stm32f401-discovery** MCU component repository is one element of the **STM32CubeF4** MCU embedded software package, providing the **STM32F401-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/stm32f401-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-l3gd20](https://github.com/STMicroelectronics/stm32-l3gd20)
* [stm32-lsm303dlhc](https://github.com/STMicroelectronics/stm32-lsm303dlhc)
## 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,727 @@
/**
******************************************************************************
* @file stm32f401_discovery.c
* @author MCD Application Team
* @brief This file provides set of firmware functions to manage LEDs and
* push-button available on STM32F401-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 "stm32f401_discovery.h"
/** @defgroup BSP BSP
* @{
*/
/** @defgroup STM32F401_DISCOVERY STM32F401 DISCOVERY
* @{
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL STM32F401 DISCOVERY LOW LEVEL
* @brief This file provides set of firmware functions to manage Leds and push-button
* available on STM32F401-Discovery Kit from STMicroelectronics.
* @{
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F401 DISCOVERY LOW LEVEL Private TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Private_Defines STM32F401 DISCOVERY LOW LEVEL Private Defines
* @{
*/
/**
* @brief STM32F401 DISCO BSP Driver version number V2.2.5
*/
#define __STM32F401_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */
#define __STM32F401_DISCO_BSP_VERSION_SUB1 (0x02) /*!< [23:16] sub1 version */
#define __STM32F401_DISCO_BSP_VERSION_SUB2 (0x05) /*!< [15:8] sub2 version */
#define __STM32F401_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
#define __STM32F401_DISCO_BSP_VERSION ((__STM32F401_DISCO_BSP_VERSION_MAIN << 24)\
|(__STM32F401_DISCO_BSP_VERSION_SUB1 << 16)\
|(__STM32F401_DISCO_BSP_VERSION_SUB2 << 8 )\
|(__STM32F401_DISCO_BSP_VERSION_RC))
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Private_Macros STM32F401 DISCOVERY LOW LEVEL Private Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Private_Variables STM32F401 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 I2C_HandleTypeDef I2cHandle;
static SPI_HandleTypeDef SpiHandle;
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32F401 DISCOVERY LOW LEVEL Private FunctionPrototypes
* @{
*/
/* I2Cx bus function */
static void I2Cx_Init(void);
static void I2Cx_WriteData(uint16_t Addr, uint8_t Reg, uint8_t Value);
static uint8_t I2Cx_ReadData(uint16_t Addr, uint8_t Reg);
static void I2Cx_Error (void);
static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c);
/* SPIx bus function */
static void SPIx_Init(void);
static uint8_t SPIx_WriteRead(uint8_t byte);
static void SPIx_Error (void);
static void SPIx_MspInit(SPI_HandleTypeDef *hspi);
/* Link function for GYRO peripheral */
void GYRO_IO_Init(void);
void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
/* Link functions for AUDIO */
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);
/* Link function for COMPASS / ACCELERO peripheral */
void COMPASSACCELERO_IO_Init(void);
void COMPASSACCELERO_IO_ITConfig(void);
void COMPASSACCELERO_IO_Write(uint16_t DeviceAddr, uint8_t RegisterAddr, uint8_t Value);
uint8_t COMPASSACCELERO_IO_Read(uint16_t DeviceAddr, uint8_t RegisterAddr);
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Private_Functions STM32F401 DISCOVERY LOW LEVEL Private Functions
* @{
*/
/**
* @brief This method returns the STM32F401 DISCO BSP Driver revision
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
*/
uint32_t BSP_GetVersion(void)
{
return __STM32F401_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]);
}
/**
* @brief Configures Button GPIO and EXTI Line.
* @param Button: Specifies the Button to be configured.
* This parameter should be: BUTTON_KEY
* @param ButtonMode: 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 ButtonMode)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable the BUTTON Clock */
BUTTONx_GPIO_CLK_ENABLE(Button);
if(ButtonMode == BUTTON_MODE_GPIO)
{
/* Configure Button pin as input */
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
}
if(ButtonMode == BUTTON_MODE_EXTI)
{
/* Configure Button pin as input with External interrupt */
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Pull = GPIO_NOPULL;
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, 0x00);
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]);
}
/*******************************************************************************
BUS OPERATIONS
*******************************************************************************/
/******************************* I2C Routines *********************************/
/**
* @brief I2Cx Bus initialization.
*/
static void I2Cx_Init(void)
{
if(HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
{
I2cHandle.Instance = DISCOVERY_I2Cx;
I2cHandle.Init.OwnAddress1 = 0x43;
I2cHandle.Init.ClockSpeed = I2Cx_MAX_COMMUNICATION_FREQ;
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2cHandle.Init.OwnAddress2 = 0x00;
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
/* Init the I2C */
I2Cx_MspInit(&I2cHandle);
HAL_I2C_Init(&I2cHandle);
}
}
/**
* @brief Writes 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
*/
static void I2Cx_WriteData(uint16_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();
}
}
/**
* @brief Reads a register of the device through BUS.
* @param Addr: Device address on BUS Bus.
* @param Reg: The target register address to write
* @retval Data read at register address
*/
static uint8_t I2Cx_ReadData(uint16_t Addr, uint8_t Reg)
{
HAL_StatusTypeDef status = HAL_OK;
uint8_t value = 0;
status = HAL_I2C_Mem_Read(&I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value, 1, I2cxTimeout);
/* Check the communication status */
if(status != HAL_OK)
{
/* Execute user timeout callback */
I2Cx_Error();
}
return value;
}
/**
* @brief I2Cx error treatment function.
*/
static void I2Cx_Error(void)
{
/* De-initialize the I2C communication BUS */
HAL_I2C_DeInit(&I2cHandle);
/* Re- Initiaize the I2C communication BUS */
I2Cx_Init();
}
/**
* @brief I2Cx MSP Init.
* @param hi2c: I2C handle
*/
static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the I2C peripheral */
DISCOVERY_I2Cx_CLOCK_ENABLE();
/* Enable SCK and SDA GPIO clocks */
DISCOVERY_I2Cx_GPIO_CLK_ENABLE();
/* I2Cx SD1 & SCK pin configuration */
GPIO_InitStructure.Pin = DISCOVERY_I2Cx_SDA_PIN | DISCOVERY_I2Cx_SCL_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Alternate = DISCOVERY_I2Cx_AF;
HAL_GPIO_Init(DISCOVERY_I2Cx_GPIO_PORT, &GPIO_InitStructure);
/* 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);
}
/******************************* 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;
/* SPI baudrate is set to 5.6 MHz (PCLK2/SPI_BaudRatePrescaler = 90/16 = 5.625 MHz)
to verify these constraints:
ILI9341 LCD SPI interface max baudrate is 10MHz for write and 6.66MHz for read
L3GD20 SPI interface max baudrate is 10MHz for write/read
PCLK2 frequency is set to 90 MHz
*/
SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
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(&SpiHandle);
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-Initiaize the SPI communication BUS */
SPIx_Init();
}
/**
* @brief SPI MSP Init.
* @param hspi: SPI handle
*/
static void SPIx_MspInit(SPI_HandleTypeDef *hspi)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable SPIx clock */
DISCOVERY_SPIx_CLOCK_ENABLE();
/* Enable SPIx GPIO clock */
DISCOVERY_SPIx_GPIO_CLK_ENABLE();
/* Configure SPIx SCK, MOSI and MISO */
GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MOSI_PIN | DISCOVERY_SPIx_MISO_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);
}
/*******************************************************************************
LINK OPERATIONS
*******************************************************************************/
/********************************* LINK GYROSCOPE *****************************/
/**
* @brief Configures the GYRO SPI interface.
*/
void GYRO_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure the Gyroscope Control pins ------------------------------------*/
/* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
GYRO_CS_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = GYRO_CS_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure);
/* Deselect : Chip Select high */
GYRO_CS_HIGH();
/* Enable INT1, INT2 GPIO clock and Configure GPIO PINs to detect Interrupts */
GYRO_INT_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = GYRO_INT1_PIN | GYRO_INT2_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Pull= GPIO_NOPULL;
HAL_GPIO_Init(GYRO_INT_GPIO_PORT, &GPIO_InitStructure);
SPIx_Init();
}
/**
* @brief Writes one byte to the GYRO.
* @param pBuffer: pointer to the buffer containing the data to be written to the GYRO.
* @param WriteAddr : GYRO's internal address to write to.
* @param NumByteToWrite: Number of bytes to write.
*/
void GYRO_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 */
GYRO_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 */
GYRO_CS_HIGH();
}
/**
* @brief Reads a block of data from the GYRO.
* @param pBuffer: pointer to the buffer that receives the data read from the GYRO.
* @param ReadAddr: GYRO's internal address to read from.
* @param NumByteToRead: Number of bytes to read from the GYRO.
*/
void GYRO_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 */
GYRO_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 GYRO (Slave device) */
*pBuffer = SPIx_WriteRead(DUMMY_BYTE);
NumByteToRead--;
pBuffer++;
}
/* Set chip select High at the end of the transmission */
GYRO_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 */
CODEC_AUDIO_POWER_OFF();
/* Wait for a delay to insure registers erasing */
HAL_Delay(5);
/* Power on the codec */
CODEC_AUDIO_POWER_ON();
/* 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);
}
/****************************** LINK ACCELEROMETER ****************************/
/**
* @brief Configures COMPASS / ACCELERO I2C interface.
*/
void COMPASSACCELERO_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable DRDY clock */
ACCELERO_DRDY_GPIO_CLK_ENABLE();
/* MEMS DRDY pin configuration */
GPIO_InitStructure.Pin = ACCELERO_DRDY_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(ACCELERO_DRDY_GPIO_PORT, &GPIO_InitStructure);
I2Cx_Init();
}
/**
* @brief Configures COMPASS / ACCELERO click IT.
*/
void COMPASSACCELERO_IO_ITConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable INT1 and INT2 GPIO clock */
ACCELERO_INT_GPIO_CLK_ENABLE();
/* Configure GPIO PINs to detect Interrupts */
GPIO_InitStructure.Pin = ACCELERO_INT1_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 COMPASS / ACCELERO Interrupt to the highest priority */
HAL_NVIC_SetPriority(ACCELERO_INT1_EXTI_IRQn, 0x00, 0x00);
HAL_NVIC_EnableIRQ(ACCELERO_INT1_EXTI_IRQn);
}
/**
* @brief Writes one byte to the COMPASS / ACCELERO.
* @param DeviceAddr: the slave address to be programmed
* @param RegisterAddr: the COMPASS / ACCELERO register to be written
* @param Value: Data to be written
*/
void COMPASSACCELERO_IO_Write(uint16_t DeviceAddr, uint8_t RegisterAddr, uint8_t Value)
{
/* Call I2Cx Read data bus function */
I2Cx_WriteData(DeviceAddr, RegisterAddr, Value);
}
/**
* @brief Reads a block of data from the COMPASS / ACCELERO.
* @param DeviceAddr: the slave address to be programmed(ACC_I2C_ADDRESS or MAG_I2C_ADDRESS).
* @param RegisterAddr: the COMPASS / ACCELERO internal address register to read from
* @retval COMPASS / ACCELERO register value
*/
uint8_t COMPASSACCELERO_IO_Read(uint16_t DeviceAddr, uint8_t RegisterAddr)
{
/* Call I2Cx Read data bus function */
return I2Cx_ReadData(DeviceAddr, RegisterAddr);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,292 @@
/**
******************************************************************************
* @file stm32f401_discovery.h
* @author MCD Application Team
* @brief This file contains definitions for STM32F401-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 __STM32F401_DISCOVERY_H
#define __STM32F401_DISCOVERY_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F401_DISCOVERY
* @{
*/
/** @addtogroup STM32F401_DISCOVERY_LOW_LEVEL
* @{
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Exported_Types STM32F401 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 STM32F401_DISCOVERY_LOW_LEVEL_Exported_Constants STM32F401 DISCOVERY LOW LEVEL Exported Constants
* @{
*/
/**
* @brief Define for STM32F401_DISCOVERY board
*/
#if !defined (USE_STM32F401_DISCO)
#define USE_STM32F401_DISCO
#endif
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_LED STM32F401 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 STM32F401_DISCOVERY_LOW_LEVEL_BUTTON STM32F401 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 STM32F401_DISCOVERY_LOW_LEVEL_BUS STM32F401 DISCOVERY LOW LEVEL BUS
* @{
*/
/*############################### I2Cx #######################################*/
#define DISCOVERY_I2Cx I2C1
#define DISCOVERY_I2Cx_CLOCK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()
#define DISCOVERY_I2Cx_GPIO_PORT GPIOB /* GPIOB */
#define DISCOVERY_I2Cx_SCL_PIN GPIO_PIN_6 /* PB.06 */
#define DISCOVERY_I2Cx_SDA_PIN GPIO_PIN_9 /* PB.09 */
#define DISCOVERY_I2Cx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define DISCOVERY_I2Cx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
#define DISCOVERY_I2Cx_AF GPIO_AF4_I2C1
#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
/* I2C speed and timeout max */
#define I2Cx_TIMEOUT_MAX 0xA000 /*<! The value of the maximal timeout for I2C waiting loops */
#define I2Cx_MAX_COMMUNICATION_FREQ ((uint32_t) 100000)
/*################################# SPI1 #####################################*/
#define DISCOVERY_SPIx SPI1
#define DISCOVERY_SPIx_CLOCK_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 ((uint32_t)0x1000)
/*################################ GYROSCOPE #################################*/
/* 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 GYRO_CS_LOW() HAL_GPIO_WritePin(GYRO_CS_GPIO_PORT, GYRO_CS_PIN, GPIO_PIN_RESET)
#define GYRO_CS_HIGH() HAL_GPIO_WritePin(GYRO_CS_GPIO_PORT, GYRO_CS_PIN, GPIO_PIN_SET)
/**
* @brief GYRO SPI Interface pins
*/
#define GYRO_CS_GPIO_PORT GPIOE /* GPIOE */
#define GYRO_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define GYRO_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
#define GYRO_CS_PIN GPIO_PIN_3 /* PE.03 */
#define GYRO_INT_GPIO_PORT GPIOE /* GPIOE */
#define GYRO_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define GYRO_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
#define GYRO_INT1_PIN GPIO_PIN_0 /* PE.00 */
#define GYRO_INT1_EXTI_IRQn EXTI0_IRQn
#define GYRO_INT2_PIN GPIO_PIN_1 /* PE.01 */
#define GYRO_INT2_EXTI_IRQn EXTI1_IRQn
/*################################### AUDIO ##################################*/
/**
* @brief AUDIO I2C Interface pins
*/
/* Device I2C address */
#define AUDIO_I2C_ADDRESS 0x94
/* Audio codec power on/off macro definition */
#define CODEC_AUDIO_POWER_OFF() HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_RESET)
#define CODEC_AUDIO_POWER_ON() HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_SET)
/* 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
/**
* @}
*/
/*############################### ACCELEROMETER ##############################*/
/**
* @brief ACCELERO I2C1 Interface pins
*/
#define ACCELERO_DRDY_GPIO_PORT GPIOE /* GPIOE */
#define ACCELERO_DRDY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define ACCELERO_DRDY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
#define ACCELERO_DRDY_PIN GPIO_PIN_2 /* PE.02 */
#define ACCELERO_DRDY_EXTI_IRQn TAMP_STAMP_IRQn
#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_4 /* PE.04 */
#define ACCELERO_INT1_EXTI_IRQn EXTI4_IRQn
#define ACCELERO_INT2_PIN GPIO_PIN_5 /* PE.05 */
#define ACCELERO_INT2_EXTI_IRQn EXTI9_5_IRQn
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Exported_Macros STM32F401 DISCOVERY LOW LEVEL Exported Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_LOW_LEVEL_Exported_Functions STM32F401 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 ButtonMode);
uint32_t BSP_PB_GetState(Button_TypeDef Button);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32F401_DISCOVERY_H */
@@ -0,0 +1,197 @@
/**
******************************************************************************
* @file stm32f401_discovery_accelerometer.c
* @author MCD Application Team
* @brief This file provides a set of functions needed to manage the
* MEMS accelerometer available on STM32F401-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 "stm32f401_discovery_accelerometer.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F401_DISCOVERY
* @{
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER STM32F401 DISCOVERY ACCELEROMETER
* @{
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Private_TypesDefinitions STM32F401 DISCOVERY ACCELEROMETER Private TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Private_Defines STM32F401 DISCOVERY ACCELEROMETER Private Defines
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Private_Macros STM32F401 DISCOVERY ACCELEROMETER Private Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Private_Variables STM32F401 DISCOVERY ACCELEROMETER Private Variables
* @{
*/
static ACCELERO_DrvTypeDef *AccelerometerDrv;
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Private_FunctionPrototypes STM32F401 DISCOVERY ACCELEROMETER Private FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Private_Functions STM32F401 DISCOVERY ACCELEROMETER Private Functions
* @{
*/
/**
* @brief Set 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;
ACCELERO_InitTypeDef LSM303DLHC_InitStructure;
ACCELERO_FilterConfigTypeDef LSM303DLHC_FilterStructure = {0,0,0,0};
if(Lsm303dlhcDrv.ReadID() == I_AM_LMS303DLHC)
{
/* Initialize the Accelerometer driver structure */
AccelerometerDrv = &Lsm303dlhcDrv;
/* MEMS configuration ----------------------------------------------------*/
/* Fill the Accelerometer structure */
LSM303DLHC_InitStructure.Power_Mode = LSM303DLHC_NORMAL_MODE;
LSM303DLHC_InitStructure.AccOutput_DataRate = LSM303DLHC_ODR_50_HZ;
LSM303DLHC_InitStructure.Axes_Enable = LSM303DLHC_AXES_ENABLE;
LSM303DLHC_InitStructure.AccFull_Scale = LSM303DLHC_FULLSCALE_2G;
LSM303DLHC_InitStructure.BlockData_Update = LSM303DLHC_BlockUpdate_Continous;
LSM303DLHC_InitStructure.Endianness = LSM303DLHC_BLE_LSB;
LSM303DLHC_InitStructure.High_Resolution = LSM303DLHC_HR_ENABLE;
/* Configure MEMS: data rate, power mode, full scale and axes */
ctrl |= (LSM303DLHC_InitStructure.Power_Mode | LSM303DLHC_InitStructure.AccOutput_DataRate | \
LSM303DLHC_InitStructure.Axes_Enable);
ctrl |= ((LSM303DLHC_InitStructure.BlockData_Update | LSM303DLHC_InitStructure.Endianness | \
LSM303DLHC_InitStructure.AccFull_Scale | LSM303DLHC_InitStructure.High_Resolution) << 8);
/* Configure the Accelerometer main parameters */
AccelerometerDrv->Init(ctrl);
/* Fill the Accelerometer LPF structure */
LSM303DLHC_FilterStructure.HighPassFilter_Mode_Selection =LSM303DLHC_HPM_NORMAL_MODE;
LSM303DLHC_FilterStructure.HighPassFilter_CutOff_Frequency = LSM303DLHC_HPFCF_16;
LSM303DLHC_FilterStructure.HighPassFilter_AOI1 = LSM303DLHC_HPF_AOI1_DISABLE;
LSM303DLHC_FilterStructure.HighPassFilter_AOI2 = LSM303DLHC_HPF_AOI2_DISABLE;
/* Configure MEMS: mode, cutoff frquency, Filter status, Click, AOI1 and AOI2 */
ctrl = (uint8_t) (LSM303DLHC_FilterStructure.HighPassFilter_Mode_Selection |\
LSM303DLHC_FilterStructure.HighPassFilter_CutOff_Frequency|\
LSM303DLHC_FilterStructure.HighPassFilter_AOI1|\
LSM303DLHC_FilterStructure.HighPassFilter_AOI2);
/* Configure the Accelerometer LPF main parameters */
AccelerometerDrv->FilterConfig(ctrl);
ret = ACCELERO_OK;
}
else
{
ret = ACCELERO_ERROR;
}
return ret;
}
/**
* @brief Reboot memory content of Accelerometer.
*/
void BSP_ACCELERO_Reset(void)
{
if(AccelerometerDrv->Reset != NULL)
{
AccelerometerDrv->Reset();
}
}
/**
* @brief Configure Accelerometer click IT.
*/
void BSP_ACCELERO_Click_ITConfig(void)
{
if(AccelerometerDrv->ConfigIT!= NULL)
{
AccelerometerDrv->ConfigIT();
}
}
/**
* @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(AccelerometerDrv->GetXYZ!= NULL)
{
AccelerometerDrv->GetXYZ(pDataXYZ);
/* Switch X and Y Axes in case of LSM303DLHC MEMS */
if(AccelerometerDrv == &Lsm303dlhcDrv)
{
SwitchXY = pDataXYZ[0];
pDataXYZ[0] = pDataXYZ[1];
/* Invert Y Axis to be conpliant with LIS3DSH */
pDataXYZ[1] = -SwitchXY;
}
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,97 @@
/**
******************************************************************************
* @file stm32f401_discovery_accelerometer.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the
* stm32f401_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 __STM32F401_DISCOVERY_ACCELEROMETER_H
#define __STM32F401_DISCOVERY_ACCELEROMETER_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f401_discovery.h"
/* Include Accelerometer component driver */
#include "../Components/lsm303dlhc/lsm303dlhc.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F401_DISCOVERY
* @{
*/
/** @addtogroup STM32F401_DISCOVERY_ACCELEROMETER
* @{
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Exported_Types STM32F401 DISCOVERY ACCELEROMETER Exported Types
* @{
*/
typedef enum
{
ACCELERO_OK = 0,
ACCELERO_ERROR = 1,
ACCELERO_TIMEOUT = 2
}ACCELERO_StatusTypeDef;
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Exported_Constants STM32F401 DISCOVERY ACCELEROMETER Exported Constants
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_ACCELEROMETER_Exported_Functions STM32F401 DISCOVERY ACCELEROMETER Exported Functions
* @{
*/
/* Accelerometer functions */
uint8_t BSP_ACCELERO_Init(void);
void BSP_ACCELERO_Reset(void);
void BSP_ACCELERO_Click_ITConfig(void);
void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32F401_DISCOVERY_ACCELEROMETER_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,254 @@
/**
******************************************************************************
* @file stm32f401_discovery_audio.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* stm32f401_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 __STM32F401_DISCOVERY_AUDIO_H
#define __STM32F401_DISCOVERY_AUDIO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Include audio component Driver */
#include "../Components/cs43l22/cs43l22.h"
#include "stm32f401_discovery.h"
#include "../../../Middlewares/ST/STM32_Audio/Addons/PDM/Inc/pdm2pcm_glo.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F401_DISCOVERY
* @{
*/
/** @addtogroup STM32F401_DISCOVERY_AUDIO
* @{
*/
/** @defgroup STM32F401_DISCOVERY_AUDIO_Exported_Types STM32F401 DISCOVERY AUDIO Exported Types
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_AUDIO_OUT_Exported_Constants STM32F401 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 STM32F401_DISCOVERY_AUDIO_Exported_Variables STM32F401 DISCOVERY AUDIO Exported Variables
* @{
*/
extern __IO uint16_t AudioInVolume;
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_AUDIO_Exported_Macros STM32F401 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 STM32F401_DISCOVERY_AUDIO_OUT_Exported_Functions STM32F401 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 STM32F401_DISCOVERY_AUDIO_IN_Exported_Functions STM32F401 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 /* __STM32F401_DISCOVERY_AUDIO_H */
@@ -0,0 +1,230 @@
/**
******************************************************************************
* @file stm32f401_discovery_gyroscope.c
* @author MCD Application Team
* @brief This file provides a set of functions needed to manage the
* MEMS gyroscope available on STM32F401-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 "stm32f401_discovery_gyroscope.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F401_DISCOVERY
* @{
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE STM32F401 DISCOVERY GYROSCOPE
* @{
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Private_TypesDefinitions STM32F401 DISCOVERY GYROSCOPE Private TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Private_Defines STM32F401 DISCOVERY GYROSCOPE Private Defines
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Private_Macros STM32F401 DISCOVERY GYROSCOPE Private Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Private_Variables STM32F401 DISCOVERY GYROSCOPE Private Variables
* @{
*/
static GYRO_DrvTypeDef *GyroscopeDrv;
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Private_FunctionPrototypes STM32F401 DISCOVERY GYROSCOPE Private FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Private_Functions STM32F401 DISCOVERY GYROSCOPE Private Functions
* @{
*/
/**
* @brief Set Gyroscope Initialization.
* @retval GYRO_OK if no problem during initialization
*/
uint8_t BSP_GYRO_Init(void)
{
uint8_t ret = GYRO_ERROR;
uint16_t ctrl = 0x0000;
GYRO_InitTypeDef L3GD20_InitStructure;
GYRO_FilterConfigTypeDef L3GD20_FilterStructure = {0,0};
if((L3gd20Drv.ReadID() == I_AM_L3GD20) || (L3gd20Drv.ReadID() == I_AM_L3GD20_TR))
{
/* Initialize the Gyroscope driver structure */
GyroscopeDrv = &L3gd20Drv;
/* MEMS configuration ----------------------------------------------------*/
/* Fill the Gyroscope structure */
L3GD20_InitStructure.Power_Mode = L3GD20_MODE_ACTIVE;
L3GD20_InitStructure.Output_DataRate = L3GD20_OUTPUT_DATARATE_1;
L3GD20_InitStructure.Axes_Enable = L3GD20_AXES_ENABLE;
L3GD20_InitStructure.Band_Width = L3GD20_BANDWIDTH_4;
L3GD20_InitStructure.BlockData_Update = L3GD20_BlockDataUpdate_Continous;
L3GD20_InitStructure.Endianness = L3GD20_BLE_LSB;
L3GD20_InitStructure.Full_Scale = L3GD20_FULLSCALE_500;
/* Configure MEMS: data rate, power mode, full scale and axes */
ctrl = (uint16_t) (L3GD20_InitStructure.Power_Mode | L3GD20_InitStructure.Output_DataRate | \
L3GD20_InitStructure.Axes_Enable | L3GD20_InitStructure.Band_Width);
ctrl |= (uint16_t) ((L3GD20_InitStructure.BlockData_Update | L3GD20_InitStructure.Endianness | \
L3GD20_InitStructure.Full_Scale) << 8);
/* Configure the Gyroscope main parameters */
GyroscopeDrv->Init(ctrl);
L3GD20_FilterStructure.HighPassFilter_Mode_Selection =L3GD20_HPM_NORMAL_MODE_RES;
L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency = L3GD20_HPFCF_0;
ctrl = (uint8_t) ((L3GD20_FilterStructure.HighPassFilter_Mode_Selection |\
L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency));
/* Configure the Gyroscope main parameters */
GyroscopeDrv->FilterConfig(ctrl) ;
GyroscopeDrv->FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE);
ret = GYRO_OK;
}
return ret;
}
/**
* @brief Read ID of Gyroscope component.
* @retval ID
*/
uint8_t BSP_GYRO_ReadID(void)
{
uint8_t id = 0x00;
if(GyroscopeDrv->ReadID != NULL)
{
id = GyroscopeDrv->ReadID();
}
return id;
}
/**
* @brief Reboot memory content of Gyroscope.
*/
void BSP_GYRO_Reset(void)
{
if(GyroscopeDrv->Reset != NULL)
{
GyroscopeDrv->Reset();
}
}
/**
* @brief Configures INT1 interrupt.
* @param pIntConfig: pointer to a L3GD20_InterruptConfig_TypeDef
* structure that contains the configuration setting for the L3GD20 Interrupt.
*/
void BSP_GYRO_ITConfig(GYRO_InterruptConfigTypeDef *pIntConfig)
{
uint16_t interruptconfig = 0x0000;
if(GyroscopeDrv->ConfigIT != NULL)
{
/* Configure latch Interrupt request and axe interrupts */
interruptconfig |= ((uint8_t)(pIntConfig->Latch_Request| \
pIntConfig->Interrupt_Axes) << 8);
interruptconfig |= (uint8_t)(pIntConfig->Interrupt_ActiveEdge);
GyroscopeDrv->ConfigIT(interruptconfig);
}
}
/**
* @brief Enables INT1 or INT2 interrupt.
* @param IntPin: Interrupt pin
* This parameter can be:
* @arg L3GD20_INT1
* @arg L3GD20_INT2
*/
void BSP_GYRO_EnableIT(uint8_t IntPin)
{
if(GyroscopeDrv->EnableIT != NULL)
{
GyroscopeDrv->EnableIT(IntPin);
}
}
/**
* @brief Disables INT1 or INT2 interrupt.
* @param IntPin: Interrupt pin
* This parameter can be:
* @arg L3GD20_INT1
* @arg L3GD20_INT2
*/
void BSP_GYRO_DisableIT(uint8_t IntPin)
{
if(GyroscopeDrv->DisableIT != NULL)
{
GyroscopeDrv->DisableIT(IntPin);
}
}
/**
* @brief Get XYZ angular acceleration.
* @param pfData: pointer on floating array
*/
void BSP_GYRO_GetXYZ(float *pfData)
{
if(GyroscopeDrv->GetXYZ!= NULL)
{
GyroscopeDrv->GetXYZ(pfData);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,106 @@
/**
******************************************************************************
* @file stm32f401_discovery_gyroscope.h
* @author MCD Application Team
* @brief This file contains definitions for stm32f401_discovery_gyroscope.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 __STM32F401_DISCOVERY_GYROSCOPE_H
#define __STM32F401_DISCOVERY_GYROSCOPE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f401_discovery.h"
/* Include Gyroscope component driver */
#include "../Components/l3gd20/l3gd20.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32F401_DISCOVERY
* @{
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE STM32F401 DISCOVERY GYROSCOPE
* @{
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Exported_Types STM32F401 DISCOVERY GYROSCOPE Exported Types
* @{
*/
typedef enum
{
GYRO_OK = 0,
GYRO_ERROR = 1,
GYRO_TIMEOUT = 2
}GYRO_StatusTypeDef;
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Exported_Constants STM32F401 DISCOVERY GYROSCOPE Exported Constants
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Exported_Macros STM32F401 DISCOVERY GYROSCOPE Exported Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32F401_DISCOVERY_GYROSCOPE_Exported_Functions STM32F401 DISCOVERY GYROSCOPE Exported Functions
* @{
*/
/* Gyroscope Functions */
uint8_t BSP_GYRO_Init(void);
void BSP_GYRO_Reset(void);
uint8_t BSP_GYRO_ReadID(void);
void BSP_GYRO_ITConfig(GYRO_InterruptConfigTypeDef *pIntConfigStruct);
void BSP_GYRO_EnableIT(uint8_t IntPin);
void BSP_GYRO_DisableIT(uint8_t IntPin);
void BSP_GYRO_GetXYZ(float *pfData);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32F401_DISCOVERY_GYROSCOPE_H */