Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
91e70b2
QSPI HAL addition
0xc0170 Nov 3, 2017
db60d57
QSPI: fix address/alt variable sizes (can be skipped)
0xc0170 Nov 7, 2017
bae6949
QSPI: change length to be in/out parameter
0xc0170 Nov 7, 2017
a905dfb
QSPI: improve mode documentation
0xc0170 Nov 8, 2017
bbbd2cf
QSPI: fix command declaration names
0xc0170 Nov 10, 2017
f813587
QSPI: initial HAL nrf52840 version
0xc0170 Nov 10, 2017
fe3c3ab
Modify QSPI HAL API to include an API for command-transfer operations
SenRamakri Nov 23, 2017
29a5888
Enabling QSPI headers in Nordic HAL implementation and fix for UART S…
SenRamakri Nov 23, 2017
4982703
QSPI driver implementation
SenRamakri Nov 23, 2017
0373cfb
Review fixes and doxygen changes
SenRamakri Nov 27, 2017
dd111e2
Fix code style issues
SenRamakri Nov 29, 2017
d4389a9
Add support for 1_1_2 and 1_2_2 modes in HAL
SenRamakri Nov 30, 2017
a6e3e23
Changing config and return definitions to adhere to HAL defs
SenRamakri Nov 30, 2017
a16d65d
Remove explicit initialize API and coding style fixes
SenRamakri Dec 1, 2017
7dbcc19
Fix bracket placements
SenRamakri Dec 1, 2017
ea85bba
Remove changes to Nordic SDK and modify HAL to track qspi init
SenRamakri Dec 4, 2017
55b13ca
Minor optimizations and code style fixes
SenRamakri Dec 4, 2017
fd8c3f7
Review fixes
SenRamakri Dec 4, 2017
75a4479
QSPI: fix address size for build qspi command
0xc0170 Dec 5, 2017
35149af
QSPI: remove initialize method
0xc0170 Dec 5, 2017
3951190
QSPI: remove spaces on empty lines
0xc0170 Dec 5, 2017
dafe6a3
QSPI HAL: fix alternative comment
0xc0170 Dec 5, 2017
0f87633
QSPI: fix arguments for write/read when alt is defined
0xc0170 Dec 6, 2017
2820ca4
QSPI: fix driver style issues
0xc0170 Dec 6, 2017
ff9442c
QSPI: fix alt size NONE instead 0
0xc0170 Dec 6, 2017
50b70eb
QSPI HAL: add disabled flag to format phase
0xc0170 Nov 23, 2017
2fd5ec6
QSPI: add STM32 implementation
0xc0170 Nov 15, 2017
778e776
QSPI STM32: fix ssel af selection
0xc0170 Nov 23, 2017
f6ddff6
QSPI STM32: fix return value in frequency
0xc0170 Nov 23, 2017
e30b670
QSPI STM32: set default command values to none
0xc0170 Nov 23, 2017
281eb87
QSPI STM32: remove polling from write/read
0xc0170 Nov 24, 2017
827314c
QSPI STM32: add qspi_command_transfer implementation
0xc0170 Dec 5, 2017
412c7c5
QSPI STM32: init returns error if failed to init
0xc0170 Dec 5, 2017
cb38c94
QSPI STM32: add QSPI_x support to pinnames
0xc0170 Dec 5, 2017
f344e5a
QSPI STM32: fix disabled format phase
0xc0170 Dec 11, 2017
5bf67f9
QSPI STM32: fix pin merging
0xc0170 Dec 12, 2017
9e6ea89
QSPI STM32: fix command transfer
0xc0170 Dec 12, 2017
6a97161
QSPI STM32: fix prepare comman - alt/address
0xc0170 Dec 12, 2017
5260810
QSPI STM32: fix default fifo and cycle
0xc0170 Dec 12, 2017
1e8df28
QSPI: hal doxygen fixes
0xc0170 Jan 9, 2018
b695d39
QSPI: add flash pins for F469 disco board
0xc0170 Jan 8, 2018
0847a97
QSPI: add flash pins for nrf52480_dk board
0xc0170 Jan 8, 2018
d4d3851
QSPI: add STM32L4 support
0xc0170 Jan 10, 2018
a00ee5d
QSPI: fix memset header file missing
0xc0170 Feb 16, 2018
a445186
QSPI: add address to command transfer
0xc0170 Feb 13, 2018
8e3c981
Fix Address.Size and AlternateByes.Size by shifting them
adustm Mar 22, 2018
99ae979
Fix Instruction with no data command
adustm Mar 22, 2018
b0898f7
Dummy cycles count is not an init parameter, but a command parameter.
adustm Mar 20, 2018
6121e24
Change default FlashSize to 64Mbit = 8Mbytes = 0x800000
adustm Mar 19, 2018
cab6eda
Move _mode from QSPI::configure_format to QSPI::QSPI
adustm Mar 30, 2018
842b859
Revert "Dummy cycles count is not an init parameter, but a command pa…
adustm Mar 30, 2018
43fa141
Enable QSPI feature for DISCO_F413ZH platform
adustm Apr 9, 2018
c727e5c
Support maximum flash size : 4Gbytes
adustm Apr 9, 2018
e2b5c27
Add MBED_WEAK for pins
adustm Apr 10, 2018
e0b7afb
Enable QSPI for DISCO_F746NG
adustm Apr 10, 2018
9b466ca
Add support for QSPI on DISCO_L476VG
adustm Apr 10, 2018
629eacd
QSPI: add doxygen options
0xc0170 Apr 24, 2018
64b289c
QSPI: fix doxy hal documentation
0xc0170 Apr 24, 2018
1eb51cf
fix qspi command transfer for NORDIC
maciejbocianski Jun 22, 2018
1cd69e1
QSPIF SFDP Block Device
Jul 10, 2018
509025c
tab to spaces
Jul 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doxyfile_options
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,7 @@ PREDEFINED = DOXYGEN_ONLY \
DEVICE_SPI \
DEVICE_SPI_ASYNCH \
DEVICE_SPISLAVE \
DEVICE_QSPI \
DEVICE_STORAGE \
"MBED_DEPRECATED_SINCE(d, m)=" \
"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=" \
Expand Down
2 changes: 1 addition & 1 deletion doxygen_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"SEARCH_INCLUDES": "YES",
"INCLUDE_PATH": "",
"INCLUDE_FILE_PATTERNS": "",
"PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_CRC DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_ITM DEVICE_LPTICKER DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_STORAGE \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\" \"MBED_DEPRECATED(s)=\"",
"PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_CRC DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_ITM DEVICE_LPTICKER DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_QSPI DEVICE_STORAGE \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\" \"MBED_DEPRECATED(s)=\"",
"EXPAND_AS_DEFINED": "",
"SKIP_FUNCTION_MACROS": "NO",
"STRIP_CODE_COMMENTS": "NO",
Expand Down
285 changes: 285 additions & 0 deletions drivers/QSPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "drivers/QSPI.h"
#include "platform/mbed_critical.h"
#include <string.h>

#if DEVICE_QSPI

namespace mbed {

QSPI* QSPI::_owner = NULL;
SingletonPtr<PlatformMutex> QSPI::_mutex;

QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel, int mode) : _qspi()
{
_qspi_io0 = io0;
_qspi_io1 = io1;
_qspi_io2 = io2;
_qspi_io3 = io3;
_qspi_clk = sclk;
_qspi_cs = ssel;
_inst_width = QSPI_CFG_BUS_SINGLE;
_address_width = QSPI_CFG_BUS_SINGLE;
_address_size = QSPI_CFG_ADDR_SIZE_24;
_alt_width = QSPI_CFG_BUS_SINGLE;
_alt_size = QSPI_CFG_ALT_SIZE_8;
_data_width = QSPI_CFG_BUS_SINGLE;
_num_dummy_cycles = 0;
_mode = mode;
_hz = ONE_MHZ;
_initialized = false;

//Go ahead init the device here with the default config
_initialize();
}

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)
{
qspi_status_t ret_status = QSPI_STATUS_OK;

lock();
_inst_width = inst_width;
_address_width = address_width;
_address_size = address_size;
_alt_width = alt_width;
_alt_size = alt_size;
_data_width = data_width;
_num_dummy_cycles = dummy_cycles;

unlock();

return ret_status;
}

qspi_status_t QSPI::set_frequency(int hz)
{
qspi_status_t ret_status = QSPI_STATUS_OK;

if (_initialized) {
lock();
_hz = hz;
//If the same owner, just change freq.
//Otherwise we may have to change mode as well, so call _acquire
if (_owner == this) {
if (QSPI_STATUS_OK != qspi_frequency(&_qspi, _hz)) {
ret_status = QSPI_STATUS_ERROR;
}
} else {
_acquire();
}
unlock();
} else {
ret_status = QSPI_STATUS_ERROR;
}

return ret_status;
}

qspi_status_t QSPI::read(unsigned int address, char *rx_buffer, size_t *rx_length)
{
qspi_status_t ret_status = QSPI_STATUS_ERROR;

if (_initialized) {
if ((rx_length != NULL) && (rx_buffer != NULL)) {
if (*rx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(-1, address, -1);
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
ret_status = QSPI_STATUS_INVALID_PARAMETER;
}
}

return ret_status;
}

qspi_status_t QSPI::write(unsigned int address, const char *tx_buffer, size_t *tx_length)
{
qspi_status_t ret_status = QSPI_STATUS_ERROR;

if (_initialized) {
if ((tx_length != NULL) && (tx_buffer != NULL)) {
if (*tx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(-1, address, -1);
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
ret_status = QSPI_STATUS_INVALID_PARAMETER;
}
}

return ret_status;
}

qspi_status_t QSPI::read(unsigned int instruction, unsigned int alt, unsigned int address, char *rx_buffer, size_t *rx_length)
{
qspi_status_t ret_status = QSPI_STATUS_ERROR;

if (_initialized) {
if ( (rx_length != NULL) && (rx_buffer != NULL) ) {
if (*rx_length != 0) {
lock();
if ( true == _acquire()) {
_build_qspi_command(instruction, address, alt);
if (QSPI_STATUS_OK == qspi_read(&_qspi, &_qspi_command, rx_buffer, rx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
ret_status = QSPI_STATUS_INVALID_PARAMETER;
}
}

return ret_status;
}

qspi_status_t QSPI::write(unsigned int instruction, unsigned int alt, unsigned int address, const char *tx_buffer, size_t *tx_length)
{
qspi_status_t ret_status = QSPI_STATUS_ERROR;

if (_initialized) {
if ( (tx_length != NULL) && (tx_buffer != NULL) ) {
if (*tx_length != 0) {
lock();
if (true == _acquire()) {
_build_qspi_command(instruction, address, alt);
if (QSPI_STATUS_OK == qspi_write(&_qspi, &_qspi_command, tx_buffer, tx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}
} else {
ret_status = QSPI_STATUS_INVALID_PARAMETER;
}
}

return ret_status;
}

qspi_status_t QSPI::command_transfer(unsigned int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length)
{
qspi_status_t ret_status = QSPI_STATUS_ERROR;

if (_initialized) {
lock();
if (true == _acquire()) {
_build_qspi_command(instruction, address, -1); //We just need the command
if (QSPI_STATUS_OK == qspi_command_transfer(&_qspi, &_qspi_command, (const void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length)) {
ret_status = QSPI_STATUS_OK;
}
}
unlock();
}

return ret_status;
}

void QSPI::lock()
{
_mutex->lock();
}

void QSPI::unlock()
{
_mutex->unlock();
}

// Note: Private helper function to initialize qspi HAL
bool QSPI::_initialize()
{
if (_mode != 0 && _mode != 1)
return QSPI_STATUS_INVALID_PARAMETER;

qspi_status_t ret = qspi_init(&_qspi, _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs, _hz, _mode );
if (QSPI_STATUS_OK == ret) {
_initialized = true;
} else {
_initialized = false;
}

return _initialized;
}

// Note: Private function with no locking
bool QSPI::_acquire()
{
if (_owner != this) {
//This will set freq as well
_initialize();
_owner = this;
}

return _initialized;
}

void QSPI::_build_qspi_command(int instruction, int address, int alt)
{
memset( &_qspi_command, 0, sizeof(qspi_command_t) );
//Set up instruction phase parameters
_qspi_command.instruction.bus_width = _inst_width;
if (instruction != -1) {
_qspi_command.instruction.value = instruction;
_qspi_command.instruction.disabled = false;
} else {
_qspi_command.instruction.disabled = true;
}

//Set up address phase parameters
_qspi_command.address.bus_width = _address_width;
_qspi_command.address.size = _address_size;
if (address != -1) {
_qspi_command.address.value = address;
_qspi_command.address.disabled = false;
} else {
_qspi_command.address.disabled = true;
}

//Set up alt phase parameters
_qspi_command.alt.bus_width = _alt_width;
_qspi_command.alt.size = _alt_size;
if (alt != -1) {
_qspi_command.alt.value = alt;
_qspi_command.alt.disabled = false;
} else {
_qspi_command.alt.disabled = true;
}

_qspi_command.dummy_count = _num_dummy_cycles;

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

} // namespace mbed

#endif
Loading