stm320518_eval.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /**
  2. ******************************************************************************
  3. * @file stm320518_eval.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 20-April-2012
  7. * @brief This file provides set of firmware functions to manage Leds,
  8. * push-button and COM ports.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm320518_eval.h"
  30. /** @addtogroup Utilities
  31. * @{
  32. */
  33. /** @addtogroup STM32_EVAL
  34. * @{
  35. */
  36. /** @addtogroup STM320518_EVAL
  37. * @{
  38. */
  39. /** @defgroup STM320518_EVAL_LOW_LEVEL
  40. * @brief This file provides firmware functions to manage Leds, push-buttons,
  41. * COM ports, SD card on SPI and temperature sensor (LM75) available on
  42. * STM320518-EVAL evaluation board from STMicroelectronics.
  43. * @{
  44. */
  45. /** @defgroup STM320518_EVAL_LOW_LEVEL_Private_TypesDefinitions
  46. * @{
  47. */
  48. /**
  49. * @}
  50. */
  51. /** @defgroup STM320518_EVAL_LOW_LEVEL_Private_Defines
  52. * @{
  53. */
  54. /**
  55. * @}
  56. */
  57. /** @defgroup STM320518_EVAL_LOW_LEVEL_Private_Macros
  58. * @{
  59. */
  60. /**
  61. * @}
  62. */
  63. /** @defgroup STM320518_EVAL_LOW_LEVEL_Private_Variables
  64. * @{
  65. */
  66. GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
  67. LED4_GPIO_PORT};
  68. const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
  69. LED4_PIN};
  70. const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
  71. LED4_GPIO_CLK};
  72. GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {TAMPER_BUTTON_GPIO_PORT, KEY_BUTTON_GPIO_PORT,
  73. RIGHT_BUTTON_GPIO_PORT, LEFT_BUTTON_GPIO_PORT,
  74. UP_BUTTON_GPIO_PORT, DOWN_BUTTON_GPIO_PORT,
  75. SEL_BUTTON_GPIO_PORT};
  76. const uint16_t BUTTON_PIN[BUTTONn] = {TAMPER_BUTTON_PIN, KEY_BUTTON_PIN,
  77. RIGHT_BUTTON_PIN, LEFT_BUTTON_PIN,
  78. UP_BUTTON_PIN, DOWN_BUTTON_PIN,
  79. SEL_BUTTON_PIN};
  80. const uint32_t BUTTON_CLK[BUTTONn] = {TAMPER_BUTTON_GPIO_CLK, KEY_BUTTON_GPIO_CLK,
  81. RIGHT_BUTTON_GPIO_CLK, LEFT_BUTTON_GPIO_CLK,
  82. UP_BUTTON_GPIO_CLK, DOWN_BUTTON_GPIO_CLK,
  83. SEL_BUTTON_GPIO_CLK};
  84. const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {TAMPER_BUTTON_EXTI_LINE,
  85. KEY_BUTTON_EXTI_LINE,
  86. RIGHT_BUTTON_EXTI_LINE,
  87. LEFT_BUTTON_EXTI_LINE,
  88. UP_BUTTON_EXTI_LINE,
  89. DOWN_BUTTON_EXTI_LINE,
  90. SEL_BUTTON_EXTI_LINE};
  91. const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {TAMPER_BUTTON_EXTI_PORT_SOURCE,
  92. KEY_BUTTON_EXTI_PORT_SOURCE,
  93. RIGHT_BUTTON_EXTI_PORT_SOURCE,
  94. LEFT_BUTTON_EXTI_PORT_SOURCE,
  95. UP_BUTTON_EXTI_PORT_SOURCE,
  96. DOWN_BUTTON_EXTI_PORT_SOURCE,
  97. SEL_BUTTON_EXTI_PORT_SOURCE};
  98. const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {TAMPER_BUTTON_EXTI_PIN_SOURCE,
  99. KEY_BUTTON_EXTI_PIN_SOURCE,
  100. RIGHT_BUTTON_EXTI_PIN_SOURCE,
  101. LEFT_BUTTON_EXTI_PIN_SOURCE,
  102. UP_BUTTON_EXTI_PIN_SOURCE,
  103. DOWN_BUTTON_EXTI_PIN_SOURCE,
  104. SEL_BUTTON_EXTI_PIN_SOURCE};
  105. const uint16_t BUTTON_IRQn[BUTTONn] = {TAMPER_BUTTON_EXTI_IRQn, KEY_BUTTON_EXTI_IRQn,
  106. RIGHT_BUTTON_EXTI_IRQn, LEFT_BUTTON_EXTI_IRQn,
  107. UP_BUTTON_EXTI_IRQn, DOWN_BUTTON_EXTI_IRQn,
  108. SEL_BUTTON_EXTI_IRQn};
  109. USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
  110. GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
  111. GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
  112. const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK};
  113. const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK};
  114. const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK};
  115. const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
  116. const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
  117. const uint16_t COM_TX_PIN_SOURCE[COMn] = {EVAL_COM1_TX_SOURCE};
  118. const uint16_t COM_RX_PIN_SOURCE[COMn] = {EVAL_COM1_RX_SOURCE};
  119. const uint16_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
  120. const uint16_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
  121. /**
  122. * @}
  123. */
  124. /** @defgroup STM320518_EVAL_LOW_LEVEL_Private_FunctionPrototypes
  125. * @{
  126. */
  127. /**
  128. * @}
  129. */
  130. /** @defgroup STM320518_EVAL_LOW_LEVEL_Private_Functions
  131. * @{
  132. */
  133. /**
  134. * @brief Configures LED GPIO.
  135. * @param Led: Specifies the Led to be configured.
  136. * This parameter can be one of following parameters:
  137. * @arg LED1
  138. * @arg LED2
  139. * @arg LED3
  140. * @arg LED4
  141. * @retval None
  142. */
  143. void STM_EVAL_LEDInit(Led_TypeDef Led)
  144. {
  145. GPIO_InitTypeDef GPIO_InitStructure;
  146. /* Enable the GPIO_LED Clock */
  147. RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
  148. /* Configure the GPIO_LED pin */
  149. GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
  150. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  151. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  152. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  153. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  154. GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
  155. GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
  156. }
  157. /**
  158. * @brief Turns selected LED On.
  159. * @param Led: Specifies the Led to be set on.
  160. * This parameter can be one of following parameters:
  161. * @arg LED1
  162. * @arg LED2
  163. * @arg LED3
  164. * @arg LED4
  165. * @retval None
  166. */
  167. void STM_EVAL_LEDOn(Led_TypeDef Led)
  168. {
  169. GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
  170. }
  171. /**
  172. * @brief Turns selected LED Off.
  173. * @param Led: Specifies the Led to be set off.
  174. * This parameter can be one of following parameters:
  175. * @arg LED1
  176. * @arg LED2
  177. * @arg LED3
  178. * @arg LED4
  179. * @retval None
  180. */
  181. void STM_EVAL_LEDOff(Led_TypeDef Led)
  182. {
  183. GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
  184. }
  185. /**
  186. * @brief Toggles the selected LED.
  187. * @param Led: Specifies the Led to be toggled.
  188. * This parameter can be one of following parameters:
  189. * @arg LED1
  190. * @arg LED2
  191. * @arg LED3
  192. * @arg LED4
  193. * @retval None
  194. */
  195. void STM_EVAL_LEDToggle(Led_TypeDef Led)
  196. {
  197. GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
  198. }
  199. /**
  200. * @brief Configures Button GPIO and EXTI Line.
  201. * @param Button: Specifies the Button to be configured.
  202. * This parameter can be one of following parameters:
  203. * @arg BUTTON_TAMPER: Tamper Push Button
  204. * @arg BUTTON_KEY: Key Push Button
  205. * @arg BUTTON_RIGHT: Joystick Right Push Button
  206. * @arg BUTTON_LEFT: Joystick Left Push Button
  207. * @arg BUTTON_UP: Joystick Up Push Button
  208. * @arg BUTTON_DOWN: Joystick Down Push Button
  209. * @arg BUTTON_SEL: Joystick Sel Push Button
  210. * @param Button_Mode: Specifies Button mode.
  211. * This parameter can be one of following parameters:
  212. * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
  213. * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
  214. * generation capability
  215. * @retval None
  216. */
  217. void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
  218. {
  219. GPIO_InitTypeDef GPIO_InitStructure;
  220. EXTI_InitTypeDef EXTI_InitStructure;
  221. NVIC_InitTypeDef NVIC_InitStructure;
  222. /* Enable the BUTTON Clock */
  223. RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
  224. RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  225. /* Configure Button pin as input */
  226. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  227. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  228. GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
  229. GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
  230. if (Button_Mode == BUTTON_MODE_EXTI)
  231. {
  232. /* Connect Button EXTI Line to Button GPIO Pin */
  233. SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
  234. /* Configure Button EXTI line */
  235. EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
  236. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  237. if ((Button != BUTTON_TAMPER) && (Button != BUTTON_KEY))
  238. {
  239. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  240. }
  241. else
  242. {
  243. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  244. }
  245. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  246. EXTI_Init(&EXTI_InitStructure);
  247. /* Enable and set Button EXTI Interrupt to the lowest priority */
  248. NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
  249. NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03;
  250. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  251. NVIC_Init(&NVIC_InitStructure);
  252. }
  253. }
  254. /**
  255. * @brief Returns the selected Button state.
  256. * @param Button: Specifies the Button to be checked.
  257. * This parameter can be one of following parameters:
  258. * @arg BUTTON_TAMPER: Tamper Push Button
  259. * @arg BUTTON_KEY: Key Push Button
  260. * @arg BUTTON_RIGHT: Joystick Right Push Button
  261. * @arg BUTTON_LEFT: Joystick Left Push Button
  262. * @arg BUTTON_UP: Joystick Up Push Button
  263. * @arg BUTTON_DOWN: Joystick Down Push Button
  264. * @arg BUTTON_SEL: Joystick Sel Push Button
  265. * @retval The Button GPIO pin value.
  266. */
  267. uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
  268. {
  269. /* There is no Wakeup button on STM320518-EVAL. */
  270. return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
  271. }
  272. /**
  273. * @brief Configures COM port.
  274. * @param COM: Specifies the COM port to be configured.
  275. * This parameter can be one of following parameters:
  276. * @arg COM1
  277. * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
  278. * contains the configuration information for the specified USART peripheral.
  279. * @retval None
  280. */
  281. void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
  282. {
  283. GPIO_InitTypeDef GPIO_InitStructure;
  284. /* Enable GPIO clock */
  285. RCC_AHBPeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
  286. /* Enable USART clock */
  287. RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
  288. /* Connect PXx to USARTx_Tx */
  289. GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
  290. /* Connect PXx to USARTx_Rx */
  291. GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
  292. /* Configure USART Tx as alternate function push-pull */
  293. GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
  294. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  295. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  296. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  297. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  298. GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
  299. /* Configure USART Rx as alternate function push-pull */
  300. GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
  301. GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
  302. /* USART configuration */
  303. USART_Init(COM_USART[COM], USART_InitStruct);
  304. /* Enable USART */
  305. USART_Cmd(COM_USART[COM], ENABLE);
  306. }
  307. /**
  308. * @brief DeInitializes the SPI interface.
  309. * @param None
  310. * @retval None
  311. */
  312. void SD_LowLevel_DeInit(void)
  313. {
  314. GPIO_InitTypeDef GPIO_InitStructure;
  315. SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
  316. SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */
  317. /*!< SD_SPI Periph clock disable */
  318. RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE);
  319. /*!< Configure SD_SPI pins: SCK */
  320. GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
  321. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  322. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  323. GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
  324. /*!< Configure SD_SPI pins: MISO */
  325. GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
  326. GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
  327. /*!< Configure SD_SPI pins: MOSI */
  328. GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
  329. GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
  330. /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
  331. GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
  332. GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
  333. /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
  334. GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
  335. GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
  336. }
  337. /**
  338. * @brief Initializes the SD Card and put it into StandBy State (Ready for
  339. * data transfer).
  340. * @param None
  341. * @retval None
  342. */
  343. void SD_LowLevel_Init(void)
  344. {
  345. GPIO_InitTypeDef GPIO_InitStructure;
  346. SPI_InitTypeDef SPI_InitStructure;
  347. /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
  348. and SD_SPI_SCK_GPIO Periph clock enable */
  349. RCC_AHBPeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
  350. SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
  351. /*!< SD_SPI Periph clock enable */
  352. RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE);
  353. /*!< Configure SD_SPI pins: SCK */
  354. GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
  355. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  356. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  357. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  358. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  359. GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
  360. /*!< Configure SD_SPI pins: MISO */
  361. GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
  362. GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
  363. /*!< Configure SD_SPI pins: MOSI */
  364. GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
  365. GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
  366. /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
  367. GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
  368. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  369. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  370. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  371. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  372. GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
  373. /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
  374. GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
  375. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  376. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  377. GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
  378. /* Connect PXx to SD_SPI_SCK */
  379. GPIO_PinAFConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_SCK_SOURCE, SD_SPI_SCK_AF);
  380. /* Connect PXx to SD_SPI_MISO */
  381. GPIO_PinAFConfig(SD_SPI_MISO_GPIO_PORT, SD_SPI_MISO_SOURCE, SD_SPI_MISO_AF);
  382. /* Connect PXx to SD_SPI_MOSI */
  383. GPIO_PinAFConfig(SD_SPI_MOSI_GPIO_PORT, SD_SPI_MOSI_SOURCE, SD_SPI_MOSI_AF);
  384. /*!< SD_SPI Config */
  385. SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  386. SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  387. SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  388. SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  389. SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  390. SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  391. SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  392. SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  393. SPI_InitStructure.SPI_CRCPolynomial = 7;
  394. SPI_Init(SD_SPI, &SPI_InitStructure);
  395. SPI_RxFIFOThresholdConfig(SD_SPI, SPI_RxFIFOThreshold_QF);
  396. SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
  397. }
  398. /**
  399. * @brief DeInitializes the LM75_I2C.
  400. * @param None
  401. * @retval None
  402. */
  403. void LM75_LowLevel_DeInit(void)
  404. {
  405. GPIO_InitTypeDef GPIO_InitStructure;
  406. /*!< Disable LM75_I2C */
  407. I2C_Cmd(LM75_I2C, DISABLE);
  408. /*!< DeInitializes the LM75_I2C */
  409. I2C_DeInit(LM75_I2C);
  410. /*!< LM75_I2C Periph clock disable */
  411. RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
  412. /*!< Configure LM75_I2C pins: SCL */
  413. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
  414. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  415. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  416. GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
  417. /*!< Configure LM75_I2C pins: SDA */
  418. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
  419. GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  420. /*!< Configure LM75_I2C pin: SMBUS ALERT */
  421. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
  422. GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
  423. }
  424. /**
  425. * @brief Initializes the LM75_I2C..
  426. * @param None
  427. * @retval None
  428. */
  429. void LM75_LowLevel_Init(void)
  430. {
  431. GPIO_InitTypeDef GPIO_InitStructure;
  432. /*!< LM75_I2C Periph clock enable */
  433. RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
  434. /* Configure the I2C clock source. The clock is derived from the HSI */
  435. RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
  436. /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
  437. and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
  438. RCC_AHBPeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
  439. LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
  440. /* Connect PXx to I2C_SCL */
  441. GPIO_PinAFConfig(LM75_I2C_SCL_GPIO_PORT, LM75_I2C_SCL_SOURCE, LM75_I2C_SCL_AF);
  442. /* Connect PXx to I2C_SDA */
  443. GPIO_PinAFConfig(LM75_I2C_SDA_GPIO_PORT, LM75_I2C_SDA_SOURCE, LM75_I2C_SDA_AF);
  444. /* Connect PXx to I2C_SMBUSALER */
  445. GPIO_PinAFConfig(LM75_I2C_SMBUSALERT_GPIO_PORT, LM75_I2C_SMBUSALERT_SOURCE, LM75_I2C_SMBUSALERT_AF);
  446. /*!< Configure LM75_I2C pins: SCL */
  447. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
  448. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  449. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  450. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  451. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  452. GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
  453. /*!< Configure LM75_I2C pins: SDA */
  454. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
  455. GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  456. /*!< Configure LM75_I2C pin: SMBUS ALERT */
  457. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
  458. GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
  459. }
  460. /**
  461. * @brief DeInitializes peripherals used by the I2C EEPROM driver.
  462. * @param None
  463. * @retval None
  464. */
  465. void sEE_LowLevel_DeInit(void)
  466. {
  467. GPIO_InitTypeDef GPIO_InitStructure;
  468. /* sEE_I2C Peripheral Disable */
  469. I2C_Cmd(sEE_I2C, DISABLE);
  470. /* sEE_I2C DeInit */
  471. I2C_DeInit(sEE_I2C);
  472. /*!< sEE_I2C Periph clock disable */
  473. RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
  474. /*!< GPIO configuration */
  475. /*!< Configure sEE_I2C pins: SCL */
  476. GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
  477. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  478. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  479. GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
  480. /*!< Configure sEE_I2C pins: SDA */
  481. GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
  482. GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  483. }
  484. /**
  485. * @brief Initializes peripherals used by the I2C EEPROM driver.
  486. * @param None
  487. * @retval None
  488. */
  489. void sEE_LowLevel_Init(void)
  490. {
  491. GPIO_InitTypeDef GPIO_InitStructure;
  492. /* Configure the I2C clock source. The clock is derived from the HSI */
  493. RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
  494. /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
  495. RCC_AHBPeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
  496. /*!< sEE_I2C Periph clock enable */
  497. RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
  498. /* Connect PXx to I2C_SCL*/
  499. GPIO_PinAFConfig(sEE_I2C_SCL_GPIO_PORT, sEE_I2C_SCL_SOURCE, sEE_I2C_SCL_AF);
  500. /* Connect PXx to I2C_SDA*/
  501. GPIO_PinAFConfig(sEE_I2C_SDA_GPIO_PORT, sEE_I2C_SDA_SOURCE, sEE_I2C_SDA_AF);
  502. /*!< GPIO configuration */
  503. /*!< Configure sEE_I2C pins: SCL */
  504. GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
  505. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  506. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  507. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  508. GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
  509. /*!< Configure sEE_I2C pins: SDA */
  510. GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
  511. GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  512. }
  513. /**
  514. * @}
  515. */
  516. /**
  517. * @}
  518. */
  519. /**
  520. * @}
  521. */
  522. /**
  523. * @}
  524. */
  525. /**
  526. * @}
  527. */
  528. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/