1
+ /*
2
+ * Copyright (c) 2018 ARM Limited. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ * Licensed under the Apache License, Version 2.0 (the License); you may
5
+ * not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
1
17
#if !DEVICE_QSPI
2
18
#error [NOT_SUPPORTED] QSPI not supported for this target
3
19
#endif
@@ -32,7 +48,7 @@ static bool mem_ready()
32
48
printf (" Reading Status Register failed \n " );
33
49
}
34
50
wait_ms (1 );
35
- } while ( (status_value[0 ] & BIT_WIP) != 0 && retries);
51
+ } while ((status_value[0 ] & BIT_WIP) != 0 && retries);
36
52
37
53
if ((status_value[0 ] & BIT_WIP) != 0 ) {
38
54
printf (" mem_ready FALSE: status value = 0x%x\n " , (int )status_value[0 ]);
@@ -51,7 +67,7 @@ static int write_enable()
51
67
return status;
52
68
}
53
69
54
- if ( false == mem_ready ()) {
70
+ if (false == mem_ready ()) {
55
71
printf (" Device not ready \n " );
56
72
return status;
57
73
}
@@ -88,7 +104,7 @@ static int flash_init()
88
104
return status;
89
105
}
90
106
91
- if ( false == mem_ready ()) {
107
+ if (false == mem_ready ()) {
92
108
printf (" Device not ready \n " );
93
109
return -1 ;
94
110
}
@@ -102,7 +118,7 @@ static int flash_init()
102
118
return status;
103
119
}
104
120
105
- if ( false == mem_ready ()) {
121
+ if (false == mem_ready ()) {
106
122
printf (" Device not ready \n " );
107
123
return -1 ;
108
124
}
@@ -116,13 +132,13 @@ static int sector_erase(unsigned int flash_addr)
116
132
return -1 ;
117
133
}
118
134
119
- if ( QSPI_STATUS_OK!= qspi_device.command_transfer (CMD_ERASE, (((int )flash_addr) & 0x00FFF000 ), NULL , 0 , NULL , 0 ))
135
+ if ( QSPI_STATUS_OK!= qspi_device.command_transfer (CMD_ERASE, (((int )flash_addr) & 0x00FFF000 ), NULL , 0 , NULL , 0 ))
120
136
{
121
137
printf (" Erase failed\n " );
122
138
return -1 ;
123
139
}
124
140
125
- if ( false == mem_ready ()) {
141
+ if (false == mem_ready ()) {
126
142
printf (" Device not ready \n " );
127
143
return -1 ;
128
144
}
@@ -157,14 +173,15 @@ int main() {
157
173
printf (" Write Enabe failed \n " );
158
174
return -1 ;
159
175
}
176
+
160
177
result = qspi_device.write (CMD_WRITE, -1 , address, tx_buf, &buf_len);
161
178
if (result != QSPI_STATUS_OK) {
162
179
printf (" Write failed\n " );
163
180
return result;
164
181
}
165
182
printf (" Write done: %s \n " , tx_buf);
166
183
167
- if ( false == mem_ready ()) {
184
+ if (false == mem_ready ()) {
168
185
printf (" Device not ready \n " );
169
186
return -1 ;
170
187
}
@@ -174,6 +191,7 @@ int main() {
174
191
printf (" Read failed\n " );
175
192
return result;
176
193
}
194
+
177
195
printf (" Data Read = %s\n " , rx_buf);
178
196
return 0 ;
179
197
}
0 commit comments