cancel
Showing results for 
Search instead for 
Did you mean: 

SPI1 MOSI pin won't remap to SPI3

mike2399
Associate II
Posted on December 04, 2014 at 16:23

Hi.

I'm using STM32F101RBT6 in a project, with custom PCB.  I need to remap the SPI1 signals to pins PB3/4/5 (which would be SPI3, only STM32F101 doesn't have one).  I also use remap to disable JTAG to free-up PB3/4 for this.  The ''normal'' SPI1 GPIO pins are in use for something else - driven directly by software.

I find that I can output SCK on PB3 as expected, but MOSI on PB5 seems stuck high.  All register contents seem correct when viewed.  If I disable remap and set the required pins to AF mode I can get the expected outputs from the SPI1 pins (PA5/6/7).  I can also set PB5 to GPIO output and drive it correctly.

I am using SPL version 3.4.0 and Ride7 IDE.

Are there any silicon or library bugs I should be aware of?

Any clues?

many thanks,

Mike.
10 REPLIES 10
mike2399
Associate II
Posted on December 05, 2014 at 12:55

I think I've found my answer from the STM32f1xx errata sheets:

2.8.7 I2C1 with SPI1 remapped and used in master mode

Conditions

• I2C1 and SPI1 are clocked.

• SPI1 is remapped.

• I/O port pin PB5 is configured as an alternate function output.

Description

Conflict between the SPI1 MOSI signal and the I2C1 SMBA signal (even if SMBA is not used).

Workaround

Do not use SPI1 remapped in master mode and I2C1 together.

When using SPI1 remapped, the I2C1 clock must be disabled.

Not overly helpful if you are using I2C as well.  I will see if I can get the SPI to work if I temporarily disable the I2C peripheral, then re-enable it after I've finished the SPI operation.

I will post again if it works or not, as it could help others with the same problem.

In the meantime, I wrote a simple function to just bash bits out of the SPI3 pins as standard GPIO.  Problem is, it's a bit slow to read/write a whole page of EEPROM, as, by the time I've called functions to set/reset GPIO pins the data rate is only a few 100kHz!  I could probably write faster code bypassing the SPL, but life's too short!

aubin
Associate II
Posted on August 07, 2015 at 09:32

hi Mike,

i  have the same problem when sending data through spi1 . Using a scope I see the MOSI waves, the CS but no clk.

I disable the clock I2C but nothing change

please do yo have any ideas to help me ?

Thanks very much in advance 

John F.
Senior
Posted on August 07, 2015 at 13:21

Wouldn't it be better to bit-bash the I2C which is probably going to run at 100kHz anyway?

aubin
Associate II
Posted on August 07, 2015 at 14:06

hi John F,

Thanks for your reply

This is my configuration of SPI1

/***********************************************************************

 ******************************************************************************/

void vSPI1_RCC_Configuration(void)

{

    /*SPI1 clocks enable */

     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

    /* GPIOB, GPIOA clocks enable */

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, DISABLE);

}

/***************************************************************************//**

 @brief Configure GPIO settings

 ******************************************************************************/

void vSPI1_GPIO_Configuration(void)

{

    /* Enable SPI1 Pins Software Remapping */

    GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);

    /* Configure SPI1 pins: SCK*/

    SPI1_GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5 ;

    SPI1_GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

    SPI1_GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOA, &SPI1_GPIO_InitStructure);

    /* Configure SPI1 pins: MISO -------------------------------*/

        SPI1_GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6 ;

        SPI1_GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

        SPI1_GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_Init(GPIOA, &SPI1_GPIO_InitStructure);

    /* Configure SPI1 pins:  Chip Select -------------------------------*/

    SPI1_GPIO_InitStructure.GPIO_Pin   =  GPIO_Pin_4;                                    /*  SPI chip select pin.*/

    SPI1_GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;

    SPI1_GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOA, &SPI1_GPIO_InitStructure);

    /* Configure SPI1 pins: MOSI-------------------------------*/

    SPI1_GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5;

    SPI1_GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

    SPI1_GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &SPI1_GPIO_InitStructure);

}

void vSPI1_NVIC_Configuration(void)

{

    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

    /* SPI1 IRQ Channel configuration */

    NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;

    NVIC_Init(&NVIC_InitStructure);

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

    NVIC_SetPriorityGrouping(0);

}

void vSPI1_Initialization(void)

{

    SPI_I2S_DeInit(SPI1);

    /* SPI1 Master configuration */

    SPI1_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // set to full duplex mode, separate MOSI and MISO lines

    SPI1_InitStructure.SPI_Mode = SPI_Mode_Master;             // configuration for Master mode

    SPI1_InitStructure.SPI_DataSize = SPI_DataSize_8b;                // one packet of data is 8 bits wide

    SPI1_InitStructure.SPI_CPOL = SPI_CPOL_High;                    /*SPI compatible interface is configured to operate in a system using CPHA = 1 and CPOL = 1*/

    SPI1_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

    SPI1_InitStructure.SPI_NSS  = SPI_NSS_Soft ;

    SPI1_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256 ;             // SPI frequency is APB2 frequency / 4  ==>32Mhz/4= 8Mhz

    SPI1_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

    SPI1_InitStructure.SPI_CRCPolynomial = 7;

    SPI_Init(SPI1, &SPI1_InitStructure);

    /* Enable SPI1 */

    SPI_Cmd(SPI1, ENABLE);

}

using the scope, i just the MOSI, CS but not clk

what is the problem of this ?.

thanks,

Zoubi

John F.
Senior
Posted on August 10, 2015 at 09:12

Zoubi, you don't say what device you're targeting. For an STM32F4 series you would enable the SPI1 clock on pin A,5 with (note AHB1),

void RCC_Configuration_Spi1(void)
{
//for SPI1 enable SPI peripheral clock and GPIO clocks for selected pins
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
}

I didn't check the rest of your initialisation ... but I think you should.
aubin
Associate II
Posted on August 11, 2015 at 08:51

Dear John,

sorry if i did not say what device i was targeting for . i use STM32F107VCT6 , then to enable clock i use  

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

i read ERRATA STM32F10xxB

I2C1 with SPI1 remapped and used in master mode

Conditions

• I2C1 and SPI1 are clocked.

• SPI1 is remapped.

• I/O port pin PB5 is configured as an alternate function output.

Description

Conflict between the SPI1 MOSI signal and the I2C1 SMBA signal (even if SMBA is not used).

Workaround

Do not use SPI1 remapped in master mode and I2C1 together.

When using SPI1 remapped, the I2C1 clock must be disabled.

but nothing change when i disabled the I2C1

John F.
Senior
Posted on August 11, 2015 at 13:41

OK I see there's no AHB and SPI and GPIO are on APB2.

You enable remapping which puts signals as Remap (NSS/PA15, SCK/PB3, MISO/PB4, MOSI/PB5).

Yet you configure GPIO for SCK/PA5, MISO/PA6, MOSI/PB5. Seems all mixed up.

aubin
Associate II
Posted on August 12, 2015 at 08:54

Ok,

Thanks

however please how to resolve that ?

John F.
Senior
Posted on August 12, 2015 at 09:18

According to the Reference Manual RM0008, you can map SPI1 to either,

NSS/PA4, SCK/PA5, MISO/PA6, MOSI/PA7

or

NSS/PA15, SCK/PB3, MISO/PB4, MOSI/PB5

You have to choose one group or the other and configure your GPIO pins accordingly. You can't mix them.

0: No remap (NSS/PA4, SCK/PA5, MISO/PA6, MOSI/PA7)

1: Remap (NSS/PA15, SCK/PB3, MISO/PB4, MOSI/PB5)

9.4.2 AF remap and debug I/O configuration register (AFIO_MAPR)