mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-10 18:24:11 +01:00
002c746076
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1378 ebee16cc-31ac-478f-84a7-5cbb03baadba
392 lines
13 KiB
C
392 lines
13 KiB
C
/**
|
|
******************************************************************************
|
|
* @file stm3210e_eval.c
|
|
* @author MCD Application Team
|
|
* @version V4.2.0
|
|
* @date 04/16/2010
|
|
* @brief This file provides
|
|
* - set of firmware functions to manage Leds, push-button and COM ports
|
|
* - low level initialization functions for SD card (on SDIO), SPI serial
|
|
* flash (sFLASH) and temperature sensor (LM75)
|
|
* available on STM3210E-EVAL evaluation board from STMicroelectronics.
|
|
******************************************************************************
|
|
* @copy
|
|
*
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
|
*
|
|
* <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "stm3210e_eval.h"
|
|
#include "stm32f10x_spi.h"
|
|
#include "stm32f10x_i2c.h"
|
|
#include "stm32f10x_sdio.h"
|
|
#include "stm32f10x_dma.h"
|
|
|
|
/** @addtogroup Utilities
|
|
* @{
|
|
*/
|
|
|
|
/** @addtogroup STM32_EVAL
|
|
* @{
|
|
*/
|
|
|
|
/** @addtogroup STM3210E_EVAL
|
|
* @{
|
|
*/
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL
|
|
* @brief This file provides firmware functions to manage Leds, push-buttons,
|
|
* COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE)
|
|
* and temperature sensor (LM75) available on STM3210E-EVAL evaluation
|
|
* board from STMicroelectronics.
|
|
* @{
|
|
*/
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_TypesDefinitions
|
|
* @{
|
|
*/
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Defines
|
|
* @{
|
|
*/
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Macros
|
|
* @{
|
|
*/
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Variables
|
|
* @{
|
|
*/
|
|
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT};
|
|
const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN};
|
|
const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK};
|
|
|
|
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT,
|
|
KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
|
|
LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
|
|
DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
|
|
|
|
const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN,
|
|
KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
|
|
LEFT_BUTTON_PIN, UP_BUTTON_PIN,
|
|
DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
|
|
|
|
const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
|
|
KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
|
|
LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
|
|
DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
|
|
|
|
const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
|
|
TAMPER_BUTTON_EXTI_LINE,
|
|
KEY_BUTTON_EXTI_LINE,
|
|
RIGHT_BUTTON_EXTI_LINE,
|
|
LEFT_BUTTON_EXTI_LINE,
|
|
UP_BUTTON_EXTI_LINE,
|
|
DOWN_BUTTON_EXTI_LINE,
|
|
SEL_BUTTON_EXTI_LINE};
|
|
|
|
const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
|
|
TAMPER_BUTTON_EXTI_PORT_SOURCE,
|
|
KEY_BUTTON_EXTI_PORT_SOURCE,
|
|
RIGHT_BUTTON_EXTI_PORT_SOURCE,
|
|
LEFT_BUTTON_EXTI_PORT_SOURCE,
|
|
UP_BUTTON_EXTI_PORT_SOURCE,
|
|
DOWN_BUTTON_EXTI_PORT_SOURCE,
|
|
SEL_BUTTON_EXTI_PORT_SOURCE};
|
|
|
|
const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
|
|
TAMPER_BUTTON_EXTI_PIN_SOURCE,
|
|
KEY_BUTTON_EXTI_PIN_SOURCE,
|
|
RIGHT_BUTTON_EXTI_PIN_SOURCE,
|
|
LEFT_BUTTON_EXTI_PIN_SOURCE,
|
|
UP_BUTTON_EXTI_PIN_SOURCE,
|
|
DOWN_BUTTON_EXTI_PIN_SOURCE,
|
|
SEL_BUTTON_EXTI_PIN_SOURCE};
|
|
|
|
const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn,
|
|
KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
|
|
LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
|
|
DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
|
|
|
|
USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2};
|
|
|
|
GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
|
|
|
|
GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
|
|
|
|
const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
|
|
|
|
const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
|
|
|
|
const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
|
|
|
|
const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
|
|
|
|
const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_FunctionPrototypes
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
|
|
/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Functions
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Configures LED GPIO.
|
|
* @param Led: Specifies the Led to be configured.
|
|
* This parameter can be one of following parameters:
|
|
* @arg LED1
|
|
* @arg LED2
|
|
* @arg LED3
|
|
* @arg LED4
|
|
* @retval None
|
|
*/
|
|
void STM_EVAL_LEDInit(Led_TypeDef Led)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
/* Enable the GPIO_LED Clock */
|
|
RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
|
|
|
|
/* Configure the GPIO_LED pin */
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
|
|
GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
|
|
}
|
|
|
|
/**
|
|
* @brief Turns selected LED On.
|
|
* @param Led: Specifies the Led to be set on.
|
|
* This parameter can be one of following parameters:
|
|
* @arg LED1
|
|
* @arg LED2
|
|
* @arg LED3
|
|
* @arg LED4
|
|
* @retval None
|
|
*/
|
|
void STM_EVAL_LEDOn(Led_TypeDef Led)
|
|
{
|
|
GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
|
|
}
|
|
|
|
/**
|
|
* @brief Turns selected LED Off.
|
|
* @param Led: Specifies the Led to be set off.
|
|
* This parameter can be one of following parameters:
|
|
* @arg LED1
|
|
* @arg LED2
|
|
* @arg LED3
|
|
* @arg LED4
|
|
* @retval None
|
|
*/
|
|
void STM_EVAL_LEDOff(Led_TypeDef Led)
|
|
{
|
|
GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
|
|
}
|
|
|
|
/**
|
|
* @brief Toggles the selected LED.
|
|
* @param Led: Specifies the Led to be toggled.
|
|
* This parameter can be one of following parameters:
|
|
* @arg LED1
|
|
* @arg LED2
|
|
* @arg LED3
|
|
* @arg LED4
|
|
* @retval None
|
|
*/
|
|
void STM_EVAL_LEDToggle(Led_TypeDef Led)
|
|
{
|
|
GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
|
|
}
|
|
|
|
/**
|
|
* @brief Configures Button GPIO and EXTI Line.
|
|
* @param Button: Specifies the Button to be configured.
|
|
* This parameter can be one of following parameters:
|
|
* @arg BUTTON_WAKEUP: Wakeup Push Button
|
|
* @arg BUTTON_TAMPER: Tamper Push Button
|
|
* @arg BUTTON_KEY: Key Push Button
|
|
* @arg BUTTON_RIGHT: Joystick Right Push Button
|
|
* @arg BUTTON_LEFT: Joystick Left Push Button
|
|
* @arg BUTTON_UP: Joystick Up Push Button
|
|
* @arg BUTTON_DOWN: Joystick Down Push Button
|
|
* @arg BUTTON_SEL: Joystick Sel Push Button
|
|
* @param Button_Mode: Specifies Button mode.
|
|
* This parameter can be one of following parameters:
|
|
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
|
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
|
|
* generation capability
|
|
* @retval None
|
|
*/
|
|
void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the selected Button state.
|
|
* @param Button: Specifies the Button to be checked.
|
|
* This parameter can be one of following parameters:
|
|
* @arg BUTTON_WAKEUP: Wakeup Push Button
|
|
* @arg BUTTON_TAMPER: Tamper Push Button
|
|
* @arg BUTTON_KEY: Key Push Button
|
|
* @arg BUTTON_RIGHT: Joystick Right Push Button
|
|
* @arg BUTTON_LEFT: Joystick Left Push Button
|
|
* @arg BUTTON_UP: Joystick Up Push Button
|
|
* @arg BUTTON_DOWN: Joystick Down Push Button
|
|
* @arg BUTTON_SEL: Joystick Sel Push Button
|
|
* @retval The Button GPIO pin value.
|
|
*/
|
|
uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
|
|
{
|
|
return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
|
}
|
|
|
|
/**
|
|
* @brief Configures COM port.
|
|
* @param COM: Specifies the COM port to be configured.
|
|
* This parameter can be one of following parameters:
|
|
* @arg COM1
|
|
* @arg COM2
|
|
* @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
|
|
* contains the configuration information for the specified USART peripheral.
|
|
* @retval None
|
|
*/
|
|
|
|
|
|
/**
|
|
* @brief DeInitializes the SDIO interface.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void SD_LowLevel_DeInit(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
/*!< Disable SDIO Clock */
|
|
SDIO_ClockCmd(DISABLE);
|
|
|
|
/*!< Set Power State to OFF */
|
|
SDIO_SetPowerState(SDIO_PowerState_OFF);
|
|
|
|
/*!< DeInitializes the SDIO peripheral */
|
|
SDIO_DeInit();
|
|
|
|
/*!< Disable the SDIO AHB Clock */
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, DISABLE);
|
|
|
|
/*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
|
/*!< Configure PD.02 CMD line */
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
|
}
|
|
|
|
/**
|
|
* @brief Initializes the SD Card and put it into StandBy State (Ready for
|
|
* data transfer).
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void SD_LowLevel_Init(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
/*!< GPIOC and GPIOD Periph clock enable */
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);
|
|
|
|
/*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
|
/*!< Configure PD.02 CMD line */
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
|
|
|
/*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
|
|
GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
|
|
|
|
/*!< Enable the SDIO AHB Clock */
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);
|
|
|
|
/*!< Enable the DMA2 Clock */
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
|
|
}
|
|
|
|
/**
|
|
* @brief Configures the DMA2 Channel4 for SDIO Tx request.
|
|
* @param BufferSRC: pointer to the source buffer
|
|
* @param BufferSize: buffer size
|
|
* @retval None
|
|
*/
|
|
|
|
/**
|
|
* @brief DeInitializes the LM75_I2C.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|