WIZnet Developer Forum

[w5500] stm32f405 SPI3 DMA 설정

안녕하세요 w5500을 가지고 펌웨어를 개발하고 있는 개발자 입니다.

사용하고 있는 MCU는 STM32f405이고 SPI3을 가지고 w5500과 DMA를 통하여 통신을 할려고 합니다.

DMA_InitTypeDef DMA_InitStructure; // DMA clock enable
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef  SPI_InitStructure;
      
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC , ENABLE); // GPIO Clock Enable
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 , ENABLE);
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3 , ENABLE);	//Ethernet MAC/PHY.          
      
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_Init(GPIOC, &GPIO_InitStructure);          
      
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3);	//CLK.
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SPI3);	//MISO. 
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3);	//MOSI.

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // Data Size
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // SIG Edge
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; // Sig Phaser
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // CS 
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;	// 21Mhz (@ APB1: 40.96MHz).
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // MSB
SPI_InitStructure.SPI_CRCPolynomial = 7; // CRC
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;// SPI Master
SPI_Init(SPI3, &SPI_InitStructure);
      
DMA_DeInit(DMA1_Stream7);	// SPI3_TX event.
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = SPI3_DR;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)gbSpi3TxBuf;
DMA_InitStructure.DMA_BufferSize = 32;
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_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream7, &DMA_InitStructure);

DMA_DeInit(DMA1_Stream0);	// SPI3_RX event.
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = SPI3_DR;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_BufferSize = 32;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)gbSpi3RxBuf;
DMA_Init(DMA1_Stream0, &DMA_InitStructure);            
      
      DMA_Cmd(DMA1_Stream0 , ENABLE);
      DMA_Cmd(DMA1_Stream7 , ENABLE);

      SPI3_CS_ETH = 0;
      ETH_RST = 1;
      ADC_SOC = 1;
      
      SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Rx | SPI_I2S_DMAReq_Tx, ENABLE);          
      SPI_Cmd(SPI3,ENABLE);

세팅은 위와 같이 하여주었고

fcLanSndByte(0xD8, PHYCFGR);	//100BT Full-duplex, Auto-negotiation disabled.
delay_ms(MSSECOND);
fcLanSndByte(0x58, PHYCFGR);	//100BT Full-duplex, Auto-negotiation disabled. with Reset.
delay_ms(MSSECOND);
fcLanSndByte(0xD8, PHYCFGR);	//100BT Full-duplex, Auto-negotiation disabled.
delay_ms(MSSECOND);

해당내용과 같이 초기화를 진행할려고 합니다.
fcLanSndByte 함수는 아래와 같습니다.

void fcLanSndByte(uint8_t data, uint32_t Addr)
{
gbSpi3TxBuf[0] = (Addr >>16) & 0xff;
gbSpi3TxBuf[1] = (Addr >>8) & 0xff;
gbSpi3TxBuf[2] = (Addr & 0xf8) + 4;
gbSpi3TxBuf[3] = data;
fcSpi3Dma(gbSpi3TxBuf, NULL, 4);
while( (SPI3->SR & (SPI_BUSY | SPI_TXE)) != SPI_TXE )
}
SPI와 통신이 잘되지 않는데 도저히 어느 부분이 잘못되었는지 찾기가 힘드네요.

그리고 DMA는 DMA1 Stream 0과 7을 사용하였습니다.

감사합니다.

증상은 DR레지스터에 값이 쓰이질 않고

SPI 3 TX Stream의 Enable이 Set이 디버깅 화면에서 안되는것 처럼 보입니다.

오실로스코프로 파형을 찍으면 해당하는 Data가 출력되는것은 확인 했습니다.

많은 도움 부탁드리겠습니다.

W5100S-EVB MUC가 stm32f103vc이며 DMA 프로젝트가 있습니다.


위의 프로젝트를 참고 하시면 좋을 것같습니다.

올려주신 code는 확인하는데 시간이 좀 걸릴 것 같습니다.
추후 확인 후 다시 답변드리겠습니다.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.