2012-07-13 01:37 AM
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 #stm322012-07-13 03:19 AM
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
regards2012-07-13 04:00 AM
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 .2012-07-13 04:54 AM
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.2012-07-13 06:17 AM
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 ?2012-07-13 07:38 AM
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);
2012-07-16 12:57 AM
It works clive thanks alot
2013-01-02 06:41 PM
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);2015-01-22 01:32 AM
Thank You it actually works great !
2016-01-04 06:12 PM
thank you clive 1