Skip to content

Instantly share code, notes, and snippets.

@njtbot
Last active August 29, 2015 14:02
Show Gist options
  • Save njtbot/6c97ca459a7eb9f40fa1 to your computer and use it in GitHub Desktop.
Save njtbot/6c97ca459a7eb9f40fa1 to your computer and use it in GitHub Desktop.
STM32 on OSX Redux

Prerequisites

  • OSX
  • STLink v2

Installation

  • If you don't use homebrew, blindly type this into your terminal -

     ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"   
     brew doctor     
     brew install wget   
    
  • Install the gcc-arm-none-eabi toolchain to your home directory

     wget "https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q2-update/+download/gcc-arm-none-eabi-4_8-2014q2-20140609-mac.tar.bz2"   
     tar -xvf gcc-arm-none-eabi*   
     mv gcc-arm-none-eabi-4_8-* ~/gcc-arm-none-eabi   
    
  • Install Eclipse C/C++

  • Via Eclipse->Help->Install New Software, add these sources and install everthing -

  • Install OpenOCD with support for stlink

     brew install openocd --enable_ft2232_libftdi --enable_stlink --with-libftdi --with-libusb     
    

Debugging

Follow this blog post setup your Eclipse installation, but using the information below.

###openocd config script###

source [find interface/stlink-v2.cfg]   
source [find target/stm32f1x_stlink.cfg]   
reset_config trst_only srst_nogate   

##gdb script##

init

target remote localhost:3333    
mon reset halt    
mon wait_halt      
mon poll   
mon flash probe 0   
mon flash protect 0 0 PAGECOUNT off   
mon reset halt   
mon stm32f1x mass_erase 0   
mon flash write_image erase <FIRMWARE>.elf   
mon flash protect 0 0 PAGECOUNT on   
disconnect   
target remote localhost:3333   
mon reset halt   

Replace PAGECOUNT with (FLASH_SIZE / PAGE_SIZE)

run

thbreak main   
continue   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment