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/stm32412g-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 [stm32412g-discovery](https://github.com/STMicroelectronics/stm32412g-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,41 @@
|
||||
# BSP STM32412G-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 **stm32412g-discovery** MCU component repository is one element of the **STM32CubeF4** MCU embedded software package, providing the **STM32412G-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/stm32412g-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-ft6x06](https://github.com/STMicroelectronics/stm32-ft6x06)
|
||||
* [stm32-ls016b8uy](https://github.com/STMicroelectronics/stm32-ls016b8uy)
|
||||
* [stm32-n25q128a](https://github.com/STMicroelectronics/stm32-n25q128a)
|
||||
* [stm32-st7789h2](https://github.com/STMicroelectronics/stm32-st7789h2)
|
||||
* [stm32-wm8994](https://github.com/STMicroelectronics/stm32-wm8994)
|
||||
|
||||
## 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.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,395 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains definitions for STM32412G_DISCOVERY's LEDs,
|
||||
* push-buttons and COM ports 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* IMPORTANT: One of the following flags must be defined in the preprocessor */
|
||||
/* options in order to select the target board revision: !!!!!!!!!! */
|
||||
/* USE_STM32412G_DISCOVERY */ /* Applicable for all boards execept STM32412G DISCOVERY REVD */
|
||||
/* USE_STM32412G_DISCOVERY_REVD */ /* Applicable only for STM32412G DISCOVERY REVD */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32412G_DISCOVERY_H
|
||||
#define __STM32412G_DISCOVERY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_LOW_LEVEL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Exported_Types STM32412G DISCOVERY Low Level Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LED1 = 0,
|
||||
LED_GREEN = LED1,
|
||||
LED2 = 1,
|
||||
LED_ORANGE = LED2,
|
||||
LED3 = 2,
|
||||
LED_RED = LED3,
|
||||
LED4 = 3,
|
||||
LED_BLUE = LED4
|
||||
}Led_TypeDef;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_WAKEUP = 0
|
||||
}Button_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_MODE_GPIO = 0,
|
||||
BUTTON_MODE_EXTI = 1
|
||||
}ButtonMode_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JOY_MODE_GPIO = 0,
|
||||
JOY_MODE_EXTI = 1
|
||||
}JOYMode_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JOY_SEL = 0,
|
||||
JOY_DOWN = 1,
|
||||
JOY_LEFT = 2,
|
||||
JOY_RIGHT = 3,
|
||||
JOY_UP = 4,
|
||||
JOY_NONE = 5
|
||||
}JOYState_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COM1 = 0
|
||||
}COM_TypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Exported_Constants STM32412G DISCOVERY Low Level Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define for STM32412G_DISCOVERY board
|
||||
*/
|
||||
#if !defined(USE_STM32412G_DISCOVERY_REVD) && \
|
||||
!defined(USE_STM32412G_DISCOVERY)
|
||||
#define USE_STM32412G_DISCOVERY
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_LOW_LEVEL_LED STM32412G DISCOVERY Low Level Led
|
||||
* @{
|
||||
*/
|
||||
#define LEDn ((uint8_t)4)
|
||||
|
||||
#define LEDx_GPIO_PORT GPIOE
|
||||
#define LEDx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
|
||||
#define LEDx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE()
|
||||
#define LED1_PIN GPIO_PIN_0
|
||||
#define LED2_PIN GPIO_PIN_1
|
||||
#define LED3_PIN GPIO_PIN_2
|
||||
#define LED4_PIN GPIO_PIN_3
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_LOW_LEVEL_BUTTON STM32412G DISCOVERY Low Level Button
|
||||
* @{
|
||||
*/
|
||||
/* Push buttons (wakeup) mapped on joystick middle select button */
|
||||
#define BUTTONn ((uint8_t)1)
|
||||
|
||||
/**
|
||||
* @brief Wakeup push-button
|
||||
*/
|
||||
#define WAKEUP_BUTTON_PIN GPIO_PIN_0
|
||||
#define WAKEUP_BUTTON_GPIO_PORT GPIOA
|
||||
#define WAKEUP_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define WAKEUP_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define WAKEUP_BUTTON_EXTI_IRQn EXTI0_IRQn
|
||||
|
||||
#define JOYn ((uint8_t)5)
|
||||
|
||||
/**
|
||||
* @brief Joystick Left push-button
|
||||
*/
|
||||
#define LEFT_JOY_PIN GPIO_PIN_15 /* PF.15 */
|
||||
#define LEFT_JOY_GPIO_PORT GPIOF
|
||||
#define LEFT_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define LEFT_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE()
|
||||
#define LEFT_JOY_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @brief Joystick Down push-button
|
||||
*/
|
||||
#define DOWN_JOY_PIN GPIO_PIN_1 /* PG.01 */
|
||||
#define DOWN_JOY_GPIO_PORT GPIOG
|
||||
#define DOWN_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
|
||||
#define DOWN_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
|
||||
#define DOWN_JOY_EXTI_IRQn EXTI1_IRQn
|
||||
|
||||
/**
|
||||
* @brief Joystick Up push-button
|
||||
*/
|
||||
#define UP_JOY_PIN GPIO_PIN_0 /* PG.00 */
|
||||
#define UP_JOY_GPIO_PORT GPIOG
|
||||
#define UP_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
|
||||
#define UP_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
|
||||
#define UP_JOY_EXTI_IRQn EXTI0_IRQn
|
||||
|
||||
/**
|
||||
* @brief Joystick Right push-button
|
||||
*/
|
||||
#define RIGHT_JOY_PIN GPIO_PIN_14 /* PF.14 */
|
||||
#define RIGHT_JOY_GPIO_PORT GPIOF
|
||||
#define RIGHT_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define RIGHT_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE()
|
||||
#define RIGHT_JOY_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @brief Joystick Selection push-button
|
||||
*/
|
||||
#define SEL_JOY_PIN GPIO_PIN_0 /* PA.00 */
|
||||
#define SEL_JOY_GPIO_PORT GPIOA
|
||||
#define SEL_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define SEL_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define SEL_JOY_EXTI_IRQn EXTI0_IRQn
|
||||
|
||||
#define JOYx_GPIO_CLK_ENABLE(__JOY__) do { if((__JOY__) == JOY_SEL) { SEL_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_DOWN) { DOWN_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_LEFT) { LEFT_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_RIGHT) { RIGHT_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_UP) { UP_JOY_GPIO_CLK_ENABLE(); } } while(0)
|
||||
|
||||
#define JOYx_GPIO_CLK_DISABLE(__JOY__) do { if((__JOY__) == JOY_SEL) { SEL_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_DOWN) { DOWN_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_LEFT) { LEFT_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_RIGHT) { RIGHT_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_UP) { UP_JOY_GPIO_CLK_DISABLE(); } } while(0)
|
||||
|
||||
#define JOY_ALL_PINS (RIGHT_JOY_PIN | LEFT_JOY_PIN | UP_JOY_PIN | DOWN_JOY_PIN | SEL_JOY_PIN)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_LOW_LEVEL_SIGNAL
|
||||
* @{
|
||||
*/
|
||||
#define SIGNALn ((uint8_t)2)
|
||||
|
||||
/**
|
||||
* @brief SD-detect signal
|
||||
*/
|
||||
#define SD_DETECT_PIN GPIO_PIN_3
|
||||
#define SD_DETECT_GPIO_PORT GPIOD
|
||||
#define SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define SD_DETECT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
|
||||
#define SD_DETECT_EXTI_IRQn EXTI3_IRQn
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tamper input TAMP1
|
||||
*/
|
||||
#define TAMPER_TAMP1_PIN GPIO_PIN_13
|
||||
#define TAMPER_TAMP1_GPIO_PORT GPIOC
|
||||
#define TAMPER_TAMP1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define TAMPER_TAMP1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
|
||||
#define TAMPER_TAMP1_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @brief TS INT pin
|
||||
*/
|
||||
#define TS_INT_PIN GPIO_PIN_5
|
||||
#define TS_INT_GPIO_PORT GPIOG
|
||||
#define TS_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
|
||||
#define TS_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
|
||||
#define TS_INT_EXTI_IRQn EXTI9_5_IRQn
|
||||
|
||||
/**
|
||||
* @brief TS RST pin
|
||||
*/
|
||||
#define TS_RST_PIN GPIO_PIN_12
|
||||
#define TS_RST_GPIO_PORT GPIOF
|
||||
#define TS_RST_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define TS_RST_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE()
|
||||
#define TS_RST_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_LOW_LEVEL_COM STM32412G DISCOVERY Low Level COM
|
||||
* @{
|
||||
*/
|
||||
#define COMn ((uint8_t)1)
|
||||
|
||||
/**
|
||||
* @brief Definition for COM port1, connected to USART2
|
||||
*/
|
||||
#define DISCOVERY_COM1 USART2
|
||||
#define DISCOVERY_COM1_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE()
|
||||
#define DISCOVERY_COM1_CLK_DISABLE() __HAL_RCC_USART2_CLK_DISABLE()
|
||||
|
||||
#define DISCOVERY_COM1_TX_PIN GPIO_PIN_2
|
||||
#define DISCOVERY_COM1_TX_GPIO_PORT GPIOA
|
||||
#define DISCOVERY_COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define DISCOVERY_COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define DISCOVERY_COM1_TX_AF GPIO_AF7_USART2
|
||||
|
||||
#define DISCOVERY_COM1_RX_PIN GPIO_PIN_3
|
||||
#define DISCOVERY_COM1_RX_GPIO_PORT GPIOA
|
||||
#define DISCOVERY_COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define DISCOVERY_COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define DISCOVERY_COM1_RX_AF GPIO_AF7_USART2
|
||||
|
||||
#define DISCOVERY_COM1_IRQn USART2_IRQn
|
||||
|
||||
#define DISCOVERY_COMx_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_CLK_ENABLE();} } while(0)
|
||||
#define DISCOVERY_COMx_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? DISCOVERY_COM1_CLK_DISABLE() : 0)
|
||||
|
||||
#define DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_TX_GPIO_CLK_ENABLE();} } while(0)
|
||||
#define DISCOVERY_COMx_TX_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? DISCOVERY_COM1_TX_GPIO_CLK_DISABLE() : 0)
|
||||
|
||||
#define DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_RX_GPIO_CLK_ENABLE();} } while(0)
|
||||
#define DISCOVERY_COMx_RX_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? DISCOVERY_COM1_RX_GPIO_CLK_DISABLE() : 0)
|
||||
|
||||
/**
|
||||
* @brief Joystick Pins definition
|
||||
*/
|
||||
|
||||
|
||||
/* Exported constant IO ------------------------------------------------------*/
|
||||
|
||||
#define AUDIO_I2C_ADDRESS ((uint16_t)0x34)
|
||||
#define EEPROM_I2C_ADDRESS_A01 ((uint16_t)0xA0)
|
||||
#define EEPROM_I2C_ADDRESS_A02 ((uint16_t)0xA6)
|
||||
#define TS_I2C_ADDRESS ((uint16_t)0x70)
|
||||
|
||||
/* User can use this section to tailor I2Cx/I2Cx instance used and associated
|
||||
resources */
|
||||
/* Definition for AUDIO I2Cx resources */
|
||||
#define DISCOVERY_AUDIO_I2Cx I2C1
|
||||
#define DISCOVERY_AUDIO_I2Cx_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()
|
||||
#define DISCOVERY_AUDIO_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
|
||||
#define DISCOVERY_AUDIO_I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET()
|
||||
#define DISCOVERY_AUDIO_I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET()
|
||||
|
||||
/* Definition for I2Cx Pins */
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_PIN GPIO_PIN_6
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT GPIOB
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF GPIO_AF4_I2C1
|
||||
#define DISCOVERY_AUDIO_I2Cx_SDA_PIN GPIO_PIN_7
|
||||
|
||||
/* I2C interrupt requests */
|
||||
#define DISCOVERY_AUDIO_I2Cx_EV_IRQn I2C1_EV_IRQn
|
||||
#define DISCOVERY_AUDIO_I2Cx_ER_IRQn I2C1_ER_IRQn
|
||||
|
||||
/* Definition for external, camera and Arduino connector I2Cx resources */
|
||||
#define DISCOVERY_EXT_I2Cx I2C2
|
||||
#define DISCOVERY_EXT_I2Cx_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE()
|
||||
#define DISCOVERY_EXT_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
|
||||
#define DISCOVERY_EXT_I2Cx_FORCE_RESET() __HAL_RCC_I2C2_FORCE_RESET()
|
||||
#define DISCOVERY_EXT_I2Cx_RELEASE_RESET() __HAL_RCC_I2C2_RELEASE_RESET()
|
||||
|
||||
/* Definition for I2Cx Pins */
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_PIN GPIO_PIN_10
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT GPIOB
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_AF GPIO_AF4_I2C2
|
||||
#define DISCOVERY_EXT_I2Cx_SDA_AF GPIO_AF9_I2C2
|
||||
#define DISCOVERY_EXT_I2Cx_SDA_PIN GPIO_PIN_9
|
||||
|
||||
/* I2C interrupt requests */
|
||||
#define DISCOVERY_EXT_I2Cx_EV_IRQn I2C2_EV_IRQn
|
||||
#define DISCOVERY_EXT_I2Cx_ER_IRQn I2C2_ER_IRQn
|
||||
|
||||
/* I2C clock speed configuration (in Hz)
|
||||
WARNING:
|
||||
Make sure that this define is not already declared in other files.
|
||||
It can be used in parallel by other modules. */
|
||||
#ifndef DISCOVERY_I2C_SPEED
|
||||
#define DISCOVERY_I2C_SPEED 100000
|
||||
#endif /* DISCOVERY_I2C_SPEED */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_LOW_LEVEL_Exported_Functions STM32412G DISCOVERY Low Level Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint32_t BSP_GetVersion(void);
|
||||
void BSP_LED_Init(Led_TypeDef Led);
|
||||
void BSP_LED_DeInit(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);
|
||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||
uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode);
|
||||
void BSP_JOY_DeInit(void);
|
||||
JOYState_TypeDef BSP_JOY_GetState(void);
|
||||
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *husart);
|
||||
void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,355 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_audio.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32412g_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 __STM32412G_DISCOVERY_AUDIO_H
|
||||
#define __STM32412G_DISCOVERY_AUDIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Include audio component Driver */
|
||||
#include "../Components/wm8994/wm8994.h"
|
||||
#include "stm32412g_discovery.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_AUDIO
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_AUDIO_Exported_Types STM32412G DISCOVERY Audio Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Frequency; /* Record Frequency */
|
||||
uint32_t BitResolution; /* Record bit resolution */
|
||||
uint32_t ChannelNbr; /* Record Channel Number */
|
||||
uint16_t *pRecBuf; /* Pointer to record user buffer */
|
||||
uint32_t RecSize; /* Size to record in mono, double size to record in stereo */
|
||||
uint32_t InputDevice; /* Audio Input Device */
|
||||
uint32_t MultiBuffMode; /* Multi buffer mode selection */
|
||||
}AUDIOIN_ContextTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_AUDIO_Exported_Constants STM32412G DISCOVERY Audio Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
AUDIO OUT CONFIGURATION
|
||||
------------------------------------------------------------------------------*/
|
||||
/* SPI Configuration defines */
|
||||
#define AUDIO_OUT_I2Sx SPI3
|
||||
#define AUDIO_OUT_I2Sx_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE()
|
||||
#define AUDIO_OUT_I2Sx_CLK_DISABLE() __HAL_RCC_SPI3_CLK_DISABLE()
|
||||
|
||||
#define AUDIO_OUT_I2Sx_MCK_PIN GPIO_PIN_7
|
||||
#define AUDIO_OUT_I2Sx_MCK_GPIO_PORT GPIOC
|
||||
#define AUDIO_OUT_I2Sx_MCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define AUDIO_OUT_I2Sx_MCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
|
||||
#define AUDIO_OUT_I2Sx_MCK_AF GPIO_AF6_SPI3
|
||||
|
||||
#define AUDIO_OUT_I2Sx_SCK_PIN GPIO_PIN_12
|
||||
#define AUDIO_OUT_I2Sx_SCK_GPIO_PORT GPIOB
|
||||
#define AUDIO_OUT_I2Sx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define AUDIO_OUT_I2Sx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define AUDIO_OUT_I2Sx_SCK_AF GPIO_AF7_SPI3
|
||||
|
||||
#define AUDIO_OUT_I2Sx_WS_PIN GPIO_PIN_4
|
||||
#define AUDIO_OUT_I2Sx_WS_GPIO_PORT GPIOA
|
||||
#define AUDIO_OUT_I2Sx_WS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define AUDIO_OUT_I2Sx_WS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define AUDIO_OUT_I2Sx_WS_AF GPIO_AF6_SPI3
|
||||
|
||||
#define AUDIO_OUT_I2Sx_SD_PIN GPIO_PIN_5
|
||||
#define AUDIO_OUT_I2Sx_SD_GPIO_PORT GPIOB
|
||||
#define AUDIO_OUT_I2Sx_SD_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define AUDIO_OUT_I2Sx_SD_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define AUDIO_OUT_I2Sx_SD_AF GPIO_AF6_SPI3
|
||||
|
||||
/* I2S DMA Stream Tx definitions */
|
||||
#define AUDIO_OUT_I2Sx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define AUDIO_OUT_I2Sx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE()
|
||||
#define AUDIO_OUT_I2Sx_DMAx_STREAM DMA1_Stream5
|
||||
#define AUDIO_OUT_I2Sx_DMAx_CHANNEL DMA_CHANNEL_0
|
||||
#define AUDIO_OUT_I2Sx_DMAx_IRQ DMA1_Stream5_IRQn
|
||||
#define AUDIO_OUT_I2Sx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
|
||||
#define AUDIO_OUT_I2Sx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
|
||||
#define DMA_MAX_SIZE 0xFFFF
|
||||
|
||||
#define AUDIO_OUT_I2Sx_DMAx_IRQHandler DMA1_Stream5_IRQHandler
|
||||
|
||||
/* Select the interrupt preemption priority for the DMA interrupt */
|
||||
#define AUDIO_OUT_IRQ_PREPRIO ((uint32_t)0x0E) /* Select the preemption priority level(0 is the highest) */
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
AUDIO IN CONFIGURATION
|
||||
------------------------------------------------------------------------------*/
|
||||
/* DFSDM Configuration defines */
|
||||
#define AUDIO_DFSDMx_MIC1_CHANNEL DFSDM1_Channel0 /* MP34DT01TR microphone on PCB top side */
|
||||
#define AUDIO_DFSDMx_MIC2_CHANNEL DFSDM1_Channel3 /* MP34DT01TR microphone on PCB top side */
|
||||
#define AUDIO_DFSDMx_MIC1_CHANNEL_FOR_FILTER DFSDM_CHANNEL_0
|
||||
#define AUDIO_DFSDMx_MIC2_CHANNEL_FOR_FILTER DFSDM_CHANNEL_3
|
||||
#define AUDIO_DFSDMx_MIC1_FILTER DFSDM1_Filter0 /* Common filter for MP34DT01TR microphone input */
|
||||
#define AUDIO_DFSDMx_MIC2_FILTER DFSDM1_Filter1 /* Common filter for MP34DT01TR microphone input */
|
||||
#define AUDIO_DFSDMx_CLK_ENABLE() __HAL_RCC_DFSDM1_CLK_ENABLE()
|
||||
#define AUDIO_DFSDMx_CKOUT_PIN GPIO_PIN_2
|
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_GPIO_PORT GPIOC
|
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_AF GPIO_AF8_DFSDM1
|
||||
#define AUDIO_DFSDMx_DMIC_PIN GPIO_PIN_1
|
||||
#define AUDIO_DFSDMx_DMIC_GPIO_PORT GPIOB
|
||||
#define AUDIO_DFSDMx_DMIC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define AUDIO_DFSDMx_DMIC_AF GPIO_AF8_DFSDM1
|
||||
|
||||
/* DFSDM DMA MIC1 and MIC2 channels definitions */
|
||||
#define AUDIO_DFSDMx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
|
||||
#define AUDIO_DFSDMx_DMAx_MIC1_STREAM DMA2_Stream6
|
||||
#define AUDIO_DFSDMx_DMAx_MIC1_CHANNEL DMA_CHANNEL_3
|
||||
#define AUDIO_DFSDMx_DMAx_MIC2_STREAM DMA2_Stream4
|
||||
#define AUDIO_DFSDMx_DMAx_MIC2_CHANNEL DMA_CHANNEL_3
|
||||
#define AUDIO_DFSDMx_DMAx_MIC1_IRQ DMA2_Stream6_IRQn
|
||||
#define AUDIO_DFSDMx_DMAx_MIC2_IRQ DMA2_Stream4_IRQn
|
||||
#define AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_WORD
|
||||
#define AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_WORD
|
||||
|
||||
#define AUDIO_DFSDM_DMAx_MIC1_IRQHandler DMA2_Stream6_IRQHandler
|
||||
#define AUDIO_DFSDM_DMAx_MIC2_IRQHandler DMA2_Stream4_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) */
|
||||
|
||||
/* HW defines for Analog mic configuration */
|
||||
#define AUDIO_IN_I2Sx SPI3
|
||||
#define AUDIO_IN_I2Sx_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE()
|
||||
#define AUDIO_IN_I2Sx_CLK_DISABLE() __HAL_RCC_SPI3_CLK_DISABLE()
|
||||
|
||||
#define AUDIO_IN_I2Sx_EXT_SD_PIN GPIO_PIN_4
|
||||
#define AUDIO_IN_I2Sx_EXT_SD_GPIO_PORT GPIOB
|
||||
#define AUDIO_IN_I2Sx_EXT_SD_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define AUDIO_IN_I2Sx_EXT_SD_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define AUDIO_IN_I2Sx_EXT_SD_AF GPIO_AF7_SPI3
|
||||
|
||||
#define AUDIO_IN_CODEC_INT_PIN GPIO_PIN_2
|
||||
#define AUDIO_IN_CODEC_INT_GPIO_PORT GPIOG
|
||||
#define AUDIO_IN_CODEC_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
|
||||
#define AUDIO_IN_CODEC_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
|
||||
#define AUDIO_IN_CODEC_INT_IRQ EXTI2_IRQn
|
||||
|
||||
/* I2S DMA Stream Rx definitions */
|
||||
#define AUDIO_IN_I2Sx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define AUDIO_IN_I2Sx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE()
|
||||
#define AUDIO_IN_I2Sx_DMAx_STREAM DMA1_Stream0
|
||||
#define AUDIO_IN_I2Sx_DMAx_CHANNEL DMA_CHANNEL_3
|
||||
#define AUDIO_IN_I2Sx_DMAx_IRQ DMA1_Stream0_IRQn
|
||||
#define AUDIO_IN_I2Sx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
|
||||
#define AUDIO_IN_I2Sx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
|
||||
|
||||
#define AUDIO_IN_I2Sx_DMAx_IRQHandler DMA1_Stream0_IRQHandler
|
||||
#define AUDIO_IN_I2Sx_DMAx_IRQ DMA1_Stream0_IRQn
|
||||
|
||||
/* Two channels are used:
|
||||
- one channel as input which is connected to I2S SCK in stereo mode
|
||||
- one channel as output which divides the frequency on the input
|
||||
*/
|
||||
|
||||
#define AUDIO_TIMx_CLK_ENABLE() __HAL_RCC_TIM4_CLK_ENABLE()
|
||||
#define AUDIO_TIMx_CLK_DISABLE() __HAL_RCC_TIM4_CLK_DISABLE()
|
||||
#define AUDIO_TIMx TIM4
|
||||
#define AUDIO_TIMx_IN_CHANNEL TIM_CHANNEL_1
|
||||
#define AUDIO_TIMx_OUT_CHANNEL TIM_CHANNEL_2 /* Select channel 2 as output */
|
||||
#define AUDIO_TIMx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define AUDIO_TIMx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define AUDIO_TIMx_GPIO_PORT GPIOB
|
||||
#define AUDIO_TIMx_IN_GPIO_PIN GPIO_PIN_6
|
||||
#define AUDIO_TIMx_OUT_GPIO_PIN GPIO_PIN_7
|
||||
#define AUDIO_TIMx_AF GPIO_AF2_TIM4
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
CONFIGURATION: Audio Driver Configuration parameters
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
#define AUDIODATA_SIZE 2 /* 16-bits audio data size */
|
||||
|
||||
/* Audio status definition */
|
||||
#define AUDIO_OK ((uint8_t)0)
|
||||
#define AUDIO_ERROR ((uint8_t)1)
|
||||
#define AUDIO_TIMEOUT ((uint8_t)2)
|
||||
|
||||
/* Audio out parameters */
|
||||
#define DEFAULT_AUDIO_OUT_FREQ I2S_AUDIOFREQ_48K
|
||||
#define DEFAULT_AUDIO_OUT_BIT_RESOLUTION ((uint8_t)16)
|
||||
#define DEFAULT_AUDIO_OUT_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */
|
||||
#define DEFAULT_AUDIO_OUT_VOLUME ((uint16_t)64)
|
||||
|
||||
/* Audio in parameters */
|
||||
#define DEFAULT_AUDIO_IN_FREQ I2S_AUDIOFREQ_16K
|
||||
#define DEFAULT_AUDIO_IN_BIT_RESOLUTION ((uint8_t)16)
|
||||
#define DEFAULT_AUDIO_IN_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */
|
||||
#define DEFAULT_AUDIO_IN_VOLUME ((uint16_t)64)
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
OUTPUT DEVICES definition
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* Alias on existing output devices to adapt for 2 headphones output */
|
||||
#define OUTPUT_DEVICE_HEADPHONE1 OUTPUT_DEVICE_HEADPHONE
|
||||
#define OUTPUT_DEVICE_HEADPHONE2 OUTPUT_DEVICE_SPEAKER /* Headphone2 is connected to Speaker output of the wm8994 */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
INPUT DEVICES definition
|
||||
------------------------------------------------------------------------------*/
|
||||
/* Analog microphone input from 3.5 audio jack connector */
|
||||
#define INPUT_DEVICE_ANALOG_MIC ((uint32_t)0x00000001)
|
||||
/* MP34DT01TR digital microphone on PCB top side */
|
||||
#define INPUT_DEVICE_DIGITAL_MIC1 ((uint32_t)0x00000010)
|
||||
#define INPUT_DEVICE_DIGITAL_MIC2 ((uint32_t)0x00000020)
|
||||
#define INPUT_DEVICE_DIGITAL_MIC ((uint32_t)(INPUT_DEVICE_DIGITAL_MIC1 | INPUT_DEVICE_DIGITAL_MIC2))
|
||||
#define DFSDM_MIC_NUMBER (2)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_AUDIO_Exported_Variables STM32412G DISCOVERY Audio Exported Variables
|
||||
* @{
|
||||
*/
|
||||
extern __IO uint16_t AudioInVolume;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_AUDIO_Exported_Macros STM32412G DISCOVERY Audio Exported Macros
|
||||
* @{
|
||||
*/
|
||||
#define DMA_MAX(x) (((x) <= DMA_MAX_SIZE)? (x):DMA_MAX_SIZE)
|
||||
#define POS_VAL(VAL) (POSITION_VAL(VAL) - 4)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_AUDIO_OUT_Exported_Functions STM32412G 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);
|
||||
void BSP_AUDIO_OUT_DeInit(void);
|
||||
|
||||
/* 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 STM32412G_DISCOVERY_AUDIO_IN_Exported_Functions STM32412G 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_InitEx(uint32_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr);
|
||||
uint8_t BSP_AUDIO_IN_ConfigMicDefault(uint32_t InputDevice);
|
||||
uint8_t BSP_AUDIO_IN_ConfigDigitalMic(uint32_t InputDevice, void *Params);
|
||||
uint8_t BSP_AUDIO_IN_AllocScratch (int32_t *pScratch, uint32_t size);
|
||||
uint8_t BSP_AUDIO_IN_Record(uint16_t *pBuf, uint32_t Size);
|
||||
uint8_t BSP_AUDIO_IN_RecordEx(uint32_t *pBuf, uint32_t Size);
|
||||
uint8_t BSP_AUDIO_IN_SetFrequency(uint32_t AudioFreq);
|
||||
uint8_t BSP_AUDIO_IN_Stop(void);
|
||||
uint8_t BSP_AUDIO_IN_StopEx(uint32_t InputDevice);
|
||||
uint8_t BSP_AUDIO_IN_Pause(void);
|
||||
uint8_t BSP_AUDIO_IN_PauseEx(uint32_t InputDevice);
|
||||
uint8_t BSP_AUDIO_IN_Resume(void);
|
||||
uint8_t BSP_AUDIO_IN_ResumeEx(uint32_t *pBuf, uint32_t InputDevice);
|
||||
uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume);
|
||||
void BSP_AUDIO_IN_DeInit(void);
|
||||
|
||||
/* 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);
|
||||
void BSP_AUDIO_IN_TransferComplete_CallBackEx(uint32_t InputDevice);
|
||||
void BSP_AUDIO_IN_HalfTransfer_CallBackEx(uint32_t InputDevice);
|
||||
|
||||
/* 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 */
|
||||
uint8_t BSP_AUDIO_IN_ClockConfig(uint32_t AudioFreq, void *Params);
|
||||
void BSP_AUDIO_IN_MspInit(void *Params);
|
||||
void BSP_AUDIO_IN_MspDeInit(void *Params);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_AUDIO_H */
|
||||
@@ -0,0 +1,422 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_eeprom.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides a set of functions needed to manage an I2C M24LR64
|
||||
* EEPROM memory.
|
||||
* To be able to use this driver, the switch EE_M24LR64 must be defined
|
||||
* in your toolchain compiler preprocessor
|
||||
*
|
||||
* ===================================================================
|
||||
* Notes:
|
||||
* - This driver is intended for STM32F4xx families devices only.
|
||||
* - The I2C EEPROM memory (M24LR64) is available on separate daughter
|
||||
* board ANT7-M24LR-A, which is not provided with the STM32412G_DISCOVERY
|
||||
* board.
|
||||
* To use this driver you have to connect the ANT7-M24LR-A to CN3
|
||||
* connector of STM32412G_DISCOVERY board.
|
||||
* ===================================================================
|
||||
*
|
||||
* It implements a high level communication layer for read and write
|
||||
* from/to this memory. The needed STM32F4xx hardware resources (I2C and
|
||||
* GPIO) are defined in stm32412g_discovery.h file, and the initialization is
|
||||
* performed in EEPROM_IO_Init() function declared in stm32412g_discovery.c
|
||||
* file.
|
||||
* You can easily tailor this driver to any other development board,
|
||||
* by just adapting the defines for hardware resources and
|
||||
* EEPROM_IO_Init() function.
|
||||
*
|
||||
* @note In this driver, basic read and write functions (BSP_EEPROM_ReadBuffer()
|
||||
* and BSP_EEPROM_WritePage()) use DMA mode to perform the data
|
||||
* transfer to/from EEPROM memory.
|
||||
*
|
||||
* @note Regarding BSP_EEPROM_WritePage(), it is a optimized function to perform
|
||||
* small write (less than 1 page) BUT The number of bytes (combined to write start address) must not
|
||||
* cross the EEPROM page boundary. This function can only write into
|
||||
* the boundaries of an EEPROM page.
|
||||
* This function doesn't check on boundaries condition (in this driver
|
||||
* the function BSP_EEPROM_WriteBuffer() which calls BSP_EEPROM_WritePage() is
|
||||
* responsible of checking on Page boundaries).
|
||||
*
|
||||
*
|
||||
* +-----------------------------------------------------------------+
|
||||
* | Pin assignment for M24LR64 EEPROM |
|
||||
* +---------------------------------------+-----------+-------------+
|
||||
* | STM32F4xx I2C Pins | EEPROM | Pin |
|
||||
* +---------------------------------------+-----------+-------------+
|
||||
* | . | E0(GND) | 1 (0V) |
|
||||
* | . | AC0 | 2 |
|
||||
* | . | AC1 | 3 |
|
||||
* | . | VSS | 4 (0V) |
|
||||
* | SDA | SDA | 5 |
|
||||
* | SCL | SCL | 6 |
|
||||
* | . | E1(GND) | 7 (0V) |
|
||||
* | . | VDD | 8 (3.3V) |
|
||||
* +---------------------------------------+-----------+-------------+
|
||||
*
|
||||
******************************************************************************
|
||||
* @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 "stm32412g_discovery_eeprom.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_EEPROM STM32412G-DISCOVERY EEPROM
|
||||
* @brief This file includes the I2C EEPROM driver of STM32412G-DISCOVERY board.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_EEPROM_Private_Variables STM32412G Discovery Eeprom Private Variables
|
||||
* @{
|
||||
*/
|
||||
__IO uint16_t EEPROMAddress = 0;
|
||||
__IO uint16_t EEPROMDataRead;
|
||||
__IO uint8_t EEPROMDataWrite;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_EEPROM_Private_Functions STM32412G Discovery Eeprom Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes peripherals used by the I2C EEPROM driver.
|
||||
* @note There are 2 different versions of M24LR64 (A01 & A02).
|
||||
* Then try to connect on 1st one (EEPROM_I2C_ADDRESS_A01)
|
||||
* and if problem, check the 2nd one (EEPROM_I2C_ADDRESS_A02)
|
||||
* @retval EEPROM_OK (0) if operation is correctly performed, else return value
|
||||
* different from EEPROM_OK (0)
|
||||
*/
|
||||
uint32_t BSP_EEPROM_Init(void)
|
||||
{
|
||||
/* I2C Initialization */
|
||||
EEPROM_IO_Init();
|
||||
|
||||
/* Select the EEPROM address for A01 and check if OK */
|
||||
EEPROMAddress = EEPROM_I2C_ADDRESS_A01;
|
||||
if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
|
||||
{
|
||||
/* Select the EEPROM address for A02 and check if OK */
|
||||
EEPROMAddress = EEPROM_I2C_ADDRESS_A02;
|
||||
if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
|
||||
{
|
||||
return EEPROM_FAIL;
|
||||
}
|
||||
}
|
||||
return EEPROM_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the EEPROM.
|
||||
* @retval EEPROM state
|
||||
*/
|
||||
uint8_t BSP_EEPROM_DeInit(void)
|
||||
{
|
||||
/* I2C won't be disabled because common to other functionalities */
|
||||
return EEPROM_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a block of data from the EEPROM.
|
||||
* @param pBuffer: pointer to the buffer that receives the data read from
|
||||
* the EEPROM.
|
||||
* @param ReadAddr: EEPROM's internal address to start reading from.
|
||||
* @param NumByteToRead: pointer to the variable holding number of bytes to
|
||||
* be read from the EEPROM.
|
||||
*
|
||||
* @note The variable pointed by NumByteToRead is reset to 0 when all the
|
||||
* data are read from the EEPROM. Application should monitor this
|
||||
* variable in order know when the transfer is complete.
|
||||
*
|
||||
* @retval EEPROM_OK (0) if operation is correctly performed, else return value
|
||||
* different from EEPROM_OK (0) or the timeout user callback.
|
||||
*/
|
||||
uint32_t BSP_EEPROM_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
|
||||
{
|
||||
uint32_t buffersize = *NumByteToRead;
|
||||
|
||||
/* Set the pointer to the Number of data to be read. This pointer will be used
|
||||
by the DMA Transfer Completer interrupt Handler in order to reset the
|
||||
variable to 0. User should check on this variable in order to know if the
|
||||
DMA transfer has been complete or not. */
|
||||
EEPROMDataRead = *NumByteToRead;
|
||||
|
||||
if(EEPROM_IO_ReadData(EEPROMAddress, ReadAddr, pBuffer, buffersize) != HAL_OK)
|
||||
{
|
||||
BSP_EEPROM_TIMEOUT_UserCallback();
|
||||
return EEPROM_FAIL;
|
||||
}
|
||||
|
||||
/* If all operations OK, return EEPROM_OK (0) */
|
||||
return EEPROM_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
|
||||
*
|
||||
* @note The number of bytes (combined to write start address) must not
|
||||
* cross the EEPROM page boundary. This function can only write into
|
||||
* the boundaries of an EEPROM page.
|
||||
* This function doesn't check on boundaries condition (in this driver
|
||||
* the function BSP_EEPROM_WriteBuffer() which calls BSP_EEPROM_WritePage() is
|
||||
* responsible of checking on Page boundaries).
|
||||
*
|
||||
* @param pBuffer: pointer to the buffer containing the data to be written to
|
||||
* the EEPROM.
|
||||
* @param WriteAddr: EEPROM's internal address to write to.
|
||||
* @param NumByteToWrite: pointer to the variable holding number of bytes to
|
||||
* be written into the EEPROM.
|
||||
*
|
||||
* @note The variable pointed by NumByteToWrite is reset to 0 when all the
|
||||
* data are written to the EEPROM. Application should monitor this
|
||||
* variable in order know when the transfer is complete.
|
||||
*
|
||||
* @note This function just configure the communication and enable the DMA
|
||||
* channel to transfer data. Meanwhile, the user application may perform
|
||||
* other tasks in parallel.
|
||||
*
|
||||
* @retval EEPROM_OK (0) if operation is correctly performed, else return value
|
||||
* different from EEPROM_OK (0) or the timeout user callback.
|
||||
*/
|
||||
uint32_t BSP_EEPROM_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
|
||||
{
|
||||
uint32_t buffersize = *NumByteToWrite;
|
||||
uint32_t status = EEPROM_OK;
|
||||
|
||||
/* Set the pointer to the Number of data to be written. This pointer will be used
|
||||
by the DMA Transfer Completer interrupt Handler in order to reset the
|
||||
variable to 0. User should check on this variable in order to know if the
|
||||
DMA transfer has been complete or not. */
|
||||
EEPROMDataWrite = *NumByteToWrite;
|
||||
|
||||
if(EEPROM_IO_WriteData(EEPROMAddress, WriteAddr, pBuffer, buffersize) != HAL_OK)
|
||||
{
|
||||
BSP_EEPROM_TIMEOUT_UserCallback();
|
||||
status = EEPROM_FAIL;
|
||||
}
|
||||
|
||||
if(BSP_EEPROM_WaitEepromStandbyState() != EEPROM_OK)
|
||||
{
|
||||
return EEPROM_FAIL;
|
||||
}
|
||||
|
||||
/* If all operations OK, return EEPROM_OK (0) */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes buffer of data to the I2C EEPROM.
|
||||
* @param pBuffer: pointer to the buffer containing the data to be written
|
||||
* to the EEPROM.
|
||||
* @param WriteAddr: EEPROM's internal address to write to.
|
||||
* @param NumByteToWrite: number of bytes to write to the EEPROM.
|
||||
* @retval EEPROM_OK (0) if operation is correctly performed, else return value
|
||||
* different from EEPROM_OK (0) or the timeout user callback.
|
||||
*/
|
||||
uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
|
||||
{
|
||||
uint16_t numofpage = 0, numofsingle = 0, count = 0;
|
||||
uint16_t addr = 0;
|
||||
uint8_t dataindex = 0;
|
||||
uint32_t status = EEPROM_OK;
|
||||
|
||||
addr = WriteAddr % EEPROM_PAGESIZE;
|
||||
count = EEPROM_PAGESIZE - addr;
|
||||
numofpage = NumByteToWrite / EEPROM_PAGESIZE;
|
||||
numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
|
||||
|
||||
/* If WriteAddr is EEPROM_PAGESIZE aligned */
|
||||
if(addr == 0)
|
||||
{
|
||||
/* If NumByteToWrite < EEPROM_PAGESIZE */
|
||||
if(numofpage == 0)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = numofsingle;
|
||||
/* Start writing data */
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
/* If NumByteToWrite > EEPROM_PAGESIZE */
|
||||
else
|
||||
{
|
||||
while(numofpage--)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = EEPROM_PAGESIZE;
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
WriteAddr += EEPROM_PAGESIZE;
|
||||
pBuffer += EEPROM_PAGESIZE;
|
||||
}
|
||||
|
||||
if(numofsingle!=0)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = numofsingle;
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If WriteAddr is not EEPROM_PAGESIZE aligned */
|
||||
else
|
||||
{
|
||||
/* If NumByteToWrite < EEPROM_PAGESIZE */
|
||||
if(numofpage== 0)
|
||||
{
|
||||
/* If the number of data to be written is more than the remaining space
|
||||
in the current page: */
|
||||
if(NumByteToWrite > count)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = count;
|
||||
/* Write the data contained in same page */
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Store the number of data to be written */
|
||||
dataindex = (NumByteToWrite - count);
|
||||
/* Write the remaining data in the following page */
|
||||
status = BSP_EEPROM_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = numofsingle;
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If NumByteToWrite > EEPROM_PAGESIZE */
|
||||
else
|
||||
{
|
||||
NumByteToWrite -= count;
|
||||
numofpage = NumByteToWrite / EEPROM_PAGESIZE;
|
||||
numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
|
||||
|
||||
if(count != 0)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = count;
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
WriteAddr += count;
|
||||
pBuffer += count;
|
||||
}
|
||||
|
||||
while(numofpage--)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = EEPROM_PAGESIZE;
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
WriteAddr += EEPROM_PAGESIZE;
|
||||
pBuffer += EEPROM_PAGESIZE;
|
||||
}
|
||||
if(numofsingle != 0)
|
||||
{
|
||||
/* Store the number of data to be written */
|
||||
dataindex = numofsingle;
|
||||
status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
|
||||
if(status != EEPROM_OK)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If all operations OK, return EEPROM_OK (0) */
|
||||
return EEPROM_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for EEPROM Standby state.
|
||||
*
|
||||
* @note This function allows to wait and check that EEPROM has finished the
|
||||
* last operation. It is mostly used after Write operation: after receiving
|
||||
* the buffer to be written, the EEPROM may need additional time to actually
|
||||
* perform the write operation. During this time, it doesn't answer to
|
||||
* I2C packets addressed to it. Once the write operation is complete
|
||||
* the EEPROM responds to its address.
|
||||
* @retval EEPROM_OK (0) if operation is correctly performed, else return value
|
||||
* different from EEPROM_OK (0) or the timeout user callback.
|
||||
*/
|
||||
uint32_t BSP_EEPROM_WaitEepromStandbyState(void)
|
||||
{
|
||||
/* Check if the maximum allowed number of trials has bee reached */
|
||||
if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
|
||||
{
|
||||
/* If the maximum number of trials has been reached, exit the function */
|
||||
BSP_EEPROM_TIMEOUT_UserCallback();
|
||||
return EEPROM_TIMEOUT;
|
||||
}
|
||||
return EEPROM_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Basic management of the timeout situation.
|
||||
*/
|
||||
__weak void BSP_EEPROM_TIMEOUT_UserCallback(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_eeprom.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for
|
||||
* the stm32412g_discovery_eeprom.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 __STM32F412G_DISCOVERY_EEPROM_H
|
||||
#define __STM32F412G_DISCOVERY_EEPROM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_EEPROM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_EEPROM_Exported_Constants STM32412G DISCOVERY EEPROM Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/* EEPROM hardware address and page size */
|
||||
#define EEPROM_PAGESIZE ((uint8_t)4)
|
||||
#define EEPROM_MAX_SIZE ((uint16_t)0x2000) /* 64Kbit */
|
||||
|
||||
|
||||
/* Maximum number of trials for EEPROM_WaitEepromStandbyState() function */
|
||||
#define EEPROM_MAX_TRIALS ((uint32_t)3000)
|
||||
|
||||
#define EEPROM_OK ((uint32_t)0)
|
||||
#define EEPROM_FAIL ((uint32_t)1)
|
||||
#define EEPROM_TIMEOUT ((uint32_t)2)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_EEPROM_Exported_Functions STM32412G DISCOVERY EEPROM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint32_t BSP_EEPROM_Init(void);
|
||||
uint8_t BSP_EEPROM_DeInit(void);
|
||||
uint32_t BSP_EEPROM_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead);
|
||||
uint32_t BSP_EEPROM_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite);
|
||||
uint32_t BSP_EEPROM_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
|
||||
uint32_t BSP_EEPROM_WaitEepromStandbyState(void);
|
||||
|
||||
/* USER Callbacks: This function is declared as __weak in EEPROM driver and
|
||||
should be implemented into user application.
|
||||
BSP_EEPROM_TIMEOUT_UserCallback() function is called whenever a timeout condition
|
||||
occurs during communication (waiting on an event that doesn't occur, bus
|
||||
errors, busy devices ...). */
|
||||
void BSP_EEPROM_TIMEOUT_UserCallback(void);
|
||||
|
||||
/* Link function for I2C EEPROM peripheral */
|
||||
void EEPROM_IO_Init(void);
|
||||
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pBuffer, uint32_t BufferSize);
|
||||
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pBuffer, uint32_t BufferSize);
|
||||
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_EEPROM_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_lcd.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32412g_discovery_lcd.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 __STM32412G_DISCOVERY_LCD_H
|
||||
#define __STM32412G_DISCOVERY_LCD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery.h"
|
||||
#include "../Components/ls016b8uy/ls016b8uy.h"
|
||||
#include "../Components/st7789h2/st7789h2.h"
|
||||
#include "../../../Utilities/Fonts/fonts.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_LCD
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_LCD_Exported_Types STM32412G DISCOVERY LCD Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t TextColor;
|
||||
uint32_t BackColor;
|
||||
sFONT *pFont;
|
||||
}LCD_DrawPropTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16_t X;
|
||||
int16_t Y;
|
||||
}Point, * pPoint;
|
||||
|
||||
/**
|
||||
* @brief Line mode structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CENTER_MODE = 0x01, /* Center mode */
|
||||
RIGHT_MODE = 0x02, /* Right mode */
|
||||
LEFT_MODE = 0x03 /* Left mode */
|
||||
}Line_ModeTypdef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_LCD_Exported_Constants STM32412G DISCOVERY LCD Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief LCD status structure definition
|
||||
*/
|
||||
#define LCD_OK ((uint8_t)0x00)
|
||||
#define LCD_ERROR ((uint8_t)0x01)
|
||||
#define LCD_TIMEOUT ((uint8_t)0x02)
|
||||
|
||||
/**
|
||||
* @brief LCD orientation
|
||||
*/
|
||||
#define LCD_ORIENTATION_PORTRAIT ((uint8_t)0x00) /*!< Portrait orientation choice of LCD screen */
|
||||
#define LCD_ORIENTATION_LANDSCAPE ((uint8_t)0x01) /*!< Landscape orientation choice of LCD screen */
|
||||
#define LCD_ORIENTATION_LANDSCAPE_ROT180 ((uint8_t)0x02) /*!< Landscape rotated 180° orientation choice of LCD screen */
|
||||
|
||||
/**
|
||||
* @brief LCD color
|
||||
*/
|
||||
#define LCD_COLOR_BLUE ((uint16_t)0x001F)
|
||||
#define LCD_COLOR_GREEN ((uint16_t)0x07E0)
|
||||
#define LCD_COLOR_RED ((uint16_t)0xF800)
|
||||
#define LCD_COLOR_CYAN ((uint16_t)0x07FF)
|
||||
#define LCD_COLOR_MAGENTA ((uint16_t)0xF81F)
|
||||
#define LCD_COLOR_YELLOW ((uint16_t)0xFFE0)
|
||||
#define LCD_COLOR_LIGHTBLUE ((uint16_t)0x841F)
|
||||
#define LCD_COLOR_LIGHTGREEN ((uint16_t)0x87F0)
|
||||
#define LCD_COLOR_LIGHTRED ((uint16_t)0xFC10)
|
||||
#define LCD_COLOR_LIGHTMAGENTA ((uint16_t)0xFC1F)
|
||||
#define LCD_COLOR_LIGHTYELLOW ((uint16_t)0xFFF0)
|
||||
#define LCD_COLOR_DARKBLUE ((uint16_t)0x0010)
|
||||
#define LCD_COLOR_DARKGREEN ((uint16_t)0x0400)
|
||||
#define LCD_COLOR_DARKRED ((uint16_t)0x8000)
|
||||
#define LCD_COLOR_DARKCYAN ((uint16_t)0x0410)
|
||||
#define LCD_COLOR_DARKMAGENTA ((uint16_t)0x8010)
|
||||
#define LCD_COLOR_DARKYELLOW ((uint16_t)0x8400)
|
||||
#define LCD_COLOR_WHITE ((uint16_t)0xFFFF)
|
||||
#define LCD_COLOR_LIGHTGRAY ((uint16_t)0xD69A)
|
||||
#define LCD_COLOR_GRAY ((uint16_t)0x8410)
|
||||
#define LCD_COLOR_DARKGRAY ((uint16_t)0x4208)
|
||||
#define LCD_COLOR_BLACK ((uint16_t)0x0000)
|
||||
#define LCD_COLOR_BROWN ((uint16_t)0xA145)
|
||||
#define LCD_COLOR_ORANGE ((uint16_t)0xFD20)
|
||||
|
||||
/**
|
||||
* @brief LCD default font
|
||||
*/
|
||||
#define LCD_DEFAULT_FONT Font12
|
||||
|
||||
/**
|
||||
* @brief LCD special pins
|
||||
*/
|
||||
/* LCD reset pin */
|
||||
#define LCD_RESET_PIN GPIO_PIN_11
|
||||
#define LCD_RESET_GPIO_PORT GPIOD
|
||||
#define LCD_RESET_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
#define LCD_RESET_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
|
||||
|
||||
/* LCD tearing effect pin */
|
||||
#define LCD_TE_PIN GPIO_PIN_4
|
||||
#define LCD_TE_GPIO_PORT GPIOG
|
||||
#define LCD_TE_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
|
||||
#define LCD_TE_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
|
||||
|
||||
/* Backlight control pin */
|
||||
#define LCD_BL_CTRL_PIN GPIO_PIN_5
|
||||
#define LCD_BL_CTRL_GPIO_PORT GPIOF
|
||||
#define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE()
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_LCD_Exported_Functions STM32412G DISCOVERY LCD Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_LCD_Init(void);
|
||||
uint8_t BSP_LCD_InitEx(uint32_t orientation);
|
||||
uint8_t BSP_LCD_DeInit(void);
|
||||
uint32_t BSP_LCD_GetXSize(void);
|
||||
uint32_t BSP_LCD_GetYSize(void);
|
||||
|
||||
uint16_t BSP_LCD_GetTextColor(void);
|
||||
uint16_t BSP_LCD_GetBackColor(void);
|
||||
void BSP_LCD_SetTextColor(__IO uint16_t Color);
|
||||
void BSP_LCD_SetBackColor(__IO uint16_t Color);
|
||||
void BSP_LCD_SetFont(sFONT *fonts);
|
||||
sFONT *BSP_LCD_GetFont(void);
|
||||
|
||||
void BSP_LCD_Clear(uint16_t Color);
|
||||
void BSP_LCD_ClearStringLine(uint16_t Line);
|
||||
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr);
|
||||
void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode);
|
||||
void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
|
||||
|
||||
uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos);
|
||||
void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code);
|
||||
void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
|
||||
void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount);
|
||||
void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius);
|
||||
void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
|
||||
void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pbmp);
|
||||
void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
|
||||
void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount);
|
||||
void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius);
|
||||
|
||||
void BSP_LCD_DisplayOff(void);
|
||||
void BSP_LCD_DisplayOn(void);
|
||||
|
||||
/* These functions can be modified in case the current settings
|
||||
need to be changed for specific application needs */
|
||||
__weak void BSP_LCD_MspInit(void);
|
||||
__weak void BSP_LCD_MspDeInit(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_LCD_H */
|
||||
@@ -0,0 +1,754 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_qspi.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file includes a standard driver for the N25Q128A QSPI
|
||||
* memory mounted on STM32412G-DISCOVERY board.
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
(#) This driver is used to drive the N25Q128A QSPI external
|
||||
memory mounted on STM32412G-DISCOVERY board.
|
||||
|
||||
(#) This driver need a specific component driver (N25Q128A) to be included with.
|
||||
|
||||
(#) Initialization steps:
|
||||
(++) Initialize the QPSI external memory using the BSP_QSPI_Init() function. This
|
||||
function includes the MSP layer hardware resources initialization and the
|
||||
QSPI interface with the external memory.
|
||||
|
||||
(#) QSPI memory operations
|
||||
(++) QSPI memory can be accessed with read/write operations once it is
|
||||
initialized.
|
||||
Read/write operation can be performed with AHB access using the functions
|
||||
BSP_QSPI_Read()/BSP_QSPI_Write().
|
||||
(++) The function BSP_QSPI_GetInfo() returns the configuration of the QSPI memory.
|
||||
(see the QSPI memory data sheet)
|
||||
(++) Perform erase block operation using the function BSP_QSPI_Erase_Block() and by
|
||||
specifying the block address. You can perform an erase operation of the whole
|
||||
chip by calling the function BSP_QSPI_Erase_Chip().
|
||||
(++) The function BSP_QSPI_GetStatus() returns the current status of the QSPI memory.
|
||||
(see the QSPI memory data sheet)
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery_qspi.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI STM32412G-DISCOVERY QSPI
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI_Private_Variables STM32412G Discovery QSPI Private Variables
|
||||
* @{
|
||||
*/
|
||||
QSPI_HandleTypeDef QSPIHandle;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI_Private_FunctionPrototypes STM32412G Discovery QSPI Private FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t QSPI_ResetMemory (QSPI_HandleTypeDef *hqspi);
|
||||
static uint8_t QSPI_DummyCyclesCfg (QSPI_HandleTypeDef *hqspi);
|
||||
static uint8_t QSPI_WriteEnable (QSPI_HandleTypeDef *hqspi);
|
||||
static uint8_t QSPI_AutoPollingMemReady(QSPI_HandleTypeDef *hqspi, uint32_t Timeout);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI_Private_Functions STM32412G Discovery QSPI Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the QSPI interface.
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_Init(void)
|
||||
{
|
||||
QSPIHandle.Instance = QUADSPI;
|
||||
|
||||
/* Call the DeInit function to reset the driver */
|
||||
if (HAL_QSPI_DeInit(&QSPIHandle) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* System level initialization */
|
||||
BSP_QSPI_MspInit(&QSPIHandle, NULL);
|
||||
|
||||
/* QSPI initialization */
|
||||
QSPIHandle.Init.ClockPrescaler = 0; /* QSPI freq = 100 MHz/(0+1) = 100 Mhz */
|
||||
QSPIHandle.Init.FifoThreshold = 4;
|
||||
QSPIHandle.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
|
||||
QSPIHandle.Init.FlashSize = POSITION_VAL(N25Q128A_FLASH_SIZE) - 1;
|
||||
QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_5_CYCLE; /* Min 50ns for nonRead command */
|
||||
QSPIHandle.Init.ClockMode = QSPI_CLOCK_MODE_0;
|
||||
QSPIHandle.Init.FlashID = QSPI_FLASH_ID_1;
|
||||
QSPIHandle.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
|
||||
|
||||
if (HAL_QSPI_Init(&QSPIHandle) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* QSPI memory reset */
|
||||
if (QSPI_ResetMemory(&QSPIHandle) != QSPI_OK)
|
||||
{
|
||||
return QSPI_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Configuration of the dummy cycles on QSPI memory side */
|
||||
if (QSPI_DummyCyclesCfg(&QSPIHandle) != QSPI_OK)
|
||||
{
|
||||
return QSPI_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Initializes the QSPI interface.
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_DeInit(void)
|
||||
{
|
||||
QSPIHandle.Instance = QUADSPI;
|
||||
|
||||
/* Call the DeInit function to reset the driver */
|
||||
if (HAL_QSPI_DeInit(&QSPIHandle) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* System level De-initialization */
|
||||
BSP_QSPI_MspDeInit(&QSPIHandle, NULL);
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads an amount of data from the QSPI memory.
|
||||
* @param pData: Pointer to data to be read
|
||||
* @param ReadAddr: Read start address
|
||||
* @param Size: Size of data to read
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
|
||||
/* Initialize the read command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = QUAD_INOUT_FAST_READ_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_4_LINES;
|
||||
s_command.AddressSize = QSPI_ADDRESS_24_BITS;
|
||||
s_command.Address = ReadAddr;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_4_LINES;
|
||||
s_command.DummyCycles = N25Q128A_DUMMY_CYCLES_READ_QUAD;
|
||||
s_command.NbData = Size;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Configure the command */
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Set S# timing for Read command: Min 20ns for N25Q128A memory */
|
||||
MODIFY_REG(QSPIHandle.Instance->DCR, QUADSPI_DCR_CSHT, QSPI_CS_HIGH_TIME_2_CYCLE);
|
||||
|
||||
/* Reception of the data */
|
||||
if (HAL_QSPI_Receive(&QSPIHandle, pData, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Restore S# timing for nonRead commands */
|
||||
MODIFY_REG(QSPIHandle.Instance->DCR, QUADSPI_DCR_CSHT, QSPI_CS_HIGH_TIME_5_CYCLE);
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes an amount of data to the QSPI memory.
|
||||
* @param pData: Pointer to data to be written
|
||||
* @param WriteAddr: Write start address
|
||||
* @param Size: Size of data to write
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
uint32_t end_addr, current_size, current_addr;
|
||||
|
||||
/* Calculation of the size between the write address and the end of the page */
|
||||
current_size = N25Q128A_PAGE_SIZE - (WriteAddr % N25Q128A_PAGE_SIZE);
|
||||
|
||||
/* Check if the size of the data is less than the remaining place in the page */
|
||||
if (current_size > Size)
|
||||
{
|
||||
current_size = Size;
|
||||
}
|
||||
|
||||
/* Initialize the address variables */
|
||||
current_addr = WriteAddr;
|
||||
end_addr = WriteAddr + Size;
|
||||
|
||||
/* Initialize the program command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = EXT_QUAD_IN_FAST_PROG_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_4_LINES;
|
||||
s_command.AddressSize = QSPI_ADDRESS_24_BITS;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_4_LINES;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Perform the write page by page */
|
||||
do
|
||||
{
|
||||
s_command.Address = current_addr;
|
||||
s_command.NbData = current_size;
|
||||
|
||||
/* Enable write operations */
|
||||
if (QSPI_WriteEnable(&QSPIHandle) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Configure the command */
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Transmission of the data */
|
||||
if (HAL_QSPI_Transmit(&QSPIHandle, pData, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Configure automatic polling mode to wait for end of program */
|
||||
if (QSPI_AutoPollingMemReady(&QSPIHandle, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Update the address and size variables for next page programming */
|
||||
current_addr += current_size;
|
||||
pData += current_size;
|
||||
current_size = ((current_addr + N25Q128A_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : N25Q128A_PAGE_SIZE;
|
||||
} while (current_addr < end_addr);
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases the specified block of the QSPI memory.
|
||||
* @param BlockAddress: Block address to erase
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_Erase_Block(uint32_t BlockAddress)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
|
||||
/* Initialize the erase command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = SUBSECTOR_ERASE_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_1_LINE;
|
||||
s_command.AddressSize = QSPI_ADDRESS_24_BITS;
|
||||
s_command.Address = BlockAddress;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_NONE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Enable write operations */
|
||||
if (QSPI_WriteEnable(&QSPIHandle) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Send the command */
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Configure automatic polling mode to wait for end of erase */
|
||||
if (QSPI_AutoPollingMemReady(&QSPIHandle, N25Q128A_SUBSECTOR_ERASE_MAX_TIME) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases the entire QSPI memory.
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_Erase_Chip(void)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
|
||||
/* Initialize the erase command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = BULK_ERASE_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_NONE;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_NONE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Enable write operations */
|
||||
if (QSPI_WriteEnable(&QSPIHandle) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Send the command */
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Configure automatic polling mode to wait for end of erase */
|
||||
if (QSPI_AutoPollingMemReady(&QSPIHandle, N25Q128A_BULK_ERASE_MAX_TIME) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads current status of the QSPI memory.
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_GetStatus(void)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
uint8_t reg;
|
||||
|
||||
/* Initialize the read flag status register command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = READ_FLAG_STATUS_REG_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_NONE;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_1_LINE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.NbData = 1;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Configure the command */
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Reception of the data */
|
||||
if (HAL_QSPI_Receive(&QSPIHandle, ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Check the value of the register */
|
||||
if ((reg & (N25Q128A_FSR_PRERR | N25Q128A_FSR_VPPERR | N25Q128A_FSR_PGERR | N25Q128A_FSR_ERERR)) != 0)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
else if ((reg & (N25Q128A_FSR_PGSUS | N25Q128A_FSR_ERSUS)) != 0)
|
||||
{
|
||||
return QSPI_SUSPENDED;
|
||||
}
|
||||
else if ((reg & N25Q128A_FSR_READY) != 0)
|
||||
{
|
||||
return QSPI_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QSPI_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the configuration of the QSPI memory.
|
||||
* @param pInfo: pointer on the configuration structure
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_GetInfo(QSPI_Info* pInfo)
|
||||
{
|
||||
/* Configure the structure with the memory configuration */
|
||||
pInfo->FlashSize = N25Q128A_FLASH_SIZE;
|
||||
pInfo->EraseSectorSize = N25Q128A_SUBSECTOR_SIZE;
|
||||
pInfo->EraseSectorsNumber = (N25Q128A_FLASH_SIZE/N25Q128A_SUBSECTOR_SIZE);
|
||||
pInfo->ProgPageSize = N25Q128A_PAGE_SIZE;
|
||||
pInfo->ProgPagesNumber = (N25Q128A_FLASH_SIZE/N25Q128A_PAGE_SIZE);
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the QSPI in memory-mapped mode
|
||||
* @retval QSPI memory status
|
||||
*/
|
||||
uint8_t BSP_QSPI_EnableMemoryMappedMode(void)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
QSPI_MemoryMappedTypeDef s_mem_mapped_cfg;
|
||||
|
||||
/* Configure the command for the read instruction */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = QUAD_INOUT_FAST_READ_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_4_LINES;
|
||||
s_command.AddressSize = QSPI_ADDRESS_24_BITS;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_4_LINES;
|
||||
s_command.DummyCycles = N25Q128A_DUMMY_CYCLES_READ_QUAD;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Configure the memory mapped mode */
|
||||
s_mem_mapped_cfg.TimeOutActivation = QSPI_TIMEOUT_COUNTER_DISABLE;
|
||||
|
||||
if (HAL_QSPI_MemoryMapped(&QSPIHandle, &s_command, &s_mem_mapped_cfg) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief QSPI MSP Initialization
|
||||
* This function configures the hardware resources used in this example:
|
||||
* - Peripheral's clock enable
|
||||
* - Peripheral's GPIO Configuration
|
||||
* - NVIC configuration for QSPI interrupt
|
||||
* @param hqspi: QSPI handle
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
*/
|
||||
__weak void BSP_QSPI_MspInit(QSPI_HandleTypeDef *hqspi, void *Params)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
||||
/* Enable the QuadSPI memory interface clock */
|
||||
QSPI_CLK_ENABLE();
|
||||
/* Reset the QuadSPI memory interface */
|
||||
QSPI_FORCE_RESET();
|
||||
QSPI_RELEASE_RESET();
|
||||
/* Enable GPIO clocks */
|
||||
QSPI_CS_GPIO_CLK_ENABLE();
|
||||
QSPI_CLK_GPIO_CLK_ENABLE();
|
||||
QSPI_Dx_GPIO_CLK_ENABLE();
|
||||
|
||||
/*##-2- Configure peripheral GPIO ##########################################*/
|
||||
/* QSPI CS GPIO pin configuration */
|
||||
gpio_init_structure.Pin = QSPI_CS_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
||||
gpio_init_structure.Alternate = GPIO_AF10_QSPI;
|
||||
HAL_GPIO_Init(QSPI_CS_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI CLK GPIO pin configuration */
|
||||
gpio_init_structure.Pin = QSPI_CLK_PIN;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Alternate = GPIO_AF9_QSPI;
|
||||
HAL_GPIO_Init(QSPI_CLK_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D0 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = QSPI_D0_PIN;
|
||||
gpio_init_structure.Alternate = GPIO_AF10_QSPI;
|
||||
HAL_GPIO_Init(QSPI_D0_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D1 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = QSPI_D1_PIN;
|
||||
gpio_init_structure.Alternate = GPIO_AF10_QSPI;
|
||||
HAL_GPIO_Init(QSPI_D1_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D2 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = QSPI_D2_PIN;
|
||||
gpio_init_structure.Alternate = GPIO_AF9_QSPI;
|
||||
HAL_GPIO_Init(QSPI_D2_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D3 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = QSPI_D3_PIN;
|
||||
gpio_init_structure.Alternate = GPIO_AF9_QSPI;
|
||||
HAL_GPIO_Init(QSPI_D3_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/*##-3- Configure the NVIC for QSPI #########################################*/
|
||||
/* NVIC configuration for QSPI interrupt */
|
||||
HAL_NVIC_SetPriority(QUADSPI_IRQn, 0x0F, 0x00);
|
||||
HAL_NVIC_EnableIRQ(QUADSPI_IRQn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief QSPI MSP De-Initialization
|
||||
* This function frees the hardware resources used in this example:
|
||||
* - Disable the Peripheral's clock
|
||||
* - Revert GPIO and NVIC configuration to their default state
|
||||
* @param hqspi: QSPI handle
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
*/
|
||||
__weak void BSP_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi, void *Params)
|
||||
{
|
||||
/*##-1- Disable the NVIC for QSPI ###########################################*/
|
||||
HAL_NVIC_DisableIRQ(QUADSPI_IRQn);
|
||||
|
||||
/*##-2- Disable peripherals and GPIO Clocks ################################*/
|
||||
/* De-Configure QSPI pins */
|
||||
HAL_GPIO_DeInit(QSPI_CS_GPIO_PORT, QSPI_CS_PIN);
|
||||
HAL_GPIO_DeInit(QSPI_CLK_GPIO_PORT, QSPI_CLK_PIN);
|
||||
HAL_GPIO_DeInit(QSPI_D0_GPIO_PORT, QSPI_D0_PIN);
|
||||
HAL_GPIO_DeInit(QSPI_D1_GPIO_PORT, QSPI_D1_PIN);
|
||||
HAL_GPIO_DeInit(QSPI_D2_GPIO_PORT, QSPI_D2_PIN);
|
||||
HAL_GPIO_DeInit(QSPI_D3_GPIO_PORT, QSPI_D3_PIN);
|
||||
|
||||
/*##-3- Reset peripherals ##################################################*/
|
||||
/* Reset the QuadSPI memory interface */
|
||||
QSPI_FORCE_RESET();
|
||||
QSPI_RELEASE_RESET();
|
||||
|
||||
/* Disable the QuadSPI memory interface clock */
|
||||
QSPI_CLK_DISABLE();
|
||||
}
|
||||
|
||||
/*********************** Static functions *************************************/
|
||||
/**
|
||||
* @brief This function reset the QSPI memory.
|
||||
* @param hqspi: QSPI handle
|
||||
*/
|
||||
static uint8_t QSPI_ResetMemory(QSPI_HandleTypeDef *hqspi)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
|
||||
/* Initialize the reset enable command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = RESET_ENABLE_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_NONE;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_NONE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Send the command */
|
||||
if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Send the reset memory command */
|
||||
s_command.Instruction = RESET_MEMORY_CMD;
|
||||
if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Configure automatic polling mode to wait the memory is ready */
|
||||
if (QSPI_AutoPollingMemReady(hqspi, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function configure the dummy cycles on memory side.
|
||||
* @param hqspi: QSPI handle
|
||||
*/
|
||||
static uint8_t QSPI_DummyCyclesCfg(QSPI_HandleTypeDef *hqspi)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
uint8_t reg;
|
||||
|
||||
/* Initialize the read volatile configuration register command */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = READ_VOL_CFG_REG_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_NONE;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_1_LINE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.NbData = 1;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
/* Configure the command */
|
||||
if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Reception of the data */
|
||||
if (HAL_QSPI_Receive(hqspi, ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Enable write operations */
|
||||
if (QSPI_WriteEnable(hqspi) != QSPI_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Update volatile configuration register (with new dummy cycles) */
|
||||
s_command.Instruction = WRITE_VOL_CFG_REG_CMD;
|
||||
MODIFY_REG(reg, N25Q128A_VCR_NB_DUMMY, (N25Q128A_DUMMY_CYCLES_READ_QUAD << POSITION_VAL(N25Q128A_VCR_NB_DUMMY)));
|
||||
|
||||
/* Configure the write volatile configuration register command */
|
||||
if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Transmission of the data */
|
||||
if (HAL_QSPI_Transmit(hqspi, ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function send a Write Enable and wait it is effective.
|
||||
* @param hqspi: QSPI handle
|
||||
*/
|
||||
static uint8_t QSPI_WriteEnable(QSPI_HandleTypeDef *hqspi)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
QSPI_AutoPollingTypeDef s_config;
|
||||
|
||||
/* Enable write operations */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = WRITE_ENABLE_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_NONE;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_NONE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
/* Configure automatic polling mode to wait for write enabling */
|
||||
s_config.Match = N25Q128A_SR_WREN;
|
||||
s_config.Mask = N25Q128A_SR_WREN;
|
||||
s_config.MatchMode = QSPI_MATCH_MODE_AND;
|
||||
s_config.StatusBytesSize = 1;
|
||||
s_config.Interval = 0x10;
|
||||
s_config.AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE;
|
||||
|
||||
s_command.Instruction = READ_STATUS_REG_CMD;
|
||||
s_command.DataMode = QSPI_DATA_1_LINE;
|
||||
|
||||
if (HAL_QSPI_AutoPolling(hqspi, &s_command, &s_config, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function read the SR of the memory and wait the EOP.
|
||||
* @param hqspi: QSPI handle
|
||||
* @param Timeout
|
||||
*/
|
||||
static uint8_t QSPI_AutoPollingMemReady(QSPI_HandleTypeDef *hqspi, uint32_t Timeout)
|
||||
{
|
||||
QSPI_CommandTypeDef s_command;
|
||||
QSPI_AutoPollingTypeDef s_config;
|
||||
|
||||
/* Configure automatic polling mode to wait for memory ready */
|
||||
s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
|
||||
s_command.Instruction = READ_STATUS_REG_CMD;
|
||||
s_command.AddressMode = QSPI_ADDRESS_NONE;
|
||||
s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
|
||||
s_command.DataMode = QSPI_DATA_1_LINE;
|
||||
s_command.DummyCycles = 0;
|
||||
s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
|
||||
s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
|
||||
s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
|
||||
|
||||
s_config.Match = 0;
|
||||
s_config.Mask = N25Q128A_SR_WIP;
|
||||
s_config.MatchMode = QSPI_MATCH_MODE_AND;
|
||||
s_config.StatusBytesSize = 1;
|
||||
s_config.Interval = 0x10;
|
||||
s_config.AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE;
|
||||
|
||||
if (HAL_QSPI_AutoPolling(hqspi, &s_command, &s_config, Timeout) != HAL_OK)
|
||||
{
|
||||
return QSPI_ERROR;
|
||||
}
|
||||
|
||||
return QSPI_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_qspi.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32412g_discovery_qspi.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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32412G_DISCOVERY_QSPI_H
|
||||
#define __STM32412G_DISCOVERY_QSPI_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "../Components/n25q128a/n25q128a.h"
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_QSPI
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI_Exported_Constants STM32412G Discovery QSPI Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/* QSPI Error codes */
|
||||
#define QSPI_OK ((uint8_t)0x00)
|
||||
#define QSPI_ERROR ((uint8_t)0x01)
|
||||
#define QSPI_BUSY ((uint8_t)0x02)
|
||||
#define QSPI_NOT_SUPPORTED ((uint8_t)0x04)
|
||||
#define QSPI_SUSPENDED ((uint8_t)0x08)
|
||||
|
||||
|
||||
/* Definition for QSPI clock resources */
|
||||
#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
|
||||
#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
|
||||
#define QSPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
|
||||
#define QSPI_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
|
||||
#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define QSPI_CLK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define QSPI_Dx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
|
||||
#define QSPI_Dx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE()
|
||||
|
||||
#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
|
||||
#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
|
||||
|
||||
/* Definition for QSPI Pins */
|
||||
#define QSPI_CS_PIN GPIO_PIN_6
|
||||
#define QSPI_CS_GPIO_PORT GPIOG
|
||||
#define QSPI_CLK_PIN GPIO_PIN_2
|
||||
#define QSPI_CLK_GPIO_PORT GPIOB
|
||||
#define QSPI_D0_PIN GPIO_PIN_8
|
||||
#define QSPI_D0_GPIO_PORT GPIOF
|
||||
#define QSPI_D1_PIN GPIO_PIN_9
|
||||
#define QSPI_D1_GPIO_PORT GPIOF
|
||||
#define QSPI_D2_PIN GPIO_PIN_7
|
||||
#define QSPI_D2_GPIO_PORT GPIOF
|
||||
#define QSPI_D3_PIN GPIO_PIN_6
|
||||
#define QSPI_D3_GPIO_PORT GPIOF
|
||||
|
||||
/* N25Q128A13EF840F Micron memory */
|
||||
/* Size of the flash */
|
||||
#define QSPI_FLASH_SIZE 23 /* Address bus width to access whole memory space */
|
||||
#define QSPI_PAGE_SIZE 256
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI_Exported_Types STM32412G Discovery QSPI Exported Types
|
||||
* @{
|
||||
*/
|
||||
/* QSPI Info */
|
||||
typedef struct {
|
||||
uint32_t FlashSize; /*!< Size of the flash */
|
||||
uint32_t EraseSectorSize; /*!< Size of sectors for the erase operation */
|
||||
uint32_t EraseSectorsNumber; /*!< Number of sectors for the erase operation */
|
||||
uint32_t ProgPageSize; /*!< Size of pages for the program operation */
|
||||
uint32_t ProgPagesNumber; /*!< Number of pages for the program operation */
|
||||
} QSPI_Info;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @defgroup STM32412G_DISCOVERY_QSPI_Exported_Functions STM32412G Discovery QSPI Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_QSPI_Init (void);
|
||||
uint8_t BSP_QSPI_DeInit (void);
|
||||
uint8_t BSP_QSPI_Read (uint8_t* pData, uint32_t ReadAddr, uint32_t Size);
|
||||
uint8_t BSP_QSPI_Write (uint8_t* pData, uint32_t WriteAddr, uint32_t Size);
|
||||
uint8_t BSP_QSPI_Erase_Block(uint32_t BlockAddress);
|
||||
uint8_t BSP_QSPI_Erase_Chip (void);
|
||||
uint8_t BSP_QSPI_GetStatus (void);
|
||||
uint8_t BSP_QSPI_GetInfo (QSPI_Info* pInfo);
|
||||
uint8_t BSP_QSPI_EnableMemoryMappedMode(void);
|
||||
/* BSP Aliased function maintained for legacy purpose */
|
||||
#define BSP_QSPI_MemoryMappedMode BSP_QSPI_EnableMemoryMappedMode
|
||||
|
||||
/* These functions can be modified in case the current settings
|
||||
need to be changed for specific application needs */
|
||||
void BSP_QSPI_MspInit(QSPI_HandleTypeDef *hqspi, void *Params);
|
||||
void BSP_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi, void *Params);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_QSPI_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,546 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_sd.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file includes the uSD card driver mounted on STM32412G-DISCOVERY
|
||||
* board.
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* File Info : -----------------------------------------------------------------
|
||||
User NOTES
|
||||
1. How To use this driver:
|
||||
--------------------------
|
||||
- This driver is used to drive the micro SD external card mounted on STM32412G-DISCOVERY
|
||||
board.
|
||||
- This driver does not need a specific component driver for the micro SD device
|
||||
to be included with.
|
||||
|
||||
2. Driver description:
|
||||
---------------------
|
||||
+ Initialization steps:
|
||||
o Initialize the micro SD card using the BSP_SD_Init() function. This
|
||||
function includes the MSP layer hardware resources initialization and the
|
||||
SDIO interface configuration to interface with the external micro SD. It
|
||||
also includes the micro SD initialization sequence.
|
||||
o To check the SD card presence you can use the function BSP_SD_IsDetected() which
|
||||
returns the detection status
|
||||
o If SD presence detection interrupt mode is desired, you must configure the
|
||||
SD detection interrupt mode by calling the function BSP_SD_ITConfig(). The interrupt
|
||||
is generated as an external interrupt whenever the micro SD card is
|
||||
plugged/unplugged in/from the board.
|
||||
o The function BSP_SD_GetCardInfo() is used to get the micro SD card information
|
||||
which is stored in the structure "HAL_SD_CardInfoTypeDef".
|
||||
|
||||
+ Micro SD card operations
|
||||
o The micro SD card can be accessed with read/write block(s) operations once
|
||||
it is ready for access. The access can be performed whether using the polling
|
||||
mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(), or by DMA
|
||||
transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA()
|
||||
o The DMA transfer complete is used with interrupt mode. Once the SD transfer
|
||||
is complete, the SD interrupt is handled using the function BSP_SD_IRQHandler(),
|
||||
the DMA Tx/Rx transfer complete are handled using the functions
|
||||
BSP_SD_DMA_Tx_IRQHandler()/BSP_SD_DMA_Rx_IRQHandler(). The corresponding user callbacks
|
||||
are implemented by the user at application level.
|
||||
o The SD erase block(s) is performed using the function BSP_SD_Erase() with specifying
|
||||
the number of blocks to erase.
|
||||
o The SD runtime status is returned when calling the function BSP_SD_GetCardState().
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery_sd.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_SD STM32412G-DISCOVERY SD
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_SD_Private_Variables STM32412G Discovery Sd Private Variables
|
||||
* @{
|
||||
*/
|
||||
SD_HandleTypeDef uSdHandle;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_SD_Private_Functions STM32412G Discovery Sd Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the SD card device.
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_Init(void)
|
||||
{
|
||||
uint8_t sd_state = MSD_OK;
|
||||
|
||||
/* uSD device interface configuration */
|
||||
uSdHandle.Instance = SDIO;
|
||||
|
||||
uSdHandle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
||||
uSdHandle.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
|
||||
uSdHandle.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||||
uSdHandle.Init.BusWide = SDIO_BUS_WIDE_1B;
|
||||
uSdHandle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_ENABLE;
|
||||
uSdHandle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
|
||||
|
||||
/* Msp SD Detect pin initialization */
|
||||
BSP_SD_Detect_MspInit(&uSdHandle, NULL);
|
||||
|
||||
/* Check if SD card is present */
|
||||
if(BSP_SD_IsDetected() != SD_PRESENT)
|
||||
{
|
||||
return MSD_ERROR_SD_NOT_PRESENT;
|
||||
}
|
||||
|
||||
/* Msp SD initialization */
|
||||
BSP_SD_MspInit(&uSdHandle, NULL);
|
||||
|
||||
/* HAL SD initialization */
|
||||
if(HAL_SD_Init(&uSdHandle) != HAL_OK)
|
||||
{
|
||||
sd_state = MSD_ERROR;
|
||||
}
|
||||
|
||||
/* Configure SD Bus width */
|
||||
if(sd_state == MSD_OK)
|
||||
{
|
||||
/* Enable wide operation */
|
||||
if(HAL_SD_ConfigWideBusOperation(&uSdHandle, SDIO_BUS_WIDE_4B) != HAL_OK)
|
||||
{
|
||||
sd_state = MSD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
sd_state = MSD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return sd_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the SD card device.
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_DeInit(void)
|
||||
{
|
||||
uint8_t sd_state = MSD_OK;
|
||||
|
||||
uSdHandle.Instance = SDIO;
|
||||
|
||||
/* HAL SD deinitialization */
|
||||
if(HAL_SD_DeInit(&uSdHandle) != HAL_OK)
|
||||
{
|
||||
sd_state = MSD_ERROR;
|
||||
}
|
||||
|
||||
/* Msp SD deinitialization */
|
||||
uSdHandle.Instance = SDIO;
|
||||
BSP_SD_MspDeInit(&uSdHandle, NULL);
|
||||
|
||||
return sd_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures Interrupt mode for SD detection pin.
|
||||
* @retval Returns MSD_OK
|
||||
*/
|
||||
uint8_t BSP_SD_ITConfig(void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Configure Interrupt mode for SD detection pin */
|
||||
gpio_init_structure.Pin = SD_DETECT_PIN;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
gpio_init_structure.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* Enable and set SD detect EXTI Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)(SD_DETECT_EXTI_IRQn), 0x0F, 0x00);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(SD_DETECT_EXTI_IRQn));
|
||||
|
||||
return MSD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detects if SD card is correctly plugged in the memory slot or not.
|
||||
* @retval Returns if SD is detected or not
|
||||
*/
|
||||
uint8_t BSP_SD_IsDetected(void)
|
||||
{
|
||||
__IO uint8_t status = SD_PRESENT;
|
||||
|
||||
/* Check SD card detect pin */
|
||||
if (HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET)
|
||||
{
|
||||
status = SD_NOT_PRESENT;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in an SD card, in polling mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param ReadAddr: Address from where data is to be read
|
||||
* @param NumOfBlocks: Number of SD blocks to read
|
||||
* @param Timeout: Timeout for read operation
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout)
|
||||
{
|
||||
if(HAL_SD_ReadBlocks(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks, Timeout) != HAL_OK)
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes block(s) to a specified address in an SD card, in polling mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param WriteAddr: Address from where data is to be written
|
||||
* @param NumOfBlocks: Number of SD blocks to write
|
||||
* @param Timeout: Timeout for write operation
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout)
|
||||
{
|
||||
if(HAL_SD_WriteBlocks(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout) != HAL_OK)
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in an SD card, in DMA mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param ReadAddr: Address from where data is to be read
|
||||
* @param NumOfBlocks: Number of SD blocks to read
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks)
|
||||
{
|
||||
/* Read block(s) in DMA transfer mode */
|
||||
if(HAL_SD_ReadBlocks_DMA(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks) != HAL_OK)
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes block(s) to a specified address in an SD card, in DMA mode.
|
||||
* @param pData: Pointer to the buffer that will contain the data to transmit
|
||||
* @param WriteAddr: Address from where data is to be written
|
||||
* @param NumOfBlocks: Number of SD blocks to write
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
|
||||
{
|
||||
/* Write block(s) in DMA transfer mode */
|
||||
if(HAL_SD_WriteBlocks_DMA(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks) != HAL_OK)
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases the specified memory area of the given SD card.
|
||||
* @param StartAddr: Start byte address
|
||||
* @param EndAddr: End byte address
|
||||
* @retval SD status
|
||||
*/
|
||||
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr)
|
||||
{
|
||||
if(HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr) != HAL_OK)
|
||||
{
|
||||
return MSD_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MSD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the SD MSP.
|
||||
* @param hsd: SD handle
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
|
||||
{
|
||||
static DMA_HandleTypeDef dma_rx_handle;
|
||||
static DMA_HandleTypeDef dma_tx_handle;
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Enable SDIO clock */
|
||||
__HAL_RCC_SDIO_CLK_ENABLE();
|
||||
|
||||
/* Enable DMA2 clocks */
|
||||
__DMAx_TxRx_CLK_ENABLE();
|
||||
|
||||
/* Enable GPIOs clock */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/* Common GPIO configuration */
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
||||
gpio_init_structure.Alternate = GPIO_AF12_SDIO;
|
||||
|
||||
/* GPIOC configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
|
||||
|
||||
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
|
||||
|
||||
/* GPIOD configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_2;
|
||||
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
|
||||
|
||||
/* NVIC configuration for SDIO interrupts */
|
||||
HAL_NVIC_SetPriority(SDIO_IRQn, 0x0E, 0);
|
||||
HAL_NVIC_EnableIRQ(SDIO_IRQn);
|
||||
|
||||
/* Configure DMA Rx parameters */
|
||||
dma_rx_handle.Init.Channel = SD_DMAx_Rx_CHANNEL;
|
||||
dma_rx_handle.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
dma_rx_handle.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
dma_rx_handle.Init.MemInc = DMA_MINC_ENABLE;
|
||||
dma_rx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
dma_rx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
dma_rx_handle.Init.Mode = DMA_PFCTRL;
|
||||
dma_rx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
||||
dma_rx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
||||
dma_rx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
dma_rx_handle.Init.MemBurst = DMA_MBURST_INC4;
|
||||
dma_rx_handle.Init.PeriphBurst = DMA_PBURST_INC4;
|
||||
|
||||
dma_rx_handle.Instance = SD_DMAx_Rx_STREAM;
|
||||
|
||||
/* Associate the DMA handle */
|
||||
__HAL_LINKDMA(hsd, hdmarx, dma_rx_handle);
|
||||
|
||||
/* Deinitialize the stream for new transfer */
|
||||
HAL_DMA_DeInit(&dma_rx_handle);
|
||||
|
||||
/* Configure the DMA stream */
|
||||
HAL_DMA_Init(&dma_rx_handle);
|
||||
|
||||
/* Configure DMA Tx parameters */
|
||||
dma_tx_handle.Init.Channel = SD_DMAx_Tx_CHANNEL;
|
||||
dma_tx_handle.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
dma_tx_handle.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
dma_tx_handle.Init.MemInc = DMA_MINC_ENABLE;
|
||||
dma_tx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
dma_tx_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
dma_tx_handle.Init.Mode = DMA_PFCTRL;
|
||||
dma_tx_handle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
||||
dma_tx_handle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
||||
dma_tx_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
dma_tx_handle.Init.MemBurst = DMA_MBURST_INC4;
|
||||
dma_tx_handle.Init.PeriphBurst = DMA_PBURST_INC4;
|
||||
|
||||
dma_tx_handle.Instance = SD_DMAx_Tx_STREAM;
|
||||
|
||||
/* Associate the DMA handle */
|
||||
__HAL_LINKDMA(hsd, hdmatx, dma_tx_handle);
|
||||
|
||||
/* Deinitialize the stream for new transfer */
|
||||
HAL_DMA_DeInit(&dma_tx_handle);
|
||||
|
||||
/* Configure the DMA stream */
|
||||
HAL_DMA_Init(&dma_tx_handle);
|
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt */
|
||||
HAL_NVIC_SetPriority(SD_DMAx_Rx_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(SD_DMAx_Rx_IRQn);
|
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt */
|
||||
HAL_NVIC_SetPriority(SD_DMAx_Tx_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(SD_DMAx_Tx_IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the SD Detect pin MSP.
|
||||
* @param hsd: SD handle
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
SD_DETECT_GPIO_CLK_ENABLE();
|
||||
|
||||
/* GPIO configuration in input for uSD_Detect signal */
|
||||
gpio_init_structure.Pin = SD_DETECT_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_INPUT;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
||||
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the SD MSP.
|
||||
* @param hsd: SD handle
|
||||
* @param Params : pointer on additional configuration parameters, can be NULL.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
|
||||
{
|
||||
static DMA_HandleTypeDef dma_rx_handle;
|
||||
static DMA_HandleTypeDef dma_tx_handle;
|
||||
|
||||
/* Disable NVIC for DMA transfer complete interrupts */
|
||||
HAL_NVIC_DisableIRQ(SD_DMAx_Rx_IRQn);
|
||||
HAL_NVIC_DisableIRQ(SD_DMAx_Tx_IRQn);
|
||||
|
||||
/* Deinitialize the stream for new transfer */
|
||||
dma_rx_handle.Instance = SD_DMAx_Rx_STREAM;
|
||||
HAL_DMA_DeInit(&dma_rx_handle);
|
||||
|
||||
/* Deinitialize the stream for new transfer */
|
||||
dma_tx_handle.Instance = SD_DMAx_Tx_STREAM;
|
||||
HAL_DMA_DeInit(&dma_tx_handle);
|
||||
|
||||
/* Disable NVIC for SDIO interrupts */
|
||||
HAL_NVIC_DisableIRQ(SDIO_IRQn);
|
||||
|
||||
/* DeInit GPIO pins can be done in the application
|
||||
(by surcharging this __weak function) */
|
||||
|
||||
/* Disable SDIO clock */
|
||||
__HAL_RCC_SDIO_CLK_DISABLE();
|
||||
|
||||
/* GPIO pins clock and DMA clocks can be shut down in the application
|
||||
by surcharging this __weak function */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current SD card data status.
|
||||
* @retval Data transfer state.
|
||||
* This value can be one of the following values:
|
||||
* @arg SD_TRANSFER_OK: No data transfer is acting
|
||||
* @arg SD_TRANSFER_BUSY: Data transfer is acting
|
||||
*/
|
||||
uint8_t BSP_SD_GetCardState(void)
|
||||
{
|
||||
return((HAL_SD_GetCardState(&uSdHandle) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get SD information about specific SD card.
|
||||
* @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure
|
||||
*/
|
||||
void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo)
|
||||
{
|
||||
/* Get SD card Information */
|
||||
HAL_SD_GetCardInfo(&uSdHandle, CardInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SD Abort callbacks
|
||||
* @param hsd: SD handle
|
||||
*/
|
||||
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_AbortCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callbacks
|
||||
* @param hsd: SD handle
|
||||
*/
|
||||
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_WriteCpltCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Transfer completed callbacks
|
||||
* @param hsd: SD handle
|
||||
*/
|
||||
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
BSP_SD_ReadCpltCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP SD Abort callbacks
|
||||
*/
|
||||
__weak void BSP_SD_AbortCallback(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP Tx Transfer completed callbacks
|
||||
*/
|
||||
__weak void BSP_SD_WriteCpltCallback(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP Rx Transfer completed callbacks
|
||||
*/
|
||||
__weak void BSP_SD_ReadCpltCallback(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_sd.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32412g_discovery_sd.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 __STM32412G_DISCOVERY_SD_H
|
||||
#define __STM32412G_DISCOVERY_SD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_SD
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_SD_Exported_Types STM32412G DISCOVERY SD Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SD Card information structure
|
||||
*/
|
||||
#define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_SD_Exported_Constants STM32412G DISCOVERY SD Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief SD status structure definition
|
||||
*/
|
||||
#define MSD_OK ((uint8_t)0x00)
|
||||
#define MSD_ERROR ((uint8_t)0x01)
|
||||
#define MSD_ERROR_SD_NOT_PRESENT ((uint8_t)0x02)
|
||||
|
||||
/**
|
||||
* @brief SD transfer state definition
|
||||
*/
|
||||
#define SD_TRANSFER_OK ((uint8_t)0x00)
|
||||
#define SD_TRANSFER_BUSY ((uint8_t)0x01)
|
||||
|
||||
#define SD_PRESENT ((uint8_t)0x01)
|
||||
#define SD_NOT_PRESENT ((uint8_t)0x00)
|
||||
|
||||
#define SD_DATATIMEOUT ((uint32_t)100000000)
|
||||
|
||||
/* DMA definitions for SD DMA transfer */
|
||||
#define __DMAx_TxRx_CLK_ENABLE __HAL_RCC_DMA2_CLK_ENABLE
|
||||
#define SD_DMAx_Tx_CHANNEL DMA_CHANNEL_4
|
||||
#define SD_DMAx_Rx_CHANNEL DMA_CHANNEL_4
|
||||
#define SD_DMAx_Tx_STREAM DMA2_Stream6
|
||||
#define SD_DMAx_Rx_STREAM DMA2_Stream3
|
||||
#define SD_DMAx_Tx_IRQn DMA2_Stream6_IRQn
|
||||
#define SD_DMAx_Rx_IRQn DMA2_Stream3_IRQn
|
||||
#define BSP_SD_IRQHandler SDIO_IRQHandler
|
||||
#define BSP_SD_DMA_Tx_IRQHandler DMA2_Stream6_IRQHandler
|
||||
#define BSP_SD_DMA_Rx_IRQHandler DMA2_Stream3_IRQHandler
|
||||
#define SD_DetectIRQHandler() HAL_GPIO_EXTI_IRQHandler(SD_DETECT_PIN)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_SD_Exported_Functions STM32412G DISCOVERY SD Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_SD_Init(void);
|
||||
uint8_t BSP_SD_DeInit(void);
|
||||
uint8_t BSP_SD_ITConfig(void);
|
||||
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout);
|
||||
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout);
|
||||
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks);
|
||||
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks);
|
||||
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr);
|
||||
uint8_t BSP_SD_GetCardState(void);
|
||||
void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypeDef *CardInfo);
|
||||
uint8_t BSP_SD_IsDetected(void);
|
||||
|
||||
/* These functions can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */
|
||||
void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params);
|
||||
void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params);
|
||||
void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params);
|
||||
void BSP_SD_AbortCallback(void);
|
||||
void BSP_SD_WriteCpltCallback(void);
|
||||
void BSP_SD_ReadCpltCallback(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_SD_H */
|
||||
@@ -0,0 +1,471 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_ts.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides a set of functions needed to manage the Touch
|
||||
* Screen on STM32412G-DISCOVERY evaluation board.
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* File Info : -----------------------------------------------------------------
|
||||
User NOTES
|
||||
1. How To use this driver:
|
||||
--------------------------
|
||||
- This driver is used to drive the touch screen module of the STM32412G-DISCOVERY
|
||||
evaluation board on the FRIDA LCD mounted on MB1209 daughter board.
|
||||
The touch screen driver IC is a FT6x36 type which share the same register naming
|
||||
with FT6206 type.
|
||||
|
||||
2. Driver description:
|
||||
---------------------
|
||||
+ Initialization steps:
|
||||
o Initialize the TS module using the BSP_TS_Init() function. This
|
||||
function includes the MSP layer hardware resources initialization and the
|
||||
communication layer configuration to start the TS use. The LCD size properties
|
||||
(x and y) are passed as parameters.
|
||||
o If TS interrupt mode is desired, you must configure the TS interrupt mode
|
||||
by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated
|
||||
as an external interrupt whenever a touch is detected.
|
||||
|
||||
+ Touch screen use
|
||||
o The touch screen state is captured whenever the function BSP_TS_GetState() is
|
||||
used. This function returns information about the last LCD touch occurred
|
||||
in the TS_StateTypeDef structure.
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery.h"
|
||||
#include "stm32412g_discovery_ts.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS STM32412G-DISCOVERY TS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS_Private_Variables STM32412G Discovery TS Private Variables
|
||||
* @{
|
||||
*/
|
||||
static TS_DrvTypeDef *tsDriver;
|
||||
static uint8_t I2C_Address = 0;
|
||||
static uint8_t tsOrientation = TS_SWAP_NONE;
|
||||
|
||||
/* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */
|
||||
char * ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None",
|
||||
"Press down",
|
||||
"Lift up",
|
||||
"Contact"
|
||||
};
|
||||
|
||||
/* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */
|
||||
char * ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None",
|
||||
"Move Up",
|
||||
"Move Right",
|
||||
"Move Down",
|
||||
"Move Left",
|
||||
"Zoom In",
|
||||
"Zoom Out"
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS_Private_Functions STM32412G Discovery TS Private Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Initializes and configures the touch screen functionalities and
|
||||
* configures all necessary hardware resources (GPIOs, I2C, clocks..).
|
||||
* @param ts_SizeX : Maximum X size of the TS area on LCD
|
||||
* @param ts_SizeY : Maximum Y size of the TS area on LCD
|
||||
* @retval TS_OK if all initializations are OK. Other value if error.
|
||||
*/
|
||||
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY)
|
||||
{
|
||||
return (BSP_TS_InitEx(ts_SizeX, ts_SizeY, TS_ORIENTATION_LANDSCAPE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes and configures the touch screen functionalities and
|
||||
* configures all necessary hardware resources (GPIOs, I2C, clocks..)
|
||||
* with a given orientation
|
||||
* @param ts_SizeX : Maximum X size of the TS area on LCD
|
||||
* @param ts_SizeY : Maximum Y size of the TS area on LCD
|
||||
* @param orientation : TS_ORIENTATION_LANDSCAPE or TS_ORIENTATION_PORTRAIT
|
||||
* @retval TS_OK if all initializations are OK. Other value if error.
|
||||
*/
|
||||
uint8_t BSP_TS_InitEx(uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation)
|
||||
{
|
||||
uint8_t ts_status = TS_OK;
|
||||
uint32_t id_value = 0;
|
||||
|
||||
/* Note : I2C_Address is un-initialized here, but is not used at all in init function */
|
||||
/* but the prototype of Init() is like that in template and should be respected */
|
||||
|
||||
/* Initialize the communication channel to sensor (I2C) if necessary */
|
||||
/* that is initialization is done only once after a power up */
|
||||
/* Scan TouchScreen IC controllers ID register by I2C Read */
|
||||
|
||||
/* ft6x06 TouchScreen IC controller reset sequence */
|
||||
BSP_TS_Reset();
|
||||
ft6x06_ts_drv.Init(I2C_Address);
|
||||
id_value = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS);
|
||||
|
||||
/* Verify this is a FT6x36 or FT3x67, otherwise this is an error case */
|
||||
if(id_value == FT6x36_ID_VALUE)
|
||||
{
|
||||
/* Found FT6x36 : Initialize the TS driver structure */
|
||||
tsDriver = &ft6x06_ts_drv;
|
||||
|
||||
I2C_Address = TS_I2C_ADDRESS;
|
||||
|
||||
/* Get LCD chosen orientation */
|
||||
if(orientation == TS_ORIENTATION_PORTRAIT)
|
||||
{
|
||||
tsOrientation = TS_SWAP_X | TS_SWAP_Y;
|
||||
}
|
||||
else if(orientation == TS_ORIENTATION_LANDSCAPE_ROT180)
|
||||
{
|
||||
tsOrientation = TS_SWAP_XY;
|
||||
}
|
||||
else
|
||||
{
|
||||
tsOrientation = TS_SWAP_XY | TS_SWAP_Y;
|
||||
}
|
||||
|
||||
if(ts_status == TS_OK)
|
||||
{
|
||||
/* Software reset the TouchScreen */
|
||||
tsDriver->Reset(I2C_Address);
|
||||
|
||||
/* Calibrate, Configure and Start the TouchScreen driver */
|
||||
tsDriver->Start(I2C_Address);
|
||||
|
||||
} /* of if(ts_status == TS_OK) */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ft3x67 TouchScreen IC controller reset sequence */
|
||||
BSP_TS_Reset();
|
||||
ft3x67_ts_drv.Init(I2C_Address);
|
||||
id_value = ft3x67_ts_drv.ReadID(TS_I2C_ADDRESS);
|
||||
|
||||
if(id_value == FT3X67_ID_VALUE)
|
||||
{
|
||||
/* Found FT3x67 : Initialize the TS driver structure */
|
||||
tsDriver = &ft3x67_ts_drv;
|
||||
|
||||
I2C_Address = TS_I2C_ADDRESS;
|
||||
|
||||
/* Get LCD chosen orientation */
|
||||
if(orientation == TS_ORIENTATION_PORTRAIT)
|
||||
{
|
||||
tsOrientation = TS_SWAP_X | TS_SWAP_Y;
|
||||
}
|
||||
else if(orientation == TS_ORIENTATION_LANDSCAPE_ROT180)
|
||||
{
|
||||
tsOrientation = TS_SWAP_XY;
|
||||
}
|
||||
else
|
||||
{
|
||||
tsOrientation = TS_SWAP_XY | TS_SWAP_Y;
|
||||
}
|
||||
|
||||
if(ts_status == TS_OK)
|
||||
{
|
||||
/* Software reset the TouchScreen */
|
||||
tsDriver->Reset(I2C_Address);
|
||||
|
||||
/* Calibrate, Configure and Start the TouchScreen driver */
|
||||
tsDriver->Start(I2C_Address);
|
||||
|
||||
} /* of if(ts_status == TS_OK) */
|
||||
}
|
||||
else
|
||||
{
|
||||
ts_status = TS_DEVICE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
return (ts_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures and enables the touch screen interrupts.
|
||||
* @retval TS_OK if all initializations are OK. Other value if error.
|
||||
*/
|
||||
uint8_t BSP_TS_ITConfig(void)
|
||||
{
|
||||
uint8_t ts_status = TS_OK;
|
||||
|
||||
/* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x36 */
|
||||
/* When touchscreen is operated in interrupt mode */
|
||||
BSP_TS_INT_MspInit();
|
||||
|
||||
/* Enable and set the TS_INT EXTI Interrupt to an intermediate priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), 0x0F, 0x00);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn));
|
||||
|
||||
/* Enable the TS in interrupt mode */
|
||||
/* In that case the INT output of FT6206 when new touch is available */
|
||||
/* is active on low level and directed on EXTI */
|
||||
tsDriver->EnableIT(I2C_Address);
|
||||
|
||||
return (ts_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns status and positions of the touch screen.
|
||||
* @param TS_State: Pointer to touch screen current state structure
|
||||
* @retval TS_OK if all initializations are OK. Other value if error.
|
||||
*/
|
||||
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State)
|
||||
{
|
||||
static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
|
||||
static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
|
||||
uint8_t ts_status = TS_OK;
|
||||
uint16_t tmp;
|
||||
uint16_t Raw_x[TS_MAX_NB_TOUCH];
|
||||
uint16_t Raw_y[TS_MAX_NB_TOUCH];
|
||||
uint16_t xDiff;
|
||||
uint16_t yDiff;
|
||||
uint32_t index;
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
uint32_t weight = 0;
|
||||
uint32_t area = 0;
|
||||
uint32_t event = 0;
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
/* Check and update the number of touches active detected */
|
||||
TS_State->touchDetected = tsDriver->DetectTouch(I2C_Address);
|
||||
if(TS_State->touchDetected)
|
||||
{
|
||||
for(index=0; index < TS_State->touchDetected; index++)
|
||||
{
|
||||
/* Get each touch coordinates */
|
||||
tsDriver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index]));
|
||||
|
||||
if(tsOrientation & TS_SWAP_XY)
|
||||
{
|
||||
tmp = Raw_x[index];
|
||||
Raw_x[index] = Raw_y[index];
|
||||
Raw_y[index] = tmp;
|
||||
}
|
||||
|
||||
if(tsOrientation & TS_SWAP_X)
|
||||
{
|
||||
Raw_x[index] = FT_6206_MAX_WIDTH_HEIGHT - 1 - Raw_x[index];
|
||||
}
|
||||
|
||||
if(tsOrientation & TS_SWAP_Y)
|
||||
{
|
||||
Raw_y[index] = FT_6206_MAX_WIDTH_HEIGHT - 1 - Raw_y[index];
|
||||
}
|
||||
|
||||
xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]);
|
||||
yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]);
|
||||
|
||||
if ((xDiff + yDiff) > 5)
|
||||
{
|
||||
_x[index] = Raw_x[index];
|
||||
_y[index] = Raw_y[index];
|
||||
}
|
||||
|
||||
|
||||
TS_State->touchX[index] = _x[index];
|
||||
TS_State->touchY[index] = _y[index];
|
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
|
||||
/* Get touch info related to the current touch */
|
||||
ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event);
|
||||
|
||||
/* Update TS_State structure */
|
||||
TS_State->touchWeight[index] = weight;
|
||||
TS_State->touchArea[index] = area;
|
||||
|
||||
/* Remap touch event */
|
||||
switch(event)
|
||||
{
|
||||
case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN :
|
||||
TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN;
|
||||
break;
|
||||
case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
|
||||
TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP;
|
||||
break;
|
||||
case FT6206_TOUCH_EVT_FLAG_CONTACT :
|
||||
TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT;
|
||||
break;
|
||||
case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
|
||||
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
|
||||
break;
|
||||
default :
|
||||
ts_status = TS_ERROR;
|
||||
break;
|
||||
} /* of switch(event) */
|
||||
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
} /* of for(index=0; index < TS_State->touchDetected; index++) */
|
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
/* Get gesture Id */
|
||||
ts_status = BSP_TS_Get_GestureId(TS_State);
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
} /* end of if(TS_State->touchDetected != 0) */
|
||||
|
||||
return (ts_status);
|
||||
}
|
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
/**
|
||||
* @brief Update gesture Id following a touch detected.
|
||||
* @param TS_State: Pointer to touch screen current state structure
|
||||
* @retval TS_OK if all initializations are OK. Other value if error.
|
||||
*/
|
||||
uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State)
|
||||
{
|
||||
uint32_t gestureId = 0;
|
||||
uint8_t ts_status = TS_OK;
|
||||
|
||||
/* Get gesture Id */
|
||||
ft6x06_TS_GetGestureID(I2C_Address, &gestureId);
|
||||
|
||||
/* Remap gesture Id to a TS_GestureIdTypeDef value */
|
||||
switch(gestureId)
|
||||
{
|
||||
case FT6206_GEST_ID_NO_GESTURE :
|
||||
TS_State->gestureId = GEST_ID_NO_GESTURE;
|
||||
break;
|
||||
case FT6206_GEST_ID_MOVE_UP :
|
||||
TS_State->gestureId = GEST_ID_MOVE_UP;
|
||||
break;
|
||||
case FT6206_GEST_ID_MOVE_RIGHT :
|
||||
TS_State->gestureId = GEST_ID_MOVE_RIGHT;
|
||||
break;
|
||||
case FT6206_GEST_ID_MOVE_DOWN :
|
||||
TS_State->gestureId = GEST_ID_MOVE_DOWN;
|
||||
break;
|
||||
case FT6206_GEST_ID_MOVE_LEFT :
|
||||
TS_State->gestureId = GEST_ID_MOVE_LEFT;
|
||||
break;
|
||||
case FT6206_GEST_ID_ZOOM_IN :
|
||||
TS_State->gestureId = GEST_ID_ZOOM_IN;
|
||||
break;
|
||||
case FT6206_GEST_ID_ZOOM_OUT :
|
||||
TS_State->gestureId = GEST_ID_ZOOM_OUT;
|
||||
break;
|
||||
default :
|
||||
ts_status = TS_ERROR;
|
||||
break;
|
||||
} /* of switch(gestureId) */
|
||||
|
||||
return(ts_status);
|
||||
}
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
/**
|
||||
* @brief Function used to reset all touch data before a new acquisition
|
||||
* of touch information.
|
||||
* @param TS_State: Pointer to touch screen current state structure
|
||||
* @retval TS_OK if OK, TE_ERROR if problem found.
|
||||
*/
|
||||
uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State)
|
||||
{
|
||||
uint8_t ts_status = TS_ERROR;
|
||||
uint32_t index;
|
||||
|
||||
if (TS_State != (TS_StateTypeDef *)NULL)
|
||||
{
|
||||
TS_State->gestureId = GEST_ID_NO_GESTURE;
|
||||
TS_State->touchDetected = 0;
|
||||
|
||||
for(index = 0; index < TS_MAX_NB_TOUCH; index++)
|
||||
{
|
||||
TS_State->touchX[index] = 0;
|
||||
TS_State->touchY[index] = 0;
|
||||
TS_State->touchArea[index] = 0;
|
||||
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
|
||||
TS_State->touchWeight[index] = 0;
|
||||
}
|
||||
|
||||
ts_status = TS_OK;
|
||||
|
||||
} /* of if (TS_State != (TS_StateTypeDef *)NULL) */
|
||||
|
||||
return (ts_status);
|
||||
}
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
/**
|
||||
* @brief Function used to Hardware reset the touch screen.
|
||||
*/
|
||||
void BSP_TS_Reset(void)
|
||||
{
|
||||
/* TouchScreen IC controller reset sequence */
|
||||
HAL_GPIO_WritePin(TS_RST_GPIO_PORT, TS_RST_PIN, GPIO_PIN_RESET);
|
||||
HAL_Delay(10);
|
||||
HAL_GPIO_WritePin(TS_RST_GPIO_PORT, TS_RST_PIN, GPIO_PIN_SET);
|
||||
|
||||
while (HAL_GPIO_ReadPin(TS_RST_GPIO_PORT , TS_RST_PIN)!= GPIO_PIN_RESET);
|
||||
while (HAL_GPIO_ReadPin(TS_INT_GPIO_PORT , TS_INT_PIN)!= GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes the TS_INT pin MSP.
|
||||
*/
|
||||
__weak void BSP_TS_INT_MspInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
TS_INT_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */
|
||||
/* TS_INT pin is active on low level on new touch available */
|
||||
gpio_init_structure.Pin = TS_INT_PIN;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
gpio_init_structure.Mode = GPIO_MODE_IT_FALLING;
|
||||
HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* Configure reset pin */
|
||||
TS_RST_GPIO_CLK_ENABLE();
|
||||
gpio_init_structure.Pin = TS_RST_PIN;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
||||
gpio_init_structure.Mode = GPIO_MODE_INPUT;
|
||||
HAL_GPIO_Init(TS_RST_GPIO_PORT, &gpio_init_structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32412g_discovery_ts.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32412g_discovery_ts.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 __STM32412G_DISCOVERY_TS_H
|
||||
#define __STM32412G_DISCOVERY_TS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32412g_discovery.h"
|
||||
#include "stm32412g_discovery_lcd.h"
|
||||
|
||||
/* Include TouchScreen component driver */
|
||||
#include "../Components/ft6x06/ft6x06.h"
|
||||
#include "../Components/ft3x67/ft3x67.h"
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32412G_DISCOVERY_TS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS_Exported_Constants STM32412G Discovery TS Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/** @brief With FT6206 : maximum 2 touches detected simultaneously
|
||||
*/
|
||||
#define TS_MAX_NB_TOUCH ((uint32_t) FT6206_MAX_DETECTABLE_TOUCH)
|
||||
|
||||
#define TS_NO_IRQ_PENDING ((uint8_t) 0)
|
||||
#define TS_IRQ_PENDING ((uint8_t) 1)
|
||||
|
||||
#define TS_SWAP_NONE ((uint8_t) 0x01)
|
||||
#define TS_SWAP_X ((uint8_t) 0x02)
|
||||
#define TS_SWAP_Y ((uint8_t) 0x04)
|
||||
#define TS_SWAP_XY ((uint8_t) 0x08)
|
||||
|
||||
#define TS_ORIENTATION_PORTRAIT ((uint8_t) 0)
|
||||
#define TS_ORIENTATION_LANDSCAPE ((uint8_t) 1)
|
||||
#define TS_ORIENTATION_LANDSCAPE_ROT180 ((uint8_t) 2)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS_Exported_Types STM32412G Discovery TS Exported Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief TS_StateTypeDef
|
||||
* Define TS State structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t touchDetected; /*!< Total number of active touches detected at last scan */
|
||||
uint16_t touchX[TS_MAX_NB_TOUCH]; /*!< Touch X[0], X[1] coordinates on 12 bits */
|
||||
uint16_t touchY[TS_MAX_NB_TOUCH]; /*!< Touch Y[0], Y[1] coordinates on 12 bits */
|
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
uint8_t touchWeight[TS_MAX_NB_TOUCH]; /*!< Touch_Weight[0], Touch_Weight[1] : weight property of touches */
|
||||
uint8_t touchEventId[TS_MAX_NB_TOUCH]; /*!< Touch_EventId[0], Touch_EventId[1] : take value of type @ref TS_TouchEventTypeDef */
|
||||
uint8_t touchArea[TS_MAX_NB_TOUCH]; /*!< Touch_Area[0], Touch_Area[1] : touch area of each touch */
|
||||
uint32_t gestureId; /*!< type of gesture detected : take value of type @ref TS_GestureIdTypeDef */
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
} TS_StateTypeDef;
|
||||
|
||||
/**
|
||||
* @brief TS_StatusTypeDef
|
||||
* Define BSP_TS_xxx() functions possible return value,
|
||||
* when status is returned by those functions.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TS_OK = 0x00, /*!< Touch Ok */
|
||||
TS_ERROR = 0x01, /*!< Touch Error */
|
||||
TS_TIMEOUT = 0x02, /*!< Touch Timeout */
|
||||
TS_DEVICE_NOT_FOUND = 0x03 /*!< Touchscreen device not found */
|
||||
} TS_StatusTypeDef;
|
||||
|
||||
/**
|
||||
* @brief TS_GestureIdTypeDef
|
||||
* Define Possible managed gesture identification values returned by touch screen
|
||||
* driver.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GEST_ID_NO_GESTURE = 0x00, /*!< Gesture not defined / recognized */
|
||||
GEST_ID_MOVE_UP = 0x01, /*!< Gesture Move Up */
|
||||
GEST_ID_MOVE_RIGHT = 0x02, /*!< Gesture Move Right */
|
||||
GEST_ID_MOVE_DOWN = 0x03, /*!< Gesture Move Down */
|
||||
GEST_ID_MOVE_LEFT = 0x04, /*!< Gesture Move Left */
|
||||
GEST_ID_ZOOM_IN = 0x05, /*!< Gesture Zoom In */
|
||||
GEST_ID_ZOOM_OUT = 0x06, /*!< Gesture Zoom Out */
|
||||
GEST_ID_NB_MAX = 0x07 /*!< max number of gesture id */
|
||||
} TS_GestureIdTypeDef;
|
||||
|
||||
/**
|
||||
* @brief TS_TouchEventTypeDef
|
||||
* Define Possible touch events kind as returned values
|
||||
* by touch screen IC Driver.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TOUCH_EVENT_NO_EVT = 0x00, /*!< Touch Event : undetermined */
|
||||
TOUCH_EVENT_PRESS_DOWN = 0x01, /*!< Touch Event Press Down */
|
||||
TOUCH_EVENT_LIFT_UP = 0x02, /*!< Touch Event Lift Up */
|
||||
TOUCH_EVENT_CONTACT = 0x03, /*!< Touch Event Contact */
|
||||
TOUCH_EVENT_NB_MAX = 0x04 /*!< max number of touch events kind */
|
||||
} TS_TouchEventTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS_Imported_Variables STM32412G DISCOVERY TS Imported Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Table for touchscreen event information display on LCD :
|
||||
* table indexed on enum @ref TS_TouchEventTypeDef information
|
||||
*/
|
||||
extern char * ts_event_string_tab[TOUCH_EVENT_NB_MAX];
|
||||
|
||||
/**
|
||||
* @brief Table for touchscreen gesture Id information display on LCD : table indexed
|
||||
* on enum @ref TS_GestureIdTypeDef information
|
||||
*/
|
||||
extern char * ts_gesture_id_string_tab[GEST_ID_NB_MAX];
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32412G_DISCOVERY_TS_Exported_Functions STM32412G Discovery TS Exported Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY);
|
||||
uint8_t BSP_TS_InitEx(uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation);
|
||||
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State);
|
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
|
||||
uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State);
|
||||
uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State);
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
|
||||
|
||||
uint8_t BSP_TS_ITConfig(void);
|
||||
void BSP_TS_Reset(void);
|
||||
|
||||
/* These __weak function can be surcharged by application code in case the current settings
|
||||
need to be changed for specific (example GPIO allocation) */
|
||||
void BSP_TS_INT_MspInit(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32412G_DISCOVERY_TS_H */
|
||||
Reference in New Issue
Block a user