7134956

Untitled

Sep 25th, 2021
1,093
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef USE_DMA
  2. inline void sFLASH_DMA_Init(void) {
  3.     /* Enable the DMA peripheral */
  4.     sFLASH_DMA_CLK_ENR |= sFLASH_DMA_CLK;
  5.     // Set DMA peripheral addres
  6.     sFLASH_DMA_TX_STREAM->CPAR = (uint32_t)&(sFLASH_SPI->DR);
  7.     sFLASH_DMA_RX_STREAM->CPAR = (uint32_t)&(sFLASH_SPI->DR);
  8. }
  9.  
  10. void sFLASH_DMA_End(void){
  11.     // Wait until the data is received
  12.     while ((sFLASH_DMA->sFLASH_DMA_ISR & sFLASH_DMA_RX_FLAG_TC) == RESET)
  13.         ;
  14.  
  15.     //Disable the DMAs
  16.     sFLASH_DMA_TX_STREAM->CCR = 0; // TX
  17.     sFLASH_DMA_RX_STREAM->CCR = 0; // RX
  18.  
  19.     //Clear DMA flags
  20.     sFLASH_DMA->sFLASH_DMA_IFCR = sFLASH_DMA_TX_FLAG_GL | sFLASH_DMA_RX_FLAG_GL;
  21. }
  22.  
  23. void sFLASH_DMA_Tx(uint32_t cmdLen, const uint8_t *cmdBuf) {
  24.     //Настраиваем и включаем нелепый поглотитель мусорных данных
  25.     sFLASH_DMA_RX_STREAM->CNDTR = cmdLen;
  26.     sFLASH_DMA_RX_STREAM->CMAR = (uint32_t) &trash;
  27. #ifdef STM32F40_41xxx
  28.     sFLASH_DMA_RX_STREAM->CCR = DMA_CCR_EN | sFLASH_DMA_RX_CHANNEL;
  29. #else
  30.     sFLASH_DMA_RX_STREAM->CCR = DMA_CCR_EN; // RX
  31. #endif
  32.     //Настраиваем и запускаем передачу
  33.     sFLASH_DMA_TX_STREAM->CNDTR = cmdLen;
  34.     sFLASH_DMA_TX_STREAM->CMAR = (uint32_t) cmdBuf;
  35. #ifdef STM32F40_41xxx
  36.     sFLASH_DMA_TX_STREAM->CCR = DMA_CCR_EN | DMA_CCR_MINC | DMA_SxCR_DIR_0 | sFLASH_DMA_TX_CHANNEL;
  37. #else
  38.     sFLASH_DMA_TX_STREAM->CCR = DMA_CCR_EN | DMA_CCR_MINC | DMA_CCR_DIR;
  39. #endif
  40.     sFLASH_DMA_End();
  41. }
  42.  
  43. void sFLASH_DMA_Rx(uint32_t dataLen, uint8_t *dataBuf) {
  44.  
  45.     // Prepare the DMA TX and RX
  46.     sFLASH_DMA_RX_STREAM->CNDTR = dataLen;
  47.     sFLASH_DMA_RX_STREAM->CMAR = (uint32_t) dataBuf;
  48. #ifdef STM32F40_41xxx
  49.     sFLASH_DMA_RX_STREAM->CCR = DMA_CCR_EN | DMA_CCR_MINC | sFLASH_DMA_RX_CHANNEL;
  50. #else
  51.     sFLASH_DMA_RX_STREAM->CCR = DMA_CCR_EN | DMA_CCR_MINC;
  52. #endif
  53.     //Настраиваем и запускаем передачу
  54.     sFLASH_DMA_TX_STREAM->CNDTR = dataLen;
  55.     sFLASH_DMA_TX_STREAM->CMAR = (uint32_t) &dummy;
  56. #ifdef STM32F40_41xxx
  57.     sFLASH_DMA_TX_STREAM->CCR = DMA_CCR_EN | DMA_SxCR_DIR_0 | sFLASH_DMA_TX_CHANNEL;
  58. #else
  59.     sFLASH_DMA_TX_STREAM->CCR = DMA_CCR_EN | DMA_CCR_DIR;
  60. #endif
  61.     sFLASH_DMA_End();
  62. }
  63. #endif /* USE_DMA */
RAW Paste Data