diff options
Diffstat (limited to 'thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL')
8 files changed, 2862 insertions, 0 deletions
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/Release_Notes.html b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/Release_Notes.html new file mode 100644 index 0000000..54c9b4a --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/Release_Notes.html @@ -0,0 +1,157 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head> + + + + + + + + + + + + + + <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> + + + <link rel="File-List" href="Library_files/filelist.xml"> + + + <link rel="Edit-Time-Data" href="Library_files/editdata.mso"><!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><title>Release Notes for STM32L152D_EVAL Evaluation Board Drivers</title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>STMicroelectronics</o:LastAuthor> <o:Revision>37</o:Revision> <o:TotalTime>136</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2009-03-01T17:56:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Words>522</o:Words> <o:Characters>2977</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>24</o:Lines> <o:Paragraphs>6</o:Paragraphs> <o:CharactersWithSpaces>3493</o:CharactersWithSpaces> <o:Version>11.6568</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> + + + + + + + + <style> +<!-- +/* Style Definitions */ +p.MsoNormal, li.MsoNormal, div.MsoNormal +{mso-style-parent:""; +margin:0in; +margin-bottom:.0001pt; +mso-pagination:widow-orphan; +font-size:12.0pt; +font-family:"Times New Roman"; +mso-fareast-font-family:"Times New Roman";} +h2 +{mso-style-next:Normal; +margin-top:12.0pt; +margin-right:0in; +margin-bottom:3.0pt; +margin-left:0in; +mso-pagination:widow-orphan; +page-break-after:avoid; +mso-outline-level:2; +font-size:14.0pt; +font-family:Arial; +font-weight:bold; +font-style:italic;} +a:link, span.MsoHyperlink +{color:blue; +text-decoration:underline; +text-underline:single;} +a:visited, span.MsoHyperlinkFollowed +{color:blue; +text-decoration:underline; +text-underline:single;} +p +{mso-margin-top-alt:auto; +margin-right:0in; +mso-margin-bottom-alt:auto; +margin-left:0in; +mso-pagination:widow-orphan; +font-size:12.0pt; +font-family:"Times New Roman"; +mso-fareast-font-family:"Times New Roman";} +@page Section1 +{size:8.5in 11.0in; +margin:1.0in 1.25in 1.0in 1.25in; +mso-header-margin:.5in; +mso-footer-margin:.5in; +mso-paper-source:0;} +div.Section1 +{page:Section1;} +--> + </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="5122"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--> + <meta content="MCD Application Team" name="author"></head> +<body link="blue" vlink="blue"> +<div class="Section1"> +<p class="MsoNormal"><span style="font-family: Arial;"><o:p><br> +</o:p></span></p> +<div align="center"> +<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900"> + <tbody> + <tr> + <td style="padding: 0cm;" valign="top"> + <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900"> + <tbody> + <tr> + <td style="vertical-align: top;"> + <p class="MsoNormal"><span style="font-size: 8pt; font-family: Arial; color: blue;"><a href="../../../Release_Notes.html">Back to Release page</a><o:p></o:p></span></p> + </td> + </tr> + <tr style=""> + <td style="padding: 1.5pt;"> + <h1 style="margin-bottom: 18pt; text-align: center;" align="center"><span style="font-size: 20pt; font-family: Verdana; color: rgb(51, 102, 255);">Release +Notes for STM32L152D_EVAL Evaluation Board Drivers</span><span style="font-size: 20pt; font-family: Verdana;"><o:p></o:p></span></h1> + <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;">Copyright +2012 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p> + <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;"><img alt="" id="_x0000_i1025" src="../../../_htmresc/logo.bmp" style="border: 0px solid ; width: 86px; height: 65px;"></span><span style="font-size: 10pt;"><o:p></o:p></span></p> + </td> + </tr> + </tbody> + </table> + <p class="MsoNormal"><span style="font-family: Arial; display: none;"><o:p> </o:p></span></p> + <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900"> + <tbody> + <tr style=""> + <td style="padding: 0cm;" valign="top"> + <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><span style="font-size: 12pt; color: white;">Contents<o:p></o:p></span></h2> + <ol style="margin-top: 0cm;" start="1" type="1"> + <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;"><a href="#History">STM32L152D_EVAL Evaluation Board Drivers +update History</a><o:p></o:p></span></li> + <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;"><a href="#License">License</a><o:p></o:p></span></li> + </ol> + <span style="font-family: "Times New Roman";"> + </span> + <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">STM32L152D_EVAL Evaluation Board Drivers update History</span></h2><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.1 / 09-March-2012<o:p></o:p></span></h3> + <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main +Changes<o:p></o:p></span></u></b></p> + + <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files: license disclaimer text update and add link to the License file on ST Internet.</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">stm32l152d_eval.c</span></li><ul><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;"> In <span style="font-style: italic;"></span><span style="font-style: italic;">LM75_LowLevel_Init()</span> function: </span><span style="font-size: 10pt; font-family: Verdana;">swap +the order of I2C IOs and alternate function (AF) +configuration (AF configuration should be done before to configure the +IOs).</span></li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0 / 24-January-2012</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main +Changes<o:p></o:p></span></u></b></p> + + <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Official version <span style="font-weight: bold; font-style: italic;"></span></span><span style="font-size: 10pt; font-family: Verdana;">for <span style="font-weight: bold; font-style: italic;">STM32L152D_EVAL</span> evaluation board RevB drivers.</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"></span><h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Verdana","sans-serif"; color: black;">Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this </span><span style="font-size: 10pt; font-family: "Verdana","sans-serif"; color: black;">package</span><span style="font-size: 10pt; font-family: "Verdana","sans-serif"; color: black;"> except in compliance with the License. You may obtain a copy of the License at:<br><br></span></p><div style="text-align: center;"><span style="font-size: 10pt; font-family: "Verdana","sans-serif"; color: black;"> <a target="_blank" href="http://www.st.com/software_license_agreement_liberty_v2">http://www.st.com/software_license_agreement_liberty_v2</a></span><br><span style="font-size: 10pt; font-family: "Verdana","sans-serif"; color: black;"></span></div><span style="font-size: 10pt; font-family: "Verdana","sans-serif"; color: black;"><br>Unless +required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, <br>WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See +the License for the specific language governing permissions and +limitations under the License.</span><b><span style="font-size: 10pt; font-family: Verdana; color: black;"></span></b> + + <div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;"> + <hr align="center" size="2" width="100%"></span></div> + <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt; text-align: center;" align="center"><span style="font-size: 10pt; font-family: Verdana; color: black;">For +complete documentation on </span><span style="font-size: 10pt; font-family: Verdana;">STM32<span style="color: black;"> Microcontrollers +visit </span><u><span style="color: blue;"><a href="http://www.st.com/internet/mcu/class/1734.jsp" target="_blank">www.st.com/STM32</a></span></u></span><span style="font-size: 10pt; font-family: Verdana;"><a target="_blank" href="http://www.st.com/internet/mcu/family/141.jsp"><u><span style="color: blue;"></span></u></a></span><span style="font-size: 10pt; font-family: Verdana;"><u><span style="color: blue;"></span></u></span><span style="color: black;"><o:p></o:p></span></p> + </td> + </tr> + </tbody> + </table> + <p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p> + </td> + </tr> + </tbody> +</table> +</div> +<p class="MsoNormal"><o:p> </o:p></p> +</div> + +</body></html>
\ No newline at end of file diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.h new file mode 100644 index 0000000..e19ca14 --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.h @@ -0,0 +1,134 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_fsmc_nor.h + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file contains all the functions prototypes for the + * stm32l152d_eval_fsmc_nor firmware driver. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32L152D_EVAL_FSMC_NOR_H +#define __STM32L152D_EVAL_FSMC_NOR_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_FSMC_NOR + * @{ + */ + +/** @defgroup STM32L152D_EVAL_FSMC_NOR_Exported_Types + * @{ + */ +typedef struct +{ + uint16_t Manufacturer_Code; + uint16_t Device_Code1; + uint16_t Device_Code2; + uint16_t Device_Code3; +}NOR_IDTypeDef; + +/* NOR Status */ +typedef enum +{ + NOR_SUCCESS = 0, + NOR_ONGOING, + NOR_ERROR, + NOR_TIMEOUT +}NOR_Status; +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_FSMC_NOR_Exported_Constants + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_FSMC_NOR_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_FSMC_NOR_Exported_Functions + * @{ + */ +void NOR_Init(void); +void NOR_ReadID(NOR_IDTypeDef* NOR_ID); +NOR_Status NOR_EraseBlock(uint32_t BlockAddr); +NOR_Status NOR_EraseChip(void); +NOR_Status NOR_WriteHalfWord(uint32_t WriteAddr, uint16_t Data); +NOR_Status NOR_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite); +NOR_Status NOR_ProgramBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite); +uint16_t NOR_ReadHalfWord(uint32_t ReadAddr); +void NOR_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead); +NOR_Status NOR_ReturnToReadMode(void); +NOR_Status NOR_Reset(void); +NOR_Status NOR_GetStatus(uint32_t Timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32L152D_EVAL_FSMC_NOR_H */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_sram.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_sram.c new file mode 100644 index 0000000..d463fec --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_sram.c @@ -0,0 +1,289 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_fsmc_sram.c + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file provides a set of functions needed to drive the + * IS61WV51216BLL SRAM memory mounted on STM32L152D-EVAL board. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval_fsmc_sram.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_FSMC_SRAM + * @brief This file provides a set of functions needed to drive the + * IS61WV51216BLL SRAM memory mounted on STM32L152D-EVAL board. + * @{ + */ + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Private_Types + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Private_Defines + * @{ + */ +/** + * @brief FSMC Bank 1 NOR/SRAM3 + */ +#define Bank1_SRAM3_ADDR ((uint32_t)0x68000000) +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Private_Macros + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Private_Variables + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Private_Function_Prototypes + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Private_Functions + * @{ + */ + +/** + * @brief Configures the FSMC and GPIOs to interface with the SRAM memory. + * This function must be called before any write/read operation + * on the SRAM. + * @param None + * @retval None + */ +void SRAM_Init(void) +{ + FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; + FSMC_NORSRAMTimingInitTypeDef p; + + GPIO_InitTypeDef GPIO_InitStructure; + + /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF | + RCC_AHBPeriph_GPIOG, ENABLE); + +/*-- GPIO Configuration ------------------------------------------------------*/ + /*!< SRAM Data lines configuration */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | + GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOD, &GPIO_InitStructure); + + GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | + GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | + GPIO_Pin_15; + GPIO_Init(GPIOE, &GPIO_InitStructure); + + GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC); + + /*!< SRAM Address lines configuration */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | + GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 | + GPIO_Pin_14 | GPIO_Pin_15; + GPIO_Init(GPIOF, &GPIO_InitStructure); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource0, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource1, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource2, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource3, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource4, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource5, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource12, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource13, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource14, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOF, GPIO_PinSource15, GPIO_AF_FSMC); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | + GPIO_Pin_4 | GPIO_Pin_5; + GPIO_Init(GPIOG, &GPIO_InitStructure); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource0, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource1, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource2, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource3, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource4, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource5, GPIO_AF_FSMC); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13; + GPIO_Init(GPIOD, &GPIO_InitStructure); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FSMC); + + /*!< NOE and NWE configuration */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5; + GPIO_Init(GPIOD, &GPIO_InitStructure); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); + + /*!< NE3 configuration */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; + GPIO_Init(GPIOG, &GPIO_InitStructure); + GPIO_PinAFConfig(GPIOG, GPIO_PinSource10, GPIO_AF_FSMC); + + /*!< NBL0, NBL1 configuration */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; + GPIO_Init(GPIOE, &GPIO_InitStructure); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_FSMC); + GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_FSMC); + +/*-- FSMC Configuration ------------------------------------------------------*/ + p.FSMC_AddressSetupTime = 0; + p.FSMC_AddressHoldTime = 0; + p.FSMC_DataSetupTime = 3; + p.FSMC_BusTurnAroundDuration = 0; + p.FSMC_CLKDivision = 0; + p.FSMC_DataLatency = 0; + p.FSMC_AccessMode = FSMC_AccessMode_A; + + FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; + FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; + FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; + FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; + FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; + FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; + FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; + FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; + FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; + FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; + FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; + FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; + FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; + FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; + FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; + + FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); + + /*!< Enable FSMC Bank1_SRAM Bank */ + FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); +} + +/** + * @brief Writes a Half-word buffer to the FSMC SRAM memory. + * @param pBuffer : pointer to buffer. + * @param WriteAddr : SRAM memory internal address from which the data will be + * written. + * @param NumHalfwordToWrite : number of half-words to write. + * @retval None + */ +void SRAM_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite) +{ + for(; NumHalfwordToWrite != 0; NumHalfwordToWrite--) /*!< while there is data to write */ + { + /*!< Transfer data to the memory */ + *(uint16_t *) (Bank1_SRAM3_ADDR + WriteAddr) = *pBuffer++; + + /*!< Increment the address*/ + WriteAddr += 2; + } +} + +/** + * @brief Reads a block of data from the FSMC SRAM memory. + * @param pBuffer : pointer to the buffer that receives the data read from the + * SRAM memory. + * @param ReadAddr : SRAM memory internal address to read from. + * @param NumHalfwordToRead : number of half-words to read. + * @retval None + */ +void SRAM_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead) +{ + for(; NumHalfwordToRead != 0; NumHalfwordToRead--) /*!< while there is data to read */ + { + /*!< Read a half-word from the memory */ + *pBuffer++ = *(__IO uint16_t*) (Bank1_SRAM3_ADDR + ReadAddr); + + /*!< Increment the address*/ + ReadAddr += 2; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_sram.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_sram.h new file mode 100644 index 0000000..c20a27b --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_sram.h @@ -0,0 +1,110 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_fsmc_sram.h + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file contains all the functions prototypes for the + * stm32l152d_eval_fsmc_sram firmware driver. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32L152D_EVAL_FSMC_SRAM_H +#define __STM32L152D_EVAL_FSMC_SRAM_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_FSMC_SRAM + * @{ + */ + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Exported_Types + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Exported_Constants + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_FSMC_SRAM_Exported_Functions + * @{ + */ + +void SRAM_Init(void); +void SRAM_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite); +void SRAM_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead); + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32L152D_EVAL_FSMC_SRAM_H */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_ee.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_ee.c new file mode 100644 index 0000000..634c049 --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_ee.c @@ -0,0 +1,818 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_i2c_ee.c + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file provides a set of functions needed to manage an I2C M24LR64 + * EEPROM memory. + * + * =================================================================== + * Notes: + * - This driver is intended for STM32L1xx families devices only. + * - The I2C EEPROM memory (M24LR64) is available in RF EEPROM daughter + * board (ANT7-M24LR-A) provided with the STM32L152D-EVAL board. + * You have to connect the ANT7-M24LR-A to CN12 connector before + * using this driver. + * =================================================================== + * + * It implements a high level communication layer for read and write + * from/to this memory. The needed STM32 hardware resources (I2C and + * GPIO) are defined in stm32l152d_eval.h file, and the initialization is + * performed in sEE_LowLevel_Init() function declared in stm32l152d_eval.c + * file. + * You can easily tailor this driver to any other development board, + * by just adapting the defines for hardware resources and + * sEE_LowLevel_Init() function. + * + * @note In this driver, basic read and write functions (sEE_ReadBuffer() + * and sEE_WritePage()) use the DMA to perform the data transfer + * to/from EEPROM memory (except when number of requested data is + * equal to 1). Thus, after calling these two functions, user + * application may perform other tasks while DMA is transferring + * data. The application should then monitor the variable holding + * the number of data in order to determine when the transfer is + * completed (variable decremented to 0). Stopping transfer tasks + * are performed into DMA interrupt handlers (which are integrated + * into this driver). + * + * +-----------------------------------------------------------------+ + * | Pin assignment | + * +---------------------------------------+-----------+-------------+ + * | STM32 I2C Pins | sEE | Pin | + * +---------------------------------------+-----------+-------------+ + * | . | E0(GND) | 1 (0V) | + * | . | AC0 | 2 | + * | . | AC1 | 3 | + * | . | VSS | 4 (0V) | + * | sEE_I2C_SDA_PIN/ SDA | SDA | 5 | + * | sEE_I2C_SCL_PIN/ SCL | SCL | 6 | + * | . | E1(GND) | 7 (0V) | + * | . | VDD | 8 (3.3V) | + * +---------------------------------------+-----------+-------------+ + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval_i2c_ee.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_I2C_EE + * @brief This file includes the I2C EEPROM driver of STM32L152D-EVAL board. + * @{ + */ + +/** @defgroup STM32L152D_EVAL_I2C_EE_Private_Types + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_I2C_EE_Private_Defines + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_I2C_EE_Private_Macros + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_I2C_EE_Private_Variables + * @{ + */ +__IO uint16_t sEEAddress = 0; +__IO uint32_t sEETimeout = sEE_LONG_TIMEOUT; +__IO uint16_t* sEEDataReadPointer; +__IO uint8_t* sEEDataWritePointer; +__IO uint8_t sEEDataNum; +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_I2C_EE_Private_Function_Prototypes + * @{ + */ +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_I2C_EE_Private_Functions + * @{ + */ + +/** + * @brief DeInitializes peripherals used by the I2C EEPROM driver. + * @param None + * @retval None + */ +void sEE_DeInit(void) +{ + sEE_LowLevel_DeInit(); +} + +/** + * @brief Initializes peripherals used by the I2C EEPROM driver. + * @param None + * @retval None + */ +void sEE_Init(void) +{ + I2C_InitTypeDef I2C_InitStructure; + + sEE_LowLevel_Init(); + + /*!< I2C configuration */ + /* sEE_I2C configuration */ + I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; + I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; + I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVE_ADDRESS7; + I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; + I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; + I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED; + + /* sEE_I2C Peripheral Enable */ + I2C_Cmd(sEE_I2C, ENABLE); + /* Apply sEE_I2C configuration after enabling it */ + I2C_Init(sEE_I2C, &I2C_InitStructure); + + /* Enable the sEE_I2C peripheral DMA requests */ + I2C_DMACmd(sEE_I2C, ENABLE); + +#if defined (sEE_M24C64_32) || defined (sEE_M24LR64) + /*!< Select the EEPROM address according to the state of E0, E1, E2 pins */ + sEEAddress = sEE_HW_ADDRESS; +#elif defined (sEE_M24C08) + /*!< depending on the sEE Address selected in the i2c_ee.h file */ + #ifdef sEE_Block0_ADDRESS + /*!< Select the sEE Block0 to write on */ + sEEAddress = sEE_Block0_ADDRESS; + #endif + + #ifdef sEE_Block1_ADDRESS + /*!< Select the sEE Block1 to write on */ + sEEAddress = sEE_Block1_ADDRESS; + #endif + + #ifdef sEE_Block2_ADDRESS + /*!< Select the sEE Block2 to write on */ + sEEAddress = sEE_Block2_ADDRESS; + #endif + + #ifdef sEE_Block3_ADDRESS + /*!< Select the sEE Block3 to write on */ + sEEAddress = sEE_Block3_ADDRESS; + #endif +#endif /*!< sEE_M24C64_32 */ +} + +/** + * @brief Reads a block of data from the EEPROM. + * @param pBuffer : pointer to the buffer that receives the data read from + * the EEPROM. + * @param ReadAddr : EEPROM's internal address to start reading from. + * @param NumByteToRead : pointer to the variable holding number of bytes to + * be read from the EEPROM. + * + * @note The variable pointed by NumByteToRead is reset to 0 when all the + * data are read from the EEPROM. Application should monitor this + * variable in order know when the transfer is complete. + * + * @note When number of data to be read is higher than 1, this function just + * configures the communication and enable the DMA channel to transfer data. + * Meanwhile, the user application may perform other tasks. + * When number of data to be read is 1, then the DMA is not used. The byte + * is read in polling mode. + * + * @retval sEE_OK (0) if operation is correctly performed, else return value + * different from sEE_OK (0) or the timeout user callback. + */ +uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead) +{ + /* Set the pointer to the Number of data to be read. This pointer will be used + by the DMA Transfer Completer interrupt Handler in order to reset the + variable to 0. User should check on this variable in order to know if the + DMA transfer has been complete or not. */ + sEEDataReadPointer = NumByteToRead; + + /*!< While the bus is busy */ + sEETimeout = sEE_LONG_TIMEOUT; + while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send START condition */ + I2C_GenerateSTART(sEE_I2C, ENABLE); + + /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send EEPROM address for write */ + I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter); + + /*!< Test on EV6 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + +#ifdef sEE_M24C08 + + /*!< Send the EEPROM's internal address to read from: Only one byte address */ + I2C_SendData(sEE_I2C, ReadAddr); + +#elif defined (sEE_M24C64_32) || defined (sEE_M24LR64) + + /*!< Send the EEPROM's internal address to read from: MSB of the address first */ + I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8)); + + /*!< Test on EV8 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send the EEPROM's internal address to read from: LSB of the address */ + I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF)); + +#endif /*!< sEE_M24C08 */ + + /*!< Test on EV8 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF) == RESET) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send STRAT condition a second time */ + I2C_GenerateSTART(sEE_I2C, ENABLE); + + /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send EEPROM address for read */ + I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Receiver); + + /* If number of data to be read is 1, then DMA couldn't be used */ + /* One Byte Master Reception procedure (POLLING) ---------------------------*/ + if ((uint16_t)(*NumByteToRead) < 2) + { + /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_ADDR) == RESET) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Disable Acknowledgement */ + I2C_AcknowledgeConfig(sEE_I2C, DISABLE); + + /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */ + (void)sEE_I2C->SR2; + + /*!< Send STOP Condition */ + I2C_GenerateSTOP(sEE_I2C, ENABLE); + + /* Wait for the byte to be received */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_RXNE) == RESET) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Read the byte received from the EEPROM */ + *pBuffer = I2C_ReceiveData(sEE_I2C); + + /*!< Decrement the read bytes counter */ + (uint16_t)(*NumByteToRead)--; + + /* Wait to make sure that STOP control bit has been cleared */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(sEE_I2C->CR1 & I2C_CR1_STOP) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Re-Enable Acknowledgement to be ready for another reception */ + I2C_AcknowledgeConfig(sEE_I2C, ENABLE); + } + else/* More than one Byte Master Reception procedure (DMA) -----------------*/ + { + /*!< Test on EV6 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /* Configure the DMA Rx Channel with the buffer address and the buffer size */ + sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint16_t)(*NumByteToRead), sEE_DIRECTION_RX); + + /* Inform the DMA that the next End Of Transfer Signal will be the last one */ + I2C_DMALastTransferCmd(sEE_I2C, ENABLE); + + /* Enable the DMA Rx Channel */ + DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, ENABLE); + } + + /* If all operations OK, return sEE_OK (0) */ + return sEE_OK; +} + +/** + * @brief Writes more than one byte to the EEPROM with a single WRITE cycle. + * + * @note The number of bytes (combined to write start address) must not + * cross the EEPROM page boundary. This function can only write into + * the boundaries of an EEPROM page. + * This function doesn't check on boundaries condition (in this driver + * the function sEE_WriteBuffer() which calls sEE_WritePage() is + * responsible of checking on Page boundaries). + * + * @param pBuffer : pointer to the buffer containing the data to be written to + * the EEPROM. + * @param WriteAddr : EEPROM's internal address to write to. + * @param NumByteToWrite : pointer to the variable holding number of bytes to + * be written into the EEPROM. + * + * @note The variable pointed by NumByteToWrite is reset to 0 when all the + * data are written to the EEPROM. Application should monitor this + * variable in order know when the transfer is complete. + * + * @note This function just configure the communication and enable the DMA + * channel to transfer data. Meanwhile, the user application may perform + * other tasks in parallel. + * + * @retval sEE_OK (0) if operation is correctly performed, else return value + * different from sEE_OK (0) or the timeout user callback. + */ +uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite) +{ + /* Set the pointer to the Number of data to be written. This pointer will be used + by the DMA Transfer Completer interrupt Handler in order to reset the + variable to 0. User should check on this variable in order to know if the + DMA transfer has been complete or not. */ + sEEDataWritePointer = NumByteToWrite; + + /*!< While the bus is busy */ + sEETimeout = sEE_LONG_TIMEOUT; + while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send START condition */ + I2C_GenerateSTART(sEE_I2C, ENABLE); + + /*!< Test on EV5 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send EEPROM address for write */ + sEETimeout = sEE_FLAG_TIMEOUT; + I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter); + + /*!< Test on EV6 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + +#ifdef sEE_M24C08 + + /*!< Send the EEPROM's internal address to write to : only one byte Address */ + I2C_SendData(sEE_I2C, WriteAddr); + +#elif defined(sEE_M24C64_32) || defined (sEE_M24LR64) + + /*!< Send the EEPROM's internal address to write to : MSB of the address first */ + I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr & 0xFF00) >> 8)); + + /*!< Test on EV8 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send the EEPROM's internal address to write to : LSB of the address */ + I2C_SendData(sEE_I2C, (uint8_t)(WriteAddr & 0x00FF)); + +#endif /*!< sEE_M24C08 */ + + /*!< Test on EV8 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /* Configure the DMA Tx Channel with the buffer address and the buffer size */ + sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint8_t)(*NumByteToWrite), sEE_DIRECTION_TX); + + /* Enable the DMA Tx Channel */ + DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, ENABLE); + + /* If all operations OK, return sEE_OK (0) */ + return sEE_OK; +} + +/** + * @brief Writes buffer of data to the I2C EEPROM. + * @param pBuffer : pointer to the buffer containing the data to be written + * to the EEPROM. + * @param WriteAddr : EEPROM's internal address to write to. + * @param NumByteToWrite : number of bytes to write to the EEPROM. + * @retval None + */ +void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite) +{ + uint16_t NumOfPage = 0, NumOfSingle = 0, count = 0; + uint16_t Addr = 0; + + Addr = WriteAddr % sEE_PAGESIZE; + count = sEE_PAGESIZE - Addr; + NumOfPage = NumByteToWrite / sEE_PAGESIZE; + NumOfSingle = NumByteToWrite % sEE_PAGESIZE; + + /*!< If WriteAddr is sEE_PAGESIZE aligned */ + if(Addr == 0) + { + /*!< If NumByteToWrite < sEE_PAGESIZE */ + if(NumOfPage == 0) + { + /* Store the number of data to be written */ + sEEDataNum = NumOfSingle; + /* Start writing data */ + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + } + /*!< If NumByteToWrite > sEE_PAGESIZE */ + else + { + while(NumOfPage--) + { + /* Store the number of data to be written */ + sEEDataNum = sEE_PAGESIZE; + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + WriteAddr += sEE_PAGESIZE; + pBuffer += sEE_PAGESIZE; + } + + if(NumOfSingle!=0) + { + /* Store the number of data to be written */ + sEEDataNum = NumOfSingle; + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + } + } + } + /*!< If WriteAddr is not sEE_PAGESIZE aligned */ + else + { + /*!< If NumByteToWrite < sEE_PAGESIZE */ + if(NumOfPage== 0) + { + /*!< If the number of data to be written is more than the remaining space + in the current page: */ + if (NumByteToWrite > count) + { + /* Store the number of data to be written */ + sEEDataNum = count; + /*!< Write the data conained in same page */ + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + + /* Store the number of data to be written */ + sEEDataNum = (NumByteToWrite - count); + /*!< Write the remaining data in the following page */ + sEE_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + } + else + { + /* Store the number of data to be written */ + sEEDataNum = NumOfSingle; + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + } + } + /*!< If NumByteToWrite > sEE_PAGESIZE */ + else + { + NumByteToWrite -= count; + NumOfPage = NumByteToWrite / sEE_PAGESIZE; + NumOfSingle = NumByteToWrite % sEE_PAGESIZE; + + if(count != 0) + { + /* Store the number of data to be written */ + sEEDataNum = count; + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + WriteAddr += count; + pBuffer += count; + } + + while(NumOfPage--) + { + /* Store the number of data to be written */ + sEEDataNum = sEE_PAGESIZE; + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + WriteAddr += sEE_PAGESIZE; + pBuffer += sEE_PAGESIZE; + } + if(NumOfSingle != 0) + { + /* Store the number of data to be written */ + sEEDataNum = NumOfSingle; + sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum)); + /* Wait transfer through DMA to be complete */ + sEETimeout = sEE_LONG_TIMEOUT; + while (sEEDataNum > 0) + { + if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;}; + } + sEE_WaitEepromStandbyState(); + } + } + } +} + +/** + * @brief Wait for EEPROM Standby state. + * + * @note This function allows to wait and check that EEPROM has finished the + * last operation. It is mostly used after Write operation: after receiving + * the buffer to be written, the EEPROM may need additional time to actually + * perform the write operation. During this time, it doesn't answer to + * I2C packets addressed to it. Once the write operation is complete + * the EEPROM responds to its address. + * + * @param None + * @retval sEE_OK (0) if operation is correctly performed, else return value + * different from sEE_OK (0) or the timeout user callback. + */ +uint32_t sEE_WaitEepromStandbyState(void) +{ + __IO uint16_t tmpSR1 = 0; + __IO uint32_t sEETrials = 0; + + /*!< While the bus is busy */ + sEETimeout = sEE_LONG_TIMEOUT; + while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /* Keep looping till the slave acknowledge his address or maximum number + of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define + in stm32l152d_eval_i2c_ee.h file) */ + while (1) + { + /*!< Send START condition */ + I2C_GenerateSTART(sEE_I2C, ENABLE); + + /*!< Test on EV5 and clear it */ + sEETimeout = sEE_FLAG_TIMEOUT; + while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) + { + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + + /*!< Send EEPROM address for write */ + I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter); + + /* Wait for ADDR flag to be set (Slave acknowledged his address) */ + sEETimeout = sEE_LONG_TIMEOUT; + do + { + /* Get the current value of the SR1 register */ + tmpSR1 = sEE_I2C->SR1; + + /* Update the timeout value and exit if it reach 0 */ + if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback(); + } + /* Keep looping till the Address is acknowledged or the AF flag is + set (address not acknowledged at time) */ + while((tmpSR1 & (I2C_SR1_ADDR | I2C_SR1_AF)) == 0); + + /* Check if the ADDR flag has been set */ + if (tmpSR1 & I2C_SR1_ADDR) + { + /* Clear ADDR Flag by reading SR1 then SR2 registers (SR1 have already + been read) */ + (void)sEE_I2C->SR2; + + /*!< STOP condition */ + I2C_GenerateSTOP(sEE_I2C, ENABLE); + + /* Exit the function */ + return sEE_OK; + } + else + { + /*!< Clear AF flag */ + I2C_ClearFlag(sEE_I2C, I2C_FLAG_AF); + } + + /* Check if the maximum allowed numbe of trials has bee reached */ + if (sEETrials++ == sEE_MAX_TRIALS_NUMBER) + { + /* If the maximum number of trials has been reached, exit the function */ + return sEE_TIMEOUT_UserCallback(); + } + } +} + +/** + * @brief This function handles the DMA Tx Channel interrupt Handler. + * @param None + * @retval None + */ +void sEE_I2C_DMA_TX_IRQHandler(void) +{ + /* Check if the DMA transfer is complete */ + if(DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_TX_TC) != RESET) + { + /* Disable the DMA Tx Channel and Clear all its Flags */ + DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE); + DMA_ClearFlag(sEE_I2C_DMA_FLAG_TX_GL); + + /*!< Wait till all data have been physically transferred on the bus */ + sEETimeout = sEE_LONG_TIMEOUT; + while(!I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF)) + { + if((sEETimeout--) == 0) sEE_TIMEOUT_UserCallback(); + } + + /*!< Send STOP condition */ + I2C_GenerateSTOP(sEE_I2C, ENABLE); + + /* Reset the variable holding the number of data to be written */ + *sEEDataWritePointer = 0; + } +} + +/** + * @brief This function handles the DMA Rx Channel interrupt Handler. + * @param None + * @retval None + */ +void sEE_I2C_DMA_RX_IRQHandler(void) +{ + /* Check if the DMA transfer is complete */ + if(DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_RX_TC) != RESET) + { + /*!< Send STOP Condition */ + I2C_GenerateSTOP(sEE_I2C, ENABLE); + + /* Disable the DMA Rx Channel and Clear all its Flags */ + DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE); + DMA_ClearFlag(sEE_I2C_DMA_FLAG_RX_GL); + + /* Reset the variable holding the number of data to be read */ + *sEEDataReadPointer = 0; + } +} + +#ifdef USE_DEFAULT_TIMEOUT_CALLBACK +/** + * @brief Basic management of the timeout situation. + * @param None. + * @retval None. + */ +uint32_t sEE_TIMEOUT_UserCallback(void) +{ + /* Block communication and all processes */ + while (1) + { + } +} +#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_ee.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_ee.h new file mode 100644 index 0000000..f06cda7 --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_ee.h @@ -0,0 +1,193 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_i2c_ee.h + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file contains all the functions prototypes for the stm32l152d_eval_i2c_ee + * firmware driver. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32L152D_EVAL_I2C_EE_H +#define __STM32L152D_EVAL_I2C_EE_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_I2C_EE + * @{ + */ + +/** @defgroup STM32L152D_EVAL_I2C_EE_Exported_Types + * @{ + */ + +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_EE_Exported_Constants + * @{ + */ + +/* Uncomment the following line to use the default sEE_TIMEOUT_UserCallback() + function implemented in stm32_evel_i2c_ee.c file. + sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition + occure during communication (waiting on an event that doesn't occur, bus + errors, busy devices ...). */ +/* #define USE_DEFAULT_TIMEOUT_CALLBACK */ + +#if !defined (sEE_M24C08) && !defined (sEE_M24C64_32) && !defined (sEE_M24LR64) +/* Use the defines below the choose the EEPROM type */ +/* #define sEE_M24C08*/ /* Support the device: M24C08. */ +/* note: Could support: M24C01, M24C02, M24C04 and M24C16 if the blocks and + HW address are correctly defined*/ +/*#define sEE_M24C64_32*/ /* Support the devices: M24C32 and M24C64 */ +#define sEE_M24LR64 +#endif + +#ifdef sEE_M24C64_32 +/* For M24C32 and M24C64 devices, E0,E1 and E2 pins are all used for device + address selection (ne need for additional address lines). According to the + Harware connection on the board (on STM3210C-EVAL board E0 = E1 = E2 = 0) */ + + #define sEE_HW_ADDRESS 0xA0 /* E0 = E1 = E2 = 0 */ + +#elif defined (sEE_M24C08) +/* The M24C08W contains 4 blocks (128byte each) with the adresses below: E2 = 0 + EEPROM Addresses defines */ + #define sEE_Block0_ADDRESS 0xA0 /* E2 = 0 */ + /*#define sEE_Block1_ADDRESS 0xA2*/ /* E2 = 0 */ + /*#define sEE_Block2_ADDRESS 0xA4*/ /* E2 = 0 */ + /*#define sEE_Block3_ADDRESS 0xA6*/ /* E2 = 0 */ + +#elif defined (sEE_M24LR64) + #define sEE_HW_ADDRESS 0xA0 + +#endif /* sEE_M24C64_32 */ + +#define I2C_SPEED 200000 +#define I2C_SLAVE_ADDRESS7 0xA0 + +#if defined (sEE_M24C08) + #define sEE_PAGESIZE 16 +#elif defined (sEE_M24C64_32) + #define sEE_PAGESIZE 32 +#elif defined (sEE_M24LR64) + #define sEE_PAGESIZE 4 +#endif + +/* Maximum Timeout values for flags and events waiting loops. These timeouts are + not based on accurate values, they just guarantee that the application will + not remain stuck if the I2C communication is corrupted. + You may modify these timeout values depending on CPU frequency and application + conditions (interrupts routines ...). */ +#define sEE_FLAG_TIMEOUT ((uint32_t)0x1000) +#define sEE_LONG_TIMEOUT ((uint32_t)(10 * sEE_FLAG_TIMEOUT)) + +/* Maximum number of trials for sEE_WaitEepromStandbyState() function */ +#define sEE_MAX_TRIALS_NUMBER 300 + +/* Defintions for the state of the DMA transfer */ +#define sEE_STATE_READY 0 +#define sEE_STATE_BUSY 1 +#define sEE_STATE_ERROR 2 + +#define sEE_OK 0 +#define sEE_FAIL 1 + +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_EE_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_EE_Exported_Functions + * @{ + */ +void sEE_DeInit(void); +void sEE_Init(void); +uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead); +uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite); +void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite); +uint32_t sEE_WaitEepromStandbyState(void); + +/* USER Callbacks: These are functions for which prototypes only are declared in + EEPROM driver and that should be implemented into user applicaiton. */ +/* sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition + occure during communication (waiting on an event that doesn't occur, bus + errors, busy devices ...). + You can use the default timeout callback implementation by uncommenting the + define USE_DEFAULT_TIMEOUT_CALLBACK in stm32_evel_i2c_ee.h file. + Typically the user implementation of this callback should reset I2C peripheral + and re-initialize communication or in worst case reset all the application. */ +uint32_t sEE_TIMEOUT_UserCallback(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32L152D_EVAL_I2C_EE_H */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + + diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_tsensor.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_tsensor.c new file mode 100644 index 0000000..9338c99 --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_tsensor.c @@ -0,0 +1,982 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_i2c_tsensor.c + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file provides a set of functions needed to manage the I2C LM75 + * temperature sensor mounted on STM32L152D-EVAL board. + * It implements a high level communication layer for read and write + * from/to this sensor. The needed STM32L hardware resources (I2C and + * GPIO) are defined in stm32l152d_eval.h file, and the initialization is + * performed in LM75_LowLevel_Init() function declared in stm32l152d_eval.c + * file. + * + * Note: + * ----- + * This driver uses the DMA method to send and receive data on I2C bus, + * which allows higher efficiency and reliability of the communication. + * + * You can easily tailor this driver to any other development board, + * by just adapting the defines for hardware resources and + * LM75_LowLevel_Init() function. + * + * +-----------------------------------------------------------------+ + * | Pin assignment | + * +---------------------------------------+-----------+-------------+ + * | STM32 I2C Pins | STLM75 | Pin | + * +---------------------------------------+-----------+-------------+ + * | LM75_I2C_SDA_PIN/ SDA | SDA | 1 | + * | LM75_I2C_SCL_PIN/ SCL | SCL | 2 | + * | LM75_I2C_SMBUSALERT_PIN/ SMBUS ALERT | OS/INT | 3 | + * | . | GND | 4 (0V) | + * | . | GND | 5 (0V) | + * | . | GND | 6 (0V) | + * | . | GND | 7 (0V) | + * | . | VDD | 8 (3.3V)| + * +---------------------------------------+-----------+-------------+ + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval_i2c_tsensor.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_I2C_TSENSOR + * @brief This file includes the LM75 Temperature Sensor driver of + * STM32-EVAL boards. + * @{ + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Private_Types + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Private_Defines + * @{ + */ +#define LM75_SD_SET 0x01 /*!< Set SD bit in the configuration register */ +#define LM75_SD_RESET 0xFE /*!< Reset SD bit in the configuration register */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Private_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Private_Variables + * @{ + */ + +__IO uint32_t LM75_Timeout = LM75_LONG_TIMEOUT; +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Private_Function_Prototypes + * @{ + */ +static void LM75_DMA_Config(LM75_DMADirection_TypeDef Direction, uint8_t* buffer, uint8_t NumData); + +/** + * @} + */ + + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Private_Functions + * @{ + */ + +/** + * @brief DeInitializes the LM75_I2C. + * @param None + * @retval None + */ +void LM75_DeInit(void) +{ + LM75_LowLevel_DeInit(); +} + +/** + * @brief Initializes the LM75_I2C. + * @param None + * @retval None + */ +void LM75_Init(void) +{ + I2C_InitTypeDef I2C_InitStructure; + + LM75_LowLevel_Init(); + + I2C_DeInit(LM75_I2C); + + /*!< LM75_I2C Init */ + I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost; + I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; + I2C_InitStructure.I2C_OwnAddress1 = 0x00; + I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; + I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; + I2C_InitStructure.I2C_ClockSpeed = LM75_I2C_SPEED; + I2C_Init(LM75_I2C, &I2C_InitStructure); + + /*!< Enable SMBus Alert interrupt */ + I2C_ITConfig(LM75_I2C, I2C_IT_ERR, ENABLE); + + /*!< LM75_I2C Init */ + I2C_Cmd(LM75_I2C, ENABLE); +} + + +/** + * @brief Configure the DMA Peripheral used to handle communication via I2C. + * @param None + * @retval None + */ + +static void LM75_DMA_Config(LM75_DMADirection_TypeDef Direction, uint8_t* buffer, uint8_t NumData) +{ + DMA_InitTypeDef DMA_InitStructure; + + RCC_AHBPeriphClockCmd(LM75_DMA_CLK, ENABLE); + + /* Initialize the DMA_PeripheralBaseAddr member */ + DMA_InitStructure.DMA_PeripheralBaseAddr = LM75_I2C_DR; + /* Initialize the DMA_MemoryBaseAddr member */ + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)buffer; + /* Initialize the DMA_PeripheralInc member */ + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + /* Initialize the DMA_MemoryInc member */ + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; + /* Initialize the DMA_PeripheralDataSize member */ + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; + /* Initialize the DMA_MemoryDataSize member */ + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; + /* Initialize the DMA_Mode member */ + DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; + /* Initialize the DMA_Priority member */ + DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; + /* Initialize the DMA_M2M member */ + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; + + /* If using DMA for Reception */ + if (Direction == LM75_DMA_RX) + { + /* Initialize the DMA_DIR member */ + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; + + /* Initialize the DMA_BufferSize member */ + DMA_InitStructure.DMA_BufferSize = NumData; + + DMA_DeInit(LM75_DMA_RX_CHANNEL); + + DMA_Init(LM75_DMA_RX_CHANNEL, &DMA_InitStructure); + } + /* If using DMA for Transmission */ + else if (Direction == LM75_DMA_TX) + { + /* Initialize the DMA_DIR member */ + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; + + /* Initialize the DMA_BufferSize member */ + DMA_InitStructure.DMA_BufferSize = NumData; + + DMA_DeInit(LM75_DMA_TX_CHANNEL); + + DMA_Init(LM75_DMA_TX_CHANNEL, &DMA_InitStructure); + } +} + + +/** + * @brief Checks the LM75 status. + * @param None + * @retval ErrorStatus: LM75 Status (ERROR or SUCCESS). + */ +ErrorStatus LM75_GetStatus(void) +{ + uint32_t I2C_TimeOut = I2C_TIMEOUT; + + /*!< Clear the LM75_I2C AF flag */ + I2C_ClearFlag(LM75_I2C, I2C_FLAG_AF); + + /*!< Enable LM75_I2C acknowledgement if it is already disabled by other function */ + I2C_AcknowledgeConfig(LM75_I2C, ENABLE); + + /*---------------------------- Transmission Phase ---------------------------*/ + + /*!< Send LM75_I2C START condition */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /*!< Test on LM75_I2C EV5 and clear it */ + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) && I2C_TimeOut) /*!< EV5 */ + { + I2C_TimeOut--; + } + if (I2C_TimeOut == 0) + { + return ERROR; + } + + I2C_TimeOut = I2C_TIMEOUT; + + /*!< Send STLM75 slave address for write */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + while ((!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) && I2C_TimeOut)/* EV6 */ + { + I2C_TimeOut--; + } + + if ((I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_AF) != 0x00) || (I2C_TimeOut == 0)) + { + return ERROR; + } + else + { + return SUCCESS; + } +} +/** + * @brief Read the specified register from the LM75. + * @param RegName: specifies the LM75 register to be read. + * This member can be one of the following values: + * - LM75_REG_TEMP: temperature register + * - LM75_REG_TOS: Over-limit temperature register + * - LM75_REG_THYS: Hysteresis temperature register + * @retval LM75 register value. + */ +uint16_t LM75_ReadReg(uint8_t RegName) +{ + uint8_t LM75_BufferRX[2] ={0,0}; + uint16_t tmp = 0; + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2); + + /* Enable DMA NACK automatic generation */ + I2C_DMALastTransferCmd(LM75_I2C, ENABLE); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send device address for write */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send the device's internal address to write to */ + I2C_SendData(LM75_I2C, RegName); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send START condition a second time */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send LM75 address for read */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA RX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_RX_TCFLAG); + + /*!< Store LM75_I2C received data */ + tmp = (uint16_t)(LM75_BufferRX[0] << 8); + tmp |= LM75_BufferRX[1]; + + /* return a Reg value */ + return (uint16_t)tmp; +} + +/** + * @brief Write to the specified register of the LM75. + * @param RegName: specifies the LM75 register to be written. + * This member can be one of the following values: + * - LM75_REG_TOS: Over-limit temperature register + * - LM75_REG_THYS: Hysteresis temperature register + * @param RegValue: value to be written to LM75 register. + * @retval None + */ +uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue) +{ + uint8_t LM75_BufferTX[2] ={0,0}; + LM75_BufferTX[0] = (uint8_t)(RegValue >> 8); + LM75_BufferTX[1] = (uint8_t)(RegValue); + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)LM75_BufferTX, 2); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Transmit the slave address and enable writing operation */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Transmit the first address for r/w operations */ + I2C_SendData(LM75_I2C, RegName); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA TX Channel */ + DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Wait until BTF Flag is set before generating STOP */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA TX Channel */ + DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA TX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_TX_TCFLAG); + + return LM75_OK; +} + +/** + * @brief Read Temperature register of LM75: double temperature value. + * @param None + * @retval LM75 measured temperature value. + */ +uint16_t LM75_ReadTemp(void) +{ + uint8_t LM75_BufferRX[2] ={0,0}; + uint16_t tmp = 0; + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2); + + /* Enable DMA NACK automatic generation */ + I2C_DMALastTransferCmd(LM75_I2C, ENABLE); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send device address for write */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send the device's internal address to write to */ + I2C_SendData(LM75_I2C, LM75_REG_TEMP); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send START condition a second time */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send LM75 address for read */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA RX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_RX_TCFLAG); + + /*!< Store LM75_I2C received data */ + tmp = (uint16_t)(LM75_BufferRX[0] << 8); + tmp |= LM75_BufferRX[1]; + + /*!< Return Temperature value */ + return (uint16_t)(tmp >> 7); +} + +/** + * @brief Read the configuration register from the LM75. + * @param None + * @retval LM75 configuration register value. + */ +uint8_t LM75_ReadConfReg(void) +{ + uint8_t LM75_BufferRX[2] ={0,0}; + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2); + + /* Enable DMA NACK automatic generation */ + I2C_DMALastTransferCmd(LM75_I2C, ENABLE); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send device address for write */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send the device's internal address to write to */ + I2C_SendData(LM75_I2C, LM75_REG_CONF); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send START condition a second time */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send LM75 address for read */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA RX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_RX_TCFLAG); + + /*!< Return Temperature value */ + return (uint8_t)LM75_BufferRX[0]; +} + +/** + * @brief Write to the configuration register of the LM75. + * @param RegValue: sepecifies the value to be written to LM75 configuration + * register. + * @retval None + */ +uint8_t LM75_WriteConfReg(uint8_t RegValue) +{ + uint8_t LM75_BufferTX = 0; + LM75_BufferTX = (uint8_t)(RegValue); + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Transmit the slave address and enable writing operation */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Transmit the first address for r/w operations */ + I2C_SendData(LM75_I2C, LM75_REG_CONF); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA TX Channel */ + DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Wait until BTF Flag is set before generating STOP */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA TX Channel */ + DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA TX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_TX_TCFLAG); + + return LM75_OK; + +} + +/** + * @brief Enables or disables the LM75. + * @param NewState: specifies the LM75 new status. This parameter can be ENABLE + * or DISABLE. + * @retval None + */ +uint8_t LM75_ShutDown(FunctionalState NewState) +{ + uint8_t LM75_BufferRX[2] ={0,0}; + uint8_t LM75_BufferTX = 0; + __IO uint8_t RegValue = 0; + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2); + + /* Enable DMA NACK automatic generation */ + I2C_DMALastTransferCmd(LM75_I2C, ENABLE); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send device address for write */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send the device's internal address to write to */ + I2C_SendData(LM75_I2C, LM75_REG_CONF); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send START condition a second time */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send LM75 address for read */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA RX Channel */ + DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA RX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_RX_TCFLAG); + + /*!< Get received data */ + RegValue = (uint8_t)LM75_BufferRX[0]; + + /*---------------------------- Transmission Phase ---------------------------*/ + + /*!< Enable or disable SD bit */ + if (NewState != DISABLE) + { + /*!< Enable LM75 */ + LM75_BufferTX = RegValue & LM75_SD_RESET; + } + else + { + /*!< Disable LM75 */ + LM75_BufferTX = RegValue | LM75_SD_SET; + } + + /* Test on BUSY Flag */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Configure DMA Peripheral */ + LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1); + + /* Enable the I2C peripheral */ + I2C_GenerateSTART(LM75_I2C, ENABLE); + + /* Test on SB Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Transmit the slave address and enable writing operation */ + I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter); + + /* Test on ADDR Flag */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Transmit the first address for r/w operations */ + I2C_SendData(LM75_I2C, LM75_REG_CONF); + + /* Test on TXE FLag (data sent) */ + LM75_Timeout = LM75_FLAG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Enable I2C DMA request */ + I2C_DMACmd(LM75_I2C,ENABLE); + + /* Enable DMA TX Channel */ + DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE); + + /* Wait until DMA Transfer Complete */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG)) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Wait until BTF Flag is set before generating STOP */ + LM75_Timeout = LM75_LONG_TIMEOUT; + while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))) + { + if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback(); + } + + /* Send STOP Condition */ + I2C_GenerateSTOP(LM75_I2C, ENABLE); + + /* Disable DMA TX Channel */ + DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE); + + /* Disable I2C DMA request */ + I2C_DMACmd(LM75_I2C,DISABLE); + + /* Clear DMA TX Transfer Complete Flag */ + DMA_ClearFlag(LM75_DMA_TX_TCFLAG); + + return LM75_OK; +} + +/** + * @} + */ + + +/** + * @} + */ + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_tsensor.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_tsensor.h new file mode 100644 index 0000000..f1f6cb6 --- /dev/null +++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_i2c_tsensor.h @@ -0,0 +1,179 @@ +/** + ****************************************************************************** + * @file stm32l152d_eval_i2c_tsensor.h + * @author MCD Application Team + * @version V1.0.1 + * @date 09-March-2012 + * @brief This file contains all the functions prototypes for the + * stm32l152d_eval_i2c_tsensor firmware driver. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32L152D_EVAL_I2C_TSENSOR_H +#define __STM32L152D_EVAL_I2C_TSENSOR_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32l152d_eval.h" + +/** @addtogroup Utilities + * @{ + */ + +/** @addtogroup STM32_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL + * @{ + */ + +/** @addtogroup STM32L152D_EVAL_I2C_TSENSOR + * @{ + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Exported_Types + * @{ + */ + + /** + * @brief IOE DMA Direction + */ +typedef enum +{ + LM75_DMA_TX = 0, + LM75_DMA_RX = 1 +}LM75_DMADirection_TypeDef; + +/** + * @brief TSENSOR Status + */ +typedef enum +{ + LM75_OK = 0, + LM75_FAIL +}LM75_Status_TypDef; + +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Exported_Constants + * @{ + */ + +/* Uncomment the following line to use Timeout_User_Callback LM75_TimeoutUserCallback(). + If This Callback is enabled, it should be implemented by user in main function . + LM75_TimeoutUserCallback() function is called whenever a timeout condition + occure during communication (waiting on an event that doesn't occur, bus + errors, busy devices ...). */ +/* #define USE_TIMEOUT_USER_CALLBACK */ + +/* Maximum Timeout values for flags and events waiting loops. These timeouts are + not based on accurate values, they just guarantee that the application will + not remain stuck if the I2C communication is corrupted. + You may modify these timeout values depending on CPU frequency and application + conditions (interrupts routines ...). */ +#define LM75_FLAG_TIMEOUT ((uint32_t)0x1000) +#define LM75_LONG_TIMEOUT ((uint32_t)(10 * LM75_FLAG_TIMEOUT)) + + +/** + * @brief Block Size + */ +#define LM75_REG_TEMP 0x00 /*!< Temperature Register of LM75 */ +#define LM75_REG_CONF 0x01 /*!< Configuration Register of LM75 */ +#define LM75_REG_THYS 0x02 /*!< Temperature Register of LM75 */ +#define LM75_REG_TOS 0x03 /*!< Over-temp Shutdown threshold Register of LM75 */ +#define I2C_TIMEOUT ((uint32_t)0x3FFFF) /*!< I2C Time out */ +#define LM75_ADDR 0x90 /*!< LM75 address */ +#define LM75_I2C_SPEED 100000 /*!< I2C Speed */ + + + +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup STM32L152D_EVAL_I2C_TSENSOR_Exported_Functions + * @{ + */ +void LM75_DeInit(void); +void LM75_Init(void); +ErrorStatus LM75_GetStatus(void); +uint16_t LM75_ReadTemp(void); +uint16_t LM75_ReadReg(uint8_t RegName); +uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue); +uint8_t LM75_ReadConfReg(void); +uint8_t LM75_WriteConfReg(uint8_t RegValue); +uint8_t LM75_ShutDown(FunctionalState NewState); + +/** + * @brief Timeout user callback function. This function is called when a timeout + * condition occurs during communication with IO Expander. Only protoype + * of this function is decalred in IO Expander driver. Its implementation + * may be done into user application. This function may typically stop + * current operations and reset the I2C peripheral and IO Expander. + * To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK + * at the top of this file. + */ +#ifdef USE_TIMEOUT_USER_CALLBACK + uint8_t LM75_TIMEOUT_UserCallback(void); +#else + #define LM75_TIMEOUT_UserCallback() LM75_FAIL +#endif /* USE_TIMEOUT_USER_CALLBACK */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32L152D_EVAL_I2C_TSENSOR_H */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |