2015-05-08 01:22 PM
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?2015-05-08 01:42 PM
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 likeGPIOA->AFR[0] = (GPIOA->AFR[0] & ~0x0F) | 0x02;2015-05-09 08:07 AM
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?