Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit d53abc2

Browse files
author
Offir Kochalsky
committed
Moved initialization from ctor to init
1 parent 98a582e commit d53abc2

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

QSPIFBlockDevice.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,43 +105,30 @@ PinName *QSPIFBlockDevice::_active_qspif_flash_csel_arr = generate_initialized_a
105105
/****************************************/
106106
QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName csel,
107107
qspif_polarity_mode clock_mode, int freq)
108-
: _qspi(io0, io1, io2, io3, sclk, csel, clock_mode), _csel(csel), _device_size_bytes(0), _init_ref_count(0),
108+
: _qspi(io0, io1, io2, io3, sclk, csel, clock_mode), _csel(csel), _freq(freq), _device_size_bytes(0),
109+
_init_ref_count(0),
109110
_is_initialized(false)
110111
{
111-
112112
_unique_device_status = add_new_csel_instance(csel);
113113
if (_unique_device_status == 0) {
114-
_min_common_erase_size = 0;
115-
_regions_count = 1;
116-
_region_erase_types_bitfield[0] = ERASE_BITMASK_NONE;
117-
118-
//Default Bus Setup 1_1_1 with 0 dummy and mode cycles
119-
_inst_width = QSPI_CFG_BUS_SINGLE;
120-
_address_width = QSPI_CFG_BUS_SINGLE;
121-
_address_size = QSPI_CFG_ADDR_SIZE_24;
122-
_data_width = QSPI_CFG_BUS_SINGLE;
123-
_dummy_and_mode_cycles = 0;
124-
125-
if (QSPI_STATUS_OK != _qspi_set_frequency(freq)) {
126-
tr_error("ERROR: QSPI Set Frequency Failed");
127-
}
114+
tr_info("INFO: Adding a new QSPIFBlockDevice csel: %d", (int)csel);
128115
} else if (_unique_device_status == -1) {
129116
tr_error("ERROR: QSPIFBlockDevice with the same csel(%d) already exists", (int)csel);
130117
} else {
131118
tr_error("ERROR: Too many different QSPIFBlockDevice devices - max allowed: %d", QSPIF_MAX_ACTIVE_FLASH_DEVICES);
132119
}
133-
134120
}
135121

136122
int QSPIFBlockDevice::init()
137123
{
138-
139-
if (_unique_device_status == -1) {
124+
if (_unique_device_status == 0) {
125+
tr_debug("DEBUG: QSPIFBlockDevice csel: %d", (int)_csel);
126+
} else if (_unique_device_status == -1) {
140127
tr_error("ERROR: QSPIFBlockDevice with the same csel(%d) already exists", (int)_csel);
141128
return QSPIF_BD_ERROR_DEVICE_NOT_UNIQE;
142-
} else if (_unique_device_status == -2) {
129+
} else {
143130
tr_error("ERROR: Too many different QSPIFBlockDevice devices - max allowed: %d", QSPIF_MAX_ACTIVE_FLASH_DEVICES);
144-
return QSPIF_BD_ERROR_DEVICE_NOT_UNIQE;
131+
return QSPIF_BD_ERROR_DEVICE_MAX_EXCEED;
145132
}
146133

147134
uint8_t vendor_device_ids[4];
@@ -165,6 +152,24 @@ int QSPIFBlockDevice::init()
165152
goto exit_point;
166153
}
167154

155+
//Initialize parameters
156+
_min_common_erase_size = 0;
157+
_regions_count = 1;
158+
_region_erase_types_bitfield[0] = ERASE_BITMASK_NONE;
159+
160+
//Default Bus Setup 1_1_1 with 0 dummy and mode cycles
161+
_inst_width = QSPI_CFG_BUS_SINGLE;
162+
_address_width = QSPI_CFG_BUS_SINGLE;
163+
_address_size = QSPI_CFG_ADDR_SIZE_24;
164+
_data_width = QSPI_CFG_BUS_SINGLE;
165+
_dummy_and_mode_cycles = 0;
166+
167+
if (QSPI_STATUS_OK != _qspi_set_frequency(_freq)) {
168+
tr_error("ERROR: QSPI Set Frequency Failed");
169+
status = QSPIF_BD_ERROR_DEVICE_ERROR;
170+
goto exit_point;
171+
}
172+
168173
// Soft Reset
169174
if ( -1 == _reset_flash_mem()) {
170175
tr_error("ERROR: init - Unable to initialize flash memory, tests failed\n");

QSPIFBlockDevice.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ enum qspif_bd_error {
3232
QSPIF_BD_ERROR_PARSING_FAILED = -4002, /* SFDP Parsing failed */
3333
QSPIF_BD_ERROR_READY_FAILED = -4003, /* Wait for Mem Ready failed */
3434
QSPIF_BD_ERROR_WREN_FAILED = -4004, /* Write Enable Failed */
35-
QSPIF_BD_ERROR_DEVICE_NOT_UNIQE = -4005 /* Only one instance per csel is allowed */
35+
QSPIF_BD_ERROR_DEVICE_NOT_UNIQE = -4005, /* Only one instance per csel is allowed */
36+
QSPIF_BD_ERROR_DEVICE_MAX_EXCEED = -4006 /* Max active QSPIF devices exceeded */
3637
};
3738

3839
/** Enum qspif polarity mode
@@ -290,6 +291,7 @@ class QSPIFBlockDevice : public BlockDevice {
290291
unsigned int _min_common_erase_size; // minimal common erase size for all regions (0 if none exists)
291292

292293
unsigned int _page_size_bytes; // Page size - 256 Bytes default
294+
int _freq;
293295
bd_size_t _device_size_bytes;
294296

295297
// Bus speed configuration

0 commit comments

Comments
 (0)