Q
Q
Qubc2016-02-19 18:37:00
Programming
Qubc, 2016-02-19 18:37:00

Learning C for microcontroller programming?

Hello.
I want to start learning pure C in order to study ARM architecture later. I found this post, Programming on the STM32 microcontroller under Cortex M3 , a selection of links to literature on arm, but it seems to me that this is all useless if you do not know the language itself. Are the directions for learning C different for micro or high-level programs?
Or, if I'm so cool, I want to immerse myself in arm, for starters, can I take any popular C tutorial? The art of circuitry, circuitry in general, everything is clear with this. But not so much with the language...

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Mirn, 2016-02-19
@Mirn

Attention: Everything I write, I write about bare metal or simple RTOS (stm32, etc.)
This programming is divided into three parts:
1. This is hardware! There are no problems with hardware, we read the manual, we use the library recommended by the hardware manufacturer for working with hardware, we get a guaranteed result. It will be difficult only at the beginning. But this experience is acquired and relatively easy.
2. Realtime and engineering skills and engineering experience: Often programs for MK will work in real time on the fly, no one will wait. A value measured twice will always be different, anything can happen and in any order. Clockwork and clock floats. The amount of transmitted and received data will always be different even for the same uart. All this should be taken into account by YOUR program and not fall in any case. As you can see, the program will deal with much more randomness than in web/PC programming and there will be almost no repeatability of events. And you have to be a bit of an engineer and know that everything you work with has deviations and noise in the results, especially analog and ADC.
3. This is programming in C as a normal language. Everything is simple and clear, there are a lot of manuals - choose according to your taste and color.
4. GENERAL ALGORITHMIC PROGRAMMING. It doesn't matter if it's hardware, but the algorithm is optimal but not too perfectionist. You have to implement and the language will not help you here, it is not related to the algorithm and there are much fewer sets of convenient libraries than for PC and web.
5. DO NOT LEARN ASSEMBLY. do not delve into circuitry, the level of a confident arduino will be enough. Assembler is now needed not for writing programs, but for licking a well-made program that is already on sale, but you need to squeeze out another 5-10% of performance, ONLY THEN. Everything else is done either by configs or by the linker's LD file. The wilds of circuitry are also not needed, the main understanding is how and why it works, without any four poles and deep analyzes of phase delays.

A
Alexey Cheremisin, 2016-02-19
@leahch

Not very different, for an introduction to the C language, start with a book by Kernighan and Ritchie, the dialect of the language is of course a little outdated, but all the basics are presented.
Focus on working with pointers, structures, and bitwise operations.
To access the device registers (processor and peripherals), the following construction is usually used:

....
volatile u_int32 *my_cool_register = 0xFFFEBEEF; /* адрес 32-разрядного регистра, ключевое слово volatile */
my_cool_register  |= 0x2; /* взвести второй бит */ 
....

Well, the Cortex-M3 has an address space where all BITS are available at separate addresses, this is often very convenient.
PS. Yes, use the libraries from the supplier, a lot has already been done there in the form of macros (about this in the book) and libraries.

L
lamazavr, 2016-02-19
@lamazavr

programming controllers differs in working with peripheral devices.
in short, you need to write / read the memory in the right order,
start by blinking the diode, display, shim, uart, etc. then it becomes clear where to go

B
beduin01, 2016-02-19
@beduin01

I advise you to look at https://github.com/redox-os/redox in terms of getting acquainted with modern programming languages ​​on the subject of writing an OS

I
iv_k, 2016-02-20
@iv_k

To learn the language, K&R + tutorials and samples for the development environment are enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question