Skip to content

Commit 8d2f426

Browse files
adustmmaciejbocianski
authored andcommitted
Dummy cycles count is not an init parameter, but a command parameter.
It can change depending on the chosen command, not only at start. This way we avoid to launch init function and break the internal status variables.
1 parent 8e08740 commit 8d2f426

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

drivers/QSPI.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, Pin
3939
_alt_width = QSPI_CFG_BUS_SINGLE;
4040
_alt_size = QSPI_CFG_ALT_SIZE_8;
4141
_data_width = QSPI_CFG_BUS_SINGLE;
42-
_num_dummy_cycles = 0;
4342
_mode = 0;
4443
_hz = ONE_MHZ;
4544
_initialized = false;
@@ -62,7 +61,6 @@ qspi_status_t QSPI::configure_format(qspi_bus_width_t inst_width, qspi_bus_width
6261
_alt_width = alt_width;
6362
_alt_size = alt_size;
6463
_data_width = data_width;
65-
_num_dummy_cycles = dummy_cycles;
6664
_mode = mode;
6765

6866
//Re-init the device, as the mode might have changed
@@ -107,7 +105,7 @@ qspi_status_t QSPI::read(unsigned int address, char *rx_buffer, size_t *rx_lengt
107105
if (*rx_length != 0) {
108106
lock();
109107
if (true == _acquire()) {
110-
_build_qspi_command(-1, address, -1);
108+
_build_qspi_command(-1, address, -1, 0);
111109
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
112110
ret_status = QSPI_STATUS_OK;
113111
}
@@ -131,7 +129,7 @@ qspi_status_t QSPI::write(unsigned int address, const char *tx_buffer, size_t *t
131129
if (*tx_length != 0) {
132130
lock();
133131
if (true == _acquire()) {
134-
_build_qspi_command(-1, address, -1);
132+
_build_qspi_command(-1, address, -1, 0);
135133
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
136134
ret_status = QSPI_STATUS_OK;
137135
}
@@ -146,7 +144,7 @@ qspi_status_t QSPI::write(unsigned int address, const char *tx_buffer, size_t *t
146144
return ret_status;
147145
}
148146

149-
qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned int address, char *rx_buffer, size_t *rx_length)
147+
qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned int dummy_cnt, unsigned int address, char *rx_buffer, size_t *rx_length)
150148
{
151149
qspi_status_t ret_status = QSPI_STATUS_ERROR;
152150

@@ -155,7 +153,7 @@ qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned in
155153
if (*rx_length != 0) {
156154
lock();
157155
if ( true == _acquire()) {
158-
_build_qspi_command(instruction, address, alt);
156+
_build_qspi_command(instruction, address, alt, dummy_cnt);
159157
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
160158
ret_status = QSPI_STATUS_OK;
161159
}
@@ -170,7 +168,7 @@ qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned in
170168
return ret_status;
171169
}
172170

173-
qspi_status_t QSPI::write(unsigned int instruction, unsigned int alt, unsigned int address, const char *tx_buffer, size_t *tx_length)
171+
qspi_status_t QSPI::write(unsigned int instruction, unsigned int alt, unsigned int dummy_cnt, unsigned int address, const char *tx_buffer, size_t *tx_length)
174172
{
175173
qspi_status_t ret_status = QSPI_STATUS_ERROR;
176174

@@ -179,7 +177,7 @@ qspi_status_t QSPI::write(unsigned int instruction, unsigned int alt, unsigned i
179177
if (*tx_length != 0) {
180178
lock();
181179
if (true == _acquire()) {
182-
_build_qspi_command(instruction, address, alt);
180+
_build_qspi_command(instruction, address, alt, dummy_cnt);
183181
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
184182
ret_status = QSPI_STATUS_OK;
185183
}
@@ -201,7 +199,7 @@ qspi_status_t QSPI::command_transfer(unsigned int instruction, int address, cons
201199
if (_initialized) {
202200
lock();
203201
if (true == _acquire()) {
204-
_build_qspi_command(instruction, address, -1); //We just need the command
202+
_build_qspi_command(instruction, address, -1, 0); //We just need the command
205203
if (QSPI_STATUS_OK == qspi_command_transfer(&_qspi, &_qspi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
206204
ret_status = QSPI_STATUS_OK;
207205
}
@@ -247,7 +245,7 @@ bool QSPI::_acquire()
247245
return _initialized;
248246
}
249247

250-
void QSPI::_build_qspi_command(int instruction, int address, int alt)
248+
void QSPI::_build_qspi_command(int instruction, int address, int alt, int dummy_cnt)
251249
{
252250
memset( &_qspi_command, 0, sizeof(qspi_command_t) );
253251
//Set up instruction phase parameters
@@ -278,8 +276,8 @@ void QSPI::_build_qspi_command(int instruction, int address, int alt)
278276
} else {
279277
_qspi_command.alt.disabled = true;
280278
}
281-
282-
_qspi_command.dummy_count = _num_dummy_cycles;
279+
280+
_qspi_command.dummy_count = dummy_cnt;
283281

284282
//Set up bus width for data phase
285283
_qspi_command.data.bus_width = _data_width;

drivers/QSPI.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,29 @@ class QSPI : private NonCopyable<QSPI> {
134134
*
135135
* @param instruction Instruction value to be used in instruction phase
136136
* @param alt Alt value to be used in instruction phase
137+
* @param dummy_cnt Amount of dummy cycles to be sent after instruction phase
137138
* @param address Address to be accessed in QSPI peripheral
138139
* @param rx_buffer Buffer for data to be read from the peripheral
139140
* @param rx_length Pointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
140141
*
141142
* @returns
142143
* Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
143144
*/
144-
qspi_status_t read(unsigned int instruction, unsigned int alt, unsigned int address, char *rx_buffer, size_t *rx_length);
145+
qspi_status_t read(unsigned int instruction, unsigned int alt, unsigned int dummy_cnt, unsigned int address, char *rx_buffer, size_t *rx_length);
145146

146147
/** Write to QSPI peripheral using custom write instruction, alt values
147148
*
148149
* @param instruction Instruction value to be used in instruction phase
149150
* @param alt Alt value to be used in instruction phase
151+
* @param dummy_cnt Amount of dummy cycles to be sent after instruction phase
150152
* @param address Address to be accessed in QSPI peripheral
151153
* @param tx_buffer Buffer containing data to be sent to peripheral
152154
* @param tx_length Pointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
153155
*
154156
* @returns
155157
* Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
156158
*/
157-
qspi_status_t write(unsigned int instruction, unsigned int alt, unsigned int address, const char *tx_buffer, size_t *tx_length);
159+
qspi_status_t write(unsigned int instruction, unsigned int alt, unsigned int dummy_cnt, unsigned int address, const char *tx_buffer, size_t *tx_length);
158160

159161
/** Perform a transaction to write to an address(a control register) and get the status results
160162
*
@@ -195,7 +197,6 @@ class QSPI : private NonCopyable<QSPI> {
195197
qspi_alt_size_t _alt_size;
196198
qspi_bus_width_t _data_width; //Bus width for Data phase
197199
qspi_command_t _qspi_command; //QSPI Hal command struct
198-
unsigned int _num_dummy_cycles; //Number of dummy cycles to be used
199200
int _hz; //Bus Frequency
200201
int _mode; //SPI mode
201202
bool _initialized;
@@ -211,7 +212,7 @@ class QSPI : private NonCopyable<QSPI> {
211212
/*
212213
* This function builds the qspi command struct to be send to Hal
213214
*/
214-
inline void _build_qspi_command(int instruction, int address, int alt);
215+
inline void _build_qspi_command(int instruction, int address, int alt, int dummy_cnt);
215216
};
216217

217218
} // namespace mbed

0 commit comments

Comments
 (0)