Clock settings for the STM32 E407 [SOLVED]

Started by sparcz, September 20, 2012, 06:03:23 PM

Previous topic - Next topic


I have built an RS232 shield to my E407 board, but don't seem to be able to make it work. The olimex protoshields has the Rx and Tx from PB7 and PB6 which I configure for USART 1 (AF7). I suspect that it could be the clocks that aren't properly set up. The source I have used comes from examples on the Discovery board, and I don't know if the clock setup is identical. Is it?



// This example requires STM32F4xx StdPeriph Lib
#include "stm32f4xx.h"

//descri:   Setup USART and config
//params:    void
//return:    none
void USART_Configuration(void)
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  // clock enable  -----------------------------------------------------------
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

  // In order to reach higher communication baudrates, it is possible to
  // enable the oversampling by 8 mode using the function USART_OverSampling8Cmd().
  //USART_OverSampling8Cmd(USART1,ENABLE); // DONT use if you are only using < 115200 BaudRate   
  //USART1 GPIO --------------------------------------------------------------
  //PB6   USART1_TX
  //PB7   USART1_RX   
  // Connect USART1 pins to AF7
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6 , GPIO_AF_USART1);
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7 , GPIO_AF_USART1);
  // Configure USART Tx and Rx as alternate function push-pull
  GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd    = GPIO_PuPd_NOPULL; // use GPIO_PuPd_UP if needed
  GPIO_InitStructure.GPIO_Pin    = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  // USART1 Configuration -----------------------------------------------------
  USART_InitStructure.USART_BaudRate = 38400;  // or what ever
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(USART1, &USART_InitStructure);
  // Enable the USART Interrupts - ONLY IF YOU ARE USING UART INTs, IF SO YOU NEED "USART1_IRQHandler"
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  // Enable USART1 Receive and Transmit interrupts - ONLY IF YOU ARE USING UART INTs, IF SO YOU NEED  "USART1_IRQHandler"
  //USART_ITConfig(USART1, USART_IT_TXE, ENABLE); // Transmit interrupt is activated upon sending of data

  // Enable the USART1


I tried to compile and run the example above, but it doesn't seem to work on my board. I have verified my shield using an AVR board, so I know that the function there is correct. However, I suspect that it is the clock setup that is wrong since the examples come from the Discovery board that has a 25 MHz HSE, and the Olimex E407 have a 12 MHz HSE.

PA: Could you tell me what HSE and PLL settings you are using?



ChibiOS/RT 2.5.0 includes a demo for that board, the use of Ethernet, SD Card and USB under the RTOS is demonstrated. Of course the clock setup is included. See my signature.



I got it to work, but I don't know which one of my changes that did the magic. First, I generated new clock settings in system_stm32f4xx.c. The patch can be found here and is quite self-explanatory. Note though, that the autogenerated text about the default HSE crystal speed is wrong. It is 12MHz.

Second, I used the example from Elias blog, The main difference in that example is the enabling of the clock for the GPIOB


Best regards,

Edit: The link to the blog above seems broken. Maybe this works: