Skip to content

Commit

Permalink
Merge pull request #165 from lechndo/bug_#161_STM32_CRC_DMA_size_limit
Browse files Browse the repository at this point in the history
Fix #161: STM32 LLD CRCv1 large data bug in DMA mode
  • Loading branch information
fpoussin committed Jul 13, 2018
2 parents d86a300 + 6ac9e40 commit fe95e90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 15 additions & 5 deletions os/hal/ports/STM32/LLD/CRCv1/hal_crc_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ static void crc_lld_serve_interrupt(CRCDriver *crcp, uint32_t flags) {
/* Stop everything.*/
dmaStreamDisable(crcp->dma);

/* Portable CRC ISR code defined in the high level driver, note, it is
a macro.*/
_crc_isr_code(crcp, crcp->crc->DR ^ crcp->config->final_val);
if (crcp->rem_data_size) {
/* Start DMA follow up transfer for next data chunk */
crc_lld_start_calc(crcp, crcp->rem_data_size,
(const void *)crcp->dma->channel->CPAR+0xffff);
} else {
/* Portable CRC ISR code defined in the high level driver, note, it is a macro.*/
_crc_isr_code(crcp, crcp->crc->DR ^ crcp->config->final_val);
}
}
#endif

Expand Down Expand Up @@ -308,12 +313,17 @@ uint32_t crc_lld_calc(CRCDriver *crcp, size_t n, const void *buf) {

#if CRC_USE_DMA == TRUE
void crc_lld_start_calc(CRCDriver *crcp, size_t n, const void *buf) {
/* The STM32 DMA can only handle max 65535 bytes per transfer
* because it's data count register has only 16 bit. */
size_t sz = (n > 0xffff) ? 0xffff : n;
crcp->rem_data_size = n-sz;

dmaStreamSetPeripheral(crcp->dma, buf);
dmaStreamSetMemory0(crcp->dma, &crcp->crc->DR);
#if STM32_CRC_PROGRAMMABLE == TRUE
dmaStreamSetTransactionSize(crcp->dma, n);
dmaStreamSetTransactionSize(crcp->dma, sz);
#else
dmaStreamSetTransactionSize(crcp->dma, (n / 4));
dmaStreamSetTransactionSize(crcp->dma, (sz / 4));
#endif
dmaStreamSetMode(crcp->dma, crcp->dmamode);

Expand Down
6 changes: 6 additions & 0 deletions os/hal/ports/STM32/LLD/CRCv1/hal_crc_lld.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ struct CRCDriver {
* @brief Waiting thread.
*/
thread_reference_t thread;
/**
* @brief Remaining data size.
* @note The DMA can handle only 65535 bytes per transfer because
* it's data count register is only 16 bits wide.
*/
size_t rem_data_size;
/**
* @brief CRC DMA stream
*/
Expand Down

0 comments on commit fe95e90

Please sign in to comment.