diff options
author | Gurjant Kalsi <me@gurjantkalsi.com> | 2015-10-16 17:59:32 -0700 |
---|---|---|
committer | Gurjant Kalsi <me@gurjantkalsi.com> | 2015-10-28 16:12:48 -0700 |
commit | e3c6b0d63df7d070374c2c0998ec10f71fbc3dae (patch) | |
tree | 1fe1742cf17f1e9574b501382189a64bd0c632fe /platform | |
parent | 7980df73b52ca7e8ccfacb227debf4f707392215 (diff) | |
download | common-e3c6b0d63df7d070374c2c0998ec10f71fbc3dae.tar.gz |
[qspi][spiflash][stm32f746] Support going into linear mode for STM32f7 qspiflash
Diffstat (limited to 'platform')
-rw-r--r-- | platform/stm32f7xx/qspi.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/platform/stm32f7xx/qspi.c b/platform/stm32f7xx/qspi.c index 7c14d6d1..2f867526 100644 --- a/platform/stm32f7xx/qspi.c +++ b/platform/stm32f7xx/qspi.c @@ -62,6 +62,8 @@ static HAL_StatusTypeDef qspi_cmd(QSPI_HandleTypeDef*, QSPI_CommandTypeDef*); static HAL_StatusTypeDef qspi_tx_dma(QSPI_HandleTypeDef*, QSPI_CommandTypeDef*, uint8_t*); static HAL_StatusTypeDef qspi_rx_dma(QSPI_HandleTypeDef*, QSPI_CommandTypeDef*, uint8_t*); +status_t qspi_enable_linear(void); + status_t qspi_dma_init(QSPI_HandleTypeDef *hqspi); static uint32_t get_specialized_instruction(uint32_t instruction, uint32_t address); @@ -381,7 +383,16 @@ finish: static int spiflash_ioctl(struct bdev* device, int request, void* argp) { - return ERR_NOT_IMPLEMENTED; + int ret = ERR_NOT_SUPPORTED; + + switch (request) { + case BIO_IOCTL_GET_MEM_MAP: + /* put the device into linear mode */ + ret = qspi_enable_linear(); + break; + } + + return ret; } static ssize_t qspi_write_page_unsafe(uint32_t addr, const uint8_t *data) @@ -757,3 +768,39 @@ static uint32_t get_specialized_instruction(uint32_t instruction, uint32_t addre return instruction; } + +status_t qspi_enable_linear(void) +{ + status_t result = NO_ERROR; + + mutex_acquire(&spiflash_mutex); + + result = qspi_dummy_cycles_cfg_unsafe(&qspi_handle); + + QSPI_CommandTypeDef s_command = { + .InstructionMode = QSPI_INSTRUCTION_1_LINE, + .AddressSize = QSPI_ADDRESS_24_BITS, + .AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE, + .DdrMode = QSPI_DDR_MODE_DISABLE, + .DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY, + .AddressMode = QSPI_ADDRESS_1_LINE, + .Instruction = QUAD_OUT_FAST_READ_CMD, + .DataMode = QSPI_DATA_4_LINES, + .DummyCycles = 10, + .SIOOMode = QSPI_SIOO_INST_EVERY_CMD + }; + + QSPI_MemoryMappedTypeDef linear_mode_cfg = { + .TimeOutActivation = QSPI_TIMEOUT_COUNTER_DISABLE, + }; + + HAL_StatusTypeDef hal_result = HAL_QSPI_MemoryMapped(&qspi_handle, &s_command, &linear_mode_cfg); + if (hal_result != HAL_OK) { + result = hal_error_to_status(hal_result); + goto err; + } + +err: + mutex_release(&spiflash_mutex); + return result; +} |