AnsweredAssumed Answered

SPI3 conflict with JATG on stm32f103RET

Question asked by patiar.ali on Jun 16, 2015
Latest reply on Jun 18, 2015 by patiar.ali
I saw lots of discussions and solutions about working with SPI3 by disabling JTAG on STM32F103 devices. But I already have problem with it.
I am using SWD for program and debug the mcu with Keil and the same code is working flawlessly for SPI1/SPI2.

here is my initialization code:

#define SD_SCK_PIN          GPIO_Pin_3
#define SD_SCK_PRT          GPIOB
#define SD_MOSI_PIN          GPIO_Pin_5
#define SD_MOSI_PRT          GPIOB
#define SD_MISO_PIN          GPIO_Pin_4
#define SD_MISO_PRT          GPIOB
#define SD_CS_PIN          GPIO_Pin_7
#define SD_CS_PRT          GPIOC
#define SD_SPI                SPI3

void SPI_SDMode(void)
     SPI_InitTypeDef  SPI_InitStructure;
     GPIO_InitTypeDef GPIO_InitStructure;

     RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB |      RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO ,ENABLE );
     RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI3,ENABLE );
     /* PB3=CLK, PB4=MISO, PB5=MOSI alternate function */
     GPIO_InitStructure.GPIO_Pin =  SD_SCK_PIN | SD_MOSI_PIN |      GPIO_Mode_IPU;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
     GPIO_Init(SD_SCK_PRT, &GPIO_InitStructure); 
     /* Configure PC7 as CS  open drain push-pull output */
     GPIO_SetBits(SD_CS_PRT, SD_CS_PIN); //set high.
     GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
     GPIO_Init(SD_CS_PRT, &GPIO_InitStructure); 
     /* SPI configuration */
     SPI_Cmd(SD_SPI, DISABLE); //disable SPI for configuration.
     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;          
     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;                              
     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;                    
     SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;                                        
     SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;                              
     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;                                        
     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;     
     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;                         
     SPI_InitStructure.SPI_CRCPolynomial = 7;                                        
     SPI_Init(SD_SPI, &SPI_InitStructure);
     /* Enable SPI  */
     GPIO_SetBits(SD_CS_PRT, SD_CS_PIN);
     /* Loop while DR register in not emplty */
         while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET);
     /* Send byte through the SPI peripheral */
         SPI_I2S_SendData(SD_SPI, 0xff);

     /* Wait to receive a byte */
         while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET);
         /* Return the byte read from the SPI bus */
     GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);    
     GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);   

can anyone help me with this matter?