Advertisement
bremenpl

Untitled

Mar 15th, 2018
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.63 KB | None | 0 0
  1. /**
  2.  * @brief   Reads the data starting from \ref address and saves it under \ref data pointer. The amount of
  3.  *          data to read is equal to \ref len.
  4.  * @param   address: address to read the data from.
  5.  * @param   data: pointer under which the data will be saved.
  6.  * @param   len: amount of data to read.
  7.  * @return  HAL_OK on succesfull read.
  8.  */
  9. HAL_StatusTypeDef qspi_read(const uint32_t address, uint8_t* const data, const uint32_t len)
  10. {
  11.     assert_param(data);
  12.  
  13.     if (qspi_rWCheckWrapError(address, len))
  14.         return HAL_ERROR;
  15.  
  16.     QSPI_CommandTypeDef sCommand;
  17.     HAL_StatusTypeDef retVal = HAL_ERROR;
  18.     qspi_setCommonCmdAndCfg(&sCommand, 0);
  19.  
  20.     sCommand.InstructionMode =      QSPI_INSTRUCTION_1_LINE;
  21.     sCommand.Instruction =          e_qspiCmd_QuadFastRead;
  22.     sCommand.AddressMode =          QSPI_ADDRESS_4_LINES;
  23.     sCommand.Address =              address;
  24.     sCommand.AlternateByteMode =    QSPI_ALTERNATE_BYTES_4_LINES;
  25.     sCommand.AlternateBytesSize =   QSPI_ALTERNATE_BYTES_8_BITS;
  26.     sCommand.AlternateBytes =       QSPI_ALT_BYTES_NO_PE_MODE;
  27.     sCommand.DataMode =             QSPI_DATA_4_LINES;
  28.     sCommand.DummyCycles =          QSPI_DUMMY_CYCLES_READ_QUAD;
  29.     sCommand.NbData =               len;
  30.  
  31.     osMutexWait(qspi.mut, osWaitForever);
  32.     do
  33.     {
  34.         if (HAL_QSPI_Command(qspi.hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  35.             break;
  36.  
  37.         // 1st lock
  38.         osSemaphoreWait(qspi.semaDma, osWaitForever);
  39.         if (HAL_QSPI_Receive_DMA(qspi.hqspi, qspi.buf) != HAL_OK)
  40.             break;
  41.  
  42.         // sync
  43.         osSemaphoreWait(qspi.semaDma, osWaitForever);
  44.         osSemaphoreRelease(qspi.semaDma);
  45.  
  46.         memcpy(data, qspi.buf + QSPI_READ_OFFSET, len);
  47.         retVal = HAL_OK;
  48.     }
  49.     while (0);
  50.  
  51.     osMutexRelease(qspi.mut);
  52.     return retVal;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement