Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @brief Reads the data starting from \ref address and saves it under \ref data pointer. The amount of
- * data to read is equal to \ref len.
- * @param address: address to read the data from.
- * @param data: pointer under which the data will be saved.
- * @param len: amount of data to read.
- * @return HAL_OK on succesfull read.
- */
- HAL_StatusTypeDef qspi_read(const uint32_t address, uint8_t* const data, const uint32_t len)
- {
- assert_param(data);
- if (qspi_rWCheckWrapError(address, len))
- return HAL_ERROR;
- QSPI_CommandTypeDef sCommand;
- HAL_StatusTypeDef retVal = HAL_ERROR;
- qspi_setCommonCmdAndCfg(&sCommand, 0);
- sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
- sCommand.Instruction = e_qspiCmd_QuadFastRead;
- sCommand.AddressMode = QSPI_ADDRESS_4_LINES;
- sCommand.Address = address;
- sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_4_LINES;
- sCommand.AlternateBytesSize = QSPI_ALTERNATE_BYTES_8_BITS;
- sCommand.AlternateBytes = QSPI_ALT_BYTES_NO_PE_MODE;
- sCommand.DataMode = QSPI_DATA_4_LINES;
- sCommand.DummyCycles = QSPI_DUMMY_CYCLES_READ_QUAD;
- sCommand.NbData = len;
- osMutexWait(qspi.mut, osWaitForever);
- do
- {
- if (HAL_QSPI_Command(qspi.hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
- break;
- // 1st lock
- osSemaphoreWait(qspi.semaDma, osWaitForever);
- if (HAL_QSPI_Receive_DMA(qspi.hqspi, qspi.buf) != HAL_OK)
- break;
- // sync
- osSemaphoreWait(qspi.semaDma, osWaitForever);
- osSemaphoreRelease(qspi.semaDma);
- memcpy(data, qspi.buf + QSPI_READ_OFFSET, len);
- retVal = HAL_OK;
- }
- while (0);
- osMutexRelease(qspi.mut);
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement