2014-02-06 03:02 PM
I'm using a DMA for the first time (on a STM32F427), and am having a bit of trouble: I don't see SCK on any of my four SPIs when trying to transfer data via the DMA (specifically, I've only tried on the Tx side so far). I tested the SPIs separately, by simply doing a while loop while constantly calling SPI_I2S_SendData(SPI1, 0x77), and it works fine: I see SCK, and data on the MOSI. But when I try to use the DMA, I see no pulses on SCK or data being moved. What's strange is that the ''transfer complete'' ISRs I have enabled are triggering.
Long story short: should I not expect to see SCK when transferring data from memory to the SPI via DMA? Sorry for not posting my code; I left my laptop at work. I can post that tomorrow morning if necessary. Thanks! #stm32 #spi #dma2014-02-07 11:29 AM
2014-02-07 02:07 PM
#define SPI2_SCK_PIN GPIO_Pin_3
#define SPI2_SCK_SOURCE GPIO_PinSource3#define SPI2_SCK_GPIO_PORT GPIOD#define SPI2_SCK_GPIO_CLK RCC_AHB1Periph_GPIODUnderstand you can't just make this stuff up, the connectivity has to be defined in the silicon. PD3 is NOT an SPI2_SCK exit point.2014-02-09 07:58 AM
http://www.st.com/web/en/resource/technical/document/datasheet/DM00071990.pdf
Page 65.2014-02-10 06:56 AM
Point taken, the F429 has additional routing, but still appears to function, clock is demonstrable on PD3
// STM32F429I-DISCO SPI2 TX DMA Demo - sourcer32@gmail.com
// SPI2 45 MHz, /256 175725 Hz
#include <
stdio.h
>
#include <
stdlib.h
>
#include ''stm32f429i_discovery.h''
//****************************************************************************
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOB and GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD, ENABLE);
/* SPI SCK/MISO/MOSI pin configuration */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource3, GPIO_AF_SPI2); // PD3 SPI2_CLK (F427/F429 Parts)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2); // PB14 SPI2_MISO
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2); // PB15 SPI2_MOSI
}
//****************************************************************************
void SPI_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
/* SPI configuration */
SPI_I2S_DeInit(SPI2);
/* Initializes the SPI communication */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI2, &SPI_InitStructure);
/* The Data transfer is performed in the SPI using Direct Memory Access */
/* Enable DMA SPI TX Stream */
DMA_Cmd(DMA1_Stream4, ENABLE);
/* Enable SPI DMA TX Requsts */
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE);
/* Enable the SPI peripheral */
SPI_Cmd(SPI2, ENABLE);
}
//****************************************************************************
uint8_t TxBuffer[] = ''The quick brown fox jumps over the lazy dog'';
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* DMA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
// DMA1 Channel0 Stream4 SPI2_TX
DMA_DeInit(DMA1_Stream4);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&SPI2->DR);
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&TxBuffer[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = sizeof(TxBuffer) - 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream4, &DMA_InitStructure);
/* Enable DMA Stream Transfer Complete interrupt */
DMA_ITConfig(DMA1_Stream4, DMA_IT_TC, ENABLE);
}
//****************************************************************************
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the DMA gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//****************************************************************************
void DMA1_Stream4_IRQHandler(void)
{
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA1_Stream4, DMA_IT_TCIF4))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA1_Stream4, DMA_IT_TCIF4);
/* Toggle LED3 */
STM_EVAL_LEDToggle(LED3);
}
}
//****************************************************************************
int main(void)
{
/* Initialize Leds mounted on STM32F429I-DISCO board */
STM_EVAL_LEDInit(LED3);
/* Turn on LED3 */
STM_EVAL_LEDOn(LED3);
NVIC_Configuration();
GPIO_Configuration();
DMA_Configuration();
SPI_Configuration();
while(1); // Do not exit
}
//****************************************************************************
// Rough SWV support in Keil, STM32F429I-DISCO, Make SB9 to connect PB3/SWO
//****************************************************************************
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
ITM_SendChar(ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
ch = 1;
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
ITM_SendChar(ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
//******************************************************************************
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d
'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
//******************************************************************************