
{"id":119,"date":"2015-01-29T16:14:21","date_gmt":"2015-01-29T16:14:21","guid":{"rendered":"http:\/\/www.elvisneedsboats.com\/?p=119"},"modified":"2016-03-10T18:56:31","modified_gmt":"2016-03-10T18:56:31","slug":"build-environment-for-braillebuzz-the-gnu-tool-chain-for-stm32f103","status":"publish","type":"post","link":"https:\/\/timallen.name\/index.php\/2015\/01\/29\/build-environment-for-braillebuzz-the-gnu-tool-chain-for-stm32f103\/","title":{"rendered":"Build environment for BrailleBuzz (the GNU tool-chain for STM32F103)"},"content":{"rendered":"<p>I am documenting from memory here, I did this over a year ago and have just now gotten round to documenting it. There are a bunch of things I gloss over and one or two inaccuracies that I am miss-remembering. Nevertheless, this should give you a clue and along with the excellent documentation over at gnu.org it should get you going. Of particular use are my bash scripts, read them, understand them, and optionally use them verbatim. Also use the docs on the olmex site. I used those development boards to bootstrap this project they are excellent! I don&#8217;t know if it&#8217;s the &#8220;right&#8221; way but what I did was to create a usr directory off my home directory. While I have root on my box, and everything else around here, my goal was to avoid using it so that I could simply zip it up and hand it off to another developer; which is what I have recently done.<br \/>\n<code style=\"font-size: 80%\"><br \/>\ntallen@timmy:~\/usr$ ls -l<br \/>\ntotal 32<br \/>\ndrwxrwxr-x  5 tallen tallen 4096 Jan 24  2014 arm-none-eabi<br \/>\ndrwxrwxr-x  2 tallen tallen 4096 Mar 24  2014 bin<br \/>\ndrwxrwxr-x 12 tallen tallen 4096 Feb 26  2014 build<br \/>\ndrwxrwxr-x  3 tallen tallen 4096 Mar 17  2014 include<br \/>\ndrwxrwxr-x  3 tallen tallen 4096 Mar 24  2014 lib<br \/>\ndrwxrwxr-x  3 tallen tallen 4096 Jan 24  2014 libexec<br \/>\ndrwxrwxr-x  9 tallen tallen 4096 Feb 12  2014 share<br \/>\ndrwxrwxr-x 11 tallen tallen 4096 Mar 24  2014 src<br \/>\n<\/code><\/p>\n<p>Under src one puts the source for the various tools, e.g. binutils, gcc, gdb, openocd, speex, and gmp, mpc, mpfr; the latter three are prerequisites for gcc.<br \/>\n<code style=\"font-size:80%\"><br \/>\ntallen@timmy:~\/usr\/src$ ls -l<br \/>\ntotal 138384<br \/>\ndrwxrwxr-x 17 tallen tallen     4096 Jan 24  2014 binutils-2.24<br \/>\n-rw-rw-r--  1 tallen tallen 22716802 Dec  2  2013 binutils-2.24.tar.bz2<br \/>\ndrwxr-xr-x 33 tallen tallen     4096 Oct 16  2013 gcc-4.8.2<br \/>\n-rw-rw-r--  1 tallen tallen 85999682 Oct 16  2013 gcc-4.8.2.tar.bz2<br \/>\ndrwxrwxr-x 15 tallen tallen     4096 Feb 11  2014 gdb-7.7<br \/>\n-rw-rw-r--  1 tallen tallen 24846320 Feb  5  2014 gdb-7.7.tar.bz2<br \/>\ndrwxr-xr-x 15 tallen tallen     4096 Sep 30  2013 gmp-5.1.3<br \/>\n-rw-rw-r--  1 tallen tallen  1818812 Sep 30  2013 gmp-5.1.3.tar.xz<br \/>\ndrwxr-xr-x  6 tallen tallen     4096 Jan 15  2014 mpc-1.0.2<br \/>\n-rw-rw-r--  1 tallen tallen   633173 Jan 15  2014 mpc-1.0.2.tar.gz<br \/>\ndrwxr-xr-x  9 tallen tallen     4096 Mar 13  2013 mpfr-3.1.2<br \/>\n-rw-rw-r--  1 tallen tallen  1074388 Mar 13  2013 mpfr-3.1.2.tar.xz<br \/>\ndrwxrwxr-x  9 tallen tallen     4096 Mar 24  2014 newlib<br \/>\ndrwxr-xr-x  8 tallen tallen     4096 May  5  2013 openocd-0.7.0<br \/>\n-rw-------  1 tallen tallen  3493924 Feb 10  2014 openocd-0.7.0.tar.bz2<br \/>\ndrwxrwxr-x  9 tallen tallen     4096 Apr  7  2014 speex-1.2rc1<br \/>\n-rw-rw-r--  1 tallen tallen  1061882 Jul 23  2008 speex-1.2rc1.tar.gz<br \/>\n<\/code><\/p>\n<p>Next one creates a build directory under usr. Under build one creates directories for each of the utilities enumerated below. I also played some games with soft links to facilitate version upgrades later:<br \/>\n<code style=\"font-size:80%\"><br \/>\ntallen@timmy:~\/usr\/build$ ls -l<br \/>\ntotal 168<br \/>\nlrwxrwxrwx  1 tallen tallen     14 Jan 24  2014 binutils -> binutils-2.24\/<br \/>\ndrwxrwxr-x 11 tallen tallen   4096 Feb 18  2014 binutils-2.24<br \/>\nlrwxrwxrwx  1 tallen tallen     11 Jan 24  2014 gcc_1 -> gcc-4.8.2_1<br \/>\nlrwxrwxrwx  1 tallen tallen     11 Jan 24  2014 gcc_2 -> gcc-4.8.2_2<br \/>\ndrwxrwxr-x 14 tallen tallen   4096 Feb 18  2014 gcc-4.8.2_1<br \/>\ndrwxrwxr-x 12 tallen tallen   4096 Mar 24  2014 gcc-4.8.2_2<br \/>\n-rw-rw-r--  1 tallen tallen 129742 Feb 10  2014 gcc_arm-eabi_build.pdf<br \/>\nlrwxrwxrwx  1 tallen tallen      7 Feb 11  2014 gdb -> gdb-7.7<br \/>\ndrwxrwxr-x 11 tallen tallen   4096 Feb 11  2014 gdb-7.7<br \/>\nlrwxrwxrwx  1 tallen tallen     10 Jan 24  2014 gmp -> gmp-5.1.3\/<br \/>\ndrwxrwxr-x 15 tallen tallen   4096 May 29 14:20 gmp-5.1.3<br \/>\nlrwxrwxrwx  1 tallen tallen     10 Jan 24  2014 mpc -> mpc-1.0.2\/<br \/>\ndrwxrwxr-x  5 tallen tallen   4096 Apr  7  2014 mpc-1.0.2<br \/>\nlrwxrwxrwx  1 tallen tallen     10 Jan 24  2014 mpfr -> mpfr-3.1.2<br \/>\ndrwxrwxr-x  6 tallen tallen   4096 Mar 17  2014 mpfr-3.1.2<br \/>\ndrwxrwxr-x  4 tallen tallen   4096 Apr  7  2014 newlib<br \/>\nlrwxrwxrwx  1 tallen tallen     14 Feb 10  2014 openocd -> openocd-0.7.0\/<br \/>\ndrwxrwxr-x  5 tallen tallen   4096 Feb 11  2014 openocd-0.7.0<br \/>\nlrwxrwxrwx  1 tallen tallen     12 Feb 26  2014 speex -> speex-1.2rc1<br \/>\ndrwxrwxr-x  9 tallen tallen   4096 Apr  9  2014 speex-1.2rc1<br \/>\n<\/code><\/p>\n<h2>binutils<\/h2>\n<p>Binutils includes things like the assembler, you do remember that the assembler is the back-end for gcc; that is, gcc really just produces assembly which is fed to the assembler, the linker, the archiver, and other tools. There are practical reasons why these steps are combined under the gcc command line interface. One creates a directory in which to one builds the binutils. I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash\r\n..\/..\/src\/binutils-2.24\/configure \r\n--target=arm-none-eabi \r\n--prefix=$HOME\/usr \r\n--enable-interwork \r\n--enable-multilib \r\n--with-gcc \r\n--with-gnu-as \r\n--with-gnu-ld \r\n--disable-nls \r\n--disable-shared \r\n--disable-werror\r\n<\/pre>\n<p>Don&#8217;t forget to do &#8220;make install&#8221;<\/p>\n<h2>gmp<\/h2>\n<p>One creates a directory in which to one builds gmp. I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash\r\n..\/..\/src\/gmp-5.1.3\/configure \r\n--disable-shared \r\n--enable-static \r\n--prefix=$HOME\/usr\r\n<\/pre>\n<h2>mpc<\/h2>\n<p>One creates a directory in which to one builds mpc. I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash\r\n..\/..\/src\/mpc-1.0.2\/configure \r\n--prefix=$HOME\/usr \r\n--with-gmp=$HOME\/usr \r\n--with-mpfr=$HOME\/usr \r\n--disable-shared \r\n--enable-static\r\n<\/pre>\n<h2>mpfr<\/h2>\n<p>One creates a directory in which to one builds mpfr. I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash\r\n..\/..\/src\/mpfr-3.1.2\/configure \r\n--prefix=$HOME\/usr \r\n--with-gmp=$HOME\/usr \r\n--disable-shared \r\n--enable-static\r\n<\/pre>\n<h2>gcc<\/h2>\n<p>One builds gcc in two steps and the previous tasks are prerequisites. Let&#8217;s take a moment and think about what we&#8217;re actually doing here. We are using the host&#8217;s native gcc compiler to build a cross compiler from (more or less) the same source that built the native compiler (look up what GNU actually stands for and see if you get the joke); that is, a compiler that runs on one arch (the host, probably an Intel variant) but produces code that will run on another arch (the target, in this case, an ARM variant). To make things more confusing the compiler actually needs itself. So one builds a striped down version of gcc (just C), and then one builds the full version of gcc (C &#038; C++). Confused yet, no? GNUs not unix&#8230; GNUs not unix&#8230;<\/p>\n<h5>gcc_1<\/h5>\n<p>One creates a directory in which to one builds the stripped down gcc, gcc_1. I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash -x\r\n..\/..\/src\/gcc-4.8.2\/configure \r\n--target=arm-none-eabi \r\n--prefix=$HOME\/usr \r\n--enable-interwork \r\n--enable-multilib \r\n--disable-libssp \r\n--enable-languages=\"c\" \r\n--with-newlib \r\n--without-headers \r\n--disable-shared \r\n--disable-threads \r\n--with-gnu-as \r\n--disable-nls \r\n--with-gnu-ld \r\n--with-gmp=$HOME\/usr \r\n--with-mpfr=$HOME\/usr \r\n--with-mpc=$HOME\/usr\r\n<\/pre>\n<p>Don&#8217;t forget to do &#8220;make install&#8221;<\/p>\n<h5>newlib or libc<\/h5>\n<p>You&#8217;ll need newlib or libc to build the full compiler. The full compiler needs libc stuff for it&#8217;s built-ins. One needs to build newlib, this is a slightly stripped down version of libc especially for MCUs and SOCs. So use the stripped down gcc to build newlib, I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash\r\n..\/..\/src\/newlib\/configure \r\n--target=arm-none-eabi \r\n--prefix=$HOME\/usr \r\n--enable-interwork \r\n--enable-multilib \r\n--with-float=soft \r\n--enable-soft-float \r\n--disable-nls \r\n--with-gnu-ld \r\n--with-gnu-as \r\n--disable-shared \r\nCFLAGS_FOR_TARGET=\" \r\n-g \r\n-Ofast \r\n-ffunction-sections \r\n-fdata-sections \r\n-DPREFER_SIZE_OVER_SPEED \r\n-D__OPTIMIZE_SIZE__ \r\n-fomit-frame-pointer \r\n-mcpu=cortex-m3 \r\n-mthumb \r\n-mfix-cortex-m3-ldrd \r\n-D__thumb2__ \r\n-D__BUFSIZ__=256\" \r\nCCASFLAGS=\"-mcpu=cortex-m3 \r\n-mthumb \r\n-mfix-cortex-m3-ldrd \r\n-D__thumb2__\"\r\n<\/pre>\n<h5>gcc_1<\/h5>\n<p>Then one builds the fill compiler in the directory gcc_2. I created a small bash script.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash -x\r\n..\/..\/src\/gcc-4.8.2\/configure \r\n--target=arm-none-eabi \r\n--prefix=$HOME\/usr \r\n--enable-interwork \r\n--enable-multilib \r\n--disable-libssp \r\n--enable-languages=\"c,c++\" \r\n--with-newlib \r\n--disable-shared \r\n--with-float=soft \r\n--with-cpu=cortex-m3 \r\n--with-tune=cortex-m3 \r\n--with-mode=thumb \r\n--with-system-zlib \r\n--with-gnu-as \r\n--with-gnu-ld \r\n--disable-nls \r\n--with-gmp=$HOME\/usr \r\n--with-mpfr=$HOME\/usr \r\n--with-mpc=$HOME\/usr\r\n<\/pre>\n<p>Notice the &#8220;&#8211;with-newlib&#8221; the full compiler needs libc stuff for it&#8217;s built-ins. One needs to build newlib, this is a slightly stripped down version of libc especially for MCUs and SOCs. So use the stripped down gcc to build newlib, then build the full version of gcc and then re-build newlib.<\/p>\n<h2>gdb<\/h2>\n<p>Your gonna want a debugger and if doesn&#8217;t get any better than gdb. Okay, it&#8217;s got a steep learning curve, the the curses stuff has issues, but it has features. Perhaps my favorite feature is that it works more or less the same on whatever platform and I don&#8217;t know about you but I haven&#8217;t the time to learn a bunch of proprietary UIs. GDB works with openocd to do remote debugging.<\/p>\n<pre class=\"lang:default decode:true \" >&lt;pre class=\"lang:default decode:true \" &gt;\r\n#!\/bin\/bash\r\n..\/..\/src\/gdb-7.7\/configure \r\n--prefix=$HOME\/usr \r\n--target=arm-none-eabi \r\n--enable-interwork \r\n--enable-multilib\r\n&lt;\/pre&gt; <\/pre>\n<h2>openocd<\/h2>\n<p>I had to build openocd from scratch to get a workable version. This was over a year ago and openocd was very young, it has matured a lot and the stock copy that comes with your distro will probably work for you nowadays, I include it here just for completeness.<\/p>\n<pre class=\"lang:default decode:true \" >\r\n#!\/bin\/bash\r\n..\/..\/src\/openocd-0.7.0\/configure \r\n--enable-ft2232_libftdi \r\n--prefix=$HOME\/usr\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am documenting from memory here, I did this over a year ago and have just now gotten round to documenting it. There are a bunch of things I gloss over and one or two inaccuracies that I am miss-remembering. Nevertheless, this should give you a clue and along with the excellent documentation over at &hellip; <a href=\"https:\/\/timallen.name\/index.php\/2015\/01\/29\/build-environment-for-braillebuzz-the-gnu-tool-chain-for-stm32f103\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Build environment for BrailleBuzz (the GNU tool-chain for STM32F103)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-aph","category-embedded"],"_links":{"self":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":3,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":312,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/119\/revisions\/312"}],"wp:attachment":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}