EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: elefurtronik on January 08, 2023, 01:34:19 pm

Title: Embedded C Learning
Post by: elefurtronik on January 08, 2023, 01:34:19 pm
Hello,
I would like to learn embedded C programming language.
I have the stm32f407v discovery kit and also the TI Tiva discovery kit. I want to start from a point to improve myself parallel in the software area besides hardware.
Could you please suggest to me free courses and sources if not possible not so expensive ones maybe?

I don't have any experience with microprocessors and microcontrollers. What do I need to be an embedded software engineer?

Thanks in advance for all the support.
Title: Re: Embedded C Learning
Post by: pcprogrammer on January 08, 2023, 02:57:44 pm
Hi elefurtronik,

do you have any experience in programming what so ever?

There is no specific embedded C programming language. C is a language that can be used for all levels of programming, and my advice is to start with just learning the basics of C on your personal computer. Do some simple "hello world" projects to train in the programming itself.

Then practice your new found skills on doing a "hello world" project on your stm32f407v discovery kit. Go to the st.com website and look for the manuals and datasheets for that microcontroller. You will need them to get familiar with the peripherals.

Or you can just look into the Arduino world and use what they have to offer.
Title: Re: Embedded C Learning
Post by: JustMeHere on January 08, 2023, 04:07:31 pm
I studied the HCS12 version of this book in college.  It was an awesome learning source.

https://www.amazon.com/PIC-Microcontroller-Introduction-Software-Interfacing/dp/1401839673 (https://www.amazon.com/PIC-Microcontroller-Introduction-Software-Interfacing/dp/1401839673)

Title: Re: Embedded C Learning
Post by: elefurtronik on January 08, 2023, 05:14:24 pm
Hello,
I know Python programming and algorithm logic. Then I can start with c language itself. Is there any difference between embedded c and c programming? Why do people call it embedded c?

Thanks for the book recommendation. I would like to learn Arm. Is it also benefical for Arm architecture?
Title: Re: Embedded C Learning
Post by: JustMeHere on January 08, 2023, 05:30:36 pm
Yeah.  "Embedded" most likely refers to the fact you access memory locations directly.  For example, you look at memory location 0xA001 to see if a pin is being pulled high or low by an outside source (i.e. button press).  There are a group of pins that are bound to something called a Port.  This Port usually has the same number of pins CPU register size (8, 16, 32)  Normally when you program, you don't need to access a specific memory location and let the compilers and pointers do the work. 

You will access hardware via registers.  See this for the Arduino chip: https://arbaranwal.github.io/tutorial/2017/06/23/atmega328-register-reference.html
Title: Re: Embedded C Learning
Post by: IanB on January 08, 2023, 05:37:02 pm
I know Python programming and algorithm logic. Then I can start with c language itself. Is there any difference between embedded c and c programming? Why do people call it embedded c?

A C program (and the C language) has two parts: the code itself, and the environment it runs in. On a microcontroller the language is the same, but the environment is different. The different environment means that some different programming techniques may be used.

For example, on a PC there is a supervisor (an operating system) to manage resources. On a microcontroller you may be directly responsible for arranging access to hardware resources.

If your program crashes on a PC the operating system will catch the failure and return control to you. On a microcontroller if your program crashes the system will stop working and you will have to reset it.

On a PC there is an extensive library of functions available that your programs can make use of. On a microcontroller there may be a much more limited library.

On a microcontroller your code is likely to make extensive use of interrupts and interrupt handlers. Timing becomes important, and you have to be careful with how long your code takes to execute. On a PC your program is more likely to be sequential and will not see hardware interrupts, but it may deal with software events, which are similar.

On a PC you can make extensive use of virtual memory and not worry too much about memory budgets. In an embedded program, you have restricted memory and you have to do much more careful memory accounting.
Title: Re: Embedded C Learning
Post by: Alaezae on January 08, 2023, 05:47:36 pm
https://github.com/cpq/bare-metal-programming-guide

Here’s a guide I used that’s pretty good for actually getting down to register level C. Definitely worth a look, but I’ll warn you if you don’t know much about computer architecture or C it may be kind of difficult to start with. Also a note, STM32 general has 3 documents you’ll need for programming: the datasheet (electrical characteristics, memory map, peripheral description), the reference manual (peripheral memory location, configuration details, etc.), and the programming guide (ARM specific peripherals and memory locations). They may have combined some of these documents for the f4 series so double check with ST’s website. If you need a primer on computer architecture, check out Ben Eater’s channel on YouTube and watch his series on building an 8 bit computer. I don’t know if there’s a python compiler for STM32 but definitely look for some tutorials online.
Title: Re: Embedded C Learning
Post by: bidrohini on January 09, 2023, 12:35:29 pm
If you are a beginner, I suggest you start with AVR microcontroller and Arduino first. Then move to STM.  Start with the easier ones.
Title: Re: Embedded C Learning
Post by: elefurtronik on January 09, 2023, 12:59:30 pm
I can already use Arduino with their IDE.


I will check Ben Eater's YouTube Channel. It looks interesting. Python is not important. I would like to learn C programming at the end.
Title: Re: Embedded C Learning
Post by: pcprogrammer on January 09, 2023, 02:31:24 pm
If you are already using Arduino, then you are doing C, but on bit higher level.

Basic C is using the programming constructs and keywords like if, while, switch, etc.

There are many sites about learning C. Here is one that starts with the basics https://www.learn-c.org/ (https://www.learn-c.org/)
Title: Re: Embedded C Learning
Post by: madires on January 09, 2023, 02:42:27 pm
I don't have any experience with microprocessors and microcontrollers. What do I need to be an embedded software engineer?

This is possibly not the answer you like to hear, but i'd recommend to start with MCU basics, i.e. how they work, architectures and instructions sets. It will help you to understand the 'embedded' part, what's feasible or not, and why some things done in a specific way and not like on a PC. The classic starting point is an 8-bit MCU, e.g. the ATmega328 of your Arduino, because it's not that complex.
Title: Re: Embedded C Learning
Post by: rstofer on January 09, 2023, 05:00:51 pm
When folks play with the Arduino, they usually use the Arduino libraries and these introduce a LOT of hand-holding.  But you don't have to use the library code...

Set up a timer and timer interrupts to blink an LED - that'll keep you busy for a while but it's good training.

Start here - the timer interrurpt starts around 37 minutes in but there's a lot to learn before getting there.

https://youtu.be/wIcC8-g9Lnw

Later on, you will be able to remove even more Arduino supplied code and use your own but one thing at a time.
Title: Re: Embedded C Learning
Post by: elefurtronik on January 09, 2023, 09:01:47 pm
I don't have any experience with microprocessors and microcontrollers. What do I need to be an embedded software engineer?

This is possibly not the answer you like to hear, but i'd recommend to start with MCU basics, i.e. how they work, architectures and instructions sets. It will help you to understand the 'embedded' part, what's feasible or not, and why some things done in a specific way and not like on a PC. The classic starting point is an 8-bit MCU, e.g. the ATmega328 of your Arduino, because it's not that complex.
No, definitely like all the other answers and suggestions, this is very good suggestion.
When folks play with the Arduino, they usually use the Arduino libraries and these introduce a LOT of hand-holding.  But you don't have to use the library code...

Set up a timer and timer interrupts to blink an LED - that'll keep you busy for a while but it's good training.

Start here - the timer interrurpt starts around 37 minutes in but there's a lot to learn before getting there.

https://youtu.be/wIcC8-g9Lnw

Later on, you will be able to remove even more Arduino supplied code and use your own but one thing at a time.


Thanks and I am starting with this video then. :)
Title: Re: Embedded C Learning
Post by: tooki on January 09, 2023, 09:42:20 pm
,
I know Python programming and algorithm logic. Then I can start with c language itself. Is there any difference between embedded c and c programming? Why do people call it embedded c?
They don’t. When you see the phrase “embedded C programming”, it means [embedded programming]+[in C], not [programming]+[in embedded C].

Yeah.  "Embedded" most likely refers to the fact you access memory locations directly.
Nope, that is not at all what “embedded” means. Computers (the opposite of embedded) in the past frequently used direct memory addressing; that is in no way related to what embedded computing is.

“Embedded” means computing that is an integrated part of a system: https://en.wikipedia.org/wiki/Embedded_system

These days, that mostly (but not exclusively) means microcontrollers, and often means computing that directly controls hardware, frequently (but not always) as or with real-time systems.
Title: Re: Embedded C Learning
Post by: HobGoblyn on January 10, 2023, 11:46:41 am
Have a look on coursera, tons of programming courses.

Most are free, they can look like there’s a charge but usually there’s a free option.

The free option usually allows free access to all course material, but you can’t submit questions or have any tests checked, and you can’t take the end of course exam. 

No ties to them whatsoever, just found them useful in the past
Title: Re: Embedded C Learning
Post by: Nominal Animal on January 10, 2023, 12:30:53 pm
When people discuss "embedded C" or "embedded C++", they are often actually referring to freestanding C or freestanding C++.

The C and C++ standards specify two environments: hosted and freestanding.

Hosted is the one where you have everything in the standard available, and are running under some operating system.

Freestanding is when you do not have the services of an operating system available, no standard C library available, and only a subset of the C++ language features available.  Very often exceptions are not supported at all, for example.

Things like operating system kernels and bare-metal microcontroller programming are often done using freestanding C.  If you use GCC or Clang, you can also use a curious mix of freestanding C/C++, with some surprising quirks in there.  (Thus, quite often the question "Can you do embedded C development?" actually means something like "How aware of the differences between hosted and freestanding C or C++ are you?  Can you develop software for such memory- and feature-constrained targets?")

For example, Arduino uses freestanding C++ with a minimal standard C library (either avr-libc or newlibc, depending on whether the target is an AVR or 32-bit ARM), and its own preprocessor (that among other things, adds function prototype declarations automatically).

In any case, "embedded" is similarly goofy and ill-defined term as "best programming language" or "Euler angles".  People think they know what it means, but they're wrong, because there is no generally agreed-upon definition for the term, so any belief on what they mean is based on opinion, not verifiable facts or observations.  Personally, when the definition matters, I prefer to explicitly use "hosted" or "freestanding", even though very few C/C++ developers actually know the terms; they, at least, have a definition one can consult (in the ISO C and C++ standard texts).
Title: Re: Embedded C Learning
Post by: dobsonr741 on January 10, 2023, 03:33:42 pm
I suggest going to the “origin”, get a copy of the K&R book: https://en.m.wikipedia.org/wiki/The_C_Programming_Language

When you are comfortable throwing around function pointers embedded into structures you’ll know you learned C.

 Don’t stop there, learn C++ next. After that, get immersed into make/cmake and unit testing. What you’ve learned at that point can be useful in generic software engineering or jumping to other languages, like Rust (for embedded) or Kotlin (for server)
Title: Re: Embedded C Learning
Post by: Sherlock Holmes on January 11, 2023, 04:15:29 pm
Hello,
I would like to learn embedded C programming language.
I have the stm32f407v discovery kit and also the TI Tiva discovery kit. I want to start from a point to improve myself parallel in the software area besides hardware.
Could you please suggest to me free courses and sources if not possible not so expensive ones maybe?

I don't have any experience with microprocessors and microcontrollers. What do I need to be an embedded software engineer?

Thanks in advance for all the support.

Do you use Linux or Windows or Mac as your main computer?

Title: Re: Embedded C Learning
Post by: elefurtronik on January 11, 2023, 04:29:30 pm
I
Hello,
I would like to learn embedded C programming language.
I have the stm32f407v discovery kit and also the TI Tiva discovery kit. I want to start from a point to improve myself parallel in the software area besides hardware.
Could you please suggest to me free courses and sources if not possible not so expensive ones maybe?

I don't have any experience with microprocessors and microcontrollers. What do I need to be an embedded software engineer?

Thanks in advance for all the support.

Do you use Linux or Windows or Mac as your main computer?


I have both. However, spending my time mostly on Windows.
Title: Re: Embedded C Learning
Post by: Sherlock Holmes on January 11, 2023, 06:35:09 pm
I
Hello,
I would like to learn embedded C programming language.
I have the stm32f407v discovery kit and also the TI Tiva discovery kit. I want to start from a point to improve myself parallel in the software area besides hardware.
Could you please suggest to me free courses and sources if not possible not so expensive ones maybe?

I don't have any experience with microprocessors and microcontrollers. What do I need to be an embedded software engineer?

Thanks in advance for all the support.

Do you use Linux or Windows or Mac as your main computer?


I have both. However, spending my time mostly on Windows.

OK I suggest you look at Visual Studio 2022 (you can use the free community edition (https://visualstudio.microsoft.com/vs/community/)) and the very powerful VisualGDB extension.

This lets you write code and debug it using Visual Studio, very attractive for anyone that routinely works with Visual Studio. The VisualGDB (https://visualgdb.com/) product is not expensive and is very robust, never gives me trouble and is an extremely good way for a non-professional at least, I use C and overall the setup is very impressive.

VisualGDB is definitely not a toy, it is very powerful and there are tons of tutorials and examples of working with CubeMX projects  (https://visualgdb.com/tutorials/arm/stm32/cube/)and so on.
Title: Re: Embedded C Learning
Post by: carb_enjoyer on January 13, 2023, 10:32:58 am
I can personally recommend this low level embedded programming course:link (https://www.youtube.com/watch?v=3V9eqvkMzHA&list=PLPW8O6W-1chwyTzI3BHwBLbGQoPFxPAPM&index=1) Author greatly describes using C language in embedded systems, stack, startup code, debugging (also assembler), how to use and understand MCU reference manual, use CMSIS libraries, RTOS etc. When learning embedded programming using high level libraries like HAL isn't very educative IMO, so for me it's a great place to start. Good luck :D
Title: Re: Embedded C Learning
Post by: elefurtronik on May 05, 2023, 06:45:15 pm
Hi everyone,
I paid and bought the course below from Udemy.
So far so good, I recommend it for those who want to learn embedded programming. He is writing on C language, therefore I am also learning C together.
https://www.udemy.com/course/embedded-systems-bare-metal-programming/ (https://www.udemy.com/course/embedded-systems-bare-metal-programming/)
Title: Re: Embedded C Learning
Post by: rstofer on May 05, 2023, 07:27:12 pm
I can already use Arduino with their IDE.


I will check Ben Eater's YouTube Channel. It looks interesting. Python is not important. I would like to learn C programming at the end.

For low level programming, C is vastly more important than Python.  But once you get to the application layer, there is a ton of work being done with Python.  Every Machine Learning example you are likely to encounter is written in Python.  Not because of the Python language but because there are libraries for just about everything.  The infrastructure is awesome!

The suggestion to start with Arduino is quite valid.  Over time you replace the Arduino library code with your own code and that will count as 'embedded programming'.  Arduino is a great way to get started.  You can use either C or C++ depending on what you want to do.  AVR uCs (including the Arduino ATmega 328) are nice to program at the lowest level.  They are nowhere near as complicated as some ARM processors.  Everything that can be done with an Arduino has been done and the results are on the web.
Title: Re: Embedded C Learning
Post by: barshatriplee on May 06, 2023, 01:22:48 pm
I find STM hard for beginners. I think it is easier to start with AVR microcontroller (ATmega 16/ Atmega32), mikro C/ATmel studio compiler, and a simple loader like the USBASP.
Title: Re: Embedded C Learning
Post by: dobsonr741 on May 06, 2023, 01:53:00 pm
+1 for learning to understand fully what goes on in https://github.com/cpq/bare-metal-programming-guide @alaezae mentioned.

It does not have the ST tool’s clout. Every single line of code has a reason, there’s not more than a low hundred lines of plan C code to bring up the MCU from scratch - aka first jump into the vector table. Perfect study animal for a beginner to dissect.

It does not matter what MCU it is - ST32 on a bare metal level is as simple as a 8051 was.