Contains the BSP driver for the B-L475E-IOT01 board.

Dependents:   mbed-os-example-ble-Thermometer DISCO_L475VG_IOT01-Telegram-BOT DISCO_L475VG_IOT01-sche_cheveux DISCO_L475VG_IOT01-QSPI_FLASH_FILE_SYSTEM ... more

https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/

Committer:
jeromecoutant
Date:
Tue Sep 24 15:30:09 2019 +0200
Revision:
7:bfe8272ced90
Parent:
6:9dfa42666f03
Update BSP files with STM32Cube L4 V1.14.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 4:137bb367ba50 1 /**
bcostm 4:137bb367ba50 2 ******************************************************************************
bcostm 4:137bb367ba50 3 * @file stm32l475e_iot01.c
bcostm 4:137bb367ba50 4 * @author MCD Application Team
bcostm 4:137bb367ba50 5 * @brief STM32L475E-IOT01 board support package
bcostm 4:137bb367ba50 6 ******************************************************************************
bcostm 4:137bb367ba50 7 * @attention
bcostm 4:137bb367ba50 8 *
jeromecoutant 7:bfe8272ced90 9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
bcostm 4:137bb367ba50 10 * All rights reserved.</center></h2>
bcostm 4:137bb367ba50 11 *
jeromecoutant 7:bfe8272ced90 12 * This software component is licensed by ST under BSD 3-Clause license,
jeromecoutant 7:bfe8272ced90 13 * the "License"; You may not use this file except in compliance with the
jeromecoutant 7:bfe8272ced90 14 * License. You may obtain a copy of the License at:
jeromecoutant 7:bfe8272ced90 15 * opensource.org/licenses/BSD-3-Clause
bcostm 4:137bb367ba50 16 *
bcostm 4:137bb367ba50 17 ******************************************************************************
bcostm 4:137bb367ba50 18 */
bcostm 4:137bb367ba50 19
bcostm 4:137bb367ba50 20 /* Includes ------------------------------------------------------------------*/
bcostm 4:137bb367ba50 21 #include "stm32l475e_iot01.h"
bcostm 5:0c70bc6d2dc0 22
bcostm 4:137bb367ba50 23 /** @defgroup BSP BSP
bcostm 4:137bb367ba50 24 * @{
bcostm 4:137bb367ba50 25 */
bcostm 4:137bb367ba50 26
bcostm 4:137bb367ba50 27 /** @defgroup STM32L475E_IOT01 STM32L475E_IOT01
bcostm 4:137bb367ba50 28 * @{
bcostm 4:137bb367ba50 29 */
bcostm 4:137bb367ba50 30
bcostm 4:137bb367ba50 31 /** @defgroup STM32L475E_IOT01_LOW_LEVEL LOW LEVEL
bcostm 4:137bb367ba50 32 * @{
bcostm 4:137bb367ba50 33 */
bcostm 4:137bb367ba50 34
bcostm 4:137bb367ba50 35 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Defines LOW LEVEL Private Def
bcostm 4:137bb367ba50 36 * @{
bcostm 4:137bb367ba50 37 */
bcostm 4:137bb367ba50 38 /**
bcostm 6:9dfa42666f03 39 * @brief STM32L475E IOT01 BSP Driver version number
bcostm 4:137bb367ba50 40 */
bcostm 4:137bb367ba50 41 #define __STM32L475E_IOT01_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
bcostm 5:0c70bc6d2dc0 42 #define __STM32L475E_IOT01_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */
jeromecoutant 7:bfe8272ced90 43 #define __STM32L475E_IOT01_BSP_VERSION_SUB2 (0x04) /*!< [15:8] sub2 version */
bcostm 4:137bb367ba50 44 #define __STM32L475E_IOT01_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
bcostm 4:137bb367ba50 45 #define __STM32L475E_IOT01_BSP_VERSION ((__STM32L475E_IOT01_BSP_VERSION_MAIN << 24)\
bcostm 4:137bb367ba50 46 |(__STM32L475E_IOT01_BSP_VERSION_SUB1 << 16)\
bcostm 4:137bb367ba50 47 |(__STM32L475E_IOT01_BSP_VERSION_SUB2 << 8 )\
bcostm 4:137bb367ba50 48 |(__STM32L475E_IOT01_BSP_VERSION_RC))
bcostm 4:137bb367ba50 49 /**
bcostm 4:137bb367ba50 50 * @}
bcostm 4:137bb367ba50 51 */
bcostm 4:137bb367ba50 52
bcostm 4:137bb367ba50 53 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Variables LOW LEVEL Variables
bcostm 4:137bb367ba50 54 * @{
bcostm 4:137bb367ba50 55 */
bcostm 4:137bb367ba50 56
bcostm 4:137bb367ba50 57 const uint32_t GPIO_PIN[LEDn] = {LED2_PIN};
bcostm 4:137bb367ba50 58
bcostm 4:137bb367ba50 59
bcostm 4:137bb367ba50 60 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT};
bcostm 4:137bb367ba50 61
bcostm 4:137bb367ba50 62
bcostm 4:137bb367ba50 63 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT};
bcostm 4:137bb367ba50 64
bcostm 4:137bb367ba50 65 const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN};
bcostm 4:137bb367ba50 66
bcostm 4:137bb367ba50 67 const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn};
bcostm 4:137bb367ba50 68
bcostm 4:137bb367ba50 69 USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1};
bcostm 4:137bb367ba50 70
bcostm 4:137bb367ba50 71 GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT};
bcostm 4:137bb367ba50 72
bcostm 4:137bb367ba50 73 GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT};
bcostm 4:137bb367ba50 74
bcostm 4:137bb367ba50 75 const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN};
bcostm 4:137bb367ba50 76
bcostm 4:137bb367ba50 77 const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN};
bcostm 4:137bb367ba50 78
bcostm 4:137bb367ba50 79 const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF};
bcostm 4:137bb367ba50 80
bcostm 4:137bb367ba50 81 const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF};
bcostm 4:137bb367ba50 82
bcostm 4:137bb367ba50 83 I2C_HandleTypeDef hI2cHandler;
bcostm 4:137bb367ba50 84 UART_HandleTypeDef hDiscoUart;
bcostm 5:0c70bc6d2dc0 85
bcostm 4:137bb367ba50 86 /**
bcostm 4:137bb367ba50 87 * @}
bcostm 4:137bb367ba50 88 */
bcostm 4:137bb367ba50 89 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_FunctionPrototypes LOW LEVEL Private Function Prototypes
bcostm 4:137bb367ba50 90 * @{
bcostm 4:137bb367ba50 91 */
bcostm 4:137bb367ba50 92 static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 93 static void I2Cx_MspDeInit(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 94 static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 95 static void I2Cx_DeInit(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 96 static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 97 static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 98 static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials);
bcostm 4:137bb367ba50 99 static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr);
bcostm 4:137bb367ba50 100
bcostm 4:137bb367ba50 101 /* Sensors IO functions */
bcostm 4:137bb367ba50 102 void SENSOR_IO_Init(void);
bcostm 4:137bb367ba50 103 void SENSOR_IO_DeInit(void);
bcostm 4:137bb367ba50 104 void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
bcostm 4:137bb367ba50 105 uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
bcostm 4:137bb367ba50 106 uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 107 void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 108 HAL_StatusTypeDef SENSOR_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
bcostm 4:137bb367ba50 109 void SENSOR_IO_Delay(uint32_t Delay);
bcostm 4:137bb367ba50 110
bcostm 5:0c70bc6d2dc0 111 void NFC_IO_Init(uint8_t GpoIrqEnable);
bcostm 5:0c70bc6d2dc0 112 void NFC_IO_DeInit(void);
bcostm 5:0c70bc6d2dc0 113 uint16_t NFC_IO_ReadMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length );
bcostm 5:0c70bc6d2dc0 114 uint16_t NFC_IO_WriteMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length);
bcostm 5:0c70bc6d2dc0 115 uint16_t NFC_IO_IsDeviceReady (uint8_t Addr, uint32_t Trials);
bcostm 5:0c70bc6d2dc0 116 void NFC_IO_ReadState(uint8_t * pPinState);
bcostm 5:0c70bc6d2dc0 117 void NFC_IO_RfDisable(uint8_t PinState);
bcostm 5:0c70bc6d2dc0 118 void NFC_IO_Delay(uint32_t Delay);
bcostm 5:0c70bc6d2dc0 119
bcostm 4:137bb367ba50 120 /**
bcostm 4:137bb367ba50 121 * @}
bcostm 4:137bb367ba50 122 */
bcostm 4:137bb367ba50 123
bcostm 4:137bb367ba50 124 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Functions LOW LEVEL Private Functions
bcostm 4:137bb367ba50 125 * @{
bcostm 4:137bb367ba50 126 */
bcostm 4:137bb367ba50 127
bcostm 4:137bb367ba50 128 /**
bcostm 4:137bb367ba50 129 * @brief This method returns the STM32L475E IOT01 BSP Driver revision
jeromecoutant 7:bfe8272ced90 130 * @retval version 0xXYZR (8bits for each decimal, R for RC)
bcostm 4:137bb367ba50 131 */
bcostm 4:137bb367ba50 132 uint32_t BSP_GetVersion(void)
bcostm 4:137bb367ba50 133 {
bcostm 4:137bb367ba50 134 return __STM32L475E_IOT01_BSP_VERSION;
bcostm 4:137bb367ba50 135 }
bcostm 4:137bb367ba50 136
bcostm 4:137bb367ba50 137 /**
jeromecoutant 7:bfe8272ced90 138 * @brief Initializes LED GPIO.
jeromecoutant 7:bfe8272ced90 139 * @param Led LED to be initialized.
jeromecoutant 7:bfe8272ced90 140 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 141 * @arg DISCO_LED2
bcostm 4:137bb367ba50 142 */
bcostm 4:137bb367ba50 143 void BSP_LED_Init(Led_TypeDef Led)
bcostm 4:137bb367ba50 144 {
bcostm 4:137bb367ba50 145 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 146
bcostm 4:137bb367ba50 147 LEDx_GPIO_CLK_ENABLE(Led);
bcostm 4:137bb367ba50 148 /* Configure the GPIO_LED pin */
bcostm 4:137bb367ba50 149 gpio_init_structure.Pin = GPIO_PIN[Led];
bcostm 4:137bb367ba50 150 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 4:137bb367ba50 151 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 4:137bb367ba50 152 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
bcostm 4:137bb367ba50 153
bcostm 4:137bb367ba50 154 HAL_GPIO_Init(GPIO_PORT[Led], &gpio_init_structure);
bcostm 4:137bb367ba50 155 }
bcostm 4:137bb367ba50 156
bcostm 4:137bb367ba50 157 /**
jeromecoutant 7:bfe8272ced90 158 * @brief DeInitializes LED GPIO.
jeromecoutant 7:bfe8272ced90 159 * @param Led LED to be deinitialized.
jeromecoutant 7:bfe8272ced90 160 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 161 * @arg DISCO_LED2
bcostm 4:137bb367ba50 162 */
bcostm 4:137bb367ba50 163 void BSP_LED_DeInit(Led_TypeDef Led)
bcostm 4:137bb367ba50 164 {
bcostm 4:137bb367ba50 165 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 166
bcostm 4:137bb367ba50 167 /* DeInit the GPIO_LED pin */
bcostm 4:137bb367ba50 168 gpio_init_structure.Pin = GPIO_PIN[Led];
bcostm 4:137bb367ba50 169
bcostm 4:137bb367ba50 170 /* Turn off LED */
bcostm 4:137bb367ba50 171 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
bcostm 4:137bb367ba50 172 HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
bcostm 4:137bb367ba50 173 }
bcostm 4:137bb367ba50 174
bcostm 4:137bb367ba50 175 /**
jeromecoutant 7:bfe8272ced90 176 * @brief Turns the selected LED On.
jeromecoutant 7:bfe8272ced90 177 * @param Led LED to be set on
jeromecoutant 7:bfe8272ced90 178 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 179 * @arg DISCO_LED2
bcostm 4:137bb367ba50 180 */
bcostm 4:137bb367ba50 181 void BSP_LED_On(Led_TypeDef Led)
bcostm 4:137bb367ba50 182 {
bcostm 4:137bb367ba50 183 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
bcostm 4:137bb367ba50 184 }
bcostm 4:137bb367ba50 185
bcostm 4:137bb367ba50 186 /**
jeromecoutant 7:bfe8272ced90 187 * @brief Turns the selected LED Off.
jeromecoutant 7:bfe8272ced90 188 * @param Led LED to be set off
jeromecoutant 7:bfe8272ced90 189 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 190 * @arg DISCO_LED2
bcostm 4:137bb367ba50 191 */
bcostm 4:137bb367ba50 192 void BSP_LED_Off(Led_TypeDef Led)
bcostm 4:137bb367ba50 193 {
bcostm 4:137bb367ba50 194 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
bcostm 4:137bb367ba50 195 }
bcostm 4:137bb367ba50 196
bcostm 4:137bb367ba50 197 /**
bcostm 4:137bb367ba50 198 * @brief Toggles the selected LED.
jeromecoutant 7:bfe8272ced90 199 * @param Led LED to be toggled
jeromecoutant 7:bfe8272ced90 200 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 201 * @arg DISCO_LED2
bcostm 4:137bb367ba50 202 */
bcostm 4:137bb367ba50 203 void BSP_LED_Toggle(Led_TypeDef Led)
bcostm 4:137bb367ba50 204 {
bcostm 4:137bb367ba50 205 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
bcostm 4:137bb367ba50 206 }
bcostm 4:137bb367ba50 207
bcostm 4:137bb367ba50 208 /**
jeromecoutant 7:bfe8272ced90 209 * @brief Initializes push button GPIO and EXTI Line.
jeromecoutant 7:bfe8272ced90 210 * @param Button Button to be configured
jeromecoutant 7:bfe8272ced90 211 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 212 * @arg BUTTON_USER User Push Button
jeromecoutant 7:bfe8272ced90 213 * @param ButtonMode Button mode
jeromecoutant 7:bfe8272ced90 214 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 215 * @arg BUTTON_MODE_GPIO Button will be used as simple IO
jeromecoutant 7:bfe8272ced90 216 * @arg BUTTON_MODE_EXTI Button will be connected to EXTI line
jeromecoutant 7:bfe8272ced90 217 * with interrupt generation capability
bcostm 4:137bb367ba50 218 */
bcostm 4:137bb367ba50 219 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
bcostm 4:137bb367ba50 220 {
bcostm 4:137bb367ba50 221 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 222
bcostm 4:137bb367ba50 223 /* Enable the BUTTON clock */
bcostm 4:137bb367ba50 224 USER_BUTTON_GPIO_CLK_ENABLE();
bcostm 4:137bb367ba50 225
bcostm 4:137bb367ba50 226 if(ButtonMode == BUTTON_MODE_GPIO)
bcostm 4:137bb367ba50 227 {
bcostm 4:137bb367ba50 228 /* Configure Button pin as input */
bcostm 4:137bb367ba50 229 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 4:137bb367ba50 230 gpio_init_structure.Mode = GPIO_MODE_INPUT;
bcostm 4:137bb367ba50 231 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 4:137bb367ba50 232 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
bcostm 4:137bb367ba50 233 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
bcostm 4:137bb367ba50 234 }
bcostm 4:137bb367ba50 235
bcostm 4:137bb367ba50 236 if(ButtonMode == BUTTON_MODE_EXTI)
bcostm 4:137bb367ba50 237 {
bcostm 4:137bb367ba50 238 /* Configure Button pin as input with External interrupt */
bcostm 4:137bb367ba50 239 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 4:137bb367ba50 240 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 4:137bb367ba50 241 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 4:137bb367ba50 242
bcostm 4:137bb367ba50 243 gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
bcostm 4:137bb367ba50 244
bcostm 4:137bb367ba50 245 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
bcostm 4:137bb367ba50 246
bcostm 4:137bb367ba50 247 /* Enable and set Button EXTI Interrupt to the lowest priority */
bcostm 4:137bb367ba50 248 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
bcostm 4:137bb367ba50 249 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
bcostm 4:137bb367ba50 250 }
bcostm 4:137bb367ba50 251 }
bcostm 4:137bb367ba50 252
bcostm 4:137bb367ba50 253 /**
jeromecoutant 7:bfe8272ced90 254 * @brief DeInitializes push button.
jeromecoutant 7:bfe8272ced90 255 * @param Button Button to be configured
jeromecoutant 7:bfe8272ced90 256 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 257 * @arg BUTTON_USER User Push Button
bcostm 4:137bb367ba50 258 * @note PB DeInit does not disable the GPIO clock
bcostm 4:137bb367ba50 259 */
bcostm 4:137bb367ba50 260 void BSP_PB_DeInit(Button_TypeDef Button)
bcostm 4:137bb367ba50 261 {
bcostm 4:137bb367ba50 262 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 263
bcostm 4:137bb367ba50 264 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 4:137bb367ba50 265 HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
bcostm 4:137bb367ba50 266 HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
bcostm 4:137bb367ba50 267 }
bcostm 4:137bb367ba50 268
bcostm 4:137bb367ba50 269
bcostm 4:137bb367ba50 270 /**
bcostm 4:137bb367ba50 271 * @brief Returns the selected button state.
jeromecoutant 7:bfe8272ced90 272 * @param Button Button to be checked
jeromecoutant 7:bfe8272ced90 273 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 274 * @arg BUTTON_USER User Push Button
bcostm 4:137bb367ba50 275 * @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed)
bcostm 4:137bb367ba50 276 */
bcostm 4:137bb367ba50 277 uint32_t BSP_PB_GetState(Button_TypeDef Button)
bcostm 4:137bb367ba50 278 {
bcostm 4:137bb367ba50 279 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
bcostm 4:137bb367ba50 280 }
bcostm 4:137bb367ba50 281
bcostm 4:137bb367ba50 282 /**
bcostm 4:137bb367ba50 283 * @brief Configures COM port.
jeromecoutant 7:bfe8272ced90 284 * @param COM COM port to be initialized.
jeromecoutant 7:bfe8272ced90 285 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 286 * @arg COM1
jeromecoutant 7:bfe8272ced90 287 * @param huart Pointer to a UART_HandleTypeDef structure that contains the
bcostm 4:137bb367ba50 288 * configuration information for the specified USART peripheral.
bcostm 4:137bb367ba50 289 */
bcostm 4:137bb367ba50 290 void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
bcostm 4:137bb367ba50 291 {
bcostm 4:137bb367ba50 292 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 293
bcostm 4:137bb367ba50 294 /* Enable GPIO clock */
bcostm 4:137bb367ba50 295 DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM);
bcostm 4:137bb367ba50 296 DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM);
bcostm 4:137bb367ba50 297
bcostm 4:137bb367ba50 298 /* Enable USART clock */
bcostm 4:137bb367ba50 299 DISCOVERY_COMx_CLK_ENABLE(COM);
bcostm 4:137bb367ba50 300
bcostm 4:137bb367ba50 301 /* Configure USART Tx as alternate function */
bcostm 4:137bb367ba50 302 gpio_init_structure.Pin = COM_TX_PIN[COM];
bcostm 4:137bb367ba50 303 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 4:137bb367ba50 304 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
bcostm 4:137bb367ba50 305 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 4:137bb367ba50 306 gpio_init_structure.Alternate = COM_TX_AF[COM];
bcostm 4:137bb367ba50 307 HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure);
bcostm 4:137bb367ba50 308
bcostm 4:137bb367ba50 309 /* Configure USART Rx as alternate function */
bcostm 4:137bb367ba50 310 gpio_init_structure.Pin = COM_RX_PIN[COM];
bcostm 4:137bb367ba50 311 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 4:137bb367ba50 312 gpio_init_structure.Alternate = COM_RX_AF[COM];
bcostm 4:137bb367ba50 313 HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure);
bcostm 4:137bb367ba50 314
bcostm 4:137bb367ba50 315 /* USART configuration */
bcostm 4:137bb367ba50 316 huart->Instance = COM_USART[COM];
bcostm 4:137bb367ba50 317 HAL_UART_Init(huart);
bcostm 4:137bb367ba50 318 }
bcostm 4:137bb367ba50 319
bcostm 4:137bb367ba50 320 /**
jeromecoutant 7:bfe8272ced90 321 * @brief DeInitializes COM port.
jeromecoutant 7:bfe8272ced90 322 * @param COM COM port to be deinitialized.
jeromecoutant 7:bfe8272ced90 323 * This parameter can be one of the following values:
jeromecoutant 7:bfe8272ced90 324 * @arg COM1
jeromecoutant 7:bfe8272ced90 325 * @param huart Pointer to a UART_HandleTypeDef structure that contains the
bcostm 4:137bb367ba50 326 * configuration information for the specified USART peripheral.
bcostm 4:137bb367ba50 327 */
bcostm 4:137bb367ba50 328 void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart)
bcostm 4:137bb367ba50 329 {
bcostm 4:137bb367ba50 330 /* USART configuration */
bcostm 4:137bb367ba50 331 huart->Instance = COM_USART[COM];
bcostm 4:137bb367ba50 332 HAL_UART_DeInit(huart);
bcostm 4:137bb367ba50 333
bcostm 4:137bb367ba50 334 /* Enable USART clock */
bcostm 4:137bb367ba50 335 DISCOVERY_COMx_CLK_DISABLE(COM);
bcostm 4:137bb367ba50 336
bcostm 4:137bb367ba50 337 /* DeInit GPIO pins can be done in the application
bcostm 4:137bb367ba50 338 (by surcharging this __weak function) */
bcostm 4:137bb367ba50 339
bcostm 4:137bb367ba50 340 /* GPIO pins clock, FMC clock and DMA clock can be shut down in the application
bcostm 4:137bb367ba50 341 by surcharging this __weak function */
bcostm 4:137bb367ba50 342 }
bcostm 4:137bb367ba50 343
bcostm 4:137bb367ba50 344
bcostm 4:137bb367ba50 345 /*******************************************************************************
bcostm 4:137bb367ba50 346 BUS OPERATIONS
bcostm 4:137bb367ba50 347 *******************************************************************************/
bcostm 4:137bb367ba50 348
bcostm 4:137bb367ba50 349 /******************************* I2C Routines *********************************/
bcostm 4:137bb367ba50 350 /**
bcostm 4:137bb367ba50 351 * @brief Initializes I2C MSP.
jeromecoutant 7:bfe8272ced90 352 * @param i2c_handler I2C handler
bcostm 4:137bb367ba50 353 * @retval None
bcostm 4:137bb367ba50 354 */
bcostm 4:137bb367ba50 355 static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 356 {
bcostm 4:137bb367ba50 357 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 358
bcostm 4:137bb367ba50 359 /*** Configure the GPIOs ***/
bcostm 4:137bb367ba50 360 /* Enable GPIO clock */
bcostm 4:137bb367ba50 361 DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
bcostm 4:137bb367ba50 362
bcostm 4:137bb367ba50 363 /* Configure I2C Tx, Rx as alternate function */
bcostm 4:137bb367ba50 364 gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN;
bcostm 4:137bb367ba50 365 gpio_init_structure.Mode = GPIO_MODE_AF_OD;
bcostm 4:137bb367ba50 366 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 4:137bb367ba50 367 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 4:137bb367ba50 368 gpio_init_structure.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
bcostm 4:137bb367ba50 369 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 4:137bb367ba50 370
bcostm 4:137bb367ba50 371 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 4:137bb367ba50 372
bcostm 4:137bb367ba50 373 /*** Configure the I2C peripheral ***/
bcostm 4:137bb367ba50 374 /* Enable I2C clock */
bcostm 4:137bb367ba50 375 DISCOVERY_I2Cx_CLK_ENABLE();
bcostm 4:137bb367ba50 376
bcostm 4:137bb367ba50 377 /* Force the I2C peripheral clock reset */
bcostm 4:137bb367ba50 378 DISCOVERY_I2Cx_FORCE_RESET();
bcostm 4:137bb367ba50 379
bcostm 4:137bb367ba50 380 /* Release the I2C peripheral clock reset */
bcostm 4:137bb367ba50 381 DISCOVERY_I2Cx_RELEASE_RESET();
bcostm 4:137bb367ba50 382
bcostm 4:137bb367ba50 383 /* Enable and set I2Cx Interrupt to a lower priority */
bcostm 4:137bb367ba50 384 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0);
bcostm 4:137bb367ba50 385 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
bcostm 4:137bb367ba50 386
bcostm 4:137bb367ba50 387 /* Enable and set I2Cx Interrupt to a lower priority */
bcostm 4:137bb367ba50 388 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0);
bcostm 4:137bb367ba50 389 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
bcostm 4:137bb367ba50 390 }
bcostm 4:137bb367ba50 391
bcostm 4:137bb367ba50 392 /**
bcostm 4:137bb367ba50 393 * @brief DeInitializes I2C MSP.
jeromecoutant 7:bfe8272ced90 394 * @param i2c_handler I2C handler
bcostm 4:137bb367ba50 395 * @retval None
bcostm 4:137bb367ba50 396 */
bcostm 4:137bb367ba50 397 static void I2Cx_MspDeInit(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 398 {
bcostm 4:137bb367ba50 399 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 400
bcostm 4:137bb367ba50 401 /* Configure I2C Tx, Rx as alternate function */
bcostm 4:137bb367ba50 402 gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN;
bcostm 4:137bb367ba50 403 HAL_GPIO_DeInit(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, gpio_init_structure.Pin);
bcostm 4:137bb367ba50 404 /* Disable GPIO clock */
bcostm 4:137bb367ba50 405 DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_DISABLE();
bcostm 4:137bb367ba50 406
bcostm 4:137bb367ba50 407 /* Disable I2C clock */
bcostm 4:137bb367ba50 408 DISCOVERY_I2Cx_CLK_DISABLE();
bcostm 4:137bb367ba50 409 }
bcostm 4:137bb367ba50 410
bcostm 4:137bb367ba50 411 /**
bcostm 4:137bb367ba50 412 * @brief Initializes I2C HAL.
jeromecoutant 7:bfe8272ced90 413 * @param i2c_handler I2C handler
bcostm 4:137bb367ba50 414 * @retval None
bcostm 4:137bb367ba50 415 */
bcostm 4:137bb367ba50 416 static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 417 {
bcostm 4:137bb367ba50 418 /* I2C configuration */
bcostm 4:137bb367ba50 419 i2c_handler->Instance = DISCOVERY_I2Cx;
bcostm 4:137bb367ba50 420 i2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING;
bcostm 4:137bb367ba50 421 i2c_handler->Init.OwnAddress1 = 0;
bcostm 4:137bb367ba50 422 i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
bcostm 4:137bb367ba50 423 i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
bcostm 4:137bb367ba50 424 i2c_handler->Init.OwnAddress2 = 0;
bcostm 4:137bb367ba50 425 i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
bcostm 4:137bb367ba50 426 i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
bcostm 5:0c70bc6d2dc0 427
bcostm 4:137bb367ba50 428 /* Init the I2C */
bcostm 4:137bb367ba50 429 I2Cx_MspInit(i2c_handler);
bcostm 4:137bb367ba50 430 HAL_I2C_Init(i2c_handler);
bcostm 4:137bb367ba50 431
bcostm 4:137bb367ba50 432 /**Configure Analogue filter */
bcostm 4:137bb367ba50 433 HAL_I2CEx_ConfigAnalogFilter(i2c_handler, I2C_ANALOGFILTER_ENABLE);
bcostm 4:137bb367ba50 434 }
bcostm 4:137bb367ba50 435
bcostm 4:137bb367ba50 436 /**
bcostm 4:137bb367ba50 437 * @brief DeInitializes I2C HAL.
jeromecoutant 7:bfe8272ced90 438 * @param i2c_handler I2C handler
bcostm 4:137bb367ba50 439 * @retval None
bcostm 4:137bb367ba50 440 */
bcostm 4:137bb367ba50 441 static void I2Cx_DeInit(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 442 { /* DeInit the I2C */
bcostm 4:137bb367ba50 443 I2Cx_MspDeInit(i2c_handler);
bcostm 4:137bb367ba50 444 HAL_I2C_DeInit(i2c_handler);
bcostm 4:137bb367ba50 445 }
bcostm 4:137bb367ba50 446
bcostm 4:137bb367ba50 447 /**
bcostm 4:137bb367ba50 448 * @brief Reads multiple data.
jeromecoutant 7:bfe8272ced90 449 * @param i2c_handler I2C handler
jeromecoutant 7:bfe8272ced90 450 * @param Addr I2C address
jeromecoutant 7:bfe8272ced90 451 * @param Reg Reg address
jeromecoutant 7:bfe8272ced90 452 * @param MemAddress memory address
jeromecoutant 7:bfe8272ced90 453 * @param Buffer Pointer to data buffer
jeromecoutant 7:bfe8272ced90 454 * @param Length Length of the data
bcostm 4:137bb367ba50 455 * @retval HAL status
bcostm 4:137bb367ba50 456 */
bcostm 4:137bb367ba50 457 static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 458 {
bcostm 4:137bb367ba50 459 HAL_StatusTypeDef status = HAL_OK;
bcostm 4:137bb367ba50 460
bcostm 4:137bb367ba50 461 status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
bcostm 4:137bb367ba50 462
bcostm 4:137bb367ba50 463 /* Check the communication status */
bcostm 4:137bb367ba50 464 if(status != HAL_OK)
bcostm 4:137bb367ba50 465 {
bcostm 4:137bb367ba50 466 /* I2C error occured */
bcostm 4:137bb367ba50 467 I2Cx_Error(i2c_handler, Addr);
bcostm 4:137bb367ba50 468 }
bcostm 4:137bb367ba50 469 return status;
bcostm 4:137bb367ba50 470 }
bcostm 4:137bb367ba50 471
bcostm 4:137bb367ba50 472
bcostm 4:137bb367ba50 473 /**
bcostm 4:137bb367ba50 474 * @brief Writes a value in a register of the device through BUS in using DMA mode.
jeromecoutant 7:bfe8272ced90 475 * @param i2c_handler I2C handler
jeromecoutant 7:bfe8272ced90 476 * @param Addr Device address on BUS Bus.
jeromecoutant 7:bfe8272ced90 477 * @param Reg The target register address to write
jeromecoutant 7:bfe8272ced90 478 * @param MemAddress memory address
jeromecoutant 7:bfe8272ced90 479 * @param Buffer The target register value to be written
jeromecoutant 7:bfe8272ced90 480 * @param Length buffer size to be written
bcostm 4:137bb367ba50 481 * @retval HAL status
bcostm 4:137bb367ba50 482 */
bcostm 4:137bb367ba50 483 static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 484 {
bcostm 4:137bb367ba50 485 HAL_StatusTypeDef status = HAL_OK;
bcostm 4:137bb367ba50 486
bcostm 4:137bb367ba50 487 status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
bcostm 4:137bb367ba50 488
bcostm 4:137bb367ba50 489 /* Check the communication status */
bcostm 4:137bb367ba50 490 if(status != HAL_OK)
bcostm 4:137bb367ba50 491 {
bcostm 4:137bb367ba50 492 /* Re-Initiaize the I2C Bus */
bcostm 4:137bb367ba50 493 I2Cx_Error(i2c_handler, Addr);
bcostm 4:137bb367ba50 494 }
bcostm 4:137bb367ba50 495 return status;
bcostm 4:137bb367ba50 496 }
bcostm 4:137bb367ba50 497
bcostm 4:137bb367ba50 498 /**
bcostm 4:137bb367ba50 499 * @brief Checks if target device is ready for communication.
bcostm 4:137bb367ba50 500 * @note This function is used with Memory devices
jeromecoutant 7:bfe8272ced90 501 * @param i2c_handler I2C handler
jeromecoutant 7:bfe8272ced90 502 * @param DevAddress Target device address
jeromecoutant 7:bfe8272ced90 503 * @param Trials Number of trials
bcostm 4:137bb367ba50 504 * @retval HAL status
bcostm 4:137bb367ba50 505 */
bcostm 4:137bb367ba50 506 static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials)
bcostm 4:137bb367ba50 507 {
bcostm 4:137bb367ba50 508 return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000));
bcostm 4:137bb367ba50 509 }
bcostm 4:137bb367ba50 510
bcostm 4:137bb367ba50 511 /**
bcostm 4:137bb367ba50 512 * @brief Manages error callback by re-initializing I2C.
jeromecoutant 7:bfe8272ced90 513 * @param i2c_handler I2C handler
jeromecoutant 7:bfe8272ced90 514 * @param Addr I2C Address
bcostm 4:137bb367ba50 515 * @retval None
bcostm 4:137bb367ba50 516 */
bcostm 4:137bb367ba50 517 static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr)
bcostm 4:137bb367ba50 518 {
bcostm 4:137bb367ba50 519 /* De-initialize the I2C communication bus */
bcostm 4:137bb367ba50 520 HAL_I2C_DeInit(i2c_handler);
bcostm 4:137bb367ba50 521
bcostm 4:137bb367ba50 522 /* Re-Initialize the I2C communication bus */
bcostm 4:137bb367ba50 523 I2Cx_Init(i2c_handler);
bcostm 4:137bb367ba50 524 }
bcostm 4:137bb367ba50 525
bcostm 4:137bb367ba50 526 /**
bcostm 4:137bb367ba50 527 * @}
bcostm 4:137bb367ba50 528 */
bcostm 4:137bb367ba50 529
bcostm 4:137bb367ba50 530 /*******************************************************************************
bcostm 4:137bb367ba50 531 LINK OPERATIONS
bcostm 4:137bb367ba50 532 *******************************************************************************/
bcostm 4:137bb367ba50 533 /******************************** LINK Sensors ********************************/
bcostm 4:137bb367ba50 534
bcostm 4:137bb367ba50 535 /**
bcostm 4:137bb367ba50 536 * @brief Initializes Sensors low level.
bcostm 4:137bb367ba50 537 * @retval None
bcostm 4:137bb367ba50 538 */
bcostm 4:137bb367ba50 539 void SENSOR_IO_Init(void)
bcostm 4:137bb367ba50 540 {
bcostm 4:137bb367ba50 541 I2Cx_Init(&hI2cHandler);
bcostm 4:137bb367ba50 542 }
bcostm 4:137bb367ba50 543
bcostm 4:137bb367ba50 544 /**
bcostm 4:137bb367ba50 545 * @brief DeInitializes Sensors low level.
bcostm 4:137bb367ba50 546 * @retval None
bcostm 4:137bb367ba50 547 */
bcostm 4:137bb367ba50 548 void SENSOR_IO_DeInit(void)
bcostm 4:137bb367ba50 549 {
bcostm 4:137bb367ba50 550 I2Cx_DeInit(&hI2cHandler);
bcostm 4:137bb367ba50 551 }
bcostm 4:137bb367ba50 552
bcostm 4:137bb367ba50 553 /**
bcostm 4:137bb367ba50 554 * @brief Writes a single data.
jeromecoutant 7:bfe8272ced90 555 * @param Addr I2C address
jeromecoutant 7:bfe8272ced90 556 * @param Reg Reg address
jeromecoutant 7:bfe8272ced90 557 * @param Value Data to be written
bcostm 4:137bb367ba50 558 * @retval None
bcostm 4:137bb367ba50 559 */
bcostm 4:137bb367ba50 560 void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
bcostm 4:137bb367ba50 561 {
bcostm 4:137bb367ba50 562 I2Cx_WriteMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
bcostm 4:137bb367ba50 563 }
bcostm 4:137bb367ba50 564
bcostm 4:137bb367ba50 565 /**
bcostm 4:137bb367ba50 566 * @brief Reads a single data.
jeromecoutant 7:bfe8272ced90 567 * @param Addr I2C address
jeromecoutant 7:bfe8272ced90 568 * @param Reg Reg address
bcostm 4:137bb367ba50 569 * @retval Data to be read
bcostm 4:137bb367ba50 570 */
bcostm 4:137bb367ba50 571 uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg)
bcostm 4:137bb367ba50 572 {
bcostm 4:137bb367ba50 573 uint8_t read_value = 0;
bcostm 4:137bb367ba50 574
bcostm 4:137bb367ba50 575 I2Cx_ReadMultiple(&hI2cHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
bcostm 4:137bb367ba50 576
bcostm 4:137bb367ba50 577 return read_value;
bcostm 4:137bb367ba50 578 }
bcostm 4:137bb367ba50 579
bcostm 4:137bb367ba50 580 /**
bcostm 4:137bb367ba50 581 * @brief Reads multiple data with I2C communication
bcostm 4:137bb367ba50 582 * channel from TouchScreen.
jeromecoutant 7:bfe8272ced90 583 * @param Addr I2C address
jeromecoutant 7:bfe8272ced90 584 * @param Reg Register address
jeromecoutant 7:bfe8272ced90 585 * @param Buffer Pointer to data buffer
jeromecoutant 7:bfe8272ced90 586 * @param Length Length of the data
bcostm 4:137bb367ba50 587 * @retval HAL status
bcostm 4:137bb367ba50 588 */
bcostm 4:137bb367ba50 589 uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 590 {
bcostm 4:137bb367ba50 591 return I2Cx_ReadMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
bcostm 4:137bb367ba50 592 }
bcostm 4:137bb367ba50 593
bcostm 4:137bb367ba50 594 /**
bcostm 4:137bb367ba50 595 * @brief Writes multiple data with I2C communication
bcostm 4:137bb367ba50 596 * channel from MCU to TouchScreen.
jeromecoutant 7:bfe8272ced90 597 * @param Addr I2C address
jeromecoutant 7:bfe8272ced90 598 * @param Reg Register address
jeromecoutant 7:bfe8272ced90 599 * @param Buffer Pointer to data buffer
jeromecoutant 7:bfe8272ced90 600 * @param Length Length of the data
bcostm 4:137bb367ba50 601 * @retval None
bcostm 4:137bb367ba50 602 */
bcostm 4:137bb367ba50 603 void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 604 {
bcostm 4:137bb367ba50 605 I2Cx_WriteMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
bcostm 4:137bb367ba50 606 }
bcostm 4:137bb367ba50 607
bcostm 4:137bb367ba50 608 /**
bcostm 4:137bb367ba50 609 * @brief Checks if target device is ready for communication.
bcostm 4:137bb367ba50 610 * @note This function is used with Memory devices
jeromecoutant 7:bfe8272ced90 611 * @param DevAddress Target device address
jeromecoutant 7:bfe8272ced90 612 * @param Trials Number of trials
bcostm 4:137bb367ba50 613 * @retval HAL status
bcostm 4:137bb367ba50 614 */
bcostm 4:137bb367ba50 615 HAL_StatusTypeDef SENSOR_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
bcostm 4:137bb367ba50 616 {
bcostm 4:137bb367ba50 617 return (I2Cx_IsDeviceReady(&hI2cHandler, DevAddress, Trials));
bcostm 4:137bb367ba50 618 }
bcostm 4:137bb367ba50 619
bcostm 4:137bb367ba50 620 /**
jeromecoutant 7:bfe8272ced90 621 * @brief Delay function used in Sensor low level driver.
jeromecoutant 7:bfe8272ced90 622 * @param Delay Delay in ms
bcostm 4:137bb367ba50 623 * @retval None
bcostm 4:137bb367ba50 624 */
bcostm 4:137bb367ba50 625 void SENSOR_IO_Delay(uint32_t Delay)
bcostm 4:137bb367ba50 626 {
bcostm 4:137bb367ba50 627 HAL_Delay(Delay);
bcostm 4:137bb367ba50 628 }
bcostm 4:137bb367ba50 629
bcostm 5:0c70bc6d2dc0 630 /******************************** LINK NFC ********************************/
bcostm 5:0c70bc6d2dc0 631
bcostm 5:0c70bc6d2dc0 632 /**
bcostm 5:0c70bc6d2dc0 633 * @brief Initializes Sensors low level.
jeromecoutant 7:bfe8272ced90 634 * @param GpoIrqEnable 0x0 is disable, otherwise enabled
bcostm 5:0c70bc6d2dc0 635 * @retval None
bcostm 5:0c70bc6d2dc0 636 */
bcostm 5:0c70bc6d2dc0 637 void NFC_IO_Init(uint8_t GpoIrqEnable)
bcostm 5:0c70bc6d2dc0 638 {
bcostm 5:0c70bc6d2dc0 639 GPIO_InitTypeDef GPIO_InitStruct;
bcostm 5:0c70bc6d2dc0 640
bcostm 5:0c70bc6d2dc0 641 /* I2C init */
bcostm 5:0c70bc6d2dc0 642 I2Cx_Init(&hI2cHandler);
bcostm 5:0c70bc6d2dc0 643
bcostm 5:0c70bc6d2dc0 644 /* GPIO Ports Clock Enable */
bcostm 5:0c70bc6d2dc0 645 NFC_GPIO_CLK_ENABLE();
bcostm 5:0c70bc6d2dc0 646
bcostm 5:0c70bc6d2dc0 647 /* Configure GPIO pins for GPO (PE4) */
bcostm 5:0c70bc6d2dc0 648 if(GpoIrqEnable == 0)
bcostm 5:0c70bc6d2dc0 649 {
bcostm 5:0c70bc6d2dc0 650 GPIO_InitStruct.Pin = NFC_GPIO_GPO_PIN;
bcostm 5:0c70bc6d2dc0 651 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
bcostm 5:0c70bc6d2dc0 652 GPIO_InitStruct.Pull = GPIO_PULLUP;
bcostm 5:0c70bc6d2dc0 653 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 5:0c70bc6d2dc0 654 HAL_GPIO_Init(NFC_GPIO_GPO_PIN_PORT, &GPIO_InitStruct);
bcostm 5:0c70bc6d2dc0 655 }
bcostm 5:0c70bc6d2dc0 656 else
bcostm 5:0c70bc6d2dc0 657 {
bcostm 5:0c70bc6d2dc0 658 GPIO_InitStruct.Pin = NFC_GPIO_GPO_PIN;
bcostm 5:0c70bc6d2dc0 659 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
bcostm 5:0c70bc6d2dc0 660 GPIO_InitStruct.Pull = GPIO_PULLUP;
bcostm 5:0c70bc6d2dc0 661 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 5:0c70bc6d2dc0 662 HAL_GPIO_Init(NFC_GPIO_GPO_PIN_PORT, &GPIO_InitStruct);
bcostm 5:0c70bc6d2dc0 663 /* Enable and set EXTI4_IRQn Interrupt to the lowest priority */
bcostm 5:0c70bc6d2dc0 664 HAL_NVIC_SetPriority(EXTI4_IRQn, 3, 0);
bcostm 5:0c70bc6d2dc0 665 HAL_NVIC_EnableIRQ(EXTI4_IRQn);
bcostm 5:0c70bc6d2dc0 666 }
bcostm 5:0c70bc6d2dc0 667
bcostm 5:0c70bc6d2dc0 668 /* Configure GPIO pins for DISABLE (PE2)*/
bcostm 5:0c70bc6d2dc0 669 GPIO_InitStruct.Pin = NFC_GPIO_RFDISABLE_PIN;
bcostm 5:0c70bc6d2dc0 670 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 5:0c70bc6d2dc0 671 GPIO_InitStruct.Pull = GPIO_NOPULL;
bcostm 5:0c70bc6d2dc0 672 HAL_GPIO_Init(NFC_GPIO_RFDISABLE_PIN_PORT, &GPIO_InitStruct);
bcostm 5:0c70bc6d2dc0 673 }
bcostm 5:0c70bc6d2dc0 674
bcostm 5:0c70bc6d2dc0 675 /**
bcostm 5:0c70bc6d2dc0 676 * @brief DeInitializes Sensors low level.
bcostm 5:0c70bc6d2dc0 677 * @retval None
bcostm 5:0c70bc6d2dc0 678 */
bcostm 5:0c70bc6d2dc0 679 void NFC_IO_DeInit(void)
bcostm 5:0c70bc6d2dc0 680 {
bcostm 5:0c70bc6d2dc0 681 I2Cx_DeInit(&hI2cHandler);
bcostm 5:0c70bc6d2dc0 682 }
bcostm 5:0c70bc6d2dc0 683
bcostm 5:0c70bc6d2dc0 684 /**
bcostm 5:0c70bc6d2dc0 685 * @brief This functions reads a response of the M24SR device
jeromecoutant 7:bfe8272ced90 686 * @param Addr: M24SR I2C address (do we really need to add??)
jeromecoutant 7:bfe8272ced90 687 * @param pBuffer Pointer on the buffer to retrieve M24SR response
jeromecoutant 7:bfe8272ced90 688 * @param Length Length of the data
jeromecoutant 7:bfe8272ced90 689 * @retval Status Success or Timeout
bcostm 5:0c70bc6d2dc0 690 */
bcostm 5:0c70bc6d2dc0 691 uint16_t NFC_IO_ReadMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length )
bcostm 5:0c70bc6d2dc0 692 {
bcostm 5:0c70bc6d2dc0 693 uint16_t status ;
bcostm 5:0c70bc6d2dc0 694
bcostm 5:0c70bc6d2dc0 695 /* Before calling this function M24SR must be ready: check to detect potential issues */
bcostm 5:0c70bc6d2dc0 696 status = NFC_IO_IsDeviceReady(Addr, NFC_I2C_TRIALS);
bcostm 5:0c70bc6d2dc0 697 if (status != NFC_I2C_STATUS_SUCCESS)
bcostm 5:0c70bc6d2dc0 698 {
bcostm 5:0c70bc6d2dc0 699 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 700 }
bcostm 5:0c70bc6d2dc0 701
bcostm 5:0c70bc6d2dc0 702 if( HAL_I2C_Master_Receive(&hI2cHandler, Addr, (uint8_t*)pBuffer, Length, NFC_I2C_TIMEOUT_STD) != HAL_OK)
bcostm 5:0c70bc6d2dc0 703 {
bcostm 5:0c70bc6d2dc0 704 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 705 }
bcostm 5:0c70bc6d2dc0 706
bcostm 5:0c70bc6d2dc0 707 return NFC_I2C_STATUS_SUCCESS;
bcostm 5:0c70bc6d2dc0 708 }
bcostm 5:0c70bc6d2dc0 709
bcostm 5:0c70bc6d2dc0 710 /**
bcostm 5:0c70bc6d2dc0 711 * @brief This functions sends the command buffer
jeromecoutant 7:bfe8272ced90 712 * @param Addr: M24SR I2C address (do we really need to add??)
jeromecoutant 7:bfe8272ced90 713 * @param pBuffer pointer to the buffer to send to the M24SR
jeromecoutant 7:bfe8272ced90 714 * @param Length Length of the data
jeromecoutant 7:bfe8272ced90 715 * @retval Status Success or Timeout
bcostm 5:0c70bc6d2dc0 716 */
bcostm 5:0c70bc6d2dc0 717 uint16_t NFC_IO_WriteMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length)
bcostm 5:0c70bc6d2dc0 718 {
bcostm 5:0c70bc6d2dc0 719 uint16_t status ;
bcostm 5:0c70bc6d2dc0 720
bcostm 5:0c70bc6d2dc0 721 /* Before calling this function M24SR must be ready: check to detect potential issues */
bcostm 5:0c70bc6d2dc0 722 status = NFC_IO_IsDeviceReady(Addr, NFC_I2C_TRIALS);
bcostm 5:0c70bc6d2dc0 723 if (status != NFC_I2C_STATUS_SUCCESS)
bcostm 5:0c70bc6d2dc0 724 {
bcostm 5:0c70bc6d2dc0 725 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 726 }
bcostm 5:0c70bc6d2dc0 727
bcostm 5:0c70bc6d2dc0 728 if( HAL_I2C_Master_Transmit(&hI2cHandler, Addr, (uint8_t*)pBuffer, Length, NFC_I2C_TIMEOUT_STD) != HAL_OK)
bcostm 5:0c70bc6d2dc0 729 {
bcostm 5:0c70bc6d2dc0 730 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 731 }
bcostm 5:0c70bc6d2dc0 732
bcostm 5:0c70bc6d2dc0 733 return NFC_I2C_STATUS_SUCCESS;
bcostm 5:0c70bc6d2dc0 734 }
bcostm 5:0c70bc6d2dc0 735
bcostm 5:0c70bc6d2dc0 736 /**
bcostm 5:0c70bc6d2dc0 737 * @brief Checks if target device is ready for communication.
jeromecoutant 7:bfe8272ced90 738 * @param Addr: M24SR I2C address (do we really need to add??)
jeromecoutant 7:bfe8272ced90 739 * @param Trials Number of trials (currently not present in M24sr)
jeromecoutant 7:bfe8272ced90 740 * @retval Status Success or Timeout
bcostm 5:0c70bc6d2dc0 741 */
bcostm 5:0c70bc6d2dc0 742 uint16_t NFC_IO_IsDeviceReady (uint8_t Addr, uint32_t Trials)
bcostm 5:0c70bc6d2dc0 743 {
bcostm 5:0c70bc6d2dc0 744 HAL_StatusTypeDef status;
bcostm 5:0c70bc6d2dc0 745 uint32_t tickstart = 0;
bcostm 5:0c70bc6d2dc0 746 uint32_t currenttick = 0;
bcostm 5:0c70bc6d2dc0 747
bcostm 5:0c70bc6d2dc0 748 /* Get tick */
bcostm 5:0c70bc6d2dc0 749 tickstart = HAL_GetTick();
bcostm 5:0c70bc6d2dc0 750
bcostm 5:0c70bc6d2dc0 751 /* Wait until M24SR is ready or timeout occurs */
bcostm 5:0c70bc6d2dc0 752 do
bcostm 5:0c70bc6d2dc0 753 {
bcostm 5:0c70bc6d2dc0 754 status = HAL_I2C_IsDeviceReady(&hI2cHandler, Addr, Trials, NFC_I2C_TIMEOUT_STD);
bcostm 5:0c70bc6d2dc0 755 currenttick = HAL_GetTick();
bcostm 5:0c70bc6d2dc0 756 } while( ( (currenttick - tickstart) < NFC_I2C_TIMEOUT_MAX) && (status != HAL_OK) );
bcostm 5:0c70bc6d2dc0 757
bcostm 5:0c70bc6d2dc0 758 if (status != HAL_OK)
bcostm 5:0c70bc6d2dc0 759 {
bcostm 5:0c70bc6d2dc0 760 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 761 }
bcostm 5:0c70bc6d2dc0 762
bcostm 5:0c70bc6d2dc0 763 return NFC_I2C_STATUS_SUCCESS;
bcostm 5:0c70bc6d2dc0 764 }
bcostm 5:0c70bc6d2dc0 765
bcostm 5:0c70bc6d2dc0 766 /**
bcostm 5:0c70bc6d2dc0 767 * @brief This function read the state of the M24SR GPO
jeromecoutant 7:bfe8272ced90 768 * @retval GPIO_PinState state of the M24SR GPO
bcostm 5:0c70bc6d2dc0 769 */
bcostm 5:0c70bc6d2dc0 770 void NFC_IO_ReadState(uint8_t * pPinState)
bcostm 5:0c70bc6d2dc0 771 {
bcostm 5:0c70bc6d2dc0 772 *pPinState = (uint8_t)HAL_GPIO_ReadPin(NFC_GPIO_GPO_PIN_PORT,NFC_GPIO_GPO_PIN);
bcostm 5:0c70bc6d2dc0 773 }
bcostm 5:0c70bc6d2dc0 774
bcostm 5:0c70bc6d2dc0 775 /**
jeromecoutant 7:bfe8272ced90 776 * @brief This function sets the state of the M24SR RF disable pin
jeromecoutant 7:bfe8272ced90 777 * @param PinState put RF disable pin of M24SR in PinState (1 or 0)
bcostm 5:0c70bc6d2dc0 778 */
bcostm 5:0c70bc6d2dc0 779 void NFC_IO_RfDisable(uint8_t PinState)
bcostm 5:0c70bc6d2dc0 780 {
bcostm 5:0c70bc6d2dc0 781 HAL_GPIO_WritePin(NFC_GPIO_RFDISABLE_PIN_PORT,NFC_GPIO_RFDISABLE_PIN,(GPIO_PinState)PinState);
bcostm 5:0c70bc6d2dc0 782 }
bcostm 5:0c70bc6d2dc0 783
bcostm 5:0c70bc6d2dc0 784 /**
jeromecoutant 7:bfe8272ced90 785 * @brief Delay function used in M24SR low level driver.
jeromecoutant 7:bfe8272ced90 786 * @param Delay Delay in ms
bcostm 5:0c70bc6d2dc0 787 * @retval None
bcostm 5:0c70bc6d2dc0 788 */
bcostm 5:0c70bc6d2dc0 789 void NFC_IO_Delay(uint32_t Delay)
bcostm 5:0c70bc6d2dc0 790 {
bcostm 5:0c70bc6d2dc0 791 HAL_Delay(Delay);
bcostm 5:0c70bc6d2dc0 792 }
bcostm 5:0c70bc6d2dc0 793
bcostm 4:137bb367ba50 794 /**
bcostm 4:137bb367ba50 795 * @}
bcostm 4:137bb367ba50 796 */
bcostm 4:137bb367ba50 797
bcostm 4:137bb367ba50 798 /**
bcostm 4:137bb367ba50 799 * @}
bcostm 4:137bb367ba50 800 */
bcostm 4:137bb367ba50 801
bcostm 4:137bb367ba50 802 /**
bcostm 4:137bb367ba50 803 * @}
bcostm 4:137bb367ba50 804 */
bcostm 4:137bb367ba50 805
bcostm 4:137bb367ba50 806 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/