2013-08-09 11:18 AM
Hello, everyone.
I am currently playing around with the USART without standard peripheral lib provided by ST (using CMSIS only) and my code strangely works in one MDK project and does not work in another MDK project (Same code!) So if you are interested, please have a look at these: int main(void) { USART2->BRR=0x330; RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN; RCC->APB1ENR|=RCC_APB1ENR_USART2EN; GPIOA->MODER|=( GPIO_MODER_MODER2_1| GPIO_MODER_MODER4_1); GPIOA->PUPDR|=( GPIO_PUPDR_PUPDR2_0| GPIO_PUPDR_PUPDR4_0); GPIOA->AFR[0]|=0x00077777; USART2->CR1|=USART_CR1_TE; USART2->CR1|=USART_CR1_UE; USART2->SR&=~(USART_SR_TC); USART2->DR=0x0000; } Any comment or idea will be appreciated! #stm32f4 #usart2013-08-11 03:02 PM
Make sure to enable clocks prior to writing to peripherals (BRR), and mask bits on to configuration registers in a manner that is immune to initial conditions.
2013-08-12 01:16 AM
Cheers, Clive!!
I am trying your suggestions. And when I put them in a project with Peripheral Standard library, though not using any of the library functions, the above code worked! So I am really confused.2013-08-12 01:25 AM
Especially when it contains the following:
If I comment them, the code will not work anymore. However, I see no way I am using these codes in the main file. The main files are exactly the same. #pragma import(__use_no_semihosting) _sys_exit(int x) { x = x; }2013-08-12 02:14 AM
Well, it is confirmed that this piece of code is crucial:
#if 1 #pragma import(__use_no_semihosting) _sys_exit(int x) { x = x; } #endif I have to put it somewhere else in another .c file instead of the main.c file. Really confusing what that is for and how it works.