Wenton Davis' Cortex-M0 Getting Started Page



Description

Although there are plenty of ARM and ARM-Cortex development systems out there, most of them suffer from a rather crucial problem - they are proprietary leading to - they are expensive.  Sure, most of them have a "limited" or "restricted" mode of operation.  Keil, for example, limits the code space available to 32K.  For classes that introduce assembly language programming, this is fine because most programs developed for introduction level classes are nowhere near this size.  Larger programs, however, or programs needing larger amounts of ROM, need the full memory space.  Therefore, this page will use the GNU toolchain, which is not restrictive in memory space.  It may not have the flashy pretty GUI that other systems have, but it is free, and widely used and supported, and did I mention, FREE?

Resources

New_2019.zip Labs and sample code
Discovery documents from ST Microelectronics




The Hardware Driver

Since Keil is proprietary software, it will be necessary to move to using the GNU toolchain.  For starters, download the STLink V2 Drivers.  For Windoze users, this is found on the st.com web site, although it takes a little work, you are looking for the STLink-V2 driver.

For Linux users, switch to root, then use git:


# git clone https://github.com/texane/stlink stlink.git
# cd stlink.git
# make

to download the repository into the new stlink.git directory and build the software.  Next, move the software into place:


# cp build/Release/bin/* /usr/local/bin/
# cp config/udev/rules.d/* /etc/udev/rules.d/

and finally restart udev:


# udevadm control --reload

Connect the STLink-V2 devices to USB.  Looking at the /var/log/messages file, you should see something like this:


Mar 10 15:43:34 thoughtmountain kernel: [3091256.545430] usb 1-4: new full-speed USB device number 24 using xhci_hcd
Mar 10 15:43:34 thoughtmountain kernel: [3091256.710319] usb 1-4: New USB device found, idVendor=0483, idProduct=3748
Mar 10 15:43:34 thoughtmountain kernel: [3091256.710321] usb 1-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar 10 15:43:34 thoughtmountain kernel: [3091256.710322] usb 1-4: Product: STM32 STLink
Mar 10 15:43:34 thoughtmountain kernel: [3091256.710323] usb 1-4: Manufacturer: STMicroelectronics
Mar 10 15:43:34 thoughtmountain kernel: [3091256.710323] usb 1-4: SerialNumber: Pÿr^FIwSUCI^D
Mar 10 15:43:35 thoughtmountain kernel: <27>[3091257.376207] udevd[592]: specified group 'usbtmc' unknown
Mar 10 15:43:35 thoughtmountain mtp-probe: checking bus 1, device 24: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4" 
Mar 10 15:43:35 thoughtmountain mtp-probe: bus: 1, device: 24 was not an MTP device 

Looking at the USB bus:


# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 024: ID 0483:3748 STMicroelectronics ST-LINK/V2
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

You want to see the line indicating "STMicroelectronics ST-LINK/V2" which indicates that the system has identified the STLink, and the USB system knows what it is.

If you have a device attached to the STLink (such as the STM32F0....) you can download the chip's memory.  You should get results like:


# st-flash read dummy.bin 0 0xFFFF
st-flash 1.6.1-209-gdc6310b
2021-03-10T15:51:49 INFO common.c: F0xx: 8 KiB SRAM, 64 KiB flash in at least 1 KiB pages.
2021-03-10T15:51:49 INFO common.c: read from address 0000000000 size 65535

At this point, you can feel confident that the STLink driver is installed and working correctly.




Get the Toolchain

The next trick is to get the toolchain.  This allows us to actually compile, assemble, and link the programs.  For Windoze users, Mac OS X, and Linux X86_64, there are prebuilt packages found at developer.arm.com.  There is also a source tarball for other systems.  Each package has a readme.txt file that contains installation instructions.

For Slackware 14.2 32-bit, use these:

arm-binutils-2.25-i586-1_slonly.txz assmbler, linker, etc.
arm-gcc-4.9.2-i586-1_slonly.txz C(++) compiler
arm-gdb-7.8.1-i586-1_slonly.txz debugger
openocd-0.8.0-i586-1_slonly.txz jtag interface

and install it:


upgradepkg --install-new your-long-package-file-name

When everything is in place, you should have the following:


arm-none-eabi-addr2line   
arm-none-eabi-ar          
arm-none-eabi-as          
arm-none-eabi-c++         
arm-none-eabi-c++filt     
arm-none-eabi-cpp         
arm-none-eabi-dwp         
arm-none-eabi-elfedit     
arm-none-eabi-g++         
arm-none-eabi-gcc         
arm-none-eabi-gcc-4.9.2   
arm-none-eabi-gcc-ar      
arm-none-eabi-gcc-nm      
arm-none-eabi-gcc-ranlib  
arm-none-eabi-gcov        
arm-none-eabi-gdb         
arm-none-eabi-gprof       
arm-none-eabi-ld          
arm-none-eabi-ld.bfd      
arm-none-eabi-ld.gold     
arm-none-eabi-nm          
arm-none-eabi-objcopy     
arm-none-eabi-objdump     
arm-none-eabi-ranlib      
arm-none-eabi-readelf     
arm-none-eabi-run         
arm-none-eabi-size        
arm-none-eabi-strings
arm-none-eabi-strip




Once you get this far, it's time for a nice sandwich.  I'm going for roast beef and swiss.

Next, let's test the toolchain!




home

If you need to reach me, you can always email me at email (wenton@ieee.org)