Channels ▼

Al Williams

Dr. Dobb's Bloggers

Strong Arm Tactics

December 28, 2012

The end of the year is always a good time to catch up on major projects. This year I put together a 3D printer (very cool; I’ll have more to say about it next year) and finally got around to working out how to program a particular ARM board from Linux.

More Insights

White Papers

More >>

Reports

More >>

Webcasts

More >>

The ARM board in question is from a Thai company called ETT and available through Futurlec. For about $25 you get an ST32F103 processor that has 64K of RAM and 512K of flash. The Cortex M3 CPU runs at 90MIPS and has the usual array of analog and digital I/O. Not bad for the price.

The board has a serial port and a bootloader, and even comes with a cable to connect to a PC. My problem is the software on the CD was all Windows-based. I lost the CD and it doesn't appear to be online anywhere. My eventual goal was to not use the bootloader anyway. I wanted to use an Olimex JTAG adapter — another inexpensive piece. Add a breadboard and a 3.3V power supply, and you have a pretty capable ARM set up for well under $100.

Recently, I complained that NXP didn't support Linux whole-heartedly. That's true, but ST's support for straight-up GNU tools is pretty much non-existent. There's great support for development tools from different vendors, but if you are looking for support for just pure GNU tools, there isn't much. Luckily, the RIDE tools are close to "stock" GCC, so the files provided for that toolchain will work, for the most part.

For the ARM compiler, you need arm-none-eabi-gcc and its friends. There are a lot of options for getting these. Codesourcery keeps current builds available. They'd also like to sell you their other tools, but the basic open source tools are free (I assume since Mentor bought them, this will continue to be the case). About the only limitation I've found with these tools is that they don't build gdb with the insight option (the GUI debugger). I'll mention a few workarounds for that in a future blog.

There are three other parts to the puzzle: The ST libraries, something to push code down to the bootloader, and something to drive the JTAG adapter. The libraries are easy enough to find on the ST site. The current version is in the file stm32f10x_stdperiph_lib.zip ( go to the ST site and click on Resources to browse for the latest version). The example projects for RIDE are close to what you need to get started.

For the bootload downloader, there are a few options but all of them load .bin files, not .hex files. Of course, it is no trouble to make the tools write out binary files. The tool I picked was stm32ld. The bootloader autodetects the baud rate, and 19200 baud seemed to work fine.

You might question why you need the ST libraries. In theory, you don't if you don't mind programming everything at the register level. You'll also need to create a startup file and a link script. Here's the first part of my demo program using the ST libraries:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

The clock enabling, for example, is quite a bit of register-level code. It is much easier to use the library code and there is even good documentation for it on the ST site.

I am mainly using the JTAG adapter to program the device, but if you are using the bootloader, you need to push the blue pushbutton on the board, which causes the boot LED to light. Then press reset. You can now run stm32ld to send a .bin file to the flash memory. To run your program, press the blue button again (the boot LED turns off) and then reset the board.

This is still a work in progress, but it is working. I'll show you more of the code and all the glue required to put it together next time. I'll also talk about JTAG, getting around the non-GUI debugger, and some of the CPU's capabilities in upcoming blogs.

Related Reading






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video