Skip to content

Commit

Permalink
SDMMCv1: added DMA bouncebuffer
Browse files Browse the repository at this point in the history
    
this allows SDMMCv1 to be used on STM32F7 where DMA safe memory is needed
  • Loading branch information
tridge committed Jun 3, 2018
1 parent 8043e9e commit 57d6259
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c
Expand Up @@ -28,6 +28,8 @@

#if HAL_USE_SDC || defined(__DOXYGEN__)

#include "bouncebuffer.h"

/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
Expand Down Expand Up @@ -756,6 +758,8 @@ bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes,
uint8_t cmd, uint32_t arg) {
uint32_t resp[1];

bouncebuffer_setup_read(sdcp->bouncebuffer, &buf, bytes);

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

Expand All @@ -766,9 +770,12 @@ bool sdc_lld_read_special(SDCDriver *sdcp, uint8_t *buf, size_t bytes,
if (sdc_lld_wait_transaction_end(sdcp, 1, resp))
goto error;

bouncebuffer_finish_read(sdcp->bouncebuffer, buf, bytes);

return HAL_SUCCESS;

error:
bouncebuffer_finish_read(sdcp->bouncebuffer, buf, 0);
sdc_lld_error_cleanup(sdcp, 1, resp);
return HAL_FAILED;
}
Expand Down Expand Up @@ -799,6 +806,8 @@ bool sdc_lld_read_aligned(SDCDriver *sdcp, uint32_t startblk,
if (_sdc_wait_for_transfer_state(sdcp))
return HAL_FAILED;

bouncebuffer_setup_read(sdcp->bouncebuffer, &buf, blocks * MMCSD_BLOCK_SIZE);

/* Prepares the DMA channel for writing.*/
dmaStreamSetMemory0(sdcp->dma, buf);
dmaStreamSetTransactionSize(sdcp->dma,
Expand Down Expand Up @@ -827,9 +836,12 @@ bool sdc_lld_read_aligned(SDCDriver *sdcp, uint32_t startblk,
if (sdc_lld_wait_transaction_end(sdcp, blocks, resp) == true)
goto error;

bouncebuffer_finish_read(sdcp->bouncebuffer, buf, blocks * MMCSD_BLOCK_SIZE);

return HAL_SUCCESS;

error:
bouncebuffer_finish_read(sdcp->bouncebuffer, buf, 0);
sdc_lld_error_cleanup(sdcp, blocks, resp);
return HAL_FAILED;
}
Expand Down Expand Up @@ -860,6 +872,8 @@ bool sdc_lld_write_aligned(SDCDriver *sdcp, uint32_t startblk,
if (_sdc_wait_for_transfer_state(sdcp))
return HAL_FAILED;

bouncebuffer_setup_write(sdcp->bouncebuffer, &buf, blocks * MMCSD_BLOCK_SIZE);

/* Prepares the DMA channel for writing.*/
dmaStreamSetMemory0(sdcp->dma, buf);
dmaStreamSetTransactionSize(sdcp->dma,
Expand Down Expand Up @@ -888,9 +902,12 @@ bool sdc_lld_write_aligned(SDCDriver *sdcp, uint32_t startblk,
if (sdc_lld_wait_transaction_end(sdcp, blocks, resp) == true)
goto error;

bouncebuffer_finish_write(sdcp->bouncebuffer, buf);

return HAL_SUCCESS;

error:
bouncebuffer_finish_write(sdcp->bouncebuffer, buf);
sdc_lld_error_cleanup(sdcp, blocks, resp);
return HAL_FAILED;
}
Expand Down
3 changes: 3 additions & 0 deletions os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.h
Expand Up @@ -350,6 +350,9 @@ struct SDCDriver {
* @note Needed for debugging aid.
*/
SDMMC_TypeDef *sdmmc;

// bouncebuffer to support DMA to all memory regions
struct bouncebuffer_t *bouncebuffer;
};

/*===========================================================================*/
Expand Down

0 comments on commit 57d6259

Please sign in to comment.