USART1 – STM32L100 Discovery

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 joudove.8u.cz (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:

http://joudove.8u.cz
Use this calculator for Baud Rate calculation !

Complete code for USART – the microcontroller get char and send it back.

MAIN.C

and system_stm32l1xx.c

Share the article:
Show your
Maker soul!
Buy a T-Shirt
Coffee for Chiptron
Give a boost to the next article

Related Articles

Digital Discovery is a crucial add-on if you have been using Analog Discovery 2, but its sampling rate was insufficient, there were not enough digital channels available, or there was too much noise to read data sent at higher speeds.…

The first article from Tutorial: STM32F746 (STM32F7 Discovery) serie. I would like to describe how to turn on LED simply controlling GPIO. Why I began to write this tutorial and why I don’t want to use HAL or Standard Peripheral…

This is another continue of STM32 tutorial (STM32F746 tutorial). I would like to show example code for turn on/off LED with button. This example code is able to use for another microcontrollers by ST as STM32L100, L152, STM32F103, F407 and…

We wrote a news about STM32F746 discovery and IDE by openstm32.org on the google+. https://time4ee.com/ got development board STM32F7 discovery by ST. We want to show MULTIPLATFORM (Linux – Ubuntu, Windows) development tools by http://openstm32.org Other tutorials with STM32F7: Tutorial:…

AVR, ATMega, ATTiny, PIC, Arduino… these are very searching words in google and I asked myself “Why?”. Yes, AVR by Atmel or PIC by Microchip family is popular, but we can program better (modern, faster, more low-power, more peripherals) microcontrollers…