99 ******************************************************************************
1010 * @attention
1111 *
12- * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
12+ * <h2><center>© Copyright (c) 2020 STMicroelectronics.
13+ * All rights reserved.</center></h2>
1314 *
14- * Redistribution and use in source and binary forms, with or without modification,
15- * are permitted provided that the following conditions are met:
16- * 1. Redistributions of source code must retain the above copyright notice,
17- * this list of conditions and the following disclaimer.
18- * 2. Redistributions in binary form must reproduce the above copyright notice,
19- * this list of conditions and the following disclaimer in the documentation
20- * and/or other materials provided with the distribution.
21- * 3. Neither the name of STMicroelectronics nor the names of its contributors
22- * may be used to endorse or promote products derived from this software
23- * without specific prior written permission.
24- *
25- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15+ * This software component is licensed by ST under BSD 3-Clause license,
16+ * the "License"; You may not use this file except in compliance with the
17+ * License. You may obtain a copy of the License at:
18+ * opensource.org/licenses/BSD-3-Clause
3519 *
3620 ******************************************************************************
3721 */
@@ -55,6 +39,7 @@ void MX25R6435FClass::begin(uint8_t data0, uint8_t data1, uint8_t data2, uint8_t
5539
5640 if (BSP_QSPI_Init (&_qspi) == MEMORY_OK) {
5741 initDone = 1 ;
42+ }
5843}
5944
6045void MX25R6435FClass::end (void )
@@ -70,11 +55,13 @@ uint32_t MX25R6435FClass::write(uint8_t data, uint32_t addr)
7055
7156uint32_t MX25R6435FClass::write (uint8_t *pData, uint32_t addr, uint32_t size)
7257{
73- if ((pData == NULL ) || (initDone == 0 ))
58+ if ((pData == NULL ) || (initDone == 0 )) {
7459 return 0 ;
60+ }
7561
76- if (BSP_QSPI_Write (&_qspi, pData, addr, size) != MEMORY_OK)
62+ if (BSP_QSPI_Write (&_qspi, pData, addr, size) != MEMORY_OK) {
7763 return 0 ;
64+ }
7865
7966 return size;
8067}
@@ -90,70 +77,79 @@ uint8_t MX25R6435FClass::read(uint32_t addr)
9077
9178void MX25R6435FClass::read (uint8_t *pData, uint32_t addr, uint32_t size)
9279{
93- if ((pData != NULL ) && (initDone == 1 ))
80+ if ((pData != NULL ) && (initDone == 1 )) {
9481 BSP_QSPI_Read (&_qspi, pData, addr, size);
82+ }
9583}
9684
9785uint8_t *MX25R6435FClass::mapped (void )
9886{
99- if (BSP_QSPI_EnableMemoryMappedMode (&_qspi) != MEMORY_OK)
87+ if (BSP_QSPI_EnableMemoryMappedMode (&_qspi) != MEMORY_OK) {
10088 return NULL ;
89+ }
10190
10291 return (uint8_t *)MEMORY_MAPPED_ADDRESS;
10392}
10493
10594uint8_t MX25R6435FClass::erase (uint32_t addr)
10695{
107- if (initDone == 0 )
96+ if (initDone == 0 ) {
10897 return MEMORY_ERROR;
98+ }
10999
110100 return BSP_QSPI_Erase_Block (&_qspi, addr);
111101}
112102
113103uint8_t MX25R6435FClass::eraseChip (void )
114104{
115- if (initDone == 0 )
105+ if (initDone == 0 ) {
116106 return MEMORY_ERROR;
107+ }
117108
118109 return BSP_QSPI_Erase_Chip (&_qspi);
119110}
120111
121112uint8_t MX25R6435FClass::eraseSector (uint32_t sector)
122113{
123- if (initDone == 0 )
114+ if (initDone == 0 ) {
124115 return MEMORY_ERROR;
116+ }
125117
126118 return BSP_QSPI_Erase_Sector (&_qspi, sector);
127119}
128120
129121uint8_t MX25R6435FClass::suspendErase (void )
130122{
131- if (initDone == 0 )
123+ if (initDone == 0 ) {
132124 return MEMORY_ERROR;
125+ }
133126
134127 return BSP_QSPI_SuspendErase (&_qspi);
135128}
136129
137130uint8_t MX25R6435FClass::resumeErase (void )
138131{
139- if (initDone == 0 )
132+ if (initDone == 0 ) {
140133 return MEMORY_ERROR;
134+ }
141135
142136 return BSP_QSPI_ResumeErase (&_qspi);
143137}
144138
145139uint8_t MX25R6435FClass::sleep (void )
146140{
147- if (initDone == 0 )
141+ if (initDone == 0 ) {
148142 return MEMORY_ERROR;
143+ }
149144
150145 return BSP_QSPI_EnterDeepPowerDown (&_qspi);
151146}
152147
153148uint8_t MX25R6435FClass::wakeup (void )
154149{
155- if (initDone == 0 )
150+ if (initDone == 0 ) {
156151 return MEMORY_ERROR;
152+ }
157153
158154 return BSP_QSPI_LeaveDeepPowerDown (&_qspi);
159155}
@@ -170,30 +166,30 @@ uint32_t MX25R6435FClass::info(memory_info_t info)
170166
171167 BSP_QSPI_GetInfo (&pInfo);
172168
173- switch (info){
169+ switch (info) {
174170 case MEMORY_SIZE:
175171 res = pInfo.FlashSize ;
176- break ;
172+ break ;
177173
178174 case MEMORY_SECTOR_SIZE:
179175 res = pInfo.EraseSectorSize ;
180- break ;
176+ break ;
181177
182178 case MEMORY_SECTOR_NUMBER:
183179 res = pInfo.EraseSectorsNumber ;
184- break ;
180+ break ;
185181
186182 case MEMORY_PAGE_SIZE:
187183 res = pInfo.ProgPageSize ;
188- break ;
184+ break ;
189185
190186 case MEMORY_PAGE_NUMBER:
191187 res = pInfo.ProgPagesNumber ;
192- break ;
188+ break ;
193189
194190 default :
195191 res = 0 ;
196- break ;
192+ break ;
197193 }
198194
199195 return res;
0 commit comments