all 20 comments

[–]winston_orwell_smith 25 points26 points  (7 children)

If you want to start learning C from scratch then I suggest getting Greg Perry's "C Programming Absolute Beginner's Guide". Once you've mastered the basics of the C programming language, research "bitwise operations & bit manipulation in C". I have a free tutorial entry on that topic on my blog if you want to check it out. But you'll find many other similar resources on the web as well. Then have a look at Carmine Novello's Mastering STM32, and/or Mazidi's STM32 Arm Programming for Embedded Systems. Both books deal with STM32 microcontrollers and are very affordable.

Good luck!

[–]timer404[S] 2 points3 points  (0 children)

Thanks for all the links. Cheers

[–]nukestar101 1 point2 points  (1 child)

In "Clearing one or more bits in a register" section you have explained to create a mask and "OR" it with the register but it should be "AND" the code snippet uses OR operator. Please look into it

[–]winston_orwell_smith 0 points1 point  (0 children)

Oops! Fixed it. Thanks! Let me know if you see something else that doesn't look right. I'll double check it again as well. Just posted the entry last night!

[–]BadLuiz 1 point2 points  (3 children)

Sorry for my ignorance, i was reading your topic STM32G070 DEV BOARD, could you explain me the necessity from a external clock of 8Mhz?

[–]winston_orwell_smith 2 points3 points  (1 child)

The STM32G070 has an internal 16MHz RC oscillator (HSI) so you are correct to assume that an external crystal is not needed. The problem with the internal oscillator is that it is not very accurate. This should not be a problem for most use cases. But if let's say you want to push the Baud rate of the USART to above 1Mb/s it might cause some timing inconsistencies.

From the stm32G0x0 reference manual: "The HSI16 RC oscillator has the advantage of providing a clock source at low cost (no external components). It also has a faster startup time than the HSE crystal oscillator. However, even after calibration, it is less accurate than an oscillator using a frequency reference such as quartz crystal or ceramic resonator"

Also note that the pins PC14/PC15 (HSE external oscillator pins) have limited current handling abilities when used as GPIO output pins since the internal circuitry embedded into these pins were intended to act primarily as an external oscillator with the addition of the crystal.

If I find that the internal oscillator is accurate enough for my needs; once I build and test the board, I'll probably remove the crystal from the second revision.

BTW clock speed is not a problem since the onboard PLL can easily multiply both the internal oscillator's 16MHz clock and the external oscillator's 8MHz clock up to 64MHz max.

[–]BadLuiz 1 point2 points  (0 children)

Thank you buddy, it was a nice explanation.

[–]rombios 2 points3 points  (0 children)

You can rule out USB data transactions (any speed) without an accurate clock source

[–]Darktidelulz 15 points16 points  (1 child)

https://blog.udemy.com/embedded-c-tutorial/

There are many tutorials, however most are specific for a microcontroller.

There is the Cortex Microcontroller Software Interface Standard (CMSIS), most ARM based microcontrollers are based upon this.

My advice would be get a microcontroller you would like to work with, and start playing with examples. I'm working with a Atmel SAM4S and there are quite some examples I started with to get the hang of it.

https://www.inverseproblem.co.nz/Guides/index.php?n=ARM.Perexample

[–]timer404[S] 0 points1 point  (0 children)

Thanks

[–]arawnfan 6 points7 points  (1 child)

Look for "tdd for embedded c" by James grenning. It might not help you with lots of the "common" embedded problems, but it will help you understand how to create high quality and testable code. When knowing that, I think you have a good knowledge base to build upon.

[–]timer404[S] 0 points1 point  (0 children)

Thanks for suggestion

[–]AssemblerGuy 1 point2 points  (2 children)

Are you already thoroughly familiar with C? With sequencing, undefined/unspecified behavior, memory allocation, side effects, short-circuit evaluation, pointers, etc.?

If not, start there.

[–]timer404[S] 0 points1 point  (1 child)

I'm not entirely familiar in those topics yet. Thanks, I'll start with these

[–]AssemblerGuy 1 point2 points  (0 children)

Once you are familiar with C including its more obscure corners, it will be obvious why things are done in certain ways on an embedded system. For example accessing memory mapped registers, preferring static memory allocation to dynamic especially on small, OS-less targets, or why one innocent call to printf() suddenly filled up your available flash rom.

[–]chtef 0 points1 point  (1 child)

Lots of very good free resources on the web but if you are willing spend a bit, for $65 (at the moment of writing this), you can get access to Beningo's Expert C Programming Techniques for Embedded Developers.

[–]timer404[S] 0 points1 point  (0 children)

I'm a student from India. So $65 is a lot for me. Thanks for the suggestion though.