Пример #1
0
 */
bool_t sdc_lld_read_aligned(SDCDriver *sdcp, uint32_t startblk,
                            uint8_t *buf, uint32_t n) {
  uint32_t resp[1];

  chDbgCheck((n < (0x1000000 / MMCSD_BLOCK_SIZE)), "max transaction size");

  //SDIO->DTIMER = STM32_SDC_READ_TIMEOUT;
  SDIO->DTIMER = 0xFFFFFFFF;    // KL

  /* Checks for errors and waits for the card to be ready for reading.*/
  if (_sdc_wait_for_transfer_state(sdcp))
    return CH_FAILED;

  /* Prepares the DMA channel for writing.*/
  dmaStreamSetMemory0(sdcp->dma, buf);
  dmaStreamSetTransactionSize(sdcp->dma,
                              (n * MMCSD_BLOCK_SIZE) / sizeof (uint32_t));
  dmaStreamSetMode(sdcp->dma, sdcp->dmamode | STM32_DMA_CR_DIR_P2M);
  dmaStreamEnable(sdcp->dma);

  /* Setting up data transfer.*/
  SDIO->ICR   = STM32_SDIO_ICR_ALL_FLAGS;
  SDIO->MASK  = SDIO_MASK_DCRCFAILIE |
                SDIO_MASK_DTIMEOUTIE |
                SDIO_MASK_STBITERRIE |
                SDIO_MASK_RXOVERRIE |
                SDIO_MASK_DATAENDIE;
  SDIO->DLEN  = n * MMCSD_BLOCK_SIZE;

  /* Talk to card what we want from it.*/
  if (sdc_lld_prepare_read(sdcp, startblk, n, resp) == TRUE)
    goto error;

  /* Transaction starts just after DTEN bit setting.*/
  SDIO->DCTRL = SDIO_DCTRL_DTDIR |
                SDIO_DCTRL_DBLOCKSIZE_3 |
                SDIO_DCTRL_DBLOCKSIZE_0 |
                SDIO_DCTRL_DMAEN |
                SDIO_DCTRL_DTEN;
  if (sdc_lld_wait_transaction_end(sdcp, n, resp) == TRUE)
    goto error;

  return CH_SUCCESS;

error:
  sdc_lld_error_cleanup(sdcp, n, resp);
  return CH_FAILED;
Пример #2
0
/**
 * @brief   Writes one or more blocks.
 *
 * @param[in] sdcp      pointer to the @p SDCDriver object
 * @param[in] startblk  first block to write
 * @param[out] buf      pointer to the write buffer
 * @param[in] n         number of blocks to write
 *
 * @return              The operation status.
 * @retval HAL_SUCCESS  operation succeeded.
 * @retval HAL_FAILED   operation failed.
 *
 * @notapi
 */
bool sdc_lld_write_aligned(SDCDriver *sdcp, uint32_t startblk,
                           const uint8_t *buf, uint32_t blocks) {
    uint32_t resp[1];

    osalDbgCheck(blocks < 0x1000000 / MMCSD_BLOCK_SIZE);

    sdcp->sdio->DTIMER = STM32_SDC_WRITE_TIMEOUT;

    /* Checks for errors and waits for the card to be ready for writing.*/
    if (_sdc_wait_for_transfer_state(sdcp))
        return HAL_FAILED;

    /* Prepares the DMA channel for writing.*/
    dmaStreamSetMemory0(sdcp->dma, buf);
    dmaStreamSetTransactionSize(sdcp->dma,
                                (blocks * MMCSD_BLOCK_SIZE) / sizeof (uint32_t));
    dmaStreamSetMode(sdcp->dma, sdcp->dmamode | STM32_DMA_CR_DIR_M2P);
    dmaStreamEnable(sdcp->dma);

    /* Setting up data transfer.*/
    sdcp->sdio->ICR   = STM32_SDIO_ICR_ALL_FLAGS;
    sdcp->sdio->MASK  = SDIO_MASK_DCRCFAILIE |
                        SDIO_MASK_DTIMEOUTIE |
                        SDIO_MASK_STBITERRIE |
                        SDIO_MASK_TXUNDERRIE |
                        SDIO_MASK_DATAENDIE;
    sdcp->sdio->DLEN  = blocks * MMCSD_BLOCK_SIZE;

    /* Talk to card what we want from it.*/
    if (sdc_lld_prepare_write(sdcp, startblk, blocks, resp) == TRUE)
        goto error;

    /* Transaction starts just after DTEN bit setting.*/
    sdcp->sdio->DCTRL = SDIO_DCTRL_DBLOCKSIZE_3 |
                        SDIO_DCTRL_DBLOCKSIZE_0 |
                        SDIO_DCTRL_DMAEN |
                        SDIO_DCTRL_DTEN;

    if (sdc_lld_wait_transaction_end(sdcp, blocks, resp) == TRUE)
        goto error;

    return HAL_SUCCESS;

error:
    sdc_lld_error_cleanup(sdcp, blocks, resp);
    return HAL_FAILED;
}
Пример #3
0
/**
 * @brief   Reads special registers using data bus.
 * @details Needs only during card detection procedure.
 *
 * @param[in] sdcp      pointer to the @p SDCDriver object
 * @param[out] buf      pointer to the read buffer
 * @param[in] bytes     number of bytes to read
 * @param[in] cmd       card command
 * @param[in] arg       argument for command
 *
 * @return              The operation status.
 * @retval HAL_SUCCESS  operation succeeded.
 * @retval HAL_FAILED   operation failed.
 *
 * @notapi
 */
bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes,
                          uint8_t cmd, uint32_t arg) {
  uint32_t resp[1];

  if(sdc_lld_prepare_read_bytes(sdcp, buf, bytes))
    goto error;

  if (sdc_lld_send_cmd_short_crc(sdcp, cmd, arg, resp)
                                 || MMCSD_R1_ERROR(resp[0]))
    goto error;

  if (sdc_lld_wait_transaction_end(sdcp, 1, resp))
    goto error;

  return HAL_SUCCESS;

error:
  sdc_lld_error_cleanup(sdcp, 1, resp);
  return HAL_FAILED;
}