comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/FSMC/NOR/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file FSMC/NOR/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-2011
7 * @brief Main program body
8 ******************************************************************************
9 * @attention
10 *
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
20 */
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm3210e_eval_fsmc_nor.h"
24 #include "stm32_eval.h"
25
26 /** @addtogroup STM32F10x_StdPeriph_Examples
27 * @{
28 */
29
30 /** @addtogroup FSMC_NOR
31 * @{
32 */
33
34 /* Private typedef -----------------------------------------------------------*/
35 /* Private define ------------------------------------------------------------*/
36 #define BUFFER_SIZE 0x400
37 #define WRITE_READ_ADDR 0x8000
38
39 /* Private macro -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 uint16_t TxBuffer[BUFFER_SIZE];
42 uint16_t RxBuffer[BUFFER_SIZE];
43 uint32_t WriteReadStatus = 0, Index = 0;
44 NOR_IDTypeDef NOR_ID;
45
46 /* Private function prototypes -----------------------------------------------*/
47 void RCC_Configuration(void);
48 void Fill_Buffer(uint16_t *pBuffer, uint16_t BufferLenght, uint32_t Offset);
49
50 /* Private functions ---------------------------------------------------------*/
51
52 /**
53 * @brief Main program.
54 * @param None
55 * @retval None
56 */
57 int main(void)
58 {
59 /*!< At this stage the microcontroller clock setting is already configured,
60 this is done through SystemInit() function which is called from startup
61 file (startup_stm32f10x_xx.s) before to branch to application main.
62 To reconfigure the default setting of SystemInit() function, refer to
63 system_stm32f10x.c file
64 */
65
66 /* Initialize Leds mounted on STM3210X-EVAL board */
67 STM_EVAL_LEDInit(LED1);
68 STM_EVAL_LEDInit(LED2);
69
70 /* Write/read to/from FSMC SRAM memory *************************************/
71 /* Enable the FSMC Clock */
72 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
73
74 /* Configure FSMC Bank1 NOR/SRAM2 */
75 NOR_Init();
76
77 /* Read NOR memory ID */
78 NOR_ReadID(&NOR_ID);
79
80 NOR_ReturnToReadMode();
81
82 /* Erase the NOR memory block to write on */
83 NOR_EraseBlock(WRITE_READ_ADDR);
84
85 /* Write data to FSMC NOR memory */
86 /* Fill the buffer to send */
87 Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x3210);
88 NOR_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
89
90 /* Read data from FSMC NOR memory */
91 NOR_ReadBuffer(RxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
92
93 /* Read back NOR memory and check content correctness */
94 for (Index = 0x00; (Index < BUFFER_SIZE) && (WriteReadStatus == 0); Index++)
95 {
96 if (RxBuffer[Index] != TxBuffer[Index])
97 {
98 WriteReadStatus = Index + 1;
99 }
100 }
101
102 if (WriteReadStatus == 0)
103 {
104 /* OK */
105 /* Turn on LED1 */
106 STM_EVAL_LEDOn(LED1);
107 }
108 else
109 {
110 /* KO */
111 /* Turn on LED2 */
112 STM_EVAL_LEDOn(LED2);
113 }
114
115 while (1)
116 {
117 }
118 }
119
120 /**
121 * @brief Fill the global buffer
122 * @param pBuffer: pointer on the Buffer to fill
123 * @param BufferSize: size of the buffer to fill
124 * @param Offset: first value to fill on the Buffer
125 */
126 void Fill_Buffer(uint16_t *pBuffer, uint16_t BufferLenght, uint32_t Offset)
127 {
128 uint16_t IndexTmp = 0;
129
130 /* Put in global buffer same values */
131 for (IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ )
132 {
133 pBuffer[IndexTmp] = IndexTmp + Offset;
134 }
135 }
136
137 #ifdef USE_FULL_ASSERT
138
139 /**
140 * @brief Reports the name of the source file and the source line number
141 * where the assert_param error has occurred.
142 * @param file: pointer to the source file name
143 * @param line: assert_param error line source number
144 * @retval None
145 */
146 void assert_failed(uint8_t* file, uint32_t line)
147 {
148 /* User can add his own implementation to report the file name and line number,
149 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
150
151 /* Infinite loop */
152 while (1)
153 {
154 }
155 }
156
157 #endif
158
159 /**
160 * @}
161 */
162
163 /**
164 * @}
165 */
166
167 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/