stm320518_eval_i2c_ee_cpal.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /**
  2. ******************************************************************************
  3. * @file stm320518_eval_i2c_ee_cpal.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 20-April-2012
  7. * @brief This file provides a set of functions needed to manage I2C
  8. * EEPROM memory.
  9. *
  10. * ===================================================================
  11. * Notes:
  12. * - This driver is a modified version of stm320518_eval_i2c_ee.c file;
  13. * I2C CPAL library drivers are used instead of the Standard Peripherals
  14. * I2C driver.
  15. * - This driver is intended for STM32F0xx families devices only.
  16. * - The I2C EEPROM memory (M24LR64) is available in RF EEPROM daughter
  17. * board (ANT7-M24LR-A) provided with the EVAL board, to use this
  18. * driver you have to connect the ANT7-M24LR-A to CN12 connector.
  19. * ===================================================================
  20. *
  21. * It implements a high level communication layer for read and write
  22. * from/to this memory.
  23. *
  24. * @note In this driver, basic read and write functions (sEE_ReadBuffer()
  25. * and sEE_WritePage()) use the DMA or Interrupt to perform the
  26. * data transfer to/from EEPROM memory.
  27. * Thus, after calling these two functions, user application may
  28. * perform other tasks while data transfer is ongoing.
  29. * The application should then monitor the variable holding
  30. * the state of EEPROM in order to determine when the transfer is
  31. * completed . Stopping transfer tasks are performed into DMA or I2C
  32. * interrupt handlers (which are integrated into this driver).
  33. ******************************************************************************
  34. * @attention
  35. *
  36. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  37. *
  38. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  39. * You may not use this file except in compliance with the License.
  40. * You may obtain a copy of the License at:
  41. *
  42. * http://www.st.com/software_license_agreement_liberty_v2
  43. *
  44. * Unless required by applicable law or agreed to in writing, software
  45. * distributed under the License is distributed on an "AS IS" BASIS,
  46. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  47. * See the License for the specific language governing permissions and
  48. * limitations under the License.
  49. *
  50. ******************************************************************************
  51. */
  52. /* Includes ------------------------------------------------------------------*/
  53. #include "stm320518_eval_i2c_ee_cpal.h"
  54. /* Private typedef -----------------------------------------------------------*/
  55. /*========= sEE_Write_TypeDef =========*/
  56. /* sEE Write parameter structure definition */
  57. typedef struct
  58. {
  59. __IO uint32_t sEEDataNum; /*!< The number of data that will be written in next transfer */
  60. uint32_t sEEWriteAddr; /*!< Physical memory address of EEPROM where data will be written */
  61. __IO uint8_t *sEEpBuffer; /*!< The address of the buffer from which data transfer should start */
  62. __IO uint16_t sEENumOfPage; /*!< The number of page that will be written */
  63. __IO uint8_t sEENumOfSingle; /*!< The number of single data that will be written */
  64. __IO uint8_t sEENextWrite; /*!< This member indicates there is remaining transfers */
  65. } sEE_WriteTypeDef;
  66. /* Private defines -----------------------------------------------------------*/
  67. /* Private macro -------------------------------------------------------------*/
  68. /* Private variables ---------------------------------------------------------*/
  69. /*========= Local Structures declaration =========*/
  70. #ifdef CPAL_USE_I2C1
  71. sEE_InitTypeDef sEE1_DevStructure = {&I2C1_DevStructure, 0, 0, 0, sEE_STATE_IDLE}; /* Initialize All structure parameters to 0 */
  72. #endif /* CPAL_USE_I2C1 */
  73. #ifdef CPAL_USE_I2C2
  74. sEE_InitTypeDef sEE2_DevStructure = {&I2C2_DevStructure, 0, 0, 0, sEE_STATE_IDLE}; /* Initialize All structure parameters to 0 */
  75. #endif /* CPAL_USE_I2C2 */
  76. sEE_InitTypeDef* sEE_DevStructures[CPAL_I2C_DEV_NUM] =
  77. {
  78. #ifdef CPAL_USE_I2C1
  79. &sEE1_DevStructure,
  80. #else
  81. pNULL,
  82. #endif
  83. #ifdef CPAL_USE_I2C2
  84. &sEE2_DevStructure,
  85. #else
  86. pNULL,
  87. #endif
  88. };
  89. #ifdef CPAL_USE_I2C1
  90. sEE_WriteTypeDef sEE1_WriteStructure = {0, 0, pNULL, 0, 0, 0}; /* Initialize All structure parameters to 0 */
  91. #endif /* CPAL_USE_I2C1 */
  92. #ifdef CPAL_USE_I2C2
  93. sEE_WriteTypeDef sEE2_WriteStructure = {0, 0, pNULL, 0, 0, 0}; /* Initialize All structure parameters to 0 */
  94. #endif /* CPAL_USE_I2C2 */
  95. sEE_WriteTypeDef* sEE_WriteStructures[CPAL_I2C_DEV_NUM] =
  96. {
  97. #ifdef CPAL_USE_I2C1
  98. &sEE1_WriteStructure,
  99. #else
  100. pNULL,
  101. #endif
  102. #ifdef CPAL_USE_I2C2
  103. &sEE2_WriteStructure,
  104. #else
  105. pNULL,
  106. #endif
  107. };
  108. #ifdef CPAL_USE_I2C1
  109. CPAL_TransferTypeDef sEE1_TXTransfer = {
  110. /* Initialize TX Transfer structure */
  111. pNULL,
  112. 0,
  113. 0,
  114. 0};
  115. CPAL_TransferTypeDef sEE1_RXTransfer = {
  116. /* Initialize RX Transfer structure */
  117. pNULL,
  118. 0,
  119. 0,
  120. 0};
  121. #endif /* CPAL_USE_I2C1 */
  122. #ifdef CPAL_USE_I2C2
  123. CPAL_TransferTypeDef sEE2_TXTransfer = {
  124. /* Initialize TX Transfer structure */
  125. pNULL,
  126. 0,
  127. 0,
  128. 0};
  129. CPAL_TransferTypeDef sEE2_RXTransfer = {
  130. /* Initialize RX Transfer structure */
  131. pNULL,
  132. 0,
  133. 0,
  134. 0};
  135. #endif /* CPAL_USE_I2C2 */
  136. CPAL_TransferTypeDef* sEE_TXTransfer[CPAL_I2C_DEV_NUM] =
  137. {
  138. #ifdef CPAL_USE_I2C1
  139. &sEE1_TXTransfer,
  140. #else
  141. pNULL,
  142. #endif
  143. #ifdef CPAL_USE_I2C2
  144. &sEE2_TXTransfer,
  145. #else
  146. pNULL,
  147. #endif
  148. };
  149. CPAL_TransferTypeDef* sEE_RXTransfer[CPAL_I2C_DEV_NUM] =
  150. {
  151. #ifdef CPAL_USE_I2C1
  152. &sEE1_RXTransfer,
  153. #else
  154. pNULL,
  155. #endif
  156. #ifdef CPAL_USE_I2C2
  157. &sEE2_RXTransfer,
  158. #else
  159. pNULL,
  160. #endif
  161. };
  162. /**
  163. * @}
  164. */
  165. /* Private function prototypes -----------------------------------------------*/
  166. static uint32_t sEE_WritePage(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
  167. uint16_t WriteAddr, uint32_t NumByteToWrite);
  168. /* Private functions ---------------------------------------------------------*/
  169. /**
  170. * @brief DeInitialize peripherals used by the I2C EEPROM driver.
  171. * @param sEEInitStruct: Pointer to sEE Device structure
  172. * @retval None
  173. */
  174. void sEE_DeInit(sEE_InitTypeDef* sEEInitStruct)
  175. {
  176. /* Deinitialize CPAL peripheral */
  177. CPAL_I2C_DeInit(sEEInitStruct->sEE_CPALStructure);
  178. }
  179. /**
  180. * @brief Initialize peripherals used by the I2C EEPROM driver.
  181. * @param sEEInitStruct: Pointer to sEE Device structure
  182. * @retval None
  183. */
  184. void sEE_Init(sEE_InitTypeDef* sEEInitStruct)
  185. {
  186. /* Initialize CPAL peripheral */
  187. CPAL_I2C_Init(sEEInitStruct->sEE_CPALStructure);
  188. }
  189. /**
  190. * @brief Initialize sEE CPAL Structure used by the I2C EEPROM driver.
  191. * @param sEEInitStruct: Pointer to sEE Device structure
  192. * @retval None
  193. */
  194. void sEE_StructInit(sEE_InitTypeDef* sEEInitStruct)
  195. {
  196. /* Set CPAL structure parameters to their default values */
  197. CPAL_I2C_StructInit(sEEInitStruct->sEE_CPALStructure);
  198. /* Set I2C clock speed */
  199. sEEInitStruct->sEE_CPALStructure->pCPAL_I2C_Struct->I2C_Timing = sEE_I2C_TIMING;
  200. #ifdef sEE_IT
  201. /* Select Interrupt programming model and disable all options */
  202. sEEInitStruct->sEE_CPALStructure->CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
  203. sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;
  204. #else
  205. /* Select DMA programming model and activate TX_DMA_TC and RX_DMA_TC interrupts */
  206. sEEInitStruct->sEE_CPALStructure->CPAL_ProgModel = CPAL_PROGMODEL_DMA;
  207. sEEInitStruct->sEE_CPALStructure->wCPAL_Options = CPAL_OPT_DMATX_TCIT | CPAL_OPT_DMARX_TCIT;
  208. #endif /* sEE_IT */
  209. }
  210. /**
  211. * @brief Reads a block of data from the EEPROM.
  212. * @param sEEInitStruct: Pointer to sEE Device structure
  213. * @param pBuffer: pointer to the buffer that receives the data read from
  214. * the EEPROM.
  215. * @param ReadAddr: EEPROM's internal address to read from.
  216. * @param NumByteToRead: pointer to the variable holding number of bytes to
  217. * read from the EEPROM.
  218. *
  219. * @note The variable pointed by NumByteToRead is reset to 0 when all the data
  220. * are read from the EEPROM. Application should monitor this variable in
  221. * order know when the transfer is complete.
  222. *
  223. * @note When number of data to be read is higher than 1, this function just
  224. * configure the communication and enable the DMA channel to transfer data.
  225. * Meanwhile, the user application may perform other tasks.
  226. * When number of data to be read is 1, then the DMA is not used.
  227. *
  228. * @retval None
  229. */
  230. uint32_t sEE_ReadBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
  231. uint16_t ReadAddr, uint32_t NumByteToRead)
  232. {
  233. if (sEEInitStruct->sEEState == sEE_STATE_IDLE)
  234. {
  235. sEEInitStruct->sEEState = sEE_STATE_READING;
  236. sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;
  237. /* Enable 16Bit memory register option on CPAL */
  238. if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_16BIT_REG)
  239. {
  240. sEEInitStruct->sEE_CPALStructure->wCPAL_Options = CPAL_OPT_16BIT_REG;
  241. }
  242. /* Enable no memory addressing mode option on CPAL */
  243. if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_NO_MEM_ADDR)
  244. {
  245. sEEInitStruct->sEE_CPALStructure->wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
  246. }
  247. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx = sEE_RXTransfer[sEEInitStruct->sEE_CPALStructure->CPAL_Dev];
  248. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wNumData = (uint32_t)(NumByteToRead);
  249. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->pbBuffer = pBuffer;
  250. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wAddr1 = (uint32_t)((uint8_t)sEEInitStruct->sEEAddress);
  251. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wAddr2 = (uint32_t)((uint16_t)ReadAddr);
  252. return CPAL_I2C_Read(sEEInitStruct->sEE_CPALStructure);
  253. }
  254. else
  255. {
  256. return CPAL_FAIL;
  257. }
  258. }
  259. /**
  260. * @brief Writes buffer of data to the I2C EEPROM.
  261. * @param sEEInitStruct: Pointer to sEE Device structure
  262. * @param pBuffer: pointer to the buffer containing the data to be written
  263. * to the EEPROM.
  264. * @param WriteAddr: EEPROM's internal address to write to.
  265. * @param NumByteToWrite: number of bytes to write to the EEPROM.
  266. * @retval None
  267. */
  268. uint32_t sEE_WriteBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
  269. uint16_t WriteAddr, uint32_t NumByteToWrite)
  270. {
  271. uint32_t DataNum = 0;
  272. uint16_t count = 0;
  273. uint16_t Addr = 0;
  274. if (sEEInitStruct->sEEState == sEE_STATE_IDLE)
  275. {
  276. sEEInitStruct->sEEState = sEE_STATE_WRITING;
  277. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = 0;
  278. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEWriteAddr = 0;
  279. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEpBuffer = pNULL;
  280. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage = 0;
  281. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENextWrite = 0;
  282. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle = 0;
  283. /* if one data will be written */
  284. if (NumByteToWrite == 1)
  285. {
  286. /* Transfer complete */
  287. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENextWrite = 0;
  288. /* update number od data for write */
  289. DataNum = NumByteToWrite;
  290. if(sEE_WritePage(sEEInitStruct, pBuffer, WriteAddr, DataNum) != CPAL_PASS)
  291. {
  292. return CPAL_FAIL;
  293. }
  294. }
  295. /* Use Write page */
  296. else
  297. {
  298. /* if Address aligned reset count value to 0 */
  299. Addr = WriteAddr % sEEInitStruct->sEEPageSize;
  300. if (Addr == 0)
  301. {
  302. count = 0;
  303. }
  304. else
  305. {
  306. count = sEEInitStruct->sEEPageSize - Addr;
  307. if (NumByteToWrite <= count)
  308. {
  309. count = NumByteToWrite;
  310. }
  311. }
  312. /* Get Number of page for write and number of single byte */
  313. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage = \
  314. (uint16_t)((NumByteToWrite - count) / sEEInitStruct->sEEPageSize);
  315. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle = \
  316. (uint8_t)((NumByteToWrite - count) % sEEInitStruct->sEEPageSize);
  317. /* If WriteAddr is sEE_PAGESIZE is not aligned */
  318. if (Addr != 0)
  319. {
  320. /* Update Number of data to write */
  321. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = count;
  322. }
  323. /* If WriteAddr is sEE_PAGESIZE is aligned */
  324. else
  325. {
  326. /* if only single byte must be written */
  327. if (sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage == 0)
  328. {
  329. /* update number of data to write */
  330. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = \
  331. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle;
  332. /* reset number of single */
  333. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle = 0;
  334. }
  335. else
  336. {
  337. /* update number of data to write */
  338. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = (uint32_t)((uint16_t)sEEInitStruct->sEEPageSize);
  339. /* update number of page */
  340. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage--;
  341. }
  342. }
  343. /* update global variable */
  344. DataNum = sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum;
  345. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEWriteAddr = (uint32_t)((uint16_t)WriteAddr);
  346. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEpBuffer = pBuffer;
  347. /* If there are remaining data to transfer */
  348. if ((sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage != 0)
  349. || (sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle != 0))
  350. {
  351. /* update global variable */
  352. sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENextWrite = 1;
  353. }
  354. /* Write data on EEPROM */
  355. if (sEE_WritePage(sEEInitStruct, pBuffer, WriteAddr, DataNum) != CPAL_PASS)
  356. {
  357. return CPAL_FAIL;
  358. }
  359. }
  360. return CPAL_PASS;
  361. }
  362. else
  363. {
  364. return CPAL_FAIL;
  365. }
  366. }
  367. /**
  368. * @brief Handle EEPROM Write operation
  369. * @param Device: sEE CPAL device instance
  370. * @retval None
  371. */
  372. uint32_t sEE_WriteHandler(CPAL_DevTypeDef Device)
  373. {
  374. uint32_t DataNum = 0;
  375. /* wait until EEPROM ready for transfer */
  376. while (sEE_WaitEepromStandbyState(Device) == CPAL_FAIL);
  377. /* if there are remaining data for write */
  378. if (sEE_WriteStructures[Device]->sEENextWrite != 0)
  379. {
  380. sEE_WriteStructures[Device]->sEEWriteAddr += sEE_WriteStructures[Device]->sEEDataNum;
  381. sEE_WriteStructures[Device]->sEEpBuffer += sEE_WriteStructures[Device]->sEEDataNum;
  382. sEE_WriteStructures[Device]->sEENextWrite = 0;
  383. /* if page must be written in EEPROM */
  384. if(sEE_WriteStructures[Device]->sEENumOfPage != 0)
  385. {
  386. sEE_WriteStructures[Device]->sEEDataNum = (uint32_t)((uint16_t)sEE_DevStructures[Device]->sEEPageSize);
  387. sEE_WriteStructures[Device]->sEENumOfPage--;
  388. }
  389. /* if single byte must be written in EEPROM */
  390. else if (sEE_WriteStructures[Device]->sEENumOfSingle != 0)
  391. {
  392. sEE_WriteStructures[Device]->sEEDataNum = (uint32_t)((uint8_t)sEE_WriteStructures[Device]->sEENumOfSingle);
  393. sEE_WriteStructures[Device]->sEENumOfSingle = 0;
  394. sEE_WriteStructures[Device]->sEENextWrite = 0;
  395. }
  396. /* update number of date for write */
  397. DataNum = sEE_WriteStructures[Device]->sEEDataNum;
  398. /* if another data must be written */
  399. if ((sEE_WriteStructures[Device]->sEENumOfPage != 0)
  400. || (sEE_WriteStructures[Device]->sEENumOfSingle != 0))
  401. {
  402. sEE_WriteStructures[Device]->sEENextWrite = 1;
  403. }
  404. /* write data in EEPROM */
  405. sEE_WritePage(sEE_DevStructures[Device],(uint8_t*)sEE_WriteStructures[Device]->sEEpBuffer, \
  406. sEE_WriteStructures[Device]->sEEWriteAddr, DataNum);
  407. }
  408. else
  409. {
  410. if (sEE_DevStructures[Device]->sEEState != sEE_STATE_ERROR)
  411. {
  412. /* Reset EEPROM State */
  413. sEE_DevStructures[Device]->sEEState = sEE_STATE_IDLE;
  414. }
  415. }
  416. return CPAL_PASS;
  417. }
  418. /**
  419. * @brief Handle EEPROM Read operation
  420. * @param Device: sEE CPAL device instance
  421. * @retval None
  422. */
  423. uint32_t sEE_ReadHandler(CPAL_DevTypeDef Device)
  424. {
  425. if (sEE_DevStructures[Device]->sEEState != sEE_STATE_ERROR)
  426. {
  427. /* Reset EEPROM State */
  428. sEE_DevStructures[Device]->sEEState = sEE_STATE_IDLE;
  429. }
  430. return CPAL_PASS;
  431. }
  432. /**
  433. * @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
  434. * @note The number of byte can't exceed the EEPROM page size.
  435. * @param sEEInitStruct: Pointer to sEE Device structure
  436. * @param pBuffer: pointer to the buffer containing the data to be written to
  437. * the EEPROM.
  438. * @param WriteAddr: EEPROM's internal address to write to.
  439. * @param NumByteToWrite: pointer to the variable holding number of bytes to
  440. * written to the EEPROM.
  441. *
  442. * @note The variable pointed by NumByteToWrite is reset to 0 when all the data
  443. * are read from the EEPROM. Application should monitor this variable in
  444. * order know when the transfer is complete.
  445. *
  446. * @note When number of data to be written is higher than 1, this function just
  447. * configure the communication and enable the DMA channel to transfer data.
  448. * Meanwhile, the user application may perform other tasks.
  449. * When number of data to be written is 1, then the DMA is not used.
  450. *
  451. * @retval None
  452. */
  453. static uint32_t sEE_WritePage(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
  454. uint16_t WriteAddr, uint32_t NumByteToWrite)
  455. {
  456. sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;
  457. /* Enable 16Bit memory register option on CPAL */
  458. if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_16BIT_REG)
  459. {
  460. sEEInitStruct->sEE_CPALStructure->wCPAL_Options = CPAL_OPT_16BIT_REG;
  461. }
  462. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx = sEE_TXTransfer[sEEInitStruct->sEE_CPALStructure->CPAL_Dev];
  463. /* Configure transfer parameters */
  464. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->wNumData = (uint32_t)(NumByteToWrite);
  465. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->pbBuffer = pBuffer;
  466. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->wAddr1 = (uint32_t)((uint8_t)sEEInitStruct->sEEAddress);
  467. sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->wAddr2 = (uint32_t)((uint16_t)WriteAddr);
  468. /* Write Operation */
  469. return CPAL_I2C_Write(sEEInitStruct->sEE_CPALStructure);
  470. }
  471. /**
  472. * @brief Wait for EEPROM Standby state
  473. * @param Device: sEE CPAL device instance
  474. * @retval None
  475. */
  476. uint32_t sEE_WaitEepromStandbyState(CPAL_DevTypeDef Device)
  477. {
  478. sEE_DevStructures[Device]->sEE_CPALStructure->pCPAL_TransferTx = sEE_TXTransfer[Device];
  479. sEE_DevStructures[Device]->sEE_CPALStructure->pCPAL_TransferTx->wAddr1 = \
  480. (uint32_t)((uint8_t)sEE_DevStructures[Device]->sEEAddress);
  481. return CPAL_I2C_IsDeviceReady(sEE_DevStructures[Device]->sEE_CPALStructure);
  482. }
  483. /**
  484. * @brief Wait for EEPROM Standby state
  485. * @param sEEInitStruct: Pointer to sEE Device structure
  486. * @retval None
  487. */
  488. uint32_t sEE_GetEepromState(sEE_InitTypeDef* sEEInitStruct)
  489. {
  490. return sEEInitStruct->sEEState;
  491. }
  492. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/