cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030K6T6 usart library?

navid ansari
Associate III
Posted on March 08, 2017 at 11:36

hi

first i look here

0690X00000606VOQAY.png

but there is no usart driver.

this is my schematic

0690X00000606VxQAI.png

according to schematic i use pa2 and pa3 as usart.

please tell me if there is any library to init usart and use it.

if there is not .

datasheet give me something but its hard to understand . what to do?

first 

Alternate function selection

/* This sequence select AF2 for GPIOA5, 8 and 9. This can be easily adapted

with another port by changing all GPIOA references by another GPIO port,

and the alternate function number can be changed by replacing 0x02 for

each pin by the targeted alternate function in the 2 last code lines. */

/* (1) Enable the peripheral clock of GPIOA */

/* (2) Select alternate function mode on GPIOA pin 5, 8 and 9 */

/* (3) Select AF2 on PA5 in AFRL for TIM2_CH1 */

/* (4) Select AF2 on PA8 and PA9 in AFRH for TIM1_CH1 and TIM1_CH2 */

RCC

->

AHBENR

|

=

RCC_AHBENR_GPIOAEN

;

/* (1) */

GPIOA

->

MODER

=

(

GPIOA

->

MODER

&

~

(

GPIO_MODER_MODER5

|

GPIO_MODER_MODER8

|

GPIO_MODER_MODER9

)

)

|

GPIO_MODER_MODER5_1

|

GPIO_MODER_MODER8_1

|

GPIO_MODER_MODER9_1

;

/* (2) */

GPIOA

->

AFR

[

0

]

|

=

0x02

<<

(

5

*

4

)

;

/* (3) */

GPIOA

->

AFR

[

1

]

|

=

0x02

|

(

0x02

<<

(

(

9

-

8

)

*

4

)

)

;

/* (4) */

??????????????

?

?

?

?

?

?

?

?

?

?

?

?

?

?

but line 3 and line 4 is so hard to get . why 5*4 why ((9-8)*4)) :!

please somebody help me

#stm32 #stm32-f0
1 REPLY 1
Amel NASRI
ST Employee
Posted on March 08, 2017 at 15:26

Hi

ansari.navid

,

What you are sharing is a snippet code available in the reference manual of your product.

It is based on direct access to register.

In the package

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32snippets/stm32snippetsf0.html

, you have a set of ready to use examples.

More other advanced examples that are well described and allow you to use USART based on a given STM32 board are available in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

package.

You can also generate your own example thanks to the

http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.