Skip to content

Commit 1910ff4

Browse files
committed
Merge branch 'macronix_ospi' of https://github.com/macronix/mbed-os into macronix_ospi
2 parents 8dc1acf + 1976609 commit 1910ff4

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

TESTS/mbed_hal/ospi/ospi_test_utils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ void OspiCommand::build(int instruction, int address, int alt)
8686
<<<<<<< HEAD
8787
<<<<<<< HEAD
8888
<<<<<<< HEAD
89+
<<<<<<< HEAD
90+
=======
91+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
8992
} else if (instruction == OSPI_CMD_RDCR2) {
9093
_cmd.dummy_count = 4;
9194
} else if ((instruction == OSPI_CMD_READ_OPI) || (instruction == OSPI_CMD_READ_DOPI)) {
9295
_cmd.dummy_count = 20;
9396
<<<<<<< HEAD
97+
<<<<<<< HEAD
9498
<<<<<<< HEAD
9599
} else {
96100
_cmd.dummy_count = 0;
@@ -123,6 +127,11 @@ void OspiCommand::build(int instruction, int address, int alt)
123127
=======
124128
}
125129
>>>>>>> 7266070... Modify the astyle
130+
=======
131+
} else {
132+
_cmd.dummy_count = 0;
133+
}
134+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
126135
}
127136
}
128137

components/storage/blockdevice/COMPONENT_OSPIF/OSPIFBlockDevice.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ int OSPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
396396
if (size % 2 != 0) {
397397
<<<<<<< HEAD
398398
<<<<<<< HEAD
399+
<<<<<<< HEAD
399400
<<<<<<< HEAD
400401
size ++;
401402
=======
@@ -407,6 +408,9 @@ int OSPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
407408
=======
408409
size ++;
409410
>>>>>>> 7266070... Modify the astyle
411+
=======
412+
size ++;
413+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
410414
}
411415

412416
if (OSPI_STATUS_OK != _ospi_send_read_command(_read_instruction, buffer, addr, size)) {
@@ -515,6 +519,7 @@ int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
515519
//cur_erase_inst should be 4-Byte erase instruction for Macronix octa flash OPI mode
516520
<<<<<<< HEAD
517521
<<<<<<< HEAD
522+
<<<<<<< HEAD
518523
<<<<<<< HEAD
519524
cur_erase_inst = (_address_size == OSPI_CFG_ADDR_SIZE_32) ? _sfdp_info.fbatbl.erase_type_4_byte_inst_arr[type] : _sfdp_info.smptbl.erase_type_inst_arr[type];
520525
=======
@@ -526,6 +531,9 @@ int OSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
526531
=======
527532
cur_erase_inst = (_address_size == OSPI_CFG_ADDR_SIZE_32) ? _sfdp_info.fbatbl.erase_type_4_byte_inst_arr[type] : _sfdp_info.smptbl.erase_type_inst_arr[type];
528533
>>>>>>> 7266070... Modify the astyle
534+
=======
535+
cur_erase_inst = (_address_size == OSPI_CFG_ADDR_SIZE_32) ? _sfdp_info.fbatbl.erase_type_4_byte_inst_arr[type] : _sfdp_info.smptbl.erase_type_inst_arr[type];
536+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
529537
eu_size = _sfdp_info.smptbl.erase_type_size_arr[type];
530538
} else {
531539
// Must use legacy 4k erase instruction
@@ -660,6 +668,7 @@ int OSPIFBlockDevice::change_mode(int mode)
660668
if (((mode == SPI) && (_read_instruction == OSPIF_INST_READ_4B)) ||
661669
<<<<<<< HEAD
662670
<<<<<<< HEAD
671+
<<<<<<< HEAD
663672
<<<<<<< HEAD
664673
((mode == SOPI) && (_read_instruction == DTROSPIF_INST_READ_OCTA_STR)) ||
665674
((mode == DOPI) && (_read_instruction == DTROSPIF_INST_READ_OCTA_DTR))) {
@@ -677,6 +686,10 @@ int OSPIFBlockDevice::change_mode(int mode)
677686
((mode == SOPI) && (_read_instruction == DTROSPIF_INST_READ_OCTA_STR)) ||
678687
((mode == DOPI) && (_read_instruction == DTROSPIF_INST_READ_OCTA_DTR))) {
679688
>>>>>>> 7266070... Modify the astyle
689+
=======
690+
((mode == SOPI) && (_read_instruction == DTROSPIF_INST_READ_OCTA_STR)) ||
691+
((mode == DOPI) && (_read_instruction == DTROSPIF_INST_READ_OCTA_DTR))) {
692+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
680693
tr_debug("Flash does not need change mode");
681694
}
682695

@@ -707,6 +720,7 @@ int OSPIFBlockDevice::change_mode(int mode)
707720
OSPI_CFG_BUS_SINGLE, 0, OSPI_CFG_BUS_SINGLE, 0);
708721
<<<<<<< HEAD
709722
<<<<<<< HEAD
723+
<<<<<<< HEAD
710724
<<<<<<< HEAD
711725
// Write new Status Register Setup
712726
=======
@@ -718,6 +732,9 @@ int OSPIFBlockDevice::change_mode(int mode)
718732
=======
719733
// Write new Status Register Setup
720734
>>>>>>> 7266070... Modify the astyle
735+
=======
736+
// Write new Status Register Setup
737+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
721738
if (_set_write_enable() != 0) {
722739
tr_error("Write Enabe failed");
723740
return -1;
@@ -746,6 +763,7 @@ int OSPIFBlockDevice::change_mode(int mode)
746763
0, _data_width, 0);
747764
<<<<<<< HEAD
748765
<<<<<<< HEAD
766+
<<<<<<< HEAD
749767
<<<<<<< HEAD
750768
} else if (mode == DOPI) {
751769
if ((_read_instruction != OSPIF_INST_READ_4B) && (_read_instruction != OSPIF_INST_READ_DEFAULT)) {//chang mode from SOPI to SPI
@@ -766,6 +784,11 @@ int OSPIFBlockDevice::change_mode(int mode)
766784
if ((_read_instruction != OSPIF_INST_READ_4B) && (_read_instruction != OSPIF_INST_READ_DEFAULT)) {//chang mode from SOPI to SPI
767785
// Write new Status Register Setup
768786
>>>>>>> 7266070... Modify the astyle
787+
=======
788+
} else if (mode == DOPI) {
789+
if ((_read_instruction != OSPIF_INST_READ_4B) && (_read_instruction != OSPIF_INST_READ_DEFAULT)) {//chang mode from SOPI to SPI
790+
// Write new Status Register Setup
791+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
769792
if (_set_write_enable() != 0) {
770793
tr_error("Write Enabe failed");
771794
return -1;
@@ -790,6 +813,7 @@ int OSPIFBlockDevice::change_mode(int mode)
790813
OSPI_CFG_BUS_SINGLE, 0, OSPI_CFG_BUS_SINGLE, 0);
791814
<<<<<<< HEAD
792815
<<<<<<< HEAD
816+
<<<<<<< HEAD
793817
<<<<<<< HEAD
794818
// Write new Status Register Setup
795819
=======
@@ -801,6 +825,9 @@ int OSPIFBlockDevice::change_mode(int mode)
801825
=======
802826
// Write new Status Register Setup
803827
>>>>>>> 7266070... Modify the astyle
828+
=======
829+
// Write new Status Register Setup
830+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
804831
if (_set_write_enable() != 0) {
805832
tr_error("Write Enabe failed");
806833
return -1;
@@ -829,6 +856,7 @@ int OSPIFBlockDevice::change_mode(int mode)
829856
0, _data_width, 0);
830857
<<<<<<< HEAD
831858
<<<<<<< HEAD
859+
<<<<<<< HEAD
832860
<<<<<<< HEAD
833861
} else if (mode == SPI) {
834862
// Write new Status Register Setup
@@ -846,6 +874,10 @@ int OSPIFBlockDevice::change_mode(int mode)
846874
} else if (mode == SPI) {
847875
// Write new Status Register Setup
848876
>>>>>>> 7266070... Modify the astyle
877+
=======
878+
} else if (mode == SPI) {
879+
// Write new Status Register Setup
880+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
849881
if (_set_write_enable() != 0) {
850882
tr_error("Write Enabe failed");
851883
return -1;
@@ -1170,6 +1202,7 @@ int OSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
11701202
_dummy_cycles = (basic_param_table_ptr[OSPIF_BASIC_PARAM_TABLE_888_READ_INST_BYTE - 1] >> 5)
11711203
<<<<<<< HEAD
11721204
<<<<<<< HEAD
1205+
<<<<<<< HEAD
11731206
<<<<<<< HEAD
11741207
+ (basic_param_table_ptr[OSPIF_BASIC_PARAM_TABLE_888_READ_INST_BYTE - 1] & 0x1F);
11751208
=======
@@ -1181,6 +1214,9 @@ int OSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
11811214
=======
11821215
+ (basic_param_table_ptr[OSPIF_BASIC_PARAM_TABLE_888_READ_INST_BYTE - 1] & 0x1F);
11831216
>>>>>>> 7266070... Modify the astyle
1217+
=======
1218+
+ (basic_param_table_ptr[OSPIF_BASIC_PARAM_TABLE_888_READ_INST_BYTE - 1] & 0x1F);
1219+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
11841220
tr_debug("Read Bus Mode set to 8-8-8, Instruction: 0x%xh", _read_instruction);
11851221
// _inst_width = OSPI_CFG_BUS_OCTA;
11861222
// _inst_size = OSPI_CFG_INST_SIZE_16;
@@ -1351,6 +1387,7 @@ int OSPIFBlockDevice::_sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_pa
13511387
_read_instruction = OSPIF_INST_READ_4B;
13521388
<<<<<<< HEAD
13531389
<<<<<<< HEAD
1390+
<<<<<<< HEAD
13541391
<<<<<<< HEAD
13551392
break;
13561393
=======
@@ -1362,6 +1399,9 @@ int OSPIFBlockDevice::_sfdp_detect_and_enable_4byte_addressing(uint8_t *basic_pa
13621399
=======
13631400
break;
13641401
>>>>>>> 7266070... Modify the astyle
1402+
=======
1403+
break;
1404+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
13651405
case 0xc2:
13661406
break;
13671407
}
@@ -1445,6 +1485,7 @@ int OSPIFBlockDevice::_sfdp_parse_4_byte_inst_table(Callback<int(bd_addr_t, void
14451485
if (four_byte_inst_table[OSPIF_4_BYTE_INST_TABLE_ERASE_SUPPORT_BYTE] & (FOURBYTE_INST_ERASE_TYPE_1_BITMASK << i_ind)) {
14461486
<<<<<<< HEAD
14471487
<<<<<<< HEAD
1488+
<<<<<<< HEAD
14481489
<<<<<<< HEAD
14491490
sfdp_info.fbatbl.erase_type_4_byte_inst_arr[i_ind] = four_byte_inst_table[OSPIF_4_BYTE_INST_TABLE_INST_ERASE_TYPE_1_BYTE + i_ind];
14501491
=======
@@ -1456,6 +1497,9 @@ int OSPIFBlockDevice::_sfdp_parse_4_byte_inst_table(Callback<int(bd_addr_t, void
14561497
=======
14571498
sfdp_info.fbatbl.erase_type_4_byte_inst_arr[i_ind] = four_byte_inst_table[OSPIF_4_BYTE_INST_TABLE_INST_ERASE_TYPE_1_BYTE + i_ind];
14581499
>>>>>>> 7266070... Modify the astyle
1500+
=======
1501+
sfdp_info.fbatbl.erase_type_4_byte_inst_arr[i_ind] = four_byte_inst_table[OSPIF_4_BYTE_INST_TABLE_INST_ERASE_TYPE_1_BYTE + i_ind];
1502+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
14591503
}
14601504
tr_debug("Erase Type %d - Inst: 0x%xh", (i_ind + 1), sfdp_info.fbatbl.erase_type_4_byte_inst_arr[i_ind]);
14611505
}
@@ -1877,13 +1921,17 @@ ospi_status_t OSPIFBlockDevice::_ospi_send_general_command(ospi_inst_t instructi
18771921
<<<<<<< HEAD
18781922
<<<<<<< HEAD
18791923
<<<<<<< HEAD
1924+
<<<<<<< HEAD
1925+
=======
1926+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
18801927
if ((_inst_width == OSPI_CFG_BUS_OCTA) || (_inst_width == OSPI_CFG_BUS_OCTA_DTR)) {
18811928
if ((instruction == OSPIF_INST_RSR1) || (instruction == OSPIF_INST_RDID) ||
18821929
(instruction == OSPIF_INST_RDCR2) || (instruction == OSPIF_INST_RDCR)) {
18831930
_ospi.configure_format(_inst_width, _inst_size, _address_width, _address_size, OSPI_CFG_BUS_SINGLE,
18841931
0, _data_width, 4);
18851932
addr = 0;
18861933
} else if ((instruction == OSPIF_INST_WSR1)) {
1934+
<<<<<<< HEAD
18871935
=======
18881936
=======
18891937
>>>>>>> 060eabb... add OSPI HAL and OSPIF driver
@@ -1909,6 +1957,8 @@ ospi_status_t OSPIFBlockDevice::_ospi_send_general_command(ospi_inst_t instructi
19091957
=======
19101958
} else if ((instruction == OSPIF_INST_WSR1)) {
19111959
>>>>>>> 7266070... Modify the astyle
1960+
=======
1961+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
19121962
addr = 0;
19131963
}
19141964
}
@@ -1922,6 +1972,7 @@ ospi_status_t OSPIFBlockDevice::_ospi_send_general_command(ospi_inst_t instructi
19221972

19231973
<<<<<<< HEAD
19241974
<<<<<<< HEAD
1975+
<<<<<<< HEAD
19251976
<<<<<<< HEAD
19261977
if (((_inst_width == OSPI_CFG_BUS_OCTA) || (_inst_width == OSPI_CFG_BUS_OCTA_DTR)) &&
19271978
((instruction == OSPIF_INST_RSR1) || (instruction == OSPIF_INST_RDID) ||
@@ -1941,6 +1992,11 @@ ospi_status_t OSPIFBlockDevice::_ospi_send_general_command(ospi_inst_t instructi
19411992
((instruction == OSPIF_INST_RSR1) || (instruction == OSPIF_INST_RDID) ||
19421993
(instruction == OSPIF_INST_RDCR2) || (instruction == OSPIF_INST_RDCR))) {
19431994
>>>>>>> 7266070... Modify the astyle
1995+
=======
1996+
if (((_inst_width == OSPI_CFG_BUS_OCTA) || (_inst_width == OSPI_CFG_BUS_OCTA_DTR)) &&
1997+
((instruction == OSPIF_INST_RSR1) || (instruction == OSPIF_INST_RDID) ||
1998+
(instruction == OSPIF_INST_RDCR2) || (instruction == OSPIF_INST_RDCR))) {
1999+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
19442000
_ospi.configure_format(_inst_width, _inst_size, _address_width, _address_size, OSPI_CFG_BUS_SINGLE,
19452001
0, _data_width, 0);
19462002
}
@@ -1957,10 +2013,14 @@ int OSPIFBlockDevice::_ospi_send_read_sfdp_command(bd_addr_t addr, void *rx_buff
19572013
if (addr < 30) {
19582014
<<<<<<< HEAD
19592015
<<<<<<< HEAD
2016+
<<<<<<< HEAD
19602017
<<<<<<< HEAD
19612018
for (uint8_t i_ind = 0; i_ind < rx_len; i_ind++) {
19622019
<<<<<<< HEAD
19632020
<<<<<<< HEAD
2021+
=======
2022+
for (uint8_t i_ind = 0; i_ind < rx_len; i_ind++) {
2023+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
19642024
*(rx_buffer_tmp + i_ind) = _sfdp_head_table[i_ind + addr];
19652025
}
19662026
} else if (addr == 0x30) {
@@ -1971,6 +2031,7 @@ int OSPIFBlockDevice::_ospi_send_read_sfdp_command(bd_addr_t addr, void *rx_buff
19712031
for (uint8_t i_ind = 0; i_ind < rx_len; i_ind++) {
19722032
*(rx_buffer_tmp + i_ind) = _sfdp_4_byte_inst_table[i_ind];
19732033
}
2034+
<<<<<<< HEAD
19742035
=======
19752036
=======
19762037
>>>>>>> 060eabb... add OSPI HAL and OSPIF driver
@@ -2005,6 +2066,8 @@ int OSPIFBlockDevice::_ospi_send_read_sfdp_command(bd_addr_t addr, void *rx_buff
20052066
>>>>>>> 3b8265d... Modify the astyle
20062067
}
20072068
>>>>>>> 7266070... Modify the astyle
2069+
=======
2070+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
20082071
}
20092072
} else {
20102073
// SFDP read instruction requires 1-1-1 bus mode with 8 dummy cycles and a 3-byte address
@@ -2082,6 +2145,7 @@ ospi_status_t OSPIFBlockDevice::_ospi_write_status_registers(uint8_t *reg_buffer
20822145
NULL, 0);
20832146
<<<<<<< HEAD
20842147
<<<<<<< HEAD
2148+
<<<<<<< HEAD
20852149
<<<<<<< HEAD
20862150
//for octa flash DOPI mode, WRSR just write 1 byte, but the byte number need to even because of protocol
20872151
=======
@@ -2093,6 +2157,9 @@ ospi_status_t OSPIFBlockDevice::_ospi_write_status_registers(uint8_t *reg_buffer
20932157
=======
20942158
//for octa flash DOPI mode, WRSR just write 1 byte, but the byte number need to even because of protocol
20952159
>>>>>>> 7266070... Modify the astyle
2160+
=======
2161+
//for octa flash DOPI mode, WRSR just write 1 byte, but the byte number need to even because of protocol
2162+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
20962163
} else if (_read_instruction == DTROSPIF_INST_READ_OCTA_DTR) {
20972164
status = _ospi_send_general_command(OSPIF_INST_WSR1, OSPI_NO_ADDRESS_COMMAND,
20982165
(char *) reg_buffer, 2,

drivers/OSPI.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef int ospi_inst_t;
4949
*
5050
<<<<<<< HEAD
5151
<<<<<<< HEAD
52+
<<<<<<< HEAD
5253
<<<<<<< HEAD
5354
* The default format is set to OCTO-SPI(1-1-1), and a clock frequency of 1MHz
5455
=======
@@ -60,6 +61,9 @@ typedef int ospi_inst_t;
6061
=======
6162
* The default format is set to OCTO-SPI(1-1-1), and a clock frequency of 1MHz
6263
>>>>>>> 7266070... Modify the astyle
64+
=======
65+
* The default format is set to OCTO-SPI(1-1-1), and a clock frequency of 1MHz
66+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
6367
* Most OSPI devices will also require Chip Select which is indicated by ssel.
6468
*
6569
* @note Synchronization level: Thread safe
@@ -154,6 +158,7 @@ class OSPI : private NonCopyable<OSPI> {
154158
<<<<<<< HEAD
155159
<<<<<<< HEAD
156160
<<<<<<< HEAD
161+
<<<<<<< HEAD
157162
<<<<<<< HEAD
158163
ospi_inst_size_t inst_size,
159164
=======
@@ -168,6 +173,9 @@ class OSPI : private NonCopyable<OSPI> {
168173
=======
169174
ospi_inst_size_t inst_size,
170175
>>>>>>> 3b8265d... Modify the astyle
176+
=======
177+
ospi_inst_size_t inst_size,
178+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
171179
ospi_bus_width_t address_width,
172180
ospi_address_size_t address_size,
173181
ospi_bus_width_t alt_width,

drivers/source/OSPI.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ OSPI::OSPI(const ospi_pinmap_t &pinmap, int mode) : _ospi()
112112
ospi_status_t OSPI::configure_format(ospi_bus_width_t inst_width, ospi_inst_size_t inst_size,
113113
<<<<<<< HEAD
114114
<<<<<<< HEAD
115+
<<<<<<< HEAD
115116
<<<<<<< HEAD
116117
ospi_bus_width_t address_width, ospi_address_size_t address_size,
117118
ospi_bus_width_t alt_width, ospi_alt_size_t alt_size,
@@ -131,6 +132,11 @@ ospi_status_t OSPI::configure_format(ospi_bus_width_t inst_width, ospi_inst_size
131132
ospi_bus_width_t alt_width, ospi_alt_size_t alt_size,
132133
ospi_bus_width_t data_width, int dummy_cycles)
133134
>>>>>>> 7266070... Modify the astyle
135+
=======
136+
ospi_bus_width_t address_width, ospi_address_size_t address_size,
137+
ospi_bus_width_t alt_width, ospi_alt_size_t alt_size,
138+
ospi_bus_width_t data_width, int dummy_cycles)
139+
>>>>>>> 197660953e3736e09bf4f46bfc7e57c8f506e304
134140
{
135141
// Check that alt_size/alt_width are a valid combination
136142
uint8_t alt_lines = convert_bus_width_to_line_count(alt_width);

0 commit comments

Comments
 (0)