cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 SPI3 remap does not work

dimacalugari
Associate II
Posted on September 11, 2015 at 09:52

Hello everybody,

I have a problem in initialization of SPI3 in STM32f I know that the pins of SPI3 are together with JTAG pins, and i've found on the internet how to disable the JTAG pins, but it still does not work. Here is the code:

void W5500_SPI_LowLevel_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE); 
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); 
/*!< W5500_SPI_CS_GPIO, W5500_SPI_MOSI_GPIO, W5500_SPI_MISO_GPIO
and W5500_SPI_SCK_GPIO Periph clock enable */
RCC_APB2PeriphClockCmd(W5500_SPI_MOSI_GPIO_CLK | W5500_SPI_MISO_GPIO_CLK | W5500_SPI_SCK_GPIO_CLK, ENABLE);
/*!< W5500_SPI Periph clock enable */
RCC_APB1PeriphClockCmd(W5500_SPI_CLK, ENABLE);
/*!< Configure W5500_SPI pins: SCK */
GPIO_InitStructure.GPIO_Pin = W5500_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(W5500_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure W5500_SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MOSI_PIN;
GPIO_Init(W5500_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure W5500_SPI pins: MISO */
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MISO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(W5500_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< SPI 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;
// ## NEEEEEEEEEEEEEEEEEEEEED SPI init code modified for SD Card Recognize (SPI mode 0)
//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_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(W5500_SPI, &SPI_InitStructure);
/*!< Enable the W5500_SPI */
SPI_Cmd(W5500_SPI, ENABLE);
}

Please tell me what's wrong in my code. Thank you in advance. #stm32f103 #jtag #spi3
9 REPLIES 9
Amel NASRI
ST Employee
Posted on September 11, 2015 at 12:56

Hi dmitri.calugari.001,

I think that the AFIO clock isn't enabled in your code. You have to add:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

Then, check the values you provided for:

- W5500_SPI_MOSI_GPIO_CLK

- W5500_SPI_MISO_GPIO_CLK - W5500_SPI_SCK_GPIO_CLK -

W5500_SPI_SCK_PIN

-

W5500_SPI_MOSI_PIN

-

W5500_SPI_MISO_PIN

-

W5500_SPI_MISO_GPIO_PORT

-

W5500_SPI_MOSI_GPIO_PORT

-

W5500_SPI_SPI_GPIO_PORT

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

dimacalugari
Associate II
Posted on September 11, 2015 at 13:54

Mayla,

thanks for the answer, I've added the line like you have recomended, but it still does not work.

The things are defined so:

#define W5500_SPI SPI3
#define W5500_SPI_CLK RCC_APB1Periph_SPI3
#define W5500_SPI_SCK_PIN GPIO_Pin_3 /* PB.3 */
#define W5500_SPI_SCK_GPIO_PORT GPIOB /* GPIOB */
#define W5500_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOB
#define W5500_SPI_MISO_PIN GPIO_Pin_4 /* PB.4 */
#define W5500_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */
#define W5500_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOB
#define W5500_SPI_MOSI_PIN GPIO_Pin_5 /* PB.5 */
#define W5500_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */
#define W5500_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOB

Amel NASRI
ST Employee
Posted on September 11, 2015 at 16:05

Does it work if you put this line before the call of GPIO_PinRemapConfig:

RCC_APB2PeriphClockCmd(W5500_SPI_MOSI_GPIO_CLK | W5500_SPI_MISO_GPIO_CLK |\
 W5500_SPI_SCK_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

dimacalugari
Associate II
Posted on September 14, 2015 at 06:53

Dear Mayla,

I've tried so and so, before and after this line, and everytime i have this picture on the SCK line:

0690X000006034QQAQ.jpg

dimacalugari
Associate II
Posted on September 14, 2015 at 07:23

... and i have connected the lines to the logic analyser, and it looks so:

(I am sending the 0xAA byte in cycle)

0690X000006052IQAQ.png

stm32forum
Associate II
Posted on September 15, 2015 at 11:36

What version of std are you using?

Try those pins as output and just toggle them to see on the scoop if the hw is ok.

dimacalugari
Associate II
Posted on September 18, 2015 at 13:54

Everything is ok now, i have changed the prescaller to 256 and it runs very well.

Thank you for your help.

dimacalugari
Associate II
Posted on September 18, 2015 at 13:55

Everything is ok now, i have changed the prescaller to 256 and it runs very well.

Thank you for your help.

dimacalugari
Associate II
Posted on September 18, 2015 at 13:58

Everything is ok now, i have changed the prescaller to 256 and it runs very well.

Thank you for your help.