Skip to content

Commit ad49388

Browse files
QSPI driver: fixes after PR 7783 review
- make QSPI::lock and QSPI::unlock protected - fix QSPI::_initialize return value - add assert on QSPI::_initialize failure - minor comments fixes
1 parent c94f22c commit ad49388

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

drivers/QSPI.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2013 ARM Limited
2+
* Copyright (c) 2006-2018 ARM Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,8 @@ QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, Pin
4545
_initialized = false;
4646

4747
//Go ahead init the device here with the default config
48-
_initialize();
48+
bool success = _initialize();
49+
MBED_ASSERT(success);
4950
}
5051

5152
qspi_status_t QSPI::configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width, qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width, int dummy_cycles)
@@ -217,8 +218,10 @@ void QSPI::unlock()
217218
// Note: Private helper function to initialize qspi HAL
218219
bool QSPI::_initialize()
219220
{
220-
if (_mode != 0 && _mode != 1)
221-
return QSPI_STATUS_INVALID_PARAMETER;
221+
if (_mode != 0 && _mode != 1) {
222+
_initialized = false;
223+
return _initialized;
224+
}
222225

223226
qspi_status_t ret = qspi_init(&_qspi, _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs, _hz, _mode );
224227
if (QSPI_STATUS_OK == ret) {

drivers/QSPI.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2015 ARM Limited
2+
* Copyright (c) 2006-2018 ARM Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ namespace mbed {
3333

3434
/** A QSPI Driver, used for communicating with QSPI slave devices
3535
*
36-
* The default format is set to Quad-SPI(4-4-4), and a clock frequency of 1MHz
36+
* The default format is set to Quad-SPI(1-1-1), and a clock frequency of 1MHz
3737
* Most QSPI devices will also require Chip Select which is indicated by ssel.
3838
*
3939
* @note Synchronization level: Thread safe
@@ -45,7 +45,7 @@ namespace mbed {
4545
* #include "mbed.h"
4646
*
4747
* // hardware ssel (where applicable)
48-
* QSPI qspi_device(p5, p6, p7, p8, p9, p10); // io0, io1, io2, io3, sclk, ssel
48+
* QSPI qspi_device(QSPI_PIN_IO0, QSPI_PIN_IO1, QSPI_PIN_IO2, QSPI_PIN_IO3, QSPI_PIN_SCK, QSPI_PIN_CSN); // io0, io1, io2, io3, sclk, ssel
4949
*
5050
*
5151
* int main() {
@@ -84,12 +84,12 @@ class QSPI : private NonCopyable<QSPI> {
8484

8585
/** Configure the data transmission format
8686
*
87-
* @param inst_width Bus width used by instruction phase(Valid values are 1,2,4)
88-
* @param address_width Bus width used by address phase(Valid values are 1,2,4)
89-
* @param address_size Size in bits used by address phase(Valid values are 8,16,24,32)
90-
* @param alt_width Bus width used by alt phase(Valid values are 1,2,4)
91-
* @param alt_size Size in bits used by alt phase(Valid values are 8,16,24,32)
92-
* @param data_width Bus width used by data phase(Valid values are 1,2,4)
87+
* @param inst_width Bus width used by instruction phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
88+
* @param address_width Bus width used by address phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
89+
* @param address_size Size in bits used by address phase(Valid values are QSPI_CFG_ADDR_SIZE_8, QSPI_CFG_ADDR_SIZE_16, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_ADDR_SIZE_32)
90+
* @param alt_width Bus width used by alt phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
91+
* @param alt_size Size in bits used by alt phase(Valid values are QSPI_CFG_ADDR_SIZE_8, QSPI_CFG_ADDR_SIZE_16, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_ADDR_SIZE_32)
92+
* @param data_width Bus width used by data phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
9393
* @param dummy_cycles Number of dummy clock cycles to be used after alt phase
9494
*
9595
*/
@@ -171,6 +171,7 @@ class QSPI : private NonCopyable<QSPI> {
171171
*/
172172
qspi_status_t command_transfer(unsigned int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length);
173173

174+
protected:
174175
/** Acquire exclusive access to this SPI bus
175176
*/
176177
virtual void lock(void);

0 commit comments

Comments
 (0)