cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107VG PB3 - PB4 - PA15 Alternate Function Usage

leventeyigel52
Associate II
Posted on July 13, 2012 at 10:37

Hello

I have to use PB3 - PB4 - PB5 alternate function for using SPI3 or SPI1

But these pins are looking on JTAG main function after reset on datasheet.

These pins are still  working on jtag main function  I can't change that.

How can I solve this problem  ?

SPI Configuration is :

 void sFLASH_Init(void)

{

  SPI_InitTypeDef SPI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  

  

//  &sharpifdef USE_STM3210C_EVAL

////  /* Enable SPI3 Pins Software Remapping */

//  GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);

//&sharpendif

  /* Configure SPI_MASTER pins: SCK, MISO and MOSI */

  GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN | sFLASH_SPI_MISO_PIN | sFLASH_SPI_MOSI_PIN;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(sFLASH_SPI_GPIO_PORT, &GPIO_InitStructure);

   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;

   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);

   

   

  /* 1 bit for pre-emption priority, 3 bits for subpriority */

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

  /* Configure and enable SPI_MASTER interrupt -------------------------------*/

  NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

 

  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_Low;

  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(sFLASH_SPI, &SPI_InitStructure);

  

 SPI_I2S_ITConfig(sFLASH_SPI, SPI_I2S_IT_TXE, ENABLE);

    /* Enable SPI_SLAVE RXNE interrupt */

  SPI_I2S_ITConfig(sFLASH_SPI, SPI_I2S_IT_RXNE, ENABLE);

    

  SPI_Cmd(sFLASH_SPI, ENABLE);

  

  sFLASH_CS_HIGH();

}

RCC Configuration :

void RCC_Configuration(void)

{

  /* PCLK2 = HCLK/2 */

  RCC_PCLK2Config(RCC_HCLK_Div2); 

/* Enable peripheral clocks --------------------------------------------------*/

&sharpifdef USE_STM3210C_EVAL

  /* Enable GPIO clock for SPI_MASTER and SPI_SLAVE */

  RCC_APB2PeriphClockCmd(sFLASH_SPI_GPIO_CLK | //SPI_SLAVE_GPIO_CLK |

                         RCC_APB2Periph_AFIO, ENABLE);

  

   RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | RCC_APB2Periph_AFIO ,ENABLE);

   

  /* Enable SPI_MASTER Periph clock */

  RCC_APB1PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);  

&sharpendif

}

Pin Defines are :

  &sharpdefine sFLASH_SPI                                  SPI3

  &sharpdefine sFLASH_SPI_CLK                        RCC_APB1Periph_SPI3

  &sharpdefine sFLASH_SPI_SCK_PIN               GPIO_Pin_3                  

  &sharpdefine sFLASH_SPI_MISO_PIN             GPIO_Pin_4                  

  &sharpdefine sFLASH_SPI_MOSI_PIN             GPIO_Pin_5                  

  &sharpdefine sFLASH_CS_PIN                          GPIO_Pin_1                

  &sharpdefine sFLASH_SPI_GPIO_PORT          GPIOB                       

  &sharpdefine sFLASH_SPI_GPIO_CLK              RCC_APB2Periph_GPIOB

  &sharpdefine sFLASH_CS_GPIO_PORT             GPIOE

  &sharpdefine sFLASH_CS_GPIO_CLK               RCC_APB2Periph_GPIOE

#spi #jtag-pb4-remap #stm32
13 REPLIES 13
devcal
Associate II
Posted on July 13, 2012 at 12:19

Hi, I'm using the same MCU and I found some register calculations mistakes for the AF using GPIOI and SPI2. maybe could be the same. check the register value after setting the AF.

my post is here

/33f7a5db

 

regards

leventeyigel52
Associate II
Posted on July 13, 2012 at 13:00

I can use SPI2 normally 

But I have to use SPI1 or SPI3 , so these pins are jtag pins at the main function after reset,  i try to use normally I/O pin .

So I have to Remap these pins  for usage I/O .

Posted on July 13, 2012 at 13:54

I'm using the same MCU and I found some register calculations mistakes for the AF using GPIOI and SPI2. maybe could be the same. check the register value after setting the AF.

You aren't using the same MCU, the F107 uses unit based peripheral remapping, L1xx, F2xx and F4xx use PIN based remapping. Your problem related to a common coding error.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
leventeyigel52
Associate II
Posted on July 13, 2012 at 15:17

Clive 

How can i remap these pins from jtag to use SPI pins ? I couldn't use SPI related to this problem 

I can't find any command about this 

  /* Enable GPIO clock for SPI_MASTER and SPI_SLAVE */

  RCC_APB2PeriphClockCmd(sFLASH_SPI_GPIO_CLK | //SPI_SLAVE_GPIO_CLK |

                         RCC_APB2Periph_AFIO, ENABLE);

  

   RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | RCC_APB2Periph_AFIO ,ENABLE);

   

  /* Enable SPI_MASTER Periph clock */

  RCC_APB1PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);  

///////////////////////////////////////////////////////////////////////////////

SPI_InitTypeDef SPI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

 /* Configure SPI_MASTER pins: SCK, MISO and MOSI */

  GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN | sFLASH_SPI_MISO_PIN | sFLASH_SPI_MOSI_PIN;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(sFLASH_SPI_GPIO_PORT, &GPIO_InitStructure);

   GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;

   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

   GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);

Where i do mistake ?

Posted on July 13, 2012 at 16:38

For GPIO it works like this

/* Disable the Serial Wire Jtag Debug Port SWJ-DP */
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
/* Configure PA.13 (JTMS/SWDAT), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as
output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_Init(GPIOB, &GPIO_InitStructure);

You might be able to use GPIO_Remap_SWJ_JTAGDisable as it's just the JTAG pins you want to free up, and providing you only connect the SWD signals to your debug header.

GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(sFLASH_SPI_GPIO_CLK | sFLASH_CS_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE); // GPIOB & GPIOE
/* Enable SPI_MASTER Periph clock */
RCC_APB1PeriphClockCmd(sFLASH_SPI_CLK, ENABLE); // SPI3 
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // Requires AFIO clock enabled, Map JTAG Off pins PB3,4,5, SWD still viable on PA13,14
/* Configure SPI3 pins: SCK, MISO and MOSI PB3,4,5 */
GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN | sFLASH_SPI_MISO_PIN | sFLASH_SPI_MOSI_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(sFLASH_SPI_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN; // PE.1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
leventeyigel52
Associate II
Posted on July 16, 2012 at 09:57

It works clive thanks alot 

devilar
Associate
Posted on January 03, 2013 at 03:41

Guy's try this magic sequence. And remember that JTAG pins should be the last in remap sequence, because it's not able to read them.

GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);    

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);  

mateusz
Associate
Posted on January 22, 2015 at 10:32

Thank You it actually works great !

enhee2706
Associate
Posted on January 05, 2016 at 03:12

thank you clive 1