Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SDFileSystemDMA-test DmdFullRGB_0_1
Fork of SDFileSystemDMA by
spi_dma_common.c
00001 #include "spi_dma.h" 00002 #include "PeripheralPins.h" 00003 00004 DMA_HandleTypeDef hdma_spi_tx; 00005 DMA_HandleTypeDef hdma_spi_rx; 00006 SPI_HandleTypeDef SpiHandle; 00007 00008 static void spi_dma_error_handler(void) 00009 { 00010 while(1) 00011 { 00012 /* infinite loop */ 00013 } 00014 } 00015 00016 static void spi_dma_start( SPI_TypeDef *spi, uint8_t *txbuff, uint8_t *rxbuff, uint16_t count) 00017 { 00018 (void)spi; 00019 if( HAL_SPI_TransmitReceive_DMA( &SpiHandle, (uint8_t *)txbuff, (uint8_t *)rxbuff, count) != HAL_OK) { 00020 spi_dma_error_handler(); 00021 } 00022 } 00023 00024 static void spi_dma_wait_end( SPI_TypeDef *spi ) 00025 { 00026 (void)spi; 00027 while (HAL_SPI_GetState( &SpiHandle ) != HAL_SPI_STATE_READY) { 00028 /* just wait */ 00029 } 00030 } 00031 00032 static void spi_dma_deinit( SPI_TypeDef *spi) 00033 { 00034 (void)spi; 00035 HAL_DMA_DeInit( &hdma_spi_tx); 00036 HAL_DMA_DeInit( &hdma_spi_rx); 00037 } 00038 00039 SPI_TypeDef *spi_get_id( PinName mosi, PinName miso, PinName sclk, PinName ssel) { 00040 // Determine the SPI to use 00041 SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI); 00042 SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO); 00043 SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK); 00044 SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL); 00045 00046 SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); 00047 SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); 00048 00049 return (SPI_TypeDef *) ( (SPIName)pinmap_merge(spi_data, spi_cntl) ); 00050 } 00051 00052 void spi_dma_init( SPI_TypeDef *spi ) { 00053 spi_dma_irq_setup( spi ); 00054 spi_dma_get_info( spi ); 00055 } 00056 00057 void __spi_dma_read_write( SPI_TypeDef *spi, uint8_t *txbuff, uint8_t *rxbuff, uint16_t count, uint8_t mode) 00058 { 00059 spi_dma_handle_setup( spi, mode ); 00060 spi_dma_start( spi, txbuff, rxbuff, count ); 00061 spi_dma_wait_end( spi ); 00062 spi_dma_deinit(spi); 00063 } 00064
Generated on Fri Jul 15 2022 11:45:50 by
1.7.2
