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/stm32f4xx-nucleo/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 [stm32f4xx-nucleo](https://github.com/STMicroelectronics/stm32f4xx-nucleo/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,36 @@
|
||||
# BSP STM32F4XX-NUCLEO 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 **stm32f4xx-nucleo** MCU component repository is one element of the **STM32CubeF4** MCU embedded software package, providing the **STM32F4XX-NUCLEO** 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/stm32f4xx-nucleo/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)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) guide.
|
||||
@@ -0,0 +1,31 @@
|
||||
# Report potential product security vulnerabilities
|
||||
|
||||
ST places a high priority on security, and our Product Security Incident
|
||||
Response Team (PSIRT) is committed to rapidly addressing potential security
|
||||
vulnerabilities affecting our products. PSIRT's long history and vast experience
|
||||
in security allows ST to perform clear analyses and provide appropriate guidance
|
||||
on mitigations and solutions when applicable.
|
||||
|
||||
If you wish to report potential security vulnerabilities regarding our products,
|
||||
**please do not report them through public GitHub issues.** Instead, we
|
||||
encourage you to report them to our ST PSIRT following the process described at:
|
||||
**https://www.st.com/content/st_com/en/security/report-vulnerabilities.html**
|
||||
|
||||
### IMPORTANT - READ CAREFULLY:
|
||||
|
||||
STMicroelectronics International N.V., on behalf of itself, its affiliates and
|
||||
subsidiaries, (collectively “ST”) takes all potential security vulnerability
|
||||
reports or other related communications (“Report(s)”) seriously. In order to
|
||||
review Your Report (the terms “You” and “Yours” include your employer, and all
|
||||
affiliates, subsidiaries and related persons or entities) and take actions as
|
||||
deemed appropriate, ST requires that we have the rights and Your permission to
|
||||
do so.
|
||||
|
||||
As such, by submitting Your Report to ST, You agree that You have the right to
|
||||
do so, and You grant to ST the rights to use the Report for purposes related to
|
||||
security vulnerability analysis, testing, correction, patching, reporting and
|
||||
any other related purpose or function.
|
||||
|
||||
By submitting Your Report, You agree that ST’s
|
||||
[Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html)
|
||||
applies to all related communications.
|
||||
@@ -0,0 +1,844 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4xx_nucleo.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides set of firmware functions to manage:
|
||||
* - LEDs and push-button available on STM32F4XX-Nucleo Kit
|
||||
* from STMicroelectronics
|
||||
* - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD
|
||||
* shield (reference ID 802)
|
||||
******************************************************************************
|
||||
* @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 "stm32f4xx_nucleo.h"
|
||||
|
||||
/** @defgroup BSP BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO STM32F4XX NUCLEO
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL STM32F4XX NUCLEO LOW LEVEL
|
||||
* @brief This file provides set of firmware functions to manage Leds and push-button
|
||||
* available on STM32F4xx-Nucleo Kit from STMicroelectronics.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions STM32F4XX NUCLEO LOW LEVEL Private TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Defines STM32F4XX NUCLEO LOW LEVEL Private Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief STM32F4xx NUCLEO BSP Driver version number V1.2.9
|
||||
*/
|
||||
#define __STM32F4xx_NUCLEO_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
|
||||
#define __STM32F4xx_NUCLEO_BSP_VERSION_SUB1 (0x02) /*!< [23:16] sub1 version */
|
||||
#define __STM32F4xx_NUCLEO_BSP_VERSION_SUB2 (0x09) /*!< [15:8] sub2 version */
|
||||
#define __STM32F4xx_NUCLEO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
|
||||
#define __STM32F4xx_NUCLEO_BSP_VERSION ((__STM32F4xx_NUCLEO_BSP_VERSION_MAIN << 24)\
|
||||
|(__STM32F4xx_NUCLEO_BSP_VERSION_SUB1 << 16)\
|
||||
|(__STM32F4xx_NUCLEO_BSP_VERSION_SUB2 << 8 )\
|
||||
|(__STM32F4xx_NUCLEO_BSP_VERSION_RC))
|
||||
|
||||
/**
|
||||
* @brief LINK SD Card
|
||||
*/
|
||||
#define SD_DUMMY_BYTE 0xFF
|
||||
#define SD_NO_RESPONSE_EXPECTED 0x80
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Macros STM32F4XX NUCLEO LOW LEVEL Private Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Variables STM32F4XX NUCLEO LOW LEVEL Private Variables
|
||||
* @{
|
||||
*/
|
||||
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT};
|
||||
|
||||
const uint16_t GPIO_PIN[LEDn] = {LED2_PIN};
|
||||
|
||||
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT};
|
||||
const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN};
|
||||
const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn};
|
||||
|
||||
/**
|
||||
* @brief BUS variables
|
||||
*/
|
||||
|
||||
#ifdef ADAFRUIT_TFT_JOY_SD_ID802
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
uint32_t SpixTimeout = NUCLEO_SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
|
||||
static SPI_HandleTypeDef hnucleo_Spi;
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
static ADC_HandleTypeDef hnucleo_Adc;
|
||||
/* ADC channel configuration structure declaration */
|
||||
static ADC_ChannelConfTypeDef sConfig;
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
#endif /* ADAFRUIT_TFT_JOY_SD_ID802 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes STM32F4XX NUCLEO LOW LEVEL Private FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
#ifdef ADAFRUIT_TFT_JOY_SD_ID802
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
static void SPIx_Init(void);
|
||||
static void SPIx_Write(uint8_t Value);
|
||||
static void SPIx_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLegnth);
|
||||
static void SPIx_Error(void);
|
||||
static void SPIx_MspInit(SPI_HandleTypeDef *hspi);
|
||||
|
||||
/* SD IO functions */
|
||||
void SD_IO_Init(void);
|
||||
void SD_IO_CSState(uint8_t state);
|
||||
void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength);
|
||||
uint8_t SD_IO_WriteByte(uint8_t Data);
|
||||
|
||||
/* LCD IO functions */
|
||||
void LCD_IO_Init(void);
|
||||
void LCD_IO_WriteData(uint8_t Data);
|
||||
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
|
||||
void LCD_IO_WriteReg(uint8_t LCDReg);
|
||||
void LCD_Delay(uint32_t delay);
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
static void ADCx_Init(void);
|
||||
static void ADCx_DeInit(void);
|
||||
static void ADCx_MspInit(ADC_HandleTypeDef *hadc);
|
||||
static void ADCx_MspDeInit(ADC_HandleTypeDef *hadc);
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#endif /* ADAFRUIT_TFT_JOY_SD_ID802 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Functions STM32F4XX NUCLEO LOW LEVEL Private Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This method returns the STM32F4xx NUCLEO BSP Driver revision
|
||||
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
uint32_t BSP_GetVersion(void)
|
||||
{
|
||||
return __STM32F4xx_NUCLEO_BSP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures LED GPIO.
|
||||
* @param Led: Specifies the Led to be configured.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED2
|
||||
*/
|
||||
void BSP_LED_Init(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable the GPIO_LED Clock */
|
||||
LEDx_GPIO_CLK_ENABLE(Led);
|
||||
|
||||
/* Configure the GPIO_LED pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN[Led];
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
|
||||
HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
|
||||
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInit LEDs.
|
||||
* @param Led: LED to be de-init.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED2
|
||||
* @note Led DeInit does not disable the GPIO clock nor disable the Mfx
|
||||
*/
|
||||
void BSP_LED_DeInit(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Turn off LED */
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
/* DeInit the GPIO_LED pin */
|
||||
gpio_init_structure.Pin = GPIO_PIN[Led];
|
||||
HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED On.
|
||||
* @param Led: Specifies the Led to be set on.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED2
|
||||
*/
|
||||
void BSP_LED_On(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED Off.
|
||||
* @param Led: Specifies the Led to be set off.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED2
|
||||
*/
|
||||
void BSP_LED_Off(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the selected LED.
|
||||
* @param Led: Specifies the Led to be toggled.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg LED2
|
||||
*/
|
||||
void BSP_LED_Toggle(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures Button GPIO and EXTI Line.
|
||||
* @param Button: Specifies the Button to be configured.
|
||||
* This parameter should be: BUTTON_KEY
|
||||
* @param ButtonMode: Specifies Button mode.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
||||
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
|
||||
* generation capability
|
||||
*/
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Enable the BUTTON Clock */
|
||||
BUTTONx_GPIO_CLK_ENABLE(Button);
|
||||
|
||||
if(ButtonMode == BUTTON_MODE_GPIO)
|
||||
{
|
||||
/* Configure Button pin as input */
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
if(ButtonMode == BUTTON_MODE_EXTI)
|
||||
{
|
||||
/* Configure Button pin as input with External interrupt */
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
|
||||
|
||||
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Push Button DeInit.
|
||||
* @param Button: Button to be configured
|
||||
* This parameter should be: BUTTON_KEY
|
||||
* @note PB DeInit does not disable the GPIO clock
|
||||
*/
|
||||
void BSP_PB_DeInit(Button_TypeDef Button)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
||||
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the selected Button state.
|
||||
* @param Button: Specifies the Button to be checked.
|
||||
* This parameter should be: BUTTON_KEY
|
||||
* @retval The Button GPIO pin value.
|
||||
*/
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
||||
{
|
||||
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
BUS OPERATIONS
|
||||
*******************************************************************************/
|
||||
#ifdef ADAFRUIT_TFT_JOY_SD_ID802
|
||||
|
||||
/******************************* SPI ********************************/
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
|
||||
/**
|
||||
* @brief Initializes SPI MSP.
|
||||
*/
|
||||
static void SPIx_MspInit(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/*** Configure the GPIOs ***/
|
||||
/* Enable GPIO clock */
|
||||
NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE();
|
||||
NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure SPI SCK */
|
||||
GPIO_InitStruct.Pin = NUCLEO_SPIx_SCK_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Alternate = NUCLEO_SPIx_SCK_AF;
|
||||
HAL_GPIO_Init(NUCLEO_SPIx_SCK_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* Configure SPI MISO and MOSI */
|
||||
GPIO_InitStruct.Pin = NUCLEO_SPIx_MOSI_PIN;
|
||||
GPIO_InitStruct.Alternate = NUCLEO_SPIx_MISO_MOSI_AF;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(NUCLEO_SPIx_MISO_MOSI_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = NUCLEO_SPIx_MISO_PIN;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(NUCLEO_SPIx_MISO_MOSI_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/*** Configure the SPI peripheral ***/
|
||||
/* Enable SPI clock */
|
||||
NUCLEO_SPIx_CLK_ENABLE();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes SPI HAL.
|
||||
*/
|
||||
static void SPIx_Init(void)
|
||||
{
|
||||
if(HAL_SPI_GetState(&hnucleo_Spi) == HAL_SPI_STATE_RESET)
|
||||
{
|
||||
/* SPI Config */
|
||||
hnucleo_Spi.Instance = NUCLEO_SPIx;
|
||||
/* SPI baudrate is set to 12,5 MHz maximum (APB1/SPI_BaudRatePrescaler = 100/8 = 12,5 MHz)
|
||||
to verify these constraints:
|
||||
- ST7735 LCD SPI interface max baudrate is 15MHz for write and 6.66MHz for read
|
||||
Since the provided driver doesn't use read capability from LCD, only constraint
|
||||
on write baudrate is considered.
|
||||
- SD card SPI interface max baudrate is 25MHz for write/read
|
||||
- PCLK2 max frequency is 100 MHz
|
||||
*/
|
||||
hnucleo_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
||||
hnucleo_Spi.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hnucleo_Spi.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||
hnucleo_Spi.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||
hnucleo_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
|
||||
hnucleo_Spi.Init.CRCPolynomial = 7;
|
||||
hnucleo_Spi.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hnucleo_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hnucleo_Spi.Init.NSS = SPI_NSS_SOFT;
|
||||
hnucleo_Spi.Init.TIMode = SPI_TIMODE_DISABLED;
|
||||
hnucleo_Spi.Init.Mode = SPI_MODE_MASTER;
|
||||
|
||||
SPIx_MspInit(&hnucleo_Spi);
|
||||
HAL_SPI_Init(&hnucleo_Spi);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI Write a byte to device
|
||||
* @param DataIn: value to be written
|
||||
* @param DataOut: value to be read
|
||||
* @param DataLegnth: length of data
|
||||
*/
|
||||
static void SPIx_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLegnth)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
status = HAL_SPI_TransmitReceive(&hnucleo_Spi, (uint8_t*) DataIn, DataOut, DataLegnth, SpixTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Execute user timeout callback */
|
||||
SPIx_Error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI Write a byte to device.
|
||||
* @param Value: value to be written
|
||||
*/
|
||||
static void SPIx_Write(uint8_t Value)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint8_t data;
|
||||
|
||||
status = HAL_SPI_TransmitReceive(&hnucleo_Spi, (uint8_t*) &Value, &data, 1, SpixTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Execute user timeout callback */
|
||||
SPIx_Error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI error treatment function.
|
||||
*/
|
||||
static void SPIx_Error (void)
|
||||
{
|
||||
/* De-initialize the SPI communication BUS */
|
||||
HAL_SPI_DeInit(&hnucleo_Spi);
|
||||
|
||||
/* Re-Initiaize the SPI communication BUS */
|
||||
SPIx_Init();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
LINK OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/********************************* LINK SD ************************************/
|
||||
/**
|
||||
* @brief Initializes the SD Card and put it into StandBy State (Ready for
|
||||
* data transfer).
|
||||
*/
|
||||
void SD_IO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
uint8_t counter;
|
||||
|
||||
/* SD_CS_GPIO Periph clock enable */
|
||||
SD_CS_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure SD_CS_PIN pin: SD Card CS pin */
|
||||
GPIO_InitStruct.Pin = SD_CS_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
HAL_GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/*------------Put SD in SPI mode--------------*/
|
||||
/* SD SPI Config */
|
||||
SPIx_Init();
|
||||
|
||||
/* SD chip select high */
|
||||
SD_CS_HIGH();
|
||||
|
||||
/* Send dummy byte 0xFF, 10 times with CS high */
|
||||
/* Rise CS and MOSI for 80 clocks cycles */
|
||||
for (counter = 0; counter <= 9; counter++)
|
||||
{
|
||||
/* Send dummy byte 0xFF */
|
||||
SD_IO_WriteByte(SD_DUMMY_BYTE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the SD_CS pin.
|
||||
* @param val: pin value.
|
||||
*/
|
||||
void SD_IO_CSState(uint8_t val)
|
||||
{
|
||||
if(val == 1)
|
||||
{
|
||||
SD_CS_HIGH();
|
||||
}
|
||||
else
|
||||
{
|
||||
SD_CS_LOW();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a byte on the SD.
|
||||
* @param DataIn: value to be written
|
||||
* @param DataOut: value to be read
|
||||
* @param DataLength: length of data
|
||||
*/
|
||||
void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength)
|
||||
{
|
||||
/* Send the byte */
|
||||
SPIx_WriteReadData(DataIn, DataOut, DataLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a byte on the SD.
|
||||
* @param Data: byte to send.
|
||||
*/
|
||||
uint8_t SD_IO_WriteByte(uint8_t Data)
|
||||
{
|
||||
uint8_t tmp;
|
||||
/* Send the byte */
|
||||
SPIx_WriteReadData(&Data,&tmp,1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/********************************* LINK LCD ***********************************/
|
||||
/**
|
||||
* @brief Initializes the LCD.
|
||||
*/
|
||||
void LCD_IO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* LCD_CS_GPIO and LCD_DC_GPIO Periph clock enable */
|
||||
LCD_CS_GPIO_CLK_ENABLE();
|
||||
LCD_DC_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure LCD_CS_PIN pin: LCD Card CS pin */
|
||||
GPIO_InitStruct.Pin = LCD_CS_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
HAL_GPIO_Init(LCD_CS_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* Configure LCD_DC_PIN pin: LCD Card DC pin */
|
||||
GPIO_InitStruct.Pin = LCD_DC_PIN;
|
||||
HAL_GPIO_Init(LCD_DC_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* LCD chip select high */
|
||||
LCD_CS_HIGH();
|
||||
|
||||
/* LCD SPI Config */
|
||||
SPIx_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes command to select the LCD register.
|
||||
* @param LCDReg: Address of the selected register.
|
||||
*/
|
||||
void LCD_IO_WriteReg(uint8_t LCDReg)
|
||||
{
|
||||
/* Reset LCD control line CS */
|
||||
LCD_CS_LOW();
|
||||
|
||||
/* Set LCD data/command line DC to Low */
|
||||
LCD_DC_LOW();
|
||||
|
||||
/* Send Command */
|
||||
SPIx_Write(LCDReg);
|
||||
|
||||
/* Deselect : Chip Select high */
|
||||
LCD_CS_HIGH();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes data to select the LCD register.
|
||||
* This function must be used after st7735_WriteReg() function
|
||||
* @param Data: data to write to the selected register.
|
||||
*/
|
||||
void LCD_IO_WriteData(uint8_t Data)
|
||||
{
|
||||
/* Reset LCD control line CS */
|
||||
LCD_CS_LOW();
|
||||
|
||||
/* Set LCD data/command line DC to High */
|
||||
LCD_DC_HIGH();
|
||||
|
||||
/* Send Data */
|
||||
SPIx_Write(Data);
|
||||
|
||||
/* Deselect : Chip Select high */
|
||||
LCD_CS_HIGH();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes register value.
|
||||
* @param pData: Pointer on the register value
|
||||
* @param Size: Size of byte to transmit to the register
|
||||
*/
|
||||
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
__IO uint32_t data = 0;
|
||||
|
||||
/* Reset LCD control line CS */
|
||||
LCD_CS_LOW();
|
||||
|
||||
/* Set LCD data/command line DC to High */
|
||||
LCD_DC_HIGH();
|
||||
|
||||
if (Size == 1)
|
||||
{
|
||||
/* Only 1 byte to be sent to LCD - general interface can be used */
|
||||
/* Send Data */
|
||||
SPIx_Write(*pData);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Several data should be sent in a raw */
|
||||
/* Direct SPI accesses for optimization */
|
||||
for (counter = Size; counter != 0; counter--)
|
||||
{
|
||||
while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE)
|
||||
{
|
||||
}
|
||||
/* Need to invert bytes for LCD*/
|
||||
*((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *(pData+1);
|
||||
|
||||
while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE)
|
||||
{
|
||||
}
|
||||
*((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *pData;
|
||||
counter--;
|
||||
pData += 2;
|
||||
}
|
||||
|
||||
/* Wait until the bus is ready before releasing Chip select */
|
||||
while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_BSY) != RESET)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty the Rx fifo */
|
||||
data = *(&hnucleo_Spi.Instance->DR);
|
||||
UNUSED(data);
|
||||
|
||||
/* Deselect : Chip Select high */
|
||||
LCD_CS_HIGH();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for loop in ms.
|
||||
* @param Delay in ms.
|
||||
*/
|
||||
void LCD_Delay(uint32_t Delay)
|
||||
{
|
||||
HAL_Delay(Delay);
|
||||
}
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
/******************************* ADC driver ********************************/
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
|
||||
/**
|
||||
* @brief Initializes ADC MSP.
|
||||
*/
|
||||
static void ADCx_MspInit(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/*** Configure the GPIOs ***/
|
||||
/* Enable GPIO clock */
|
||||
NUCLEO_ADCx_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure the selected ADC Channel as analog input */
|
||||
GPIO_InitStruct.Pin = NUCLEO_ADCx_GPIO_PIN ;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(NUCLEO_ADCx_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/*** Configure the ADC peripheral ***/
|
||||
/* Enable ADC clock */
|
||||
NUCLEO_ADCx_CLK_ENABLE();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes ADC MSP.
|
||||
* @note ADC DeInit does not disable the GPIO clock
|
||||
*/
|
||||
static void ADCx_MspDeInit(ADC_HandleTypeDef *hadc)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/*** DeInit the ADC peripheral ***/
|
||||
/* Disable ADC clock */
|
||||
NUCLEO_ADCx_CLK_DISABLE();
|
||||
|
||||
/* Configure the selected ADC Channel as analog input */
|
||||
GPIO_InitStruct.Pin = NUCLEO_ADCx_GPIO_PIN ;
|
||||
HAL_GPIO_DeInit(NUCLEO_ADCx_GPIO_PORT, GPIO_InitStruct.Pin);
|
||||
|
||||
/* Disable GPIO clock has to be done by the application*/
|
||||
/* NUCLEO_ADCx_GPIO_CLK_DISABLE(); */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes ADC HAL.
|
||||
*/
|
||||
static void ADCx_Init(void)
|
||||
{
|
||||
if(HAL_ADC_GetState(&hnucleo_Adc) == HAL_ADC_STATE_RESET)
|
||||
{
|
||||
/* ADC Config */
|
||||
hnucleo_Adc.Instance = NUCLEO_ADCx;
|
||||
hnucleo_Adc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4; /* (must not exceed 36MHz) */
|
||||
hnucleo_Adc.Init.Resolution = ADC_RESOLUTION12b;
|
||||
hnucleo_Adc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hnucleo_Adc.Init.ContinuousConvMode = DISABLE;
|
||||
hnucleo_Adc.Init.DiscontinuousConvMode = DISABLE;
|
||||
hnucleo_Adc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hnucleo_Adc.Init.EOCSelection = EOC_SINGLE_CONV;
|
||||
hnucleo_Adc.Init.NbrOfConversion = 1;
|
||||
hnucleo_Adc.Init.DMAContinuousRequests = DISABLE;
|
||||
|
||||
ADCx_MspInit(&hnucleo_Adc);
|
||||
HAL_ADC_Init(&hnucleo_Adc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes ADC HAL.
|
||||
*/
|
||||
static void ADCx_DeInit(void)
|
||||
{
|
||||
hnucleo_Adc.Instance = NUCLEO_ADCx;
|
||||
|
||||
HAL_ADC_DeInit(&hnucleo_Adc);
|
||||
ADCx_MspDeInit(&hnucleo_Adc);
|
||||
}
|
||||
|
||||
/******************************* LINK JOYSTICK ********************************/
|
||||
|
||||
/**
|
||||
* @brief Configures joystick available on adafruit 1.8" TFT shield
|
||||
* managed through ADC to detect motion.
|
||||
* @retval Joystickstatus (0=> success, 1=> fail)
|
||||
*/
|
||||
uint8_t BSP_JOY_Init(void)
|
||||
{
|
||||
uint8_t status = HAL_ERROR;
|
||||
|
||||
ADCx_Init();
|
||||
|
||||
/* Select the ADC Channel to be converted */
|
||||
sConfig.Channel = NUCLEO_ADCx_CHANNEL;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
|
||||
sConfig.Rank = 1;
|
||||
status = HAL_ADC_ConfigChannel(&hnucleo_Adc, &sConfig);
|
||||
|
||||
/* Return Joystick initialization status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInit joystick GPIOs.
|
||||
* @note JOY DeInit does not disable the Mfx, just set the Mfx pins in Off mode.
|
||||
*/
|
||||
void BSP_JOY_DeInit(void)
|
||||
{
|
||||
ADCx_DeInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the Joystick key pressed.
|
||||
* @note To know which Joystick key is pressed we need to detect the voltage
|
||||
* level on each key output
|
||||
* - None : 3.3 V / 4095
|
||||
* - SEL : 1.055 V / 1308
|
||||
* - DOWN : 0.71 V / 88
|
||||
* - LEFT : 3.0 V / 3720
|
||||
* - RIGHT : 0.595 V / 737
|
||||
* - UP : 1.65 V / 2046
|
||||
* @retval JOYState_TypeDef: Code of the Joystick key pressed.
|
||||
*/
|
||||
JOYState_TypeDef BSP_JOY_GetState(void)
|
||||
{
|
||||
JOYState_TypeDef state;
|
||||
uint16_t keyconvertedvalue = 0;
|
||||
|
||||
/* Start the conversion process */
|
||||
HAL_ADC_Start(&hnucleo_Adc);
|
||||
|
||||
/* Wait for the end of conversion */
|
||||
HAL_ADC_PollForConversion(&hnucleo_Adc, 10);
|
||||
|
||||
/* Check if the continuous conversion of regular channel is finished */
|
||||
if(((HAL_ADC_GetState(&hnucleo_Adc) & HAL_ADC_STATE_EOC_REG) == HAL_ADC_STATE_EOC_REG))
|
||||
{
|
||||
/* Get the converted value of regular channel */
|
||||
keyconvertedvalue = HAL_ADC_GetValue(&hnucleo_Adc);
|
||||
}
|
||||
|
||||
if((keyconvertedvalue > 2010) && (keyconvertedvalue < 2090))
|
||||
{
|
||||
state = JOY_UP;
|
||||
}
|
||||
else if((keyconvertedvalue > 680) && (keyconvertedvalue < 780))
|
||||
{
|
||||
state = JOY_RIGHT;
|
||||
}
|
||||
else if((keyconvertedvalue > 1270) && (keyconvertedvalue < 1350))
|
||||
{
|
||||
state = JOY_SEL;
|
||||
}
|
||||
else if((keyconvertedvalue > 50) && (keyconvertedvalue < 130))
|
||||
{
|
||||
state = JOY_DOWN;
|
||||
}
|
||||
else if((keyconvertedvalue > 3680) && (keyconvertedvalue < 3760))
|
||||
{
|
||||
state = JOY_LEFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = JOY_NONE;
|
||||
}
|
||||
|
||||
/* Loop while a key is pressed */
|
||||
if(state != JOY_NONE)
|
||||
{
|
||||
keyconvertedvalue = HAL_ADC_GetValue(&hnucleo_Adc);
|
||||
}
|
||||
/* Return the code of the Joystick key pressed */
|
||||
return state;
|
||||
}
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#endif /* ADAFRUIT_TFT_JOY_SD_ID802 */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4xx_nucleo.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains definitions for:
|
||||
* - LEDs and push-button available on STM32F4XX-Nucleo Kit
|
||||
* from STMicroelectronics
|
||||
* - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD
|
||||
* shield (reference ID 802)
|
||||
******************************************************************************
|
||||
* @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 __STM32F4XX_NUCLEO_H
|
||||
#define __STM32F4XX_NUCLEO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
/* To be defined only if the board is provided with the related shield */
|
||||
/* https://www.adafruit.com/products/802 */
|
||||
#define ADAFRUIT_TFT_JOY_SD_ID802
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4XX_NUCLEO
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4XX_NUCLEO_LOW_LEVEL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Types STM32F4XX NUCLEO LOW LEVEL Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LED2 = 0
|
||||
}Led_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_USER = 0,
|
||||
/* Alias */
|
||||
BUTTON_KEY = BUTTON_USER
|
||||
} Button_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_MODE_GPIO = 0,
|
||||
BUTTON_MODE_EXTI = 1
|
||||
}ButtonMode_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JOY_NONE = 0,
|
||||
JOY_SEL = 1,
|
||||
JOY_DOWN = 2,
|
||||
JOY_LEFT = 3,
|
||||
JOY_RIGHT = 4,
|
||||
JOY_UP = 5
|
||||
}JOYState_TypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Constants STM32F4XX NUCLEO LOW LEVEL Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define for STM32F4XX_NUCLEO board
|
||||
*/
|
||||
#if !defined (USE_STM32F4XX_NUCLEO)
|
||||
#define USE_STM32F4XX_NUCLEO
|
||||
#endif
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_LED STM32F4XX NUCLEO LOW LEVEL LED
|
||||
* @{
|
||||
*/
|
||||
#define LEDn 1
|
||||
|
||||
#define LED2_PIN GPIO_PIN_5
|
||||
#define LED2_GPIO_PORT GPIOA
|
||||
#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
|
||||
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) LED2_GPIO_CLK_ENABLE()
|
||||
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED2_GPIO_CLK_DISABLE()
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_BUTTON STM32F4XX NUCLEO LOW LEVEL BUTTON
|
||||
* @{
|
||||
*/
|
||||
#define BUTTONn 1
|
||||
|
||||
/**
|
||||
* @brief Key push-button
|
||||
*/
|
||||
#define USER_BUTTON_PIN GPIO_PIN_13
|
||||
#define USER_BUTTON_GPIO_PORT GPIOC
|
||||
#define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
|
||||
#define USER_BUTTON_EXTI_LINE GPIO_PIN_13
|
||||
#define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) USER_BUTTON_GPIO_CLK_ENABLE()
|
||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) USER_BUTTON_GPIO_CLK_DISABLE()
|
||||
|
||||
/* Aliases */
|
||||
#define KEY_BUTTON_PIN USER_BUTTON_PIN
|
||||
#define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
|
||||
#define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
|
||||
#define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
|
||||
#define KEY_BUTTON_EXTI_LINE USER_BUTTON_EXTI_LINE
|
||||
#define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_BUS STM32F4XX NUCLEO LOW LEVEL BUS
|
||||
* @{
|
||||
*/
|
||||
/*############################### SPI1 #######################################*/
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
|
||||
#define NUCLEO_SPIx SPI1
|
||||
#define NUCLEO_SPIx_CLK_ENABLE() __HAL_RCC_SPI1_CLK_ENABLE()
|
||||
|
||||
#define NUCLEO_SPIx_SCK_AF GPIO_AF5_SPI1
|
||||
#define NUCLEO_SPIx_SCK_GPIO_PORT GPIOA
|
||||
#define NUCLEO_SPIx_SCK_PIN GPIO_PIN_5
|
||||
#define NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define NUCLEO_SPIx_SCK_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
|
||||
#define NUCLEO_SPIx_MISO_MOSI_AF GPIO_AF5_SPI1
|
||||
#define NUCLEO_SPIx_MISO_MOSI_GPIO_PORT GPIOA
|
||||
#define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define NUCLEO_SPIx_MISO_PIN GPIO_PIN_6
|
||||
#define NUCLEO_SPIx_MOSI_PIN GPIO_PIN_7
|
||||
/* Maximum Timeout values for flags waiting loops. These timeouts are not based
|
||||
on accurate values, they just guarantee that the application will not remain
|
||||
stuck if the SPI communication is corrupted.
|
||||
You may modify these timeout values depending on CPU frequency and application
|
||||
conditions (interrupts routines ...). */
|
||||
#define NUCLEO_SPIx_TIMEOUT_MAX 1000
|
||||
|
||||
/**
|
||||
* @brief SD Control Lines management
|
||||
*/
|
||||
#define SD_CS_LOW() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_RESET)
|
||||
#define SD_CS_HIGH() HAL_GPIO_WritePin(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_PIN_SET)
|
||||
|
||||
/**
|
||||
* @brief LCD Control Lines management
|
||||
*/
|
||||
#define LCD_CS_LOW() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_RESET)
|
||||
#define LCD_CS_HIGH() HAL_GPIO_WritePin(LCD_CS_GPIO_PORT, LCD_CS_PIN, GPIO_PIN_SET)
|
||||
#define LCD_DC_LOW() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_RESET)
|
||||
#define LCD_DC_HIGH() HAL_GPIO_WritePin(LCD_DC_GPIO_PORT, LCD_DC_PIN, GPIO_PIN_SET)
|
||||
|
||||
/**
|
||||
* @brief SD Control Interface pins (shield D4)
|
||||
*/
|
||||
#define SD_CS_PIN GPIO_PIN_5
|
||||
#define SD_CS_GPIO_PORT GPIOB
|
||||
#define SD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define SD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
|
||||
/**
|
||||
* @brief LCD Control Interface pins (shield D10)
|
||||
*/
|
||||
#define LCD_CS_PIN GPIO_PIN_6
|
||||
#define LCD_CS_GPIO_PORT GPIOB
|
||||
#define LCD_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define LCD_CS_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
|
||||
/**
|
||||
* @brief LCD Data/Command Interface pins (shield D8)
|
||||
*/
|
||||
#define LCD_DC_PIN GPIO_PIN_9
|
||||
#define LCD_DC_GPIO_PORT GPIOA
|
||||
#define LCD_DC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define LCD_DC_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
/*################################ ADC1 ######################################*/
|
||||
/**
|
||||
* @brief ADC Interface pins
|
||||
* used to detect motion of Joystick available on Adafruit 1.8" TFT shield
|
||||
*/
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
|
||||
#define NUCLEO_ADCx ADC1
|
||||
#define NUCLEO_ADCx_CLK_ENABLE() __HAL_RCC_ADC1_CLK_ENABLE()
|
||||
#define NUCLEO_ADCx_CLK_DISABLE() __HAL_RCC_ADC1_CLK_DISABLE()
|
||||
|
||||
#define NUCLEO_ADCx_CHANNEL ADC_CHANNEL_8
|
||||
|
||||
#define NUCLEO_ADCx_GPIO_PORT GPIOB
|
||||
#define NUCLEO_ADCx_GPIO_PIN GPIO_PIN_0
|
||||
#define NUCLEO_ADCx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define NUCLEO_ADCx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Macros STM32F4XX NUCLEO LOW LEVEL Exported Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Exported_Functions STM32F4XX NUCLEO 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);
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
uint8_t BSP_JOY_Init(void);
|
||||
JOYState_TypeDef BSP_JOY_GetState(void);
|
||||
void BSP_JOY_DeInit(void);
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4XX_NUCLEO_H */
|
||||
Reference in New Issue
Block a user