STM32F0xx Standard Peripherals Firmware Library
|
STM32F0xx_StdPeriph_Examples/SPI/SPI_MSD/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file SPI/SPI_MSD/main.c 00004 * @author MCD Application Team 00005 * @version V1.4.0 00006 * @date 24-July-2014 00007 * @brief Main program body 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 00029 /* Includes ------------------------------------------------------------------*/ 00030 #include "main.h" 00031 00032 /** @addtogroup STM32F0xx_StdPeriph_Examples 00033 * @{ 00034 */ 00035 00036 /** @addtogroup SPI_MSD 00037 * @{ 00038 */ 00039 00040 /* Private typedef -----------------------------------------------------------*/ 00041 /* Private define ------------------------------------------------------------*/ 00042 /* Private macro -------------------------------------------------------------*/ 00043 /* Private variables ---------------------------------------------------------*/ 00044 uint8_t Buffer_Block_Tx[BUFFERSIZE], Buffer_Block_Rx[BUFFERSIZE]; 00045 TestStatus TransferStatus = FAILED; 00046 uint16_t Status = 0; 00047 00048 /* Private function prototypes -----------------------------------------------*/ 00049 static void Fill_Buffer(uint8_t *pBuffer, uint16_t BufferLenght, uint8_t Offset); 00050 static TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength); 00051 00052 /* Private functions ---------------------------------------------------------*/ 00053 00054 /** 00055 * @brief Main program. 00056 * @param None 00057 * @retval None 00058 */ 00059 int main(void) 00060 { 00061 /*!< At this stage the microcontroller clock setting is already configured, 00062 this is done through SystemInit() function which is called from startup 00063 file (startup_stm32f0xx.s) before to branch to application main. 00064 To reconfigure the default setting of SystemInit() function, refer to 00065 system_stm32f0xx.c file 00066 */ 00067 00068 /* Initialize Leds mounted on STM320518-EVAL board */ 00069 STM_EVAL_LEDInit(LED1); 00070 STM_EVAL_LEDInit(LED2); 00071 00072 /* Initializes the SD/SPI communication */ 00073 Status = SD_Init(); 00074 00075 /* If SD is responding */ 00076 if (Status == SD_RESPONSE_NO_ERROR) 00077 { 00078 /* Fill the buffer to send */ 00079 Fill_Buffer(Buffer_Block_Tx, BUFFERSIZE, 0x0); 00080 00081 /* Write block of 512 bytes on address 0 */ 00082 Status = SD_WriteBlock(Buffer_Block_Tx, 0, BUFFERSIZE); 00083 00084 /* Read block of 512 bytes from address 0 */ 00085 Status = SD_ReadBlock(Buffer_Block_Rx, 0, BUFFERSIZE); 00086 00087 /* Check the corectness of written dada */ 00088 TransferStatus = Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, BUFFERSIZE); 00089 00090 if (TransferStatus == PASSED) 00091 { 00092 /* OK: Turn on LD1 */ 00093 STM_EVAL_LEDOn(LED1); 00094 } 00095 else 00096 { 00097 /* Error: Turn on LD2 */ 00098 STM_EVAL_LEDOn(LED2); 00099 } 00100 } 00101 else 00102 { 00103 /* Error: Turn on LD2 */ 00104 STM_EVAL_LEDOn(LED2); 00105 } 00106 00107 while (1) 00108 { 00109 } 00110 00111 } 00112 00113 /** 00114 * @brief Fill the gloal buffer. 00115 * @param pBuffer: pointer on the Buffer to fill 00116 * @param BufferLenght: length of the buffer to fill 00117 * @param Offset: first value to fill on the Buffer 00118 * @retval None. 00119 */ 00120 static void Fill_Buffer(uint8_t *pBuffer, uint16_t BufferLenght, uint8_t Offset) 00121 { 00122 uint16_t IndexTmp; 00123 00124 /* Put in global buffer same values */ 00125 for( IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ ) 00126 { 00127 pBuffer[IndexTmp] =IndexTmp + Offset; 00128 } 00129 } 00130 00131 /** 00132 * @brief Compares two buffers. 00133 * @param pBuffer1, pBuffer2: buffers to be compared. 00134 * @param BufferLength: buffer's length 00135 * @retval PASSED: pBuffer1 identical to pBuffer2 00136 * FAILED: pBuffer1 differs from pBuffer2 00137 */ 00138 static TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) 00139 { 00140 while (BufferLength--) 00141 { 00142 if (*pBuffer1 != *pBuffer2) 00143 { 00144 return FAILED; 00145 } 00146 00147 pBuffer1++; 00148 pBuffer2++; 00149 } 00150 00151 return PASSED; 00152 } 00153 00154 00155 #ifdef USE_FULL_ASSERT 00156 00157 /** 00158 * @brief Reports the name of the source file and the source line number 00159 * where the assert_param error has occurred. 00160 * @param file: pointer to the source file name 00161 * @param line: assert_param error line source number 00162 * @retval None 00163 */ 00164 void assert_failed(uint8_t* file, uint32_t line) 00165 { 00166 /* User can add his own implementation to report the file name and line number, 00167 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00168 00169 /* Infinite loop */ 00170 while (1) 00171 { 00172 } 00173 } 00174 #endif 00175 00176 /** 00177 * @} 00178 */ 00179 00180 /** 00181 * @} 00182 */ 00183 00184 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/