Posts

Semihosting

Image
Have you ever had situation when you wanted to send string over uart from microcontroller to PC, but you didn't have UART-USB converter? I bet you have experienced it. Today I will show you a workaround of it. Programing console or windows application on Windows or Linux is easier than programming embedded systems in some cases. I mean printf function is present default . Printf function allows show string in formatted way. Embedded systems built on microcontrollers also allows usage printf function. Today I will show you how to implement printf function in semihosting mode. Semihosting is the feature of the st-link debugger. STM32F401 development board, and SW4STM32 workbench will be used. Depending on debugger and integrated development environment(IDE) enabling of semihosting may look different. There are just few steps to enable printf capability. 1. Add monitor arm semihosting enable command in Debug configurations ...

How long the piece of code is executed?

Image
Hello, Does anyone know how long piece of code is executed? Today I will teach you how to check it. To measure time there are needed two timestamps t1 and t2. Timestamp t1 describes time when the measurment is started, t2 when the measurment is finished. For this puprpose one gpio will be used. Speaking more precisely: t1 is when the rising edge occured t2 is when the falling edged occured Time of execution doSomething2 function equal is t2 - t1. It is showed at the picture below: Time will be measured by logic analyzer like this: This is one of the cheapest logic analyzer, but for this purpose is excellent. The oscilloscope can be used also. What will happen if the interrupt occurred during measurement? An interrupt breaks the execution of instructions and diverts its execution to interrupt service ...

Two ways to compare a variable in a condition statement

Image
Hello Imagine, we have to compare whether variable is equal 1. In this case variable is called "flag". There are two ways(even more) to achieve this task. First one is here: if(flag == 1) Second one is following: if(1 == flag) At the first glance both ways are the same, but really one of them is better. Do you know which one is better and why? Let's assume, that one equal sign has been skipped. What would happen in first case, and what in seceond case? In first case compiler does not report an error. In addition flag is set to true, therefore the output of the program is not the same, which we would expect. Is not it? In second case compiler report an error because this assignment is not possible. Therefore this sort of bug can be solved immediately. Definitely second method is bett...

What is this blog about?

Hi! My name is Mateusz In this blog I will write about embedded systems, microcontrollers, C language, FPGA's. See you soon.