cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 discovery GPIO remapping

defacato
Associate II
Posted on May 08, 2015 at 22:22

Hi everyone from London in the UK.

My name is Steve. I have an STM32 F4 discovery board and am attempting to get I2S and the audio codec working for the STM32Duino project. The project is the brainchild of Roger Clark from Melbourne and gives Arduino IDE capability to the discovery board. I am trying to get I2S working and am wracking my brains on how to remap SPI3 to the pins for the I2S. I have been looking at the reference manual and in particular the GPIO alternate function registers. I need some help in understanding how I would remap the SPI 3 to the I2S pins using bare metal code. Could someone please help me with this? 
2 REPLIES 2
Posted on May 08, 2015 at 22:42

For pin/peripheral associations you want the Data Sheet

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf

The mux settings for each pin in a GPIO bank are described by 4 bits giving 16 possible combinations. Far fewer choices actually exist. You'd mask off the 4-bits for the pin in the AFR and set the peripheral selection into them.

For AF2 on to PA0 for example, something like

GPIOA->AFR[0] = (GPIOA->AFR[0] & ~0x0F) | 0x02;

 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
defacato
Associate II
Posted on May 09, 2015 at 17:07 Hi Clive and thanks for the help. OK, so For AF2 on to PA0 for example, something like GPIOA->AFR[0] = (GPIOA->AFR[0] & ~0x0F) | 0x02; will set PA0 to the peripheral function on AF2. In the gpio.c file that is included in the libmaple distribution is a function that looks like this:

void gpio_set_af_mode(gpio_dev *dev, uint8 pin, int mode) {
gpio_reg_map *regs = dev->regs;
regs->AFR[pin/8] = (regs->AFR[pin/8] & ~(15 << (4*(pin&7)))) | (((mode >> 0) & 15) << (4*(pin&7)));
}

the gpio_dev points to the port (GPIOx), the pin is the pin and the mode... so does the mode look to you like its setting the AFR[x] registers? If so, the alternate function remap for SPI3 is on AF6, so I'm guessing I would use this function like this: gpio_set_af_mode (GPIOC,10,6); if I wanted to set the SCK of SPI3 on C does it look right?