hk32f103x_eval.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /**
  2. ******************************************************************************
  3. * @file stm3210b_eval.c
  4. * @author MCD Application Team
  5. * @version V4.5.0
  6. * @date 07-March-2011
  7. * @brief This file provides
  8. * - set of firmware functions to manage Leds, push-button and COM ports
  9. * - low level initialization functions for SD card (on SPI), SPI serial
  10. * flash (sFLASH) and temperature sensor (LM75)
  11. * available on STM3210B-EVAL evaluation board from STMicroelectronics.
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  16. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  17. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  18. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  19. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  20. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  21. *
  22. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  23. ******************************************************************************
  24. */
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "hk32f103x_eval.h"
  27. /** @addtogroup Utilities
  28. * @{
  29. */
  30. /** @addtogroup STM32_EVAL
  31. * @{
  32. */
  33. /** @defgroup STM3210B_EVAL_LOW_LEVEL
  34. * @brief This file provides firmware functions to manage Leds, push-buttons,
  35. * COM ports, SD card on SPI, serial flash (sFLASH), serial EEPROM (sEE)
  36. * and temperature sensor (LM75) available on STM3210B-EVAL evaluation
  37. * board from STMicroelectronics.
  38. * @{
  39. */
  40. /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_TypesDefinitions
  41. * @{
  42. */
  43. /**
  44. * @}
  45. */
  46. /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Defines
  47. * @{
  48. */
  49. /**
  50. * @}
  51. */
  52. /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Macros
  53. * @{
  54. */
  55. /**
  56. * @}
  57. */
  58. /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Variables
  59. * @{
  60. */
  61. GPIO_TypeDef* GPIO_PORT[LEDn] = {LED0_GPIO_PORT, LED1_GPIO_PORT};
  62. const uint16_t GPIO_PIN[LEDn] = {LED0_PIN, LED1_PIN};
  63. const uint32_t GPIO_CLK[LEDn] = {LED0_GPIO_CLK, LED1_GPIO_CLK};
  64. GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT,
  65. KEY0_BUTTON_GPIO_PORT,
  66. KEY1_BUTTON_GPIO_PORT};
  67. const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN,
  68. KEY0_BUTTON_PIN,
  69. KEY1_BUTTON_PIN};
  70. const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK,
  71. KEY0_BUTTON_GPIO_CLK,
  72. KEY1_BUTTON_GPIO_CLK};
  73. const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
  74. KEY0_BUTTON_EXTI_LINE,
  75. KEY1_BUTTON_EXTI_LINE};
  76. const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
  77. KEY0_BUTTON_EXTI_PORT_SOURCE,
  78. KEY1_BUTTON_EXTI_PORT_SOURCE};
  79. const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
  80. KEY0_BUTTON_EXTI_PIN_SOURCE,
  81. KEY1_BUTTON_EXTI_PIN_SOURCE};
  82. const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn,
  83. KEY0_BUTTON_EXTI_IRQn,
  84. KEY1_BUTTON_EXTI_IRQn};
  85. USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2};
  86. GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
  87. GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
  88. const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
  89. const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
  90. const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
  91. const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
  92. const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
  93. /**
  94. * @}
  95. */
  96. /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_FunctionPrototypes
  97. * @{
  98. */
  99. /**
  100. * @}
  101. */
  102. /** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Functions
  103. * @{
  104. */
  105. /**
  106. * @brief Configures LED GPIO.
  107. * @param Led: Specifies the Led to be configured.
  108. * This parameter can be one of following parameters:
  109. * @arg LED0
  110. * @arg LED1
  111. * @retval None
  112. */
  113. void STM_EVAL_LEDInit(Led_TypeDef Led)
  114. {
  115. GPIO_InitTypeDef GPIO_InitStructure;
  116. /* Enable the GPIO_LED Clock */
  117. RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
  118. /* Configure the GPIO_LED pin */
  119. GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
  120. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  121. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  122. GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
  123. }
  124. /**
  125. * @brief Turns selected LED On.
  126. * @param Led: Specifies the Led to be set on.
  127. * This parameter can be one of following parameters:
  128. * @arg LED0
  129. * @arg LED0
  130. * @retval None
  131. */
  132. void STM_EVAL_LEDOn(Led_TypeDef Led)
  133. {
  134. GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
  135. }
  136. /**
  137. * @brief Turns selected LED Off.
  138. * @param Led: Specifies the Led to be set off.
  139. * This parameter can be one of following parameters:
  140. * @arg LED0
  141. * @arg LED1
  142. * @retval None
  143. */
  144. void STM_EVAL_LEDOff(Led_TypeDef Led)
  145. {
  146. GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
  147. }
  148. /**
  149. * @brief Toggles the selected LED.
  150. * @param Led: Specifies the Led to be toggled.
  151. * This parameter can be one of following parameters:
  152. * @arg LED0
  153. * @arg LED1
  154. * @retval None
  155. */
  156. void STM_EVAL_LEDToggle(Led_TypeDef Led)
  157. {
  158. GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
  159. }
  160. /**
  161. * @brief Configures Button GPIO and EXTI Line.
  162. * @param Button: Specifies the Button to be configured.
  163. * This parameter can be one of following parameters:
  164. * @arg BUTTON_WAKEUP: Wakeup Push Button
  165. * @arg BUTTON_KEY0: Key Push Button
  166. * @arg BUTTON_KEY1: Key Push Button
  167. * @param Button_Mode: Specifies Button mode.
  168. * This parameter can be one of following parameters:
  169. * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
  170. * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
  171. * generation capability
  172. * @retval None
  173. */
  174. void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
  175. {
  176. GPIO_InitTypeDef GPIO_InitStructure;
  177. EXTI_InitTypeDef EXTI_InitStructure;
  178. NVIC_InitTypeDef NVIC_InitStructure;
  179. /* Enable the BUTTON Clock */
  180. RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
  181. /* Configure Button pin as input floating */
  182. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  183. GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
  184. GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
  185. if (Button_Mode == BUTTON_MODE_EXTI)
  186. {
  187. /* Connect Button EXTI Line to Button GPIO Pin */
  188. GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
  189. /* Configure Button EXTI line */
  190. EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
  191. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  192. if(Button != BUTTON_WAKEUP)
  193. {
  194. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  195. }
  196. else
  197. {
  198. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  199. }
  200. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  201. EXTI_Init(&EXTI_InitStructure);
  202. /* Enable and set Button EXTI Interrupt to the lowest priority */
  203. NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
  204. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  205. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  206. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  207. NVIC_Init(&NVIC_InitStructure);
  208. }
  209. }
  210. /**
  211. * @brief Returns the selected Button state.
  212. * @param Button: Specifies the Button to be checked.
  213. * This parameter can be one of following parameters:
  214. * @arg BUTTON_WAKEUP: Wakeup Push Button
  215. * @arg BUTTON_KEY0: Key Push Button
  216. * @arg BUTTON_KEY1: Key Push Button
  217. * @retval The Button GPIO pin value.
  218. */
  219. uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
  220. {
  221. return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
  222. }
  223. /**
  224. * @brief Configures COM port.
  225. * @param COM: Specifies the COM port to be configured.
  226. * This parameter can be one of following parameters:
  227. * @arg COM1
  228. * @arg COM2
  229. * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
  230. * contains the configuration information for the specified USART peripheral.
  231. * @retval None
  232. */
  233. void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
  234. {
  235. GPIO_InitTypeDef GPIO_InitStructure;
  236. /* Enable GPIO clock */
  237. RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
  238. if (COM == COM1)
  239. {
  240. RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
  241. }
  242. else
  243. {
  244. /* Enable the USART2 Pins Software Remapping */
  245. GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
  246. RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
  247. }
  248. /* Configure USART Tx as alternate function push-pull */
  249. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  250. GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
  251. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  252. GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
  253. /* Configure USART Rx as input floating */
  254. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  255. GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
  256. GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
  257. /* USART configuration */
  258. USART_Init(COM_USART[COM], USART_InitStruct);
  259. /* Enable USART */
  260. USART_Cmd(COM_USART[COM], ENABLE);
  261. }
  262. /**
  263. * @brief DeInitializes the SD/SD communication.
  264. * @param None
  265. * @retval None
  266. */
  267. void SD_LowLevel_DeInit(void)
  268. {
  269. GPIO_InitTypeDef GPIO_InitStructure;
  270. SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
  271. SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */
  272. /*!< SD_SPI Periph clock disable */
  273. RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE);
  274. /*!< Configure SD_SPI pins: SCK */
  275. GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
  276. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  277. GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
  278. /*!< Configure SD_SPI pins: MISO */
  279. GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
  280. GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
  281. /*!< Configure SD_SPI pins: MOSI */
  282. GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
  283. GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
  284. /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
  285. GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
  286. GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
  287. /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
  288. GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
  289. GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
  290. }
  291. /**
  292. * @brief Initializes the SD_SPI and CS pins.
  293. * @param None
  294. * @retval None
  295. */
  296. void SD_LowLevel_Init(void)
  297. {
  298. GPIO_InitTypeDef GPIO_InitStructure;
  299. SPI_InitTypeDef SPI_InitStructure;
  300. /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
  301. and SD_SPI_SCK_GPIO Periph clock enable */
  302. RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
  303. SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
  304. /*!< SD_SPI Periph clock enable */
  305. RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE);
  306. /*!< Configure SD_SPI pins: SCK */
  307. GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
  308. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  309. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  310. GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
  311. /*!< Configure SD_SPI pins: MOSI */
  312. GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
  313. GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
  314. /*!< Configure SD_SPI pins: MISO */
  315. GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
  316. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  317. GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
  318. /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
  319. GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
  320. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  321. GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
  322. /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
  323. GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
  324. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  325. GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
  326. /*!< SD_SPI Config */
  327. SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  328. SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  329. SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  330. SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  331. SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  332. SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  333. SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  334. SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  335. SPI_InitStructure.SPI_CRCPolynomial = 7;
  336. SPI_Init(SD_SPI, &SPI_InitStructure);
  337. SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
  338. }
  339. /**
  340. * @brief DeInitializes the peripherals used by the SPI FLASH driver.
  341. * @param None
  342. * @retval None
  343. */
  344. void sFLASH_LowLevel_DeInit(void)
  345. {
  346. GPIO_InitTypeDef GPIO_InitStructure;
  347. /*!< Disable the sFLASH_SPI */
  348. SPI_Cmd(sFLASH_SPI, DISABLE);
  349. /*!< DeInitializes the sFLASH_SPI */
  350. SPI_I2S_DeInit(sFLASH_SPI);
  351. /*!< sFLASH_SPI Periph clock disable */
  352. RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE);
  353. /*!< Configure sFLASH_SPI pins: SCK */
  354. GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
  355. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  356. GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
  357. /*!< Configure sFLASH_SPI pins: MISO */
  358. GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
  359. GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
  360. /*!< Configure sFLASH_SPI pins: MOSI */
  361. GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
  362. GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
  363. /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
  364. GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
  365. GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
  366. }
  367. /**
  368. * @brief Initializes the peripherals used by the SPI FLASH driver.
  369. * @param None
  370. * @retval None
  371. */
  372. void sFLASH_LowLevel_Init(void)
  373. {
  374. GPIO_InitTypeDef GPIO_InitStructure;
  375. /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO
  376. and sFLASH_SPI_SCK_GPIO Periph clock enable */
  377. RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK |
  378. sFLASH_SPI_SCK_GPIO_CLK, ENABLE);
  379. /*!< sFLASH_SPI Periph clock enable */
  380. RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);
  381. /*!< Configure sFLASH_SPI pins: SCK */
  382. GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
  383. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  384. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  385. GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
  386. /*!< Configure sFLASH_SPI pins: MOSI */
  387. GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
  388. GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
  389. /*!< Configure sFLASH_SPI pins: MISO */
  390. GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
  391. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  392. GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
  393. /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
  394. GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
  395. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  396. GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
  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_FLOATING;
  415. GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
  416. /*!< Configure LM75_I2C pins: SDA */
  417. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
  418. GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  419. /*!< Configure LM75_I2C pin: SMBUS ALERT */
  420. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
  421. GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
  422. }
  423. /**
  424. * @brief Initializes the LM75_I2C.
  425. * @param None
  426. * @retval None
  427. */
  428. void LM75_LowLevel_Init(void)
  429. {
  430. GPIO_InitTypeDef GPIO_InitStructure;
  431. /*!< LM75_I2C Periph clock enable */
  432. RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
  433. /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
  434. and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
  435. RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
  436. LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
  437. /*!< Configure LM75_I2C pins: SCL */
  438. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
  439. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  440. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  441. GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
  442. /*!< Configure LM75_I2C pins: SDA */
  443. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
  444. GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
  445. /*!< Configure LM75_I2C pin: SMBUS ALERT */
  446. GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
  447. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  448. GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
  449. }
  450. /**
  451. * @}
  452. */
  453. /**
  454. * @}
  455. */
  456. /**
  457. * @}
  458. */
  459. /**
  460. * @}
  461. */
  462. /**
  463. * @}
  464. */
  465. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/