Share us

RSS feeds

USART1 - STM32L100 DiscoveryPrint

If you program microcontrollers by STM (STM32F4, STM32F0, STM32L1) with Standard Peripheral Library your code is bigger than without Standard Peripheral Library. It is motivation why we can program of microcontrollers without Standard Peripheral Library. Nevertheless, if you program without Standard Peripheral Library, the support will be wrong for you. More people don't work without Standard Peripheral Library.
Now, I describe USART1 for STM32L100, but you can this code transfer on the other microcontrollers. For example STM32F053, STM32L152, STM32L303 and more.

The article is inspired by (Czech language).

The basic information about USART you can find on the wikipedia. You find the description some bits on the registers on the datasheet (reference manual).

My first mistake:

missing character |
You set the pins straight. But, On this PORT is programming interface - SWD.
The Integrated Development Environment (IDE) Keil send Waring in the terminal.
Internal command error
If you load your code, send warning:
No target connected and next Error: Flash Download failed - Target DLL has been cancelled
If you open Flash -> Configure Flash Tools -> Debug -> Settings (programmer) -> SW Device: No Cortex-M SW Device Found
In this moment is not the microcontroller visible. You have to repair it.
If you use the Attolic TrueStudio, it send warning: Remote failure reply: E31, but the atollic ask you if you want kill process. Push "y" - yes. The microcontroller is visible and you have to repair your code.
Back to our problem. How to repair it in IDE Keil?
You use Atollic TrueStudio OR you use ST-LINK utility and you check Target -> Settings -> Mode: Connect Under Reset OR last possibility.
You repair your code and once you load the code to the microcontroller, push the reset on the development board. More precisely.
You press the RESET button and you press "Load" button in the Keil then realease RESET button.
Note from comments: You can choose "Connect under reset" in the Keil - programmer settings. Thanks.
If you reapair the code and load code to the microcontroller, in the Flash -> Configure Flash Tools -> Debug -> Settings (programmer) -> SW Device: you will see your microcontroller.
Following mistake. Bad setting alternate function:

On this picture is setting of the register AFR - setting alternate function.

Each PIN can have up to 16 alternate functions and each PINs are reserved 4 bits in 32 bits register AFR. The register AFR[0] is register for PINs 0 - 7 and AFR[1] is PINs for 8 - 15.

And last problem. How to set right Baud Rate. The register is divided into 2 parts. 4 bits for Fraction and 12 bits for Mantissu. The formule is easy and you can find on the website:
Use this calculator for Baud Rate calculation !
Complete code for USART - the microcontroller get char and send it back.

and system_stm32l1xx.c
No Comments have been Posted.

Post Comment

Please Login to Post a Comment.