STM32F429ZI Discovery board drivers
Dependents: 2a 2b 2c 2d1 ... more
stm32f429i_discovery.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f429i_discovery.c 00004 * @author MCD Application Team 00005 * @brief This file provides set of firmware functions to manage Leds and 00006 * push-button available on STM32F429I-Discovery Kit from STMicroelectronics. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32f429i_discovery.h" 00039 #include "cmsis_nvic.h" // // Added for mbed 00040 00041 // Added for mbed. This function replaces HAL_Delay() 00042 void wait_ms(int ms); 00043 00044 /** @defgroup BSP BSP 00045 * @{ 00046 */ 00047 00048 /** @defgroup STM32F429I_DISCOVERY STM32F429I DISCOVERY 00049 * @{ 00050 */ 00051 00052 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL STM32F429I DISCOVERY LOW LEVEL 00053 * @brief This file provides set of firmware functions to manage Leds and push-button 00054 * available on STM32F429I-Discovery Kit from STMicroelectronics. 00055 * @{ 00056 */ 00057 00058 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F429I DISCOVERY LOW LEVEL Private TypesDefinitions 00059 * @{ 00060 */ 00061 /** 00062 * @} 00063 */ 00064 00065 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Defines STM32F429I DISCOVERY LOW LEVEL Private Defines 00066 * @{ 00067 */ 00068 00069 /** 00070 * @brief STM32F429I DISCO BSP Driver version number V2.1.6 00071 */ 00072 #define __STM32F429I_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */ 00073 #define __STM32F429I_DISCO_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */ 00074 #define __STM32F429I_DISCO_BSP_VERSION_SUB2 (0x06) /*!< [15:8] sub2 version */ 00075 #define __STM32F429I_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ 00076 #define __STM32F429I_DISCO_BSP_VERSION ((__STM32F429I_DISCO_BSP_VERSION_MAIN << 24)\ 00077 |(__STM32F429I_DISCO_BSP_VERSION_SUB1 << 16)\ 00078 |(__STM32F429I_DISCO_BSP_VERSION_SUB2 << 8 )\ 00079 |(__STM32F429I_DISCO_BSP_VERSION_RC)) 00080 /** 00081 * @} 00082 */ 00083 00084 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Macros STM32F429I DISCOVERY LOW LEVEL Private Macros 00085 * @{ 00086 */ 00087 /** 00088 * @} 00089 */ 00090 00091 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Variables STM32F429I DISCOVERY LOW LEVEL Private Variables 00092 * @{ 00093 */ 00094 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, 00095 LED4_GPIO_PORT}; 00096 00097 const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, 00098 LED4_PIN}; 00099 00100 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT}; 00101 const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN}; 00102 const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn}; 00103 00104 uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */ 00105 uint32_t SpixTimeout = SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */ 00106 00107 I2C_HandleTypeDef EEP_I2cHandle; 00108 static SPI_HandleTypeDef SpiHandle; 00109 static uint8_t Is_LCD_IO_Initialized = 0; 00110 00111 /** 00112 * @} 00113 */ 00114 00115 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32F429I DISCOVERY LOW LEVEL Private FunctionPrototypes 00116 * @{ 00117 */ 00118 /* I2Cx bus function */ 00119 static void I2Cx_Init(void); 00120 static void I2Cx_ITConfig(void); 00121 static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value); 00122 static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length); 00123 static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg); 00124 static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length); 00125 static void I2Cx_Error(void); 00126 static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c); 00127 #ifdef EE_M24LR64 00128 static HAL_StatusTypeDef I2Cx_WriteBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length); 00129 static HAL_StatusTypeDef I2Cx_ReadBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length); 00130 static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials); 00131 static void EEPROM_I2C_DMA_TX_IRQHandler(void); 00132 static void EEPROM_I2C_DMA_RX_IRQHandler(void); 00133 #endif /* EE_M24LR64 */ 00134 00135 /* SPIx bus function */ 00136 static void SPIx_Init(void); 00137 static void SPIx_Write(uint16_t Value); 00138 static uint32_t SPIx_Read(uint8_t ReadSize); 00139 static uint8_t SPIx_WriteRead(uint8_t Byte); 00140 static void SPIx_Error(void); 00141 static void SPIx_MspInit(SPI_HandleTypeDef *hspi); 00142 00143 /* Link function for LCD peripheral */ 00144 void LCD_IO_Init(void); 00145 void LCD_IO_WriteData(uint16_t RegValue); 00146 void LCD_IO_WriteReg(uint8_t Reg); 00147 uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize); 00148 void LCD_Delay(uint32_t delay); 00149 00150 /* IOExpander IO functions */ 00151 void IOE_Init(void); 00152 void IOE_ITConfig(void); 00153 void IOE_Delay(uint32_t Delay); 00154 void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); 00155 uint8_t IOE_Read(uint8_t Addr, uint8_t Reg); 00156 uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length); 00157 void IOE_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length); 00158 00159 /* Link function for GYRO peripheral */ 00160 void GYRO_IO_Init(void); 00161 void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite); 00162 void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead); 00163 00164 #ifdef EE_M24LR64 00165 /* Link function for I2C EEPROM peripheral */ 00166 void EEPROM_IO_Init(void); 00167 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize); 00168 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize); 00169 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials); 00170 #endif /* EE_M24LR64 */ 00171 00172 /** 00173 * @} 00174 */ 00175 00176 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Functions STM32F429I DISCOVERY LOW LEVEL Private Functions 00177 * @{ 00178 */ 00179 00180 /** 00181 * @brief This method returns the STM32F429I DISCO BSP Driver revision 00182 * @retval version: 0xXYZR (8bits for each decimal, R for RC) 00183 */ 00184 uint32_t BSP_GetVersion(void) 00185 { 00186 return __STM32F429I_DISCO_BSP_VERSION; 00187 } 00188 00189 /** 00190 * @brief Configures LED GPIO. 00191 * @param Led: Specifies the Led to be configured. 00192 * This parameter can be one of following parameters: 00193 * @arg LED3 00194 * @arg LED4 00195 */ 00196 void BSP_LED_Init(Led_TypeDef Led) 00197 { 00198 GPIO_InitTypeDef GPIO_InitStruct; 00199 00200 /* Enable the GPIO_LED Clock */ 00201 LEDx_GPIO_CLK_ENABLE(Led); 00202 00203 /* Configure the GPIO_LED pin */ 00204 GPIO_InitStruct.Pin = GPIO_PIN[Led]; 00205 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 00206 GPIO_InitStruct.Pull = GPIO_PULLUP; 00207 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; 00208 00209 HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct); 00210 00211 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); 00212 } 00213 00214 /** 00215 * @brief Turns selected LED On. 00216 * @param Led: Specifies the Led to be set on. 00217 * This parameter can be one of following parameters: 00218 * @arg LED3 00219 * @arg LED4 00220 */ 00221 void BSP_LED_On(Led_TypeDef Led) 00222 { 00223 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET); 00224 } 00225 00226 /** 00227 * @brief Turns selected LED Off. 00228 * @param Led: Specifies the Led to be set off. 00229 * This parameter can be one of following parameters: 00230 * @arg LED3 00231 * @arg LED4 00232 */ 00233 void BSP_LED_Off(Led_TypeDef Led) 00234 { 00235 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); 00236 } 00237 00238 /** 00239 * @brief Toggles the selected LED. 00240 * @param Led: Specifies the Led to be toggled. 00241 * This parameter can be one of following parameters: 00242 * @arg LED3 00243 * @arg LED4 00244 */ 00245 void BSP_LED_Toggle(Led_TypeDef Led) 00246 { 00247 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]); 00248 } 00249 00250 /** 00251 * @brief Configures Button GPIO and EXTI Line. 00252 * @param Button: Specifies the Button to be configured. 00253 * This parameter should be: BUTTON_KEY 00254 * @param ButtonMode: Specifies Button mode. 00255 * This parameter can be one of following parameters: 00256 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO 00257 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt 00258 * generation capability 00259 */ 00260 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) 00261 { 00262 GPIO_InitTypeDef GPIO_InitStruct; 00263 00264 /* Enable the BUTTON Clock */ 00265 BUTTONx_GPIO_CLK_ENABLE(Button); 00266 00267 if (ButtonMode == BUTTON_MODE_GPIO) 00268 { 00269 /* Configure Button pin as input */ 00270 GPIO_InitStruct.Pin = BUTTON_PIN[Button]; 00271 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 00272 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00273 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; 00274 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct); 00275 } 00276 00277 if (ButtonMode == BUTTON_MODE_EXTI) 00278 { 00279 /* Configure Button pin as input with External interrupt */ 00280 GPIO_InitStruct.Pin = BUTTON_PIN[Button]; 00281 GPIO_InitStruct.Pull = GPIO_NOPULL; 00282 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 00283 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct); 00284 00285 /* Enable and set Button EXTI Interrupt to the lowest priority */ 00286 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00); 00287 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); 00288 } 00289 } 00290 00291 /** 00292 * @brief Returns the selected Button state. 00293 * @param Button: Specifies the Button to be checked. 00294 * This parameter should be: BUTTON_KEY 00295 * @retval The Button GPIO pin value. 00296 */ 00297 uint32_t BSP_PB_GetState(Button_TypeDef Button) 00298 { 00299 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); 00300 } 00301 00302 /******************************************************************************* 00303 BUS OPERATIONS 00304 *******************************************************************************/ 00305 00306 /******************************* I2C Routines *********************************/ 00307 00308 /** 00309 * @brief I2Cx MSP Initialization 00310 * @param hi2c: I2C handle 00311 */ 00312 static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c) 00313 { 00314 GPIO_InitTypeDef GPIO_InitStruct; 00315 #ifdef EE_M24LR64 00316 static DMA_HandleTypeDef hdma_tx; 00317 static DMA_HandleTypeDef hdma_rx; 00318 00319 I2C_HandleTypeDef* pI2cHandle; 00320 pI2cHandle = &EEP_I2cHandle; 00321 #endif /* EE_M24LR64 */ 00322 00323 if (hi2c->Instance == DISCOVERY_I2Cx) 00324 { 00325 /* Configure the GPIOs ---------------------------------------------------*/ 00326 /* Enable GPIO clock */ 00327 DISCOVERY_I2Cx_SDA_GPIO_CLK_ENABLE(); 00328 DISCOVERY_I2Cx_SCL_GPIO_CLK_ENABLE(); 00329 00330 /* Configure I2C Tx as alternate function */ 00331 GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SCL_PIN; 00332 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; 00333 GPIO_InitStruct.Pull = GPIO_NOPULL; 00334 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; 00335 GPIO_InitStruct.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF; 00336 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct); 00337 00338 /* Configure I2C Rx as alternate function */ 00339 GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SDA_PIN; 00340 HAL_GPIO_Init(DISCOVERY_I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct); 00341 00342 00343 /* Configure the Discovery I2Cx peripheral -------------------------------*/ 00344 /* Enable I2C3 clock */ 00345 DISCOVERY_I2Cx_CLOCK_ENABLE(); 00346 00347 /* Force the I2C Peripheral Clock Reset */ 00348 DISCOVERY_I2Cx_FORCE_RESET(); 00349 00350 /* Release the I2C Peripheral Clock Reset */ 00351 DISCOVERY_I2Cx_RELEASE_RESET(); 00352 00353 /* Enable and set Discovery I2Cx Interrupt to the lowest priority */ 00354 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0); 00355 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn); 00356 00357 /* Enable and set Discovery I2Cx Interrupt to the lowest priority */ 00358 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0); 00359 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn); 00360 00361 #ifdef EE_M24LR64 00362 /* I2C DMA TX and RX channels configuration */ 00363 /* Enable the DMA clock */ 00364 EEPROM_I2C_DMA_CLK_ENABLE(); 00365 00366 /* Configure the DMA stream for the EE I2C peripheral TX direction */ 00367 /* Configure the DMA Stream */ 00368 hdma_tx.Instance = EEPROM_I2C_DMA_STREAM_TX; 00369 /* Set the parameters to be configured */ 00370 hdma_tx.Init.Channel = EEPROM_I2C_DMA_CHANNEL; 00371 hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; 00372 hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE; 00373 hdma_tx.Init.MemInc = DMA_MINC_ENABLE; 00374 hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 00375 hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 00376 hdma_tx.Init.Mode = DMA_NORMAL; 00377 hdma_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH; 00378 hdma_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE; 00379 hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; 00380 hdma_tx.Init.MemBurst = DMA_MBURST_SINGLE; 00381 hdma_tx.Init.PeriphBurst = DMA_PBURST_SINGLE; 00382 00383 /* Associate the initilalized hdma_tx handle to the the pI2cHandle handle */ 00384 __HAL_LINKDMA(pI2cHandle, hdmatx, hdma_tx); 00385 00386 /* Configure the DMA Stream */ 00387 HAL_DMA_Init(&hdma_tx); 00388 00389 // Added for mbed 00390 /* Configure and enable I2C DMA TX Channel interrupt */ 00391 //HAL_NVIC_SetPriority((IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn), EEPROM_I2C_DMA_PREPRIO, 0); 00392 //HAL_NVIC_EnableIRQ((IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn)); 00393 // Enable interrupt 00394 IRQn_Type irqn = (IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn); 00395 NVIC_ClearPendingIRQ(irqn); 00396 NVIC_DisableIRQ(irqn); 00397 NVIC_SetPriority(irqn, EEPROM_I2C_DMA_PREPRIO); 00398 NVIC_SetVector(irqn, (uint32_t)EEPROM_I2C_DMA_TX_IRQHandler); 00399 NVIC_EnableIRQ(irqn); 00400 00401 /* Configure the DMA stream for the EE I2C peripheral TX direction */ 00402 /* Configure the DMA Stream */ 00403 hdma_rx.Instance = EEPROM_I2C_DMA_STREAM_RX; 00404 /* Set the parameters to be configured */ 00405 hdma_rx.Init.Channel = EEPROM_I2C_DMA_CHANNEL; 00406 hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; 00407 hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE; 00408 hdma_rx.Init.MemInc = DMA_MINC_ENABLE; 00409 hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 00410 hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 00411 hdma_rx.Init.Mode = DMA_NORMAL; 00412 hdma_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH; 00413 hdma_rx.Init.FIFOMode = DMA_FIFOMODE_ENABLE; 00414 hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; 00415 hdma_rx.Init.MemBurst = DMA_MBURST_SINGLE; 00416 hdma_rx.Init.PeriphBurst = DMA_PBURST_SINGLE; 00417 00418 /* Associate the initilalized hdma_rx handle to the the pI2cHandle handle*/ 00419 __HAL_LINKDMA(pI2cHandle, hdmarx, hdma_rx); 00420 00421 /* Configure the DMA Stream */ 00422 HAL_DMA_Init(&hdma_rx); 00423 00424 // Added for mbed 00425 /* Configure and enable I2C DMA RX Channel interrupt */ 00426 //HAL_NVIC_SetPriority((IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn), EEPROM_I2C_DMA_PREPRIO, 0); 00427 //HAL_NVIC_EnableIRQ((IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn)); 00428 // Enable interrupt 00429 irqn = (IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn); 00430 NVIC_ClearPendingIRQ(irqn); 00431 NVIC_DisableIRQ(irqn); 00432 NVIC_SetPriority(irqn, EEPROM_I2C_DMA_PREPRIO); 00433 NVIC_SetVector(irqn, (uint32_t)EEPROM_I2C_DMA_RX_IRQHandler); 00434 NVIC_EnableIRQ(irqn); 00435 00436 #endif /* EE_M24LR64 */ 00437 } 00438 } 00439 00440 /** 00441 * @brief I2Cx Bus initialization. 00442 */ 00443 static void I2Cx_Init(void) 00444 { 00445 if(HAL_I2C_GetState(&EEP_I2cHandle) == HAL_I2C_STATE_RESET) 00446 { 00447 EEP_I2cHandle.Instance = DISCOVERY_I2Cx; 00448 EEP_I2cHandle.Init.ClockSpeed = BSP_I2C_SPEED; 00449 EEP_I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; 00450 EEP_I2cHandle.Init.OwnAddress1 = 0; 00451 EEP_I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; 00452 EEP_I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; 00453 EEP_I2cHandle.Init.OwnAddress2 = 0; 00454 EEP_I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; 00455 EEP_I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; 00456 00457 /* Init the I2C */ 00458 I2Cx_MspInit(&EEP_I2cHandle); 00459 HAL_I2C_Init(&EEP_I2cHandle); 00460 } 00461 } 00462 00463 /** 00464 * @brief Configures Interruption pin for I2C communication. 00465 */ 00466 static void I2Cx_ITConfig(void) 00467 { 00468 GPIO_InitTypeDef GPIO_InitStruct; 00469 00470 /* Enable the GPIO EXTI Clock */ 00471 STMPE811_INT_CLK_ENABLE(); 00472 00473 GPIO_InitStruct.Pin = STMPE811_INT_PIN; 00474 GPIO_InitStruct.Pull = GPIO_PULLUP; 00475 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; 00476 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; 00477 HAL_GPIO_Init(STMPE811_INT_GPIO_PORT, &GPIO_InitStruct); 00478 00479 /* Enable and set GPIO EXTI Interrupt to the highest priority */ 00480 HAL_NVIC_SetPriority((IRQn_Type)(STMPE811_INT_EXTI), 0x0F, 0x00); 00481 HAL_NVIC_EnableIRQ((IRQn_Type)(STMPE811_INT_EXTI)); 00482 } 00483 00484 /** 00485 * @brief Writes a value in a register of the device through BUS. 00486 * @param Addr: Device address on BUS Bus. 00487 * @param Reg: The target register address to write 00488 * @param Value: The target register value to be written 00489 */ 00490 static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value) 00491 { 00492 HAL_StatusTypeDef status = HAL_OK; 00493 00494 status = HAL_I2C_Mem_Write(&EEP_I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout); 00495 00496 /* Check the communication status */ 00497 if(status != HAL_OK) 00498 { 00499 /* Re-Initialize the BUS */ 00500 I2Cx_Error(); 00501 } 00502 } 00503 00504 /** 00505 * @brief Writes a value in a register of the device through BUS. 00506 * @param Addr: Device address on BUS Bus. 00507 * @param Reg: The target register address to write 00508 * @param pBuffer: The target register value to be written 00509 * @param Length: buffer size to be written 00510 */ 00511 static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length) 00512 { 00513 HAL_StatusTypeDef status = HAL_OK; 00514 00515 status = HAL_I2C_Mem_Write(&EEP_I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout); 00516 00517 /* Check the communication status */ 00518 if(status != HAL_OK) 00519 { 00520 /* Re-Initialize the BUS */ 00521 I2Cx_Error(); 00522 } 00523 } 00524 00525 /** 00526 * @brief Reads a register of the device through BUS. 00527 * @param Addr: Device address on BUS Bus. 00528 * @param Reg: The target register address to write 00529 * @retval Data read at register address 00530 */ 00531 static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg) 00532 { 00533 HAL_StatusTypeDef status = HAL_OK; 00534 uint8_t value = 0; 00535 00536 status = HAL_I2C_Mem_Read(&EEP_I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value, 1, I2cxTimeout); 00537 00538 /* Check the communication status */ 00539 if(status != HAL_OK) 00540 { 00541 /* Re-Initialize the BUS */ 00542 I2Cx_Error(); 00543 00544 } 00545 return value; 00546 } 00547 00548 /** 00549 * @brief Reads multiple data on the BUS. 00550 * @param Addr: I2C Address 00551 * @param Reg: Reg Address 00552 * @param pBuffer: pointer to read data buffer 00553 * @param Length: length of the data 00554 * @retval 0 if no problems to read multiple data 00555 */ 00556 static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length) 00557 { 00558 HAL_StatusTypeDef status = HAL_OK; 00559 00560 status = HAL_I2C_Mem_Read(&EEP_I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout); 00561 00562 /* Check the communication status */ 00563 if(status == HAL_OK) 00564 { 00565 return 0; 00566 } 00567 else 00568 { 00569 /* Re-Initialize the BUS */ 00570 I2Cx_Error(); 00571 00572 return 1; 00573 } 00574 } 00575 00576 #ifdef EE_M24LR64 00577 /** 00578 * @brief Writes a value in a register of the device through BUS in using DMA mode. 00579 * @param Addr: Device address on BUS Bus. 00580 * @param Reg: The target register address to write 00581 * @param pBuffer: The target register value to be written 00582 * @param Length: buffer size to be written 00583 * @retval HAL status 00584 */ 00585 static HAL_StatusTypeDef I2Cx_WriteBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length) 00586 { 00587 HAL_StatusTypeDef status = HAL_OK; 00588 00589 status = HAL_I2C_Mem_Write_DMA(&EEP_I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_16BIT, pBuffer, Length); 00590 00591 /* Check the communication status */ 00592 if(status != HAL_OK) 00593 { 00594 /* Re-Initialize the BUS */ 00595 I2Cx_Error(); 00596 } 00597 00598 return status; 00599 } 00600 00601 /** 00602 * @brief Reads multiple data on the BUS in using DMA mode. 00603 * @param Addr: I2C Address 00604 * @param Reg: Reg Address 00605 * @param pBuffer: pointer to read data buffer 00606 * @param Length: length of the data 00607 * @retval HAL status 00608 */ 00609 static HAL_StatusTypeDef I2Cx_ReadBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length) 00610 { 00611 HAL_StatusTypeDef status = HAL_OK; 00612 00613 status = HAL_I2C_Mem_Read_DMA(&EEP_I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_16BIT, pBuffer, Length); 00614 00615 /* Check the communication status */ 00616 if(status != HAL_OK) 00617 { 00618 /* Re-Initialize the BUS */ 00619 I2Cx_Error(); 00620 } 00621 00622 return status; 00623 } 00624 00625 /** 00626 * @brief Checks if target device is ready for communication. 00627 * @note This function is used with Memory devices 00628 * @param DevAddress: Target device address 00629 * @param Trials: Number of trials 00630 * @retval HAL status 00631 */ 00632 static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials) 00633 { 00634 return (HAL_I2C_IsDeviceReady(&EEP_I2cHandle, DevAddress, Trials, I2cxTimeout)); 00635 } 00636 #endif /* EE_M24LR64 */ 00637 00638 /** 00639 * @brief I2Cx error treatment function 00640 */ 00641 static void I2Cx_Error(void) 00642 { 00643 /* De-initialize the I2C communication BUS */ 00644 HAL_I2C_DeInit(&EEP_I2cHandle); 00645 00646 /* Re-Initialize the I2C communication BUS */ 00647 I2Cx_Init(); 00648 } 00649 00650 /******************************* SPI Routines *********************************/ 00651 00652 /** 00653 * @brief SPIx Bus initialization 00654 */ 00655 static void SPIx_Init(void) 00656 { 00657 if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET) 00658 { 00659 /* SPI configuration -----------------------------------------------------*/ 00660 SpiHandle.Instance = DISCOVERY_SPIx; 00661 /* SPI baudrate is set to 5.6 MHz (PCLK2/SPI_BaudRatePrescaler = 90/16 = 5.625 MHz) 00662 to verify these constraints: 00663 - ILI9341 LCD SPI interface max baudrate is 10MHz for write and 6.66MHz for read 00664 - l3gd20 SPI interface max baudrate is 10MHz for write/read 00665 - PCLK2 frequency is set to 90 MHz 00666 */ 00667 SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; 00668 00669 /* On STM32F429I-Discovery, LCD ID cannot be read then keep a common configuration */ 00670 /* for LCD and GYRO (SPI_DIRECTION_2LINES) */ 00671 /* Note: To read a register a LCD, SPI_DIRECTION_1LINE should be set */ 00672 SpiHandle.Init.Direction = SPI_DIRECTION_2LINES; 00673 SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE; 00674 SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW; 00675 SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; 00676 SpiHandle.Init.CRCPolynomial = 7; 00677 SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; 00678 SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; 00679 SpiHandle.Init.NSS = SPI_NSS_SOFT; 00680 SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED; 00681 SpiHandle.Init.Mode = SPI_MODE_MASTER; 00682 00683 SPIx_MspInit(&SpiHandle); 00684 HAL_SPI_Init(&SpiHandle); 00685 } 00686 } 00687 00688 /** 00689 * @brief Reads 4 bytes from device. 00690 * @param ReadSize: Number of bytes to read (max 4 bytes) 00691 * @retval Value read on the SPI 00692 */ 00693 static uint32_t SPIx_Read(uint8_t ReadSize) 00694 { 00695 HAL_StatusTypeDef status = HAL_OK; 00696 uint32_t readvalue; 00697 00698 status = HAL_SPI_Receive(&SpiHandle, (uint8_t*) &readvalue, ReadSize, SpixTimeout); 00699 00700 /* Check the communication status */ 00701 if(status != HAL_OK) 00702 { 00703 /* Re-Initialize the BUS */ 00704 SPIx_Error(); 00705 } 00706 00707 return readvalue; 00708 } 00709 00710 /** 00711 * @brief Writes a byte to device. 00712 * @param Value: value to be written 00713 */ 00714 static void SPIx_Write(uint16_t Value) 00715 { 00716 HAL_StatusTypeDef status = HAL_OK; 00717 00718 status = HAL_SPI_Transmit(&SpiHandle, (uint8_t*) &Value, 1, SpixTimeout); 00719 00720 /* Check the communication status */ 00721 if(status != HAL_OK) 00722 { 00723 /* Re-Initialize the BUS */ 00724 SPIx_Error(); 00725 } 00726 } 00727 00728 /** 00729 * @brief Sends a Byte through the SPI interface and return the Byte received 00730 * from the SPI bus. 00731 * @param Byte: Byte send. 00732 * @retval The received byte value 00733 */ 00734 static uint8_t SPIx_WriteRead(uint8_t Byte) 00735 { 00736 uint8_t receivedbyte = 0; 00737 00738 /* Send a Byte through the SPI peripheral */ 00739 /* Read byte from the SPI bus */ 00740 if(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*) &Byte, (uint8_t*) &receivedbyte, 1, SpixTimeout) != HAL_OK) 00741 { 00742 SPIx_Error(); 00743 } 00744 00745 return receivedbyte; 00746 } 00747 00748 /** 00749 * @brief SPIx error treatment function. 00750 */ 00751 static void SPIx_Error(void) 00752 { 00753 /* De-initialize the SPI communication BUS */ 00754 HAL_SPI_DeInit(&SpiHandle); 00755 00756 /* Re- Initialize the SPI communication BUS */ 00757 SPIx_Init(); 00758 } 00759 00760 /** 00761 * @brief SPI MSP Init. 00762 * @param hspi: SPI handle 00763 */ 00764 static void SPIx_MspInit(SPI_HandleTypeDef *hspi) 00765 { 00766 GPIO_InitTypeDef GPIO_InitStructure; 00767 00768 /* Enable SPIx clock */ 00769 DISCOVERY_SPIx_CLK_ENABLE(); 00770 00771 /* Enable DISCOVERY_SPI GPIO clock */ 00772 DISCOVERY_SPIx_GPIO_CLK_ENABLE(); 00773 00774 /* configure SPI SCK, MOSI and MISO */ 00775 GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MOSI_PIN | DISCOVERY_SPIx_MISO_PIN); 00776 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; 00777 GPIO_InitStructure.Pull = GPIO_PULLDOWN; 00778 GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM; 00779 GPIO_InitStructure.Alternate = DISCOVERY_SPIx_AF; 00780 HAL_GPIO_Init(DISCOVERY_SPIx_GPIO_PORT, &GPIO_InitStructure); 00781 } 00782 00783 /********************************* LINK LCD ***********************************/ 00784 00785 /** 00786 * @brief Configures the LCD_SPI interface. 00787 */ 00788 void LCD_IO_Init(void) 00789 { 00790 GPIO_InitTypeDef GPIO_InitStructure; 00791 00792 if(Is_LCD_IO_Initialized == 0) 00793 { 00794 Is_LCD_IO_Initialized = 1; 00795 00796 /* Configure NCS in Output Push-Pull mode */ 00797 LCD_WRX_GPIO_CLK_ENABLE(); 00798 GPIO_InitStructure.Pin = LCD_WRX_PIN; 00799 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 00800 GPIO_InitStructure.Pull = GPIO_NOPULL; 00801 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; 00802 HAL_GPIO_Init(LCD_WRX_GPIO_PORT, &GPIO_InitStructure); 00803 00804 LCD_RDX_GPIO_CLK_ENABLE(); 00805 GPIO_InitStructure.Pin = LCD_RDX_PIN; 00806 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 00807 GPIO_InitStructure.Pull = GPIO_NOPULL; 00808 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; 00809 HAL_GPIO_Init(LCD_RDX_GPIO_PORT, &GPIO_InitStructure); 00810 00811 /* Configure the LCD Control pins ----------------------------------------*/ 00812 LCD_NCS_GPIO_CLK_ENABLE(); 00813 00814 /* Configure NCS in Output Push-Pull mode */ 00815 GPIO_InitStructure.Pin = LCD_NCS_PIN; 00816 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 00817 GPIO_InitStructure.Pull = GPIO_NOPULL; 00818 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; 00819 HAL_GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure); 00820 00821 /* Set or Reset the control line */ 00822 LCD_CS_LOW(); 00823 LCD_CS_HIGH(); 00824 00825 SPIx_Init(); 00826 } 00827 } 00828 00829 /** 00830 * @brief Writes register value. 00831 */ 00832 void LCD_IO_WriteData(uint16_t RegValue) 00833 { 00834 /* Set WRX to send data */ 00835 LCD_WRX_HIGH(); 00836 00837 /* Reset LCD control line(/CS) and Send data */ 00838 LCD_CS_LOW(); 00839 SPIx_Write(RegValue); 00840 00841 /* Deselect: Chip Select high */ 00842 LCD_CS_HIGH(); 00843 } 00844 00845 /** 00846 * @brief Writes register address. 00847 */ 00848 void LCD_IO_WriteReg(uint8_t Reg) 00849 { 00850 /* Reset WRX to send command */ 00851 LCD_WRX_LOW(); 00852 00853 /* Reset LCD control line(/CS) and Send command */ 00854 LCD_CS_LOW(); 00855 SPIx_Write(Reg); 00856 00857 /* Deselect: Chip Select high */ 00858 LCD_CS_HIGH(); 00859 } 00860 00861 /** 00862 * @brief Reads register value. 00863 * @param RegValue Address of the register to read 00864 * @param ReadSize Number of bytes to read 00865 * @retval Content of the register value 00866 */ 00867 uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) 00868 { 00869 uint32_t readvalue = 0; 00870 00871 /* Select: Chip Select low */ 00872 LCD_CS_LOW(); 00873 00874 /* Reset WRX to send command */ 00875 LCD_WRX_LOW(); 00876 00877 SPIx_Write(RegValue); 00878 00879 readvalue = SPIx_Read(ReadSize); 00880 00881 /* Set WRX to send data */ 00882 LCD_WRX_HIGH(); 00883 00884 /* Deselect: Chip Select high */ 00885 LCD_CS_HIGH(); 00886 00887 return readvalue; 00888 } 00889 00890 /** 00891 * @brief Wait for loop in ms. 00892 * @param Delay in ms. 00893 */ 00894 void LCD_Delay(uint32_t Delay) 00895 { 00896 //HAL_Delay(Delay); 00897 wait_ms(Delay); 00898 } 00899 00900 /******************************************************************************* 00901 LINK OPERATIONS 00902 *******************************************************************************/ 00903 00904 /********************************* LINK IOE ***********************************/ 00905 00906 /** 00907 * @brief IOE Low Level Initialization. 00908 */ 00909 void IOE_Init(void) 00910 { 00911 I2Cx_Init(); 00912 } 00913 00914 /** 00915 * @brief IOE Low Level Interrupt configuration. 00916 */ 00917 void IOE_ITConfig(void) 00918 { 00919 I2Cx_ITConfig(); 00920 } 00921 00922 /** 00923 * @brief IOE Writes single data operation. 00924 * @param Addr: I2C Address 00925 * @param Reg: Reg Address 00926 * @param Value: Data to be written 00927 */ 00928 void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) 00929 { 00930 I2Cx_WriteData(Addr, Reg, Value); 00931 } 00932 00933 /** 00934 * @brief IOE Reads single data. 00935 * @param Addr: I2C Address 00936 * @param Reg: Reg Address 00937 * @retval The read data 00938 */ 00939 uint8_t IOE_Read(uint8_t Addr, uint8_t Reg) 00940 { 00941 return I2Cx_ReadData(Addr, Reg); 00942 } 00943 00944 /** 00945 * @brief IOE Writes multiple data. 00946 * @param Addr: I2C Address 00947 * @param Reg: Reg Address 00948 * @param pBuffer: pointer to data buffer 00949 * @param Length: length of the data 00950 */ 00951 void IOE_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length) 00952 { 00953 I2Cx_WriteBuffer(Addr, Reg, pBuffer, Length); 00954 } 00955 00956 /** 00957 * @brief IOE Reads multiple data. 00958 * @param Addr: I2C Address 00959 * @param Reg: Reg Address 00960 * @param pBuffer: pointer to data buffer 00961 * @param Length: length of the data 00962 * @retval 0 if no problems to read multiple data 00963 */ 00964 uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length) 00965 { 00966 return I2Cx_ReadBuffer(Addr, Reg, pBuffer, Length); 00967 } 00968 00969 /** 00970 * @brief IOE Delay. 00971 * @param Delay in ms 00972 */ 00973 void IOE_Delay(uint32_t Delay) 00974 { 00975 //HAL_Delay(Delay); 00976 wait_ms(Delay); 00977 } 00978 00979 /********************************* LINK GYROSCOPE *****************************/ 00980 00981 /** 00982 * @brief Configures the Gyroscope SPI interface. 00983 */ 00984 void GYRO_IO_Init(void) 00985 { 00986 GPIO_InitTypeDef GPIO_InitStructure; 00987 00988 /* Configure the Gyroscope Control pins ------------------------------------*/ 00989 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */ 00990 GYRO_CS_GPIO_CLK_ENABLE(); 00991 GPIO_InitStructure.Pin = GYRO_CS_PIN; 00992 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 00993 GPIO_InitStructure.Pull = GPIO_NOPULL; 00994 GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM; 00995 HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure); 00996 00997 /* Deselect: Chip Select high */ 00998 GYRO_CS_HIGH(); 00999 01000 /* Enable INT1, INT2 GPIO clock and Configure GPIO PINs to detect Interrupts */ 01001 GYRO_INT_GPIO_CLK_ENABLE(); 01002 GPIO_InitStructure.Pin = GYRO_INT1_PIN | GYRO_INT2_PIN; 01003 GPIO_InitStructure.Mode = GPIO_MODE_INPUT; 01004 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; 01005 GPIO_InitStructure.Pull= GPIO_NOPULL; 01006 HAL_GPIO_Init(GYRO_INT_GPIO_PORT, &GPIO_InitStructure); 01007 01008 SPIx_Init(); 01009 } 01010 01011 /** 01012 * @brief Writes one byte to the Gyroscope. 01013 * @param pBuffer: Pointer to the buffer containing the data to be written to the Gyroscope. 01014 * @param WriteAddr: Gyroscope's internal address to write to. 01015 * @param NumByteToWrite: Number of bytes to write. 01016 */ 01017 void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) 01018 { 01019 /* Configure the MS bit: 01020 - When 0, the address will remain unchanged in multiple read/write commands. 01021 - When 1, the address will be auto incremented in multiple read/write commands. 01022 */ 01023 if(NumByteToWrite > 0x01) 01024 { 01025 WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD; 01026 } 01027 /* Set chip select Low at the start of the transmission */ 01028 GYRO_CS_LOW(); 01029 01030 /* Send the Address of the indexed register */ 01031 SPIx_WriteRead(WriteAddr); 01032 01033 /* Send the data that will be written into the device (MSB First) */ 01034 while(NumByteToWrite >= 0x01) 01035 { 01036 SPIx_WriteRead(*pBuffer); 01037 NumByteToWrite--; 01038 pBuffer++; 01039 } 01040 01041 /* Set chip select High at the end of the transmission */ 01042 GYRO_CS_HIGH(); 01043 } 01044 01045 /** 01046 * @brief Reads a block of data from the Gyroscope. 01047 * @param pBuffer: Pointer to the buffer that receives the data read from the Gyroscope. 01048 * @param ReadAddr: Gyroscope's internal address to read from. 01049 * @param NumByteToRead: Number of bytes to read from the Gyroscope. 01050 */ 01051 void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead) 01052 { 01053 if(NumByteToRead > 0x01) 01054 { 01055 ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD); 01056 } 01057 else 01058 { 01059 ReadAddr |= (uint8_t)READWRITE_CMD; 01060 } 01061 /* Set chip select Low at the start of the transmission */ 01062 GYRO_CS_LOW(); 01063 01064 /* Send the Address of the indexed register */ 01065 SPIx_WriteRead(ReadAddr); 01066 01067 /* Receive the data that will be read from the device (MSB First) */ 01068 while(NumByteToRead > 0x00) 01069 { 01070 /* Send dummy byte (0x00) to generate the SPI clock to Gyroscope (Slave device) */ 01071 *pBuffer = SPIx_WriteRead(DUMMY_BYTE); 01072 NumByteToRead--; 01073 pBuffer++; 01074 } 01075 01076 /* Set chip select High at the end of the transmission */ 01077 GYRO_CS_HIGH(); 01078 } 01079 01080 01081 #ifdef EE_M24LR64 01082 01083 /******************************** LINK I2C EEPROM *****************************/ 01084 01085 /** 01086 * @brief Initializes peripherals used by the I2C EEPROM driver. 01087 */ 01088 void EEPROM_IO_Init(void) 01089 { 01090 I2Cx_Init(); 01091 } 01092 01093 /** 01094 * @brief Writes data to I2C EEPROM driver in using DMA channel. 01095 * @param DevAddress: Target device address 01096 * @param MemAddress: Internal memory address 01097 * @param pBuffer: Pointer to data buffer 01098 * @param BufferSize: Amount of data to be sent 01099 * @retval HAL status 01100 */ 01101 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize) 01102 { 01103 return (I2Cx_WriteBufferDMA(DevAddress, MemAddress, pBuffer, BufferSize)); 01104 } 01105 01106 /** 01107 * @brief Reads data from I2C EEPROM driver in using DMA channel. 01108 * @param DevAddress: Target device address 01109 * @param MemAddress: Internal memory address 01110 * @param pBuffer: Pointer to data buffer 01111 * @param BufferSize: Amount of data to be read 01112 * @retval HAL status 01113 */ 01114 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize) 01115 { 01116 return (I2Cx_ReadBufferDMA(DevAddress, MemAddress, pBuffer, BufferSize)); 01117 } 01118 01119 /** 01120 * @brief Checks if target device is ready for communication. 01121 * @note This function is used with Memory devices 01122 * @param DevAddress: Target device address 01123 * @param Trials: Number of trials 01124 * @retval HAL status 01125 */ 01126 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials) 01127 { 01128 return (I2Cx_IsDeviceReady(DevAddress, Trials)); 01129 } 01130 01131 // Added for mbed 01132 /** 01133 * @brief This function handles sEE DMA TX interrupt request. 01134 * @param None 01135 * @retval None 01136 */ 01137 static void EEPROM_I2C_DMA_TX_IRQHandler(void) 01138 { 01139 HAL_DMA_IRQHandler(EEP_I2cHandle.hdmatx); 01140 } 01141 01142 /** 01143 * @brief This function handles sEE DMA RX interrupt request. 01144 * @param None 01145 * @retval None 01146 */ 01147 static void EEPROM_I2C_DMA_RX_IRQHandler(void) 01148 { 01149 HAL_DMA_IRQHandler(EEP_I2cHandle.hdmarx); 01150 } 01151 01152 #endif /* EE_M24LR64 */ 01153 01154 /** 01155 * @} 01156 */ 01157 01158 /** 01159 * @} 01160 */ 01161 01162 /** 01163 * @} 01164 */ 01165 01166 /** 01167 * @} 01168 */ 01169 01170 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 16:29:23 by 1.7.2