Skip to content

Commit 427d5df

Browse files
authored
Merge pull request #3 from FRASTM/octospi
[B_L4S5I_IOT01A] update to support OCTOSPI
2 parents 81995f4 + 389edd9 commit 427d5df

File tree

7 files changed

+1921
-1625
lines changed

7 files changed

+1921
-1625
lines changed

README.md

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
11
# MX25R6435F
2-
Arduino library to support the Quad-SPI NOR Flash memory MX25R6435F
2+
Arduino library to support the Quad-SPI NOR Flash memory MX25R6435F using the Quad SPI flash memories interface. Since library version 2.0.0 and [STM32 core](https://github.com/stm32duino/Arduino_Core_STM32) version 2.0.0 the OctoSPI Flash memories interface can also be used.
33

44
## API
55

66
The library provides the following API:
77

8-
* begin()
9-
* end()
10-
* write()
11-
* read()
12-
* mapped()
13-
* erase()
14-
* eraseChip()
15-
* eraseSector()
16-
* suspendErase()
17-
* resumeErase()
18-
* sleep()
19-
* wakeup()
20-
* status()
21-
* info()
22-
* length()
8+
* `begin()`
9+
* `end()`
10+
* `write()`
11+
* `read()`
12+
* `mapped()`
13+
* `erase()`
14+
* `eraseChip()`
15+
* `eraseSector()`
16+
* `suspendErase()`
17+
* `resumeErase()`
18+
* `sleep()`
19+
* `wakeup()`
20+
* `status()`
21+
* `info()`
22+
* `length()`
23+
24+
Since library version 2.0.0, xSPI pins can be defined at sketch level, using:
25+
26+
* To redefine the default one before call of `begin()`:
27+
28+
* `setDx(uint32_t data0, uint32_t data1, uint32_t data2, uint32_t data3)`
29+
* `setDx(PinName data0, PinName data1, PinName data2, PinName data3)`
30+
* `setSSEL(uint32_t ssel)`
31+
* `setSSEL(PinName ssel)`
32+
* `setSCLK(uint32_t sclk)`
33+
* `setSCLK(PinName sclk)`
34+
35+
*Code snippet:*
36+
```C++
37+
MX25R6435F.setDx(PE12, PE13, PE14, PE15); // using pin number
38+
MX25R6435F.setSCLK(PE10);
39+
MX25R6435F.setSSEL(PE_11); // using PinName
40+
MX25R6435F.begin();
41+
```
42+
43+
* or using the `begin()` method:
44+
45+
* `MX25R6435FClass(uint8_t data0, uint8_t data1, uint8_t data2, uint8_t data3, uint8_t clk, uint8_t ssel)`
46+
47+
*Code snippet:*
48+
```C++
49+
MX25R6435F.begin(PE12, PE13, PE14, PE15, PE10, PE11);
50+
```
51+
52+
* or by redefining the default pins definition (using [build_opt.h](https://github.com/stm32duino/wiki/wiki/Customize-build-options-using-build_opt.h) or [hal_conf_extra.h](https://github.com/stm32duino/wiki/wiki/HAL-configuration#customize-hal-or-variant-definition)):
53+
54+
* `MX25R6435F_D0`
55+
* `MX25R6435F_D1`
56+
* `MX25R6435F_D2`
57+
* `MX25R6435F_D3`
58+
* `MX25R6435F_SCLK`
59+
* `MX25R6435F_SSEL`
2360

2461
## Examples
2562

26-
3 sketches provide basic examples to show how to use the library API.
27-
demo.ino uses basic read/write functions.
28-
eraseChip.ino erases all data present in the memory.
29-
memoryMappedMode.ino shows how to use the mapped mode.
63+
3 sketches provide basic examples to show how to use the library API:
64+
* `demo.ino` uses basic read/write functions.
65+
* `eraseChip.ino` erases all data present in the memory.
66+
* `memoryMappedMode.ino` shows how to use the mapped mode.
3067

3168
## Documentation
3269

keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ wakeup KEYWORD2
2626
status KEYWORD2
2727
info KEYWORD2
2828
length KEYWORD2
29+
setDx KEYWORD2
30+
setSCLK KEYWORD2
31+
setSSEL KEYWORD2
2932

3033
#######################################
3134
# Constants (LITERAL1)

src/MX25R6435F.cpp

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,13 @@
99
******************************************************************************
1010
* @attention
1111
*
12-
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
12+
* <h2><center>&copy; 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
*/
@@ -42,18 +26,25 @@ MX25R6435FClass MX25R6435F;
4226

4327
MX25R6435FClass::MX25R6435FClass(): initDone(0)
4428
{
45-
4629
}
4730

48-
void MX25R6435FClass::begin(void)
31+
void MX25R6435FClass::begin(uint8_t data0, uint8_t data1, uint8_t data2, uint8_t data3, uint8_t sclk, uint8_t ssel)
4932
{
50-
if(BSP_QSPI_Init() == MEMORY_OK)
33+
_qspi.pin_d0 = digitalPinToPinName(data0);
34+
_qspi.pin_d1 = digitalPinToPinName(data1);
35+
_qspi.pin_d2 = digitalPinToPinName(data2);
36+
_qspi.pin_d3 = digitalPinToPinName(data3);
37+
_qspi.pin_sclk = digitalPinToPinName(sclk);
38+
_qspi.pin_ssel = digitalPinToPinName(ssel);
39+
40+
if (BSP_QSPI_Init(&_qspi) == MEMORY_OK) {
5141
initDone = 1;
42+
}
5243
}
5344

5445
void MX25R6435FClass::end(void)
5546
{
56-
BSP_QSPI_DeInit();
47+
BSP_QSPI_DeInit(&_qspi);
5748
initDone = 0;
5849
}
5950

@@ -64,11 +55,13 @@ uint32_t MX25R6435FClass::write(uint8_t data, uint32_t addr)
6455

6556
uint32_t MX25R6435FClass::write(uint8_t *pData, uint32_t addr, uint32_t size)
6657
{
67-
if((pData == NULL) || (initDone == 0))
58+
if ((pData == NULL) || (initDone == 0)) {
6859
return 0;
60+
}
6961

70-
if(BSP_QSPI_Write(pData, addr, size) != MEMORY_OK)
62+
if (BSP_QSPI_Write(&_qspi, pData, addr, size) != MEMORY_OK) {
7163
return 0;
64+
}
7265

7366
return size;
7467
}
@@ -84,77 +77,86 @@ uint8_t MX25R6435FClass::read(uint32_t addr)
8477

8578
void MX25R6435FClass::read(uint8_t *pData, uint32_t addr, uint32_t size)
8679
{
87-
if((pData != NULL) && (initDone == 1))
88-
BSP_QSPI_Read(pData, addr, size);
80+
if ((pData != NULL) && (initDone == 1)) {
81+
BSP_QSPI_Read(&_qspi, pData, addr, size);
82+
}
8983
}
9084

9185
uint8_t *MX25R6435FClass::mapped(void)
9286
{
93-
if(BSP_QSPI_EnableMemoryMappedMode() != MEMORY_OK)
87+
if (BSP_QSPI_EnableMemoryMappedMode(&_qspi) != MEMORY_OK) {
9488
return NULL;
89+
}
9590

9691
return (uint8_t *)MEMORY_MAPPED_ADDRESS;
9792
}
9893

9994
uint8_t MX25R6435FClass::erase(uint32_t addr)
10095
{
101-
if(initDone == 0)
96+
if (initDone == 0) {
10297
return MEMORY_ERROR;
98+
}
10399

104-
return BSP_QSPI_Erase_Block(addr);
100+
return BSP_QSPI_Erase_Block(&_qspi, addr);
105101
}
106102

107103
uint8_t MX25R6435FClass::eraseChip(void)
108104
{
109-
if(initDone == 0)
105+
if (initDone == 0) {
110106
return MEMORY_ERROR;
107+
}
111108

112-
return BSP_QSPI_Erase_Chip();
109+
return BSP_QSPI_Erase_Chip(&_qspi);
113110
}
114111

115112
uint8_t MX25R6435FClass::eraseSector(uint32_t sector)
116113
{
117-
if(initDone == 0)
114+
if (initDone == 0) {
118115
return MEMORY_ERROR;
116+
}
119117

120-
return BSP_QSPI_Erase_Sector(sector);
118+
return BSP_QSPI_Erase_Sector(&_qspi, sector);
121119
}
122120

123121
uint8_t MX25R6435FClass::suspendErase(void)
124122
{
125-
if(initDone == 0)
123+
if (initDone == 0) {
126124
return MEMORY_ERROR;
125+
}
127126

128-
return BSP_QSPI_SuspendErase();
127+
return BSP_QSPI_SuspendErase(&_qspi);
129128
}
130129

131130
uint8_t MX25R6435FClass::resumeErase(void)
132131
{
133-
if(initDone == 0)
132+
if (initDone == 0) {
134133
return MEMORY_ERROR;
134+
}
135135

136-
return BSP_QSPI_ResumeErase();
136+
return BSP_QSPI_ResumeErase(&_qspi);
137137
}
138138

139139
uint8_t MX25R6435FClass::sleep(void)
140140
{
141-
if(initDone == 0)
141+
if (initDone == 0) {
142142
return MEMORY_ERROR;
143+
}
143144

144-
return BSP_QSPI_EnterDeepPowerDown();
145+
return BSP_QSPI_EnterDeepPowerDown(&_qspi);
145146
}
146147

147148
uint8_t MX25R6435FClass::wakeup(void)
148149
{
149-
if(initDone == 0)
150+
if (initDone == 0) {
150151
return MEMORY_ERROR;
152+
}
151153

152-
return BSP_QSPI_LeaveDeepPowerDown();
154+
return BSP_QSPI_LeaveDeepPowerDown(&_qspi);
153155
}
154156

155157
uint8_t MX25R6435FClass::status(void)
156158
{
157-
return BSP_QSPI_GetStatus();
159+
return BSP_QSPI_GetStatus(&_qspi);
158160
}
159161

160162
uint32_t MX25R6435FClass::info(memory_info_t info)
@@ -164,30 +166,30 @@ uint32_t MX25R6435FClass::info(memory_info_t info)
164166

165167
BSP_QSPI_GetInfo(&pInfo);
166168

167-
switch(info){
169+
switch (info) {
168170
case MEMORY_SIZE:
169171
res = pInfo.FlashSize;
170-
break;
172+
break;
171173

172174
case MEMORY_SECTOR_SIZE:
173175
res = pInfo.EraseSectorSize;
174-
break;
176+
break;
175177

176178
case MEMORY_SECTOR_NUMBER:
177179
res = pInfo.EraseSectorsNumber;
178-
break;
180+
break;
179181

180182
case MEMORY_PAGE_SIZE:
181183
res = pInfo.ProgPageSize;
182-
break;
184+
break;
183185

184186
case MEMORY_PAGE_NUMBER:
185187
res = pInfo.ProgPagesNumber;
186-
break;
188+
break;
187189

188190
default:
189191
res = 0;
190-
break;
192+
break;
191193
}
192194

193195
return res;

0 commit comments

Comments
 (0)