Printf on a Microcontroller | Embedded System Project Series #19

  Рет қаралды 2,988

Artful Bytes

Artful Bytes

Күн бұрын

I add a printf implementation suitable for microcontrollers so that I can print formatted strings to the terminal. Underneath, it calls the UART driver I implemented in the last video. I further wrap the printf function in a TRACE macro to prefix every trace with filename and line number. Finally, I add trace to my assert function, but only trace the program counter (PC) to save space and show how to get the corresponding file+line with addr2line.
0:00 What and Why
3:28 Add mpaland/printf
6:52 Implement _putchar
9:20 Call printf
11:40 TRACE macro
17:13 Verify TRACE
19:10 Avoid format and cppcheck
22:20 Commit
22:58 Fix mistake 1
23:25 Fix mistake 2
24:00 Add trace to ASSERT
28:30 Program counter assembly
29:53 UART polling in ASSERT
32:20 Fix mistakes
34:05 addr2line
36:25 Commit
37:20 Possible improvements
#embeddedsystems #cprogramming #microcontroller
🌍 Related links
github.com/artfulbytes/nsumo_...
interrupt.memfault.com/blog/a...
github.com/mpaland/printf
🌍 Find me here
GitHub - github.com/artfulbytes
Website - www.artfulbytes.com
👨‍💻 About me
Hi and welcome. I'm Niklas, an embedded systems engineer from Sweden. On this channel, I make practical videos about embedded systems or, in general terms, about building and programming hardware.

Пікірлер: 28
@lewiskim9986
@lewiskim9986 Жыл бұрын
Your Sumobot making series is literally amazing! I learn a lot from your contents. Thx😊
@nfjeldberg
@nfjeldberg Жыл бұрын
Thank you for all your hard work, amazing work and worth its weight in gold!
@artfulbytes
@artfulbytes Жыл бұрын
❤❤
@tufanyou
@tufanyou 9 ай бұрын
Thank you for your share ... it is good👏👏
@tedelctro6849
@tedelctro6849 Жыл бұрын
Good job 👍
@olivialinden8699
@olivialinden8699 Жыл бұрын
Smart !
@prashkd7684
@prashkd7684 Жыл бұрын
Stm32cube ide had those feature baked in . Sprintf can print on jtag aerial port .
@artfulbytes
@artfulbytes Жыл бұрын
Yes, that's good to be aware of if you are on STM32, can save you some effort depending on your needs. Other microcontrollers + IDEs may also have out-of-box support for terminal printing. Though, it often requires the debug probe (and sometimes slower). UART is a more general approach in some sense.
@sfnembedded
@sfnembedded Жыл бұрын
Wow thanks for the tutorial! Can you share which IDE do you used?
@artfulbytes
@artfulbytes Жыл бұрын
No IDE in this video. I'm running Ubuntu with i3, vim as my editor in the terminal alacritty. I describe it here www.artfulbytes.com/devenv.
@sfnembedded
@sfnembedded Жыл бұрын
@@artfulbytes Oh sorry I mean your editor. By the way many thanks!
@pedro_alonso
@pedro_alonso Жыл бұрын
Nice video! Can you share which font are you using in the terminal?
@artfulbytes
@artfulbytes Жыл бұрын
Yes, iosevka nerd font mono github.com/niklasab/dotfiles/blob/main/.fonts/iosevka-term-nerd-font-complete-mono.ttf
@devrim-oguz
@devrim-oguz Жыл бұрын
esp-idf has printf built-in. As well as Arduino's Serial.printf()
@artfulbytes
@artfulbytes Жыл бұрын
Is there anything they don't have "inbuilt"? 😉 They give you an entire software stack for better worse. And if we are talking esp32 that plays in an entirely different league 🙂
@kesmik
@kesmik Жыл бұрын
The escape sequence is really strange :) Is it correct or you wanted to implement oposite? Asking because never heard of that, but looks strange if printf will be somehing like printf("hi "); it will become "hi " P.S. seems added comment under wrong video, ment to be on previous.. (did not watched this yet).
@artfulbytes
@artfulbytes Жыл бұрын
Damn it, you are right! I got it mixed up. Thanks, will fix it in future video 😅
@olivialinden8699
@olivialinden8699 Жыл бұрын
The left eye is black
@artfulbytes
@artfulbytes Жыл бұрын
AR!🏴‍☠
@walidoulondon8107
@walidoulondon8107 Жыл бұрын
Hello are you Italian?
@artfulbytes
@artfulbytes Жыл бұрын
No, I'm from Sweden :)
@user-zp9cn8mu3d
@user-zp9cn8mu3d Ай бұрын
What use of static void,()?
@artfulbytes
@artfulbytes Ай бұрын
"Local" function with no return value. In other words, it's a function that is only accessible in the .c file where it's defined and it doesn't return anything.
@user-zp9cn8mu3d
@user-zp9cn8mu3d Ай бұрын
If static function is .h library it can access in any library .c .if I include
@artfulbytes
@artfulbytes Ай бұрын
@@user-zp9cn8mu3d Yes it's possible to define a static function in a header file and then include that header file in other c files. Not sure why you would do that though, apart from some very rare use-case.
@user-zp9cn8mu3d
@user-zp9cn8mu3d Ай бұрын
Now I understand use of static keyword but I didn't know where I use static variable and static function?
@user-zp9cn8mu3d
@user-zp9cn8mu3d Ай бұрын
Most of the functions in .h file written in static function example:static void toggle_Gpio that 's I confusing .
ADC driver with DMA in C | Embedded System Project Series #22
41:33
Artful Bytes
Рет қаралды 1,7 М.
УГАДАЙ ГДЕ ПРАВИЛЬНЫЙ ЦВЕТ?😱
00:14
МЯТНАЯ ФАНТА
Рет қаралды 3,9 МЛН
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 81 МЛН
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 5 М.
Motor Control with PWM in C | Embedded System Project Series #21
57:53
How to Board Bring-up | Embedded System Project Series #24
33:09
Artful Bytes
Рет қаралды 3,6 М.
Economist fact-checks Scott Galloway’s Anti-Boomer TED Talk
26:05
Money & Macro
Рет қаралды 38 М.
Microcontroller Interrupts | Embedded System Project Series #17
54:40
The End | Embedded System Project Series #28
7:23
Artful Bytes
Рет қаралды 3,6 М.
Look, this is the 97th generation of the phone?
0:13
Edcers
Рет қаралды 6 МЛН
Rate This Smartphone Cooler Set-up ⭐
0:10
Shakeuptech
Рет қаралды 3 МЛН
Самый тонкий смартфон в мире!
0:55
Не шарю!
Рет қаралды 175 М.
Опасность фирменной зарядки Apple
0:57
SuperCrastan
Рет қаралды 3,8 МЛН
Лазер против камеры смартфона
1:01
NEWTONLABS
Рет қаралды 660 М.