So a very broad question. first and formost what exactly was your avr experience, clearly if you started at main.c then someone else built your sandbox/tool environment for you including the bootstrap. The avr is more harvard-ish than arm so actually it is more of a PITA to truly build for without someone doing the work for you.
There is no reason why the experience cannot be exactly the same. You can take an avr document read about the registers for some peripheral poke at the registers for that peripheral in your program and make it work. You can take the st document, read about the registers fro some peripheral, poke at the registers for that peripheral in your program and make it work.
You can take some library like arduino for your avr, read about the api calls, write a program that makes some calls, program the device. Can take some library for your st chip and do the same thing, api calls wont be the same. arduino libraries are not the same api calls as other avr libraries made by atmel or some other party. You could jump on mbed.org and start writing api calls for your or some st chips and poof a working binary.
All mcu chip vendors need to provide libraries as not everyone is willing or (so they think) able to bare metal their way through (not that the libraries are not bare metal but are just api calls so system like). they wouldnt survive in this day and age. Likewise you have to have newer better with some new name so the libraries change. ARM is wonderful but at the same time a royal PITA. Because they make cores not chips, and their cores are surrounded by different stuff. there are a ton of cortex-m4 solutions that use the same cortex-m4 core, but you cant write one cortex-m4 program that works on all of them as the chip vendor specific stuff is all different (sure a massive if-then-else program would work if you could get it to fit). ARM is trying to make a magic layer that looks the same ish and the vendors are being dragged along so this CMSIS and MBED are ARM driven notions to solve this problem. AVR doesnt have this problem, the core and the chip vendor are one in the same. Now there are a number of different AVR cores and even if you had the same peripheral you might not be able to write one binary that works across all of them and or there might be binaries for one (xmega) that dont work on another (tiny) because of differences in the avr core implementation even if the peripherals were the same. the avr problem is much smaller than the arm problem though, but all contained within one company. so the peripherals if they vary are not going to vary nearly as much as atmel vs nxp vs st vs ti vs others using the same arm cores (or at least same named, there are items in the arm source that are easy to modify, with or without floating point with 16 bit fetches or 32 bit fetches, etc, documented in the trm for that core, creating more pain).
within a company like ST across just the cortex-ms they have created different peripherals a number of timers, gpio, uart, pll/clock, etc. If you take the bare metal, talk to the registers no other libraries approach, you will see that the transition from the cortex-m3 to the cortex-m0 they started using a different gpio peripheral, but maybe some of the others were the same. Fast forward to today we have cortex-m3, cortex-m0, cortex-m0+, cortex-m4 and cortex-m7 based devices just from ST, and there are peripherals that mix and match one product line may have a timer similar to an early cortex-m3 product but the gpio that is more like the first cortex-m0 product. And they seem to mix and match each new family they create from a pool of peripherals. So I might have code for a specific chip that works great on some other specific chip, same family or maybe even a little different. But move that to another st stm32 family and maybe the uart code works but the gpio doesnt, take that first program and move it to yet another family and maybe the gpio works and the uart doesnt. Once you have a library of your own for each of the different peripherals you can mix and match that and their libraries attempt to do that, and use a common-ish ideally call such that the code ports a little better but you have to build for the different chip to get the different stuff linked in. Not perfect.
Also look at how old say the very popular thanks to arduino and perhaps avr-freaks before that atmega328p that thing is relatively ancient. In the time since that came out all the stm32s were created, and for various reasons size/speed/internal politics/etc different peripheral choices were created. All the above mentioned cortex-m variations were created with different target use cases within the mcu world in the time that the atmega328p didnt change.
So if you take one avr document and one avr, and have a somewhat working toolchain, you can write programs straight from the avr docs. If you take one stm32 document for one stm32 chip, take just about any of the gcc cross compilers for arm (arm-none-eabi, arm-linux-gnueabi, etc), do your own boostrap and linker script which are pretty trivial for the cortex-m, you can write programs straight from the stm32 docs and the arm docs, no problems both are somewhat well written. repeat for a different stm32 chip, repeat for a cortex-m based nxp chip, repeat for a cortex-m based ti chip.
As a programmer though you want to write one program for two chips you need to look at the two chips and see what is common and different and design your program to either avoid the differences or if-then-else or use a link time if-then-else solution.
I find the libraries from the chip vendors harder to use than just reading the docs and programming registers. YMMV. I recommend you continue to attempt to use their old and their new libraries and try going directly to the registers and find what fits you best. the arms will run circles around the avrs at similar prices, power, etc. so there is value in attempting to use these other parts. avr, msp430, etc have become also-rans to cortex-m based products so professionally you should dig into one or more.
so for example a simple led blinker for the stm32f411 with an led on pa5
flash.s
.thumb
.thumb_func
.global _start
_start:
stacktop: .word 0x20001000
.word reset
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.thumb_func
reset:
bl notmain
b hang
.thumb_func
hang: b .
.align
.thumb_func
.globl PUT16
PUT16:
strh r1,[r0]
bx lr
.thumb_func
.globl PUT32
PUT32:
str r1,[r0]
bx lr
.thumb_func
.globl GET32
GET32:
ldr r0,[r0]
bx lr
.thumb_func
.globl dummy
dummy:
bx lr
.end
notmain.c
void PUT32 ( unsigned int, unsigned int );
unsigned int GET32 ( unsigned int );
void dummy ( unsigned int );
#define RCCBASE 0x40023800
#define RCC_AHB1ENR (RCCBASE+0x30)
#define GPIOABASE 0x40020000
#define GPIOA_MODER (GPIOABASE+0x00)
#define GPIOA_OTYPER (GPIOABASE+0x04)
#define GPIOA_OSPEEDR (GPIOABASE+0x08)
#define GPIOA_PUPDR (GPIOABASE+0x0C)
#define GPIOA_BSRR (GPIOABASE+0x18)
#define STK_CSR 0xE000E010
#define STK_RVR 0xE000E014
#define STK_CVR 0xE000E018
static void led_init ( void )
{
unsigned int ra;
ra=GET32(RCC_AHB1ENR);
ra|=1<<0; //enable GPIOA
PUT32(RCC_AHB1ENR,ra);
ra=GET32(GPIOA_MODER);
ra&=~(3<<10); //PA5
ra|=1<<10; //PA5
PUT32(GPIOA_MODER,ra);
ra=GET32(GPIOA_OTYPER);
ra&=~(1<<5); //PA5
PUT32(GPIOA_OTYPER,ra);
ra=GET32(GPIOA_OSPEEDR);
ra|=3<<10; //PA5
PUT32(GPIOA_OSPEEDR,ra);
//pupdr
ra=GET32(GPIOA_PUPDR);
ra&=~(3<<10); //PA5
PUT32(GPIOA_PUPDR,ra);
}
static void led_on ( void )
{
PUT32(GPIOA_BSRR,((1<<5)<<0));
}
static void led_off ( void )
{
PUT32(GPIOA_BSRR,((1<<5)<<16));
}
void do_delay ( unsigned int sec )
{
unsigned int ra,rb,rc,rd;
rb=GET32(STK_CVR);
for(rd=0;rd<sec;)
{
ra=GET32(STK_CVR);
rc=(rb-ra)&0x00FFFFFF;
if(rc>=16000000)
{
rb=ra;
rd++;
}
}
}
int notmain ( void )
{
unsigned int rx;
led_init();
PUT32(STK_CSR,0x00000004);
PUT32(STK_RVR,0xFFFFFFFF);
PUT32(STK_CSR,0x00000005);
for(rx=0;rx<5;rx++)
{
led_on();
while(1) if(GET32(STK_CVR)&0x200000) break;
led_off();
while(1) if((GET32(STK_CVR)&0x200000)==0) break;
}
while(1)
{
led_on();
do_delay(10);
led_off();
do_delay(1);
}
return(0);
}
flash.ld
MEMORY
{
rom : ORIGIN = 0x08000000, LENGTH = 0x1000
ram : ORIGIN = 0x20000000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > rom
.rodata : { *(.rodata*) } > rom
.bss : { *(.bss*) } > ram
}
then compile
arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m4 flash.s -o flash.o
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -mthumb -mcpu=cortex-m4 -c notmain.c -o notmain.o
arm-none-eabi-ld -o notmain.elf -T flash.ld flash.o notmain.o
arm-none-eabi-objdump -D notmain.elf > notmain.list
arm-none-eabi-objcopy notmain.elf notmain.bin -O binary
can replace with arm-whatever-linux-gnueabi and will still build and run.
there are some toolchains that add extra stuff when they see main() so historically I personally avoid that. I dont use .data on mcus/etc that boot off of flash so dont have to copy that over (burns .text yes), and I dont assume .bss is zero I initialize things before I use them. So I can cheat on my bootstrap, but there are many examples of slightly more complicated linker scripts that give you bss offset and size and .data offset and size and destination to take this to the next level if you wish to have your C more pure. I also prefer to control the instruction used for loads and stores, some/many hope the compiler chooses correctly, have seen that fail. YMMV. so there is a lot of personal style, but take your stm32f11 document and look at those addresses and registers and even if you completely hate my code or style you should still see how easy it was to use that peripheral. Likewise the timers are in the arm docs. These days st being one of them some vendors have their own versions of the arm docs in a modified form so much of the arm info is covered but still some gaps.
As a general rule for arm figure out from the chip vendors documentation what arm core you have in your chip. Then go to arms site and find the technical reference manual (TRM) for that core (cortex-m4 in this case). then in that document arm mentions that is architecture armv7-m get the architectural reference manual for armv7-m. These three documents are your primary sources of information, after your first cortex-m4 you probably only need the chip vendor docs 99% of the time, certainly within a chip vendor. Also find the cpuid registers or chip id or whatever that doc calls it and compare it to what you read out of the chip/arm core. Sometimes there are different versions of the arm core (r1p3 meaning revision 1.3) and rare but happens a change between revisions means using the newest doc against an older core can result in subtle differences. again arm and arm based chips are improving/changing wayy faster than atmel avr based ones. After the first or second you get the hang of it...
If you were going to use a PIC32 for example it would be a similar story microchip for the pic32 docs, then off to mips for the core docs (and then wishing that microchip documented their peripherals even as half as good as atmel (which they now own), ti, st, nxp, etc). Another mixing of buy a processor core and wrap my own stuff around it. the pic32s are painful to program this way, really need libraries buried in the microchip toolchain, and use a ton more power, etc. no reason why mips based shouldnt be able to compete with arm based, but they dont...mips or chip vendors or a combination are at fault there.