diff options
Diffstat (limited to 'thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous')
3 files changed, 510 insertions, 0 deletions
diff --git a/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/main.c b/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/main.c new file mode 100644 index 0000000..e00afbe --- /dev/null +++ b/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/main.c @@ -0,0 +1,306 @@ +/** + ****************************************************************************** + * @file USART/Synchronous/main.c + * @author MCD Application Team + * @version V3.5.0 + * @date 08-April-2011 + * @brief Main program body + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x.h" +#include "platform_config.h" + +/** @addtogroup STM32F10x_StdPeriph_Examples + * @{ + */ + +/** @addtogroup USART_Synchronous + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; + +/* Private define ------------------------------------------------------------*/ +#define TxBufferSize1 (countof(TxBuffer1) - 1) +#define TxBufferSize2 (countof(TxBuffer2) - 1) +#define DYMMY_BYTE 0x00 + +/* Private macro -------------------------------------------------------------*/ +#define countof(a) (sizeof(a) / sizeof(*(a))) + +/* Private variables ---------------------------------------------------------*/ +USART_InitTypeDef USART_InitStructure; +USART_ClockInitTypeDef USART_ClockInitStructure; + +uint8_t TxBuffer1[] = "USART Synchronous Example: USARTy -> SPIy using TXE and RXNE Flags"; +uint8_t TxBuffer2[] = "USART Synchronous Example: SPIy -> USARTy using TXE and RXNE Flags"; +uint8_t RxBuffer1[TxBufferSize2]; +uint8_t RxBuffer2[TxBufferSize1]; +__IO uint8_t NbrOfDataToRead1 = TxBufferSize2; +__IO uint8_t NbrOfDataToRead2 = TxBufferSize1; +__IO uint8_t TxCounter1 = 0, RxCounter1 = 0; +__IO uint8_t TxCounter2 = 0, RxCounter2 = 0; +volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; + +/* Private function prototypes -----------------------------------------------*/ +void RCC_Configuration(void); +void GPIO_Configuration(void); +void SPI_Configuration(void); +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); + +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Main program + * @param None + * @retval None + */ +int main(void) +{ + /*!< At this stage the microcontroller clock setting is already configured, + this is done through SystemInit() function which is called from startup + file (startup_stm32f10x_xx.s) before to branch to application main. + To reconfigure the default setting of SystemInit() function, refer to + system_stm32f10x.c file + */ + + /* System Clocks Configuration */ + RCC_Configuration(); + + /* Configure the GPIO ports */ + GPIO_Configuration(); + + /* Configure the SPI */ + SPI_Configuration(); + +/* USARTy configuration ------------------------------------------------------*/ + /* USARTy configured as follow: + - BaudRate = 115200 baud + - Word Length = 8 Bits + - One Stop Bit + - No parity + - Hardware flow control disabled (RTS and CTS signals) + - Receive and transmit enabled + - USART Clock Enabled + - USART CPOL: Clock is active High + - USART CPHA: Data is captured on the second edge + - USART LastBit: The clock pulse of the last data bit is output to + the SCLK pin + */ + USART_ClockInitStructure.USART_Clock = USART_Clock_Enable; + USART_ClockInitStructure.USART_CPOL = USART_CPOL_High; + USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; + USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable; + USART_ClockInit(USARTy, &USART_ClockInitStructure); + + USART_InitStructure.USART_BaudRate = 115200; + USART_InitStructure.USART_WordLength = USART_WordLength_8b; + USART_InitStructure.USART_StopBits = USART_StopBits_1; + USART_InitStructure.USART_Parity = USART_Parity_No ; + USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; + USART_Init(USARTy, &USART_InitStructure); + + /* Configure the USARTy */ + USART_Init(USARTy, &USART_InitStructure); + + /* Enable the USARTy */ + USART_Cmd(USARTy, ENABLE); + + while(NbrOfDataToRead2--) + { + /* Write one byte in the USARTy Transmit Data Register */ + USART_SendData(USARTy, TxBuffer1[TxCounter1++]); + /* Wait until end of transmit */ + while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET) + { + } + /* Wait the byte is entirely received by SPIy */ + while(SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_RXNE) == RESET) + { + } + /* Store the received byte in the RxBuffer2 */ + RxBuffer2[RxCounter2++] = SPI_I2S_ReceiveData(SPIy); + } + + /* Clear the USARTy Data Register */ + USART_ReceiveData(USARTy); + + while(NbrOfDataToRead1--) + { + /* Wait until end of transmit */ + while(SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_TXE)== RESET) + { + } + /* Write one byte in the SPIy Transmit Data Register */ + SPI_I2S_SendData(SPIy, TxBuffer2[TxCounter2++]); + + /* Send a Dummy byte to generate clock to slave */ + USART_SendData(USARTy, DYMMY_BYTE); + /* Wait until end of transmit */ + while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET) + { + } + /* Wait the byte is entirely received by USARTy */ + while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET) + { + } + /* Store the received byte in the RxBuffer1 */ + RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy); + } + + /* Check the received data with the send ones */ + TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); + /* TransferStatus = PASSED, if the data transmitted from USARTy and + received by SPIy are the same */ + /* TransferStatus = FAILED, if the data transmitted from USARTy and + received by SPIy are different */ + TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); + /* TransferStatus = PASSED, if the data transmitted from SPIy and + received by USARTy are the same */ + /* TransferStatus = FAILED, if the data transmitted from SPIy and + received by USARTy are different */ + + while (1) + { + } +} + +/** + * @brief Configures the different system clocks. + * @param None + * @retval None + */ +void RCC_Configuration(void) +{ + /* Enable GPIO clock */ + RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | SPIy_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE); + + /* Enable USARTy Clock */ + RCC_APB2PeriphClockCmd(USARTy_CLK, ENABLE); + /* Enable SPIy Clock */ + RCC_APB2PeriphClockCmd(SPIy_CLK, ENABLE); +} + +/** + * @brief Configures the different GPIO ports. + * @param None + * @retval None + */ +void GPIO_Configuration(void) +{ + GPIO_InitTypeDef GPIO_InitStructure; + + /* Configure USARTy TX and USARTy CK pins as alternate function push-pull */ + GPIO_InitStructure.GPIO_Pin = USARTy_TxPin | USARTy_ClkPin; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Init(USARTy_GPIO, &GPIO_InitStructure); + + /* Configure SPI1 pins: SCK, MISO and MOSI */ + GPIO_InitStructure.GPIO_Pin = SPIy_SCKPin | SPIy_MISOPin | SPIy_MOSIPin; + GPIO_Init(SPIy_GPIO, &GPIO_InitStructure); + + /* Configure USARTy RX as input floating */ + GPIO_InitStructure.GPIO_Pin = USARTy_RxPin; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(USARTy_GPIO, &GPIO_InitStructure); +} + +/** + * @brief Configures the SPI. + * @param None + * @retval None + */ +void SPI_Configuration(void) +{ + SPI_InitTypeDef SPI_InitStructure; + + SPI_StructInit(&SPI_InitStructure); + + SPI_I2S_DeInit(SPIy); + + /* SPIy Config */ + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; + + /* Configure SPIy */ + SPI_Init(SPIy, &SPI_InitStructure); + + /* SPIy enable */ + SPI_Cmd(SPIy, ENABLE); +} + +/** + * @brief Compares two buffers. + * @param pBuffer1, pBuffer2: buffers to be compared. + * @param BufferLength: buffer's length + * @retval PASSED: pBuffer1 identical to pBuffer2 + * FAILED: pBuffer1 differs from pBuffer2 + */ +TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) +{ + while(BufferLength--) + { + if(*pBuffer1 != *pBuffer2) + { + return FAILED; + } + + pBuffer1++; + pBuffer2++; + } + + return PASSED; +} + +#ifdef USE_FULL_ASSERT + +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t* file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + + /* Infinite loop */ + while (1) + { + } +} + +#endif + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/readme.txt b/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/readme.txt new file mode 100644 index 0000000..7d8dffd --- /dev/null +++ b/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/readme.txt @@ -0,0 +1,127 @@ +/** + @page USART_Synchronous USART Synchronous example + + @verbatim + ******************** (C) COPYRIGHT 2011 STMicroelectronics ******************* + * @file USART/Synchronous/readme.txt + * @author MCD Application Team + * @version V3.5.0 + * @date 08-April-2011 + * @brief Description of the USART Synchronous example. + ****************************************************************************** + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + ****************************************************************************** + @endverbatim + +@par Example Description + +This example provides a basic communication between USARTy (Synchronous mode) +and SPIy using flags. USARTy and SPIy can be USART1 and SPI1 or USART2 and SPI3, +depending on the STMicroelectronics EVAL board you are using. + +First, the USARTy sends data from TxBuffer1 buffer to SPIy using USARTy TXE flag. +Data received, using RXNE flag, by SPIy is stored in RxBuffer2 then compared with +the sent ones and the result of this comparison is stored in the "TransferStatus1" +variable. + +Then, the SPIy sends data from TxBuffer2 buffer to USARTy using SPIy TXE flag. +Data received, using RXNE flag, by USARTy is stored in RxBuffer1 then compared with +the sent ones and the result of this comparison is stored in the "TransferStatus2" +variable. + +USARTy configured as follow: + - BaudRate = 115200 baud + - Word Length = 8 Bits + - One Stop Bit + - No parity + - Hardware flow control disabled (RTS and CTS signals) + - Receive and transmit enabled + - USART Clock enabled + - USART CPOL: Clock is active high + - USART CPHA: Data is captured on the second edge + - USART LastBit: The clock pulse of the last data bit is output to the SCLK pin + +SPIy configured as follow: + - Direction = 2 Lines FullDuplex + - Mode = Slave Mode + - DataSize = 8 Bits + - CPOL = Clock is active high + - CPHA = Data is captured on the second edge + - NSS = NSS Software + - First Bit = First Bit is the LSB + + +@par Directory contents + + - USART/Synchronous/platform_config.h Evaluation board specific configuration file + - USART/Synchronous/stm32f10x_conf.h Library Configuration file + - USART/Synchronous/stm32f10x_it.h Interrupt handlers header file + - USART/Synchronous/stm32f10x_it.c Interrupt handlers + - USART/Synchronous/main.c Main program + - USART/Synchronous/system_stm32f10x.c STM32F10x system source file + +@par Hardware and Software environment + + - This example runs on STM32F10x Connectivity line, High-Density, High-Density + Value line, Medium-Density, XL-Density, Medium-Density Value line, Low-Density + and Low-Density Value line Devices. + + - This example has been tested with STMicroelectronics STM32100E-EVAL (High-Density + Value line), STM32100B-EVAL (Medium-Density Value line), STM3210E-EVAL + (High-Density and XL-Density) and STM3210B-EVAL (Medium-Density) evaluation + boards and can be easily tailored to any other supported device and development + board. + This example can't be tested with STM3210C-EVAL (Connectivity Line) evaluation + board since the USART CK pins are already used by other on-board modules. + To select the STMicroelectronics evaluation board used to run the example, + uncomment the corresponding line in USART/Synchronous/platform_config.h file + + - STM32100E-EVAL Set-up + - Connect USART1_Tx(PA.09) to SPI1_MOSI(PA.07), USART1_Rx(PA.10) to + SPI1_MISO(PA.06) and USART1_CK(PA.08) to SPI1_SCK(PA.05). + + - STM32100B-EVAL Set-up + - Connect USART1_Tx(PA.09) to SPI1_MOSI(PA.07), USART1_Rx(PA.10) to + SPI1_MISO(PA.06) and USART1_CK(PA.08) to SPI1_SCK(PA.05). + + - STM3210E-EVAL Set-up + - Connect USART1_Tx(PA.09) to SPI1_MOSI(PA.07), USART1_Rx(PA.10) to + SPI1_MISO(PA.06) and USART1_CK(PA.08) to SPI1_SCK(PA.05). + + - STM3210B-EVAL Set-up + - Connect USART1_Tx(PA.09) to SPI1_MOSI(PA.07), USART1_Rx(PA.10) to + SPI1_MISO(PA.06) and USART1_CK(PA.08) to SPI1_SCK(PA.05). + +@par How to use it ? + +In order to make the program work, you must do the following : + - Copy all source files from this example folder to the template folder under + Project\STM32F10x_StdPeriph_Template + - Open your preferred toolchain + - Rebuild all files and load your image into target memory + - Run the example + +@note + - Low-density Value line devices are STM32F100xx microcontrollers where the + Flash memory density ranges between 16 and 32 Kbytes. + - Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx + microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes. + - Medium-density Value line devices are STM32F100xx microcontrollers where + the Flash memory density ranges between 64 and 128 Kbytes. + - Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx + microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes. + - High-density Value line devices are STM32F100xx microcontrollers where + the Flash memory density ranges between 256 and 512 Kbytes. + - High-density devices are STM32F101xx and STM32F103xx microcontrollers where + the Flash memory density ranges between 256 and 512 Kbytes. + - XL-density devices are STM32F101xx and STM32F103xx microcontrollers where + the Flash memory density ranges between 512 and 1024 Kbytes. + - Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers. + + * <h3><center>© COPYRIGHT 2011 STMicroelectronics</center></h3> + */ diff --git a/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/stm32f10x_conf.h b/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/stm32f10x_conf.h new file mode 100644 index 0000000..317f17f --- /dev/null +++ b/thirdparty/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/USART/Synchronous/stm32f10x_conf.h @@ -0,0 +1,77 @@ +/** + ****************************************************************************** + * @file USART/Synchronous/stm32f10x_conf.h + * @author MCD Application Team + * @version V3.5.0 + * @date 08-April-2011 + * @brief Library configuration file. + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F10x_CONF_H +#define __STM32F10x_CONF_H + +/* Includes ------------------------------------------------------------------*/ +/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ +#include "stm32f10x_adc.h" +#include "stm32f10x_bkp.h" +#include "stm32f10x_can.h" +#include "stm32f10x_cec.h" +#include "stm32f10x_crc.h" +#include "stm32f10x_dac.h" +#include "stm32f10x_dbgmcu.h" +#include "stm32f10x_dma.h" +#include "stm32f10x_exti.h" +#include "stm32f10x_flash.h" +#include "stm32f10x_fsmc.h" +#include "stm32f10x_gpio.h" +#include "stm32f10x_i2c.h" +#include "stm32f10x_iwdg.h" +#include "stm32f10x_pwr.h" +#include "stm32f10x_rcc.h" +#include "stm32f10x_rtc.h" +#include "stm32f10x_sdio.h" +#include "stm32f10x_spi.h" +#include "stm32f10x_tim.h" +#include "stm32f10x_usart.h" +#include "stm32f10x_wwdg.h" +#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Uncomment the line below to expanse the "assert_param" macro in the + Standard Peripheral Library drivers code */ +/* #define USE_FULL_ASSERT 1 */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT + +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function which reports + * the name of the source file and the source line number of the call + * that failed. If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#endif /* __STM32F10x_CONF_H */ + +/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |