Hi, all-
I've been programming bare metal C on 8-bit ATmega, ATtiny, and PIC MCUs for the past 5 years or so, and have become very comfortable with the workflow, i.e. efficient scanning of the datasheet, set a handful of registers for a given peripheral, and write the program. Despite my enduring love for the 8-bit-ers, it's become increasingly apparent that I need to familiarize myself with the ARM Cortex-M family. However, every time I try I find the whole process quite discouraging.
Spot on.
I simply declined to do anything else than what I had been doing with Atmel or PIC MCUs, and that was a great success. You describe the process which works for AVRs and PICs - and guess what, it works for ARM Cortex-M microcontrollers equally well.
Of course, having more features, the documents are longer. Instead of a 400-page "datasheet", you might have a 200-page datasheet just for physical/electrical properties, plus a 2000-page "reference manual" which explains all the peripherals, plus a few hundred pages of CPU core documentation (rarely needed).
Being more complex, there are more traps. OTOH, you have likely experienced such traps already, this isn't going to change the game.
So the
process is the same, and all your prior experience helps you.
It seems that what makes the architecture great (many manufacturers to choose from, tons of different peripherals available, etc) also makes it easy to get lost. For example, I picked up an NXP LPC54114 dev board a while back. There are diehard endorsements across the web of different software from Keil, IAR, Eclipse, stfu use emacs, etc. Well, NXP wants you to install their IDE, and their SDK. Fine, I'll do that. The SDK has a fairly hefty API, with functions that do a lot of register setting, peripheral configuration, etc. It also includes a number of CMSIS libraries, which initially looked like a great concept but it soon becomes clear that it isn't nearly as portable as it should be. The board itself includes a "Link 2" debug probe, but many will tell you to pick up a Black Magic Probe or J-Link EDU.
Note there is absolutely
nothing in the
architecture that dictates this. The ARM microcontroller architecture and typical MCU peripheral implementations actually tend to be quite sane and understandable, and easily worked with in C, from scratch, just reading the documentation.
I just looked for the .h files that define the register names in the reference manual, and that's it. Some manufacturers may require you to install some stupid software package just to extract the files. This sucks; alternatively, just google for the header files and you'll find copies hanging around the 'net.
Any way that programs a chip works. UART bootloader, or the integrated debug interface of the eval board you have.
So now we have multiple compilers,
Use GCC.
multiple C library implementations,
Nothing wrong with newlib, I think? Don't think about it too much, you'll find out if you need something else.
Get everything here:
https://launchpad.net/gcc-arm-embeddedmany IDEs
No need to use any IDE. If you
want to, then you obviously know what you want to use.
I currently use gedit to write code. Programmer's notepad, Notepad++ and so on come to mind on Windows.
three overlapping ways to write the code (SDK, CMSIS, register manipulation),
Do it like you did with AVR or PIC. Consider using libraries only with complex things (USB, TCP/IP...)
and three ways to debug and program.
I started with UART bootloader on STM32 and still mostly use it. No special hardware needed, an improvement over AVR.
Equivalent of "printf debugging", i.e., "turn on LED debugging" works fine and is scalable for complex/demanding projects where debug interfaces and IDE debug tools do not suffice anymore.
Yes, without a "debugger" you can't easily single-step through all code to see if it does what you think you wanted to do, but that's not a viable way to write code anyway, despite people doing that.
The worst part is that everywhere you look for help, all you find is tutorials about the SDK, mbed, FreeRTOS, proprietary vendor tools, etc.
It took some time for me to realize that all these tutorials exist because all such systems
are so freaking difficult, hence the need for tutorials!
To do what you did with AVR/PIC, you don't need too many tutorials - a few code samples, like those given by ataradov, suffice. Basically, just follow the advice of ataradov.
Is there any toolchain that will provide a workflow similar to that in MPLAB or Atmel Studio 7? I don't want 10k of program memory eaten up by vendor bloatware, but on the other hand I quite enjoy some level of abstraction in terms of SFR macros, etc. After all, I'd just use assembly if I was anti-abstraction. I'm not looking for an "Arduino solution", but I don't want to have to write my own reset vector with inline assembly. I hope this makes sense, and thanks for your time.
Yes, I understand where you are coming from: for the standard AVR workflow, avr-gcc somehow autogenerated the startup code (or picked a correct file automatically), and was able to map the data and code to the correct memory addresses - i.e., choose a correct linker script -, all this happened behind my back, didn't have to think about it at all.
arm-gcc-none-eabi does not do this. So I need to supply startup code and a linker script. But, in the end, this won't ruin your day. Copy-paste the startup code and linker script, modify when needed - problem solved in a very pragmatic way. You still have the benefit of being able to
look at them if you need to understand what happens under the hood - not to mention being able to
modify them when you later find out you have special requirements and want to use the fancy features higher-end MCUs offer, such as core-coupled fast RAMs. The best part, what you learn here, is all applicable on all ARM MCUs, and not only ARM, it's basic computer science that has been relevant for decades, and will be relevant for decades to come. This is
complete opposite to time wasted going through tutorials and learning how to install the trend IDE and trend framework of the year, only to learn the new trends the next year (or the next device you use).