now I have a configuration problem with PLLCLK. My baudrate is 1.5 times faster as it should be. The Primer2 use a 12MHz crystal. The example codes from Raisonance are written for 8MHz eval-boards. So I change the code from
I thing I compile stm32f10x_conf.h again because: I cleaned the Project and build it again and when I rename the stm32f10x_conf.h I get an Error message. Thats why I think I do.
Effectively the macro "#define HSE_Value ((u32)12000000)" does not fix your problem, because it is usefull only if you configure the external crystal as the the system clock source. In your case, the PLL is the system clock source, and the PLL divider is the right solution if you have declared the macro "#define SYSCLK_FREQ_72MHz 72000000".
If you are using Ride, you can visualize during the debug session, the calculated bautrate in the debug tab, item USARTx. But be carreful, you have to enter first the right frequency value (12 MHz) in the "RLink Configuration/Advanced options/Crystal frequency" field.
You can also verify the systems clocks, because USART1 uses the PCLK2 (for APB2 peripherals bus), and the others use PCLK1 ((for APB1 peripherals bus).
I found out that HSE_Value in not used in main.c or anywhere else. With your suggestion I saw in debug mode (Ride7 12MHz) the "wrong" calculated baudrate 14400. It should be 9600 baud.
Unfortunately I don´t understand which function to call for using "#define SYSCLK_FREQ_72MHz 72000000".
I think my unlucky code needs a minimal modification. Here is my main.c. Maybe someone can give me a hint.
Regards FunRice
/* Includes ------------------------------------------------------------------*/ #include "stm32f10x_lib.h"
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif
/* System Clocks Configuration */ RCC_Configuration();
/* NVIC configuration */ NVIC_Configuration();
/* Configure the GPIO ports */ GPIO_Configuration();
USART_Configuration();
while(TxCounter <= 1) { /* Send one byte from USART1 to USART2 */ //USART_SendData(USART2, TxBuffer[TxCounter++]); USART_SendData(USART2, 0xFF); TxCounter++;
/* Loop until USART2 DR register is empty */ while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET) { }
/* Loop until the USART1 Receive Data Register is not empty */ // while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET) // { // }
/* Store the received byte in RxBuffer */ RxBuffer[RxCounter++] = (USART_ReceiveData(USART1) & 0x7F);
} /* Check the received data with the send ones */ TransferStatus = Buffercmp(TxBuffer, RxBuffer, TxBufferSize); /* TransferStatus = PASSED, if the data transmitted from USART1 and received by USART2 are the same */ /* TransferStatus = FAILED, if the data transmitted from USART1 and received by USART2 are different */
while (1) { } }
/******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/ /* RCC system reset(for debug purpose) */ RCC_DeInit();
/* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp();
/* Wait till PLL is ready */ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } else { /* If HSE fails to start-up, the application will have wrong clock configuration. User can add here some code to deal with this error */
/* Enable the USART1 */ USART_Cmd(USART1, ENABLE);
/* Enable the USART2 */ USART_Cmd(USART2, ENABLE); }
/******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif }
/******************************************************************************* * Function Name : Buffercmp * Description : Compares two buffers. * Input : - pBuffer1, pBuffer2: buffers to be compared. * : - BufferLength: buffer's length * Output : None * Return : PASSED: pBuffer1 identical to pBuffer2 * FAILED: pBuffer1 differs from pBuffer2 *******************************************************************************/ TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength) { while(BufferLength--) { if(*pBuffer1 != *pBuffer2) { return FAILED; }
pBuffer1++; pBuffer2++; }
return PASSED; }
#ifdef DEBUG /******************************************************************************* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert_param error has occurred. * Input : - file: pointer to the source file name * - line: assert_param error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */ while (1) { } } #endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
Wow, till now there are to many things I don´t know about STM32 and the IDE. It´s a bigger step from AVR to STM32 as I thought before. STM32 are much more complex.
Your code seems correct. The problem is the ST lib function "USART_Init" that calculates bad divider values, because it considers that PLCLK are 48 and 24MHz instead 72 and 36MHz. To be continued...
And that is because the pre-compiled lib things HSE is 8Mhz and calculates the baudrate settings for this, becasue that is setup in the library before compilling, know the rcc is changed after the library is compiled and therefore it will not work.
I made this error once also, and got the advice to take very good care when using pre-compiled libs, after that i avoided that as much as possible and compiles all files.
I suggest you remove the pre-compild ST-lib and uses all the source files needed.
But i think it is not easy to see if you use pre-compiled lib, then you have to submit a picture from your IDE
Building C:\Projekt\STM32\MyProjects\MyPolling00\MyPolling.rapp Running: LD \"C:\Software\Ride7\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -mthumb -Wl,-T -Xlinker "C:\Projekt\STM32\MyProjects\MyPolling00\MyPolling.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-Map -Xlinker "C:\Projekt\STM32\MyProjects\MyPolling00\MyPolling.map" -Wl,--warn-once C:\Projekt\STM32\MyProjects\MyPolling00\main.o: In function `NVIC_Configuration': C:\Projekt\STM32\MyProjects\MyPolling00/main.c:259: undefined reference to `NVIC_SetVectorTable' C:\Projekt\STM32\MyProjects\MyPolling00\main.o: In function `USART_Configuration': C:\Projekt\STM32\MyProjects\MyPolling00/main.c:234: undefined reference to `USART_Init' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:239: undefined reference to `USART_Cmd' C:\Projekt\STM32\MyProjects\MyPolling00\main.o: In function `GPIO_Configuration': C:\Projekt\STM32\MyProjects\MyPolling00/main.c:198: undefined reference to `GPIO_Init' C:\Projekt\STM32\MyProjects\MyPolling00\main.o: In function `RCC_Configuration': C:\Projekt\STM32\MyProjects\MyPolling00/main.c:117: undefined reference to `RCC_DeInit' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:120: undefined reference to `RCC_HSEConfig' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:123: undefined reference to `RCC_WaitForHSEStartUp' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:128: undefined reference to `FLASH_PrefetchBufferCmd' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:131: undefined reference to `FLASH_SetLatency' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:134: undefined reference to `RCC_HCLKConfig' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:137: undefined reference to `RCC_PCLK2Config' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:140: undefined reference to `RCC_PCLK1Config' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:143: undefined reference to `RCC_PLLConfig' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:146: undefined reference to `RCC_PLLCmd' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:149: undefined reference to `RCC_GetFlagStatus' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:154: undefined reference to `RCC_SYSCLKConfig' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:157: undefined reference to `RCC_GetSYSCLKSource' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:173: undefined reference to `RCC_APB2PeriphClockCmd' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:175: undefined reference to `RCC_APB1PeriphClockCmd' C:\Projekt\STM32\MyProjects\MyPolling00\main.o: In function `main': C:\Projekt\STM32\MyProjects\MyPolling00/main.c:77: undefined reference to `USART_SendData' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:81: undefined reference to `USART_GetFlagStatus' C:\Projekt\STM32\MyProjects\MyPolling00/main.c:91: undefined reference to `USART_ReceiveData' collect2: ld returned 1 exit status
Good job Repzak ! I have forgotten that I also met this problem with precompiled library (for IrdA speed I guess). I agree with you, and we also recommand to do not use for now the precompiled library, and include library souces files into new Circle projects.
Now I add the necessary *.c files to the Project and copy the libraries into the project folder. And now (finally) the baudrate is calculated correct !!!
But now it seems I have a problem with my TTL-RS232 converter. I think my converter don´t like the 2,8V Primer2-signal .
I will check it out in the next days with a storage oscilloscope.
I am already using a 3,3V device. It´s the Prolific 2303 USB to Serial Comm Port. The next step is to analyse the serial signal. Unfortunately my Saleae-Logic-Analyser has a problem capture high-signals at 2,8V and need to repair. So I must test it with a storage oscilloscope, but I can´t do it immediately. As soon as I can I will post the result.
I test the signal with a storage oscilloscope and it looks perfect. After that I found out that my USB to serial converter has a connection / soldering problem at it´s PCB that I fixed. These are hard barriers for getting started with the Primer2.
Thank you very much for your help. I fear that the next uncommon problems are coming soon.