June 4, 2015

New(ish) Tools for STM32 Development – STM32Cube

About 2 years ago, I authored a five-part tutorial on setting up a free/open source toolchain with Eclipse and GCC to develop code on ST's line of STM32 microcontrollers. (Part 1, Part 2, Part 3, Part 4, Part 5, Followup) That series demonstrated how challenging it can be to properly set up these tools and get them configured for the microcontroller of your choice.

Since then, ST has really upped their game and has introduced two tools that really make the process of developing for the STM32 line of parts much, much easier. In fact, I'd go so far as to say my tutorial series has been made obsolete.

The first tool is STM32Cube. STM32Cube (also called STM32CubeMX) is a Java based GUI tool that assists in the selection of an appropriate microcontroller, in the setup and configuration of on-chip peripherals, and in building a project that has all of the proper dependencies and initialization code built in. I haven't used this tool a whole lot yet, but I can tell you that I'm already wowed by it. STM32Cube is a free download from the ST website. It currently is packaged as a .zip file that includes an .exe. Running the .exe opens the GUI. Though it is a Java tool, ST only provides a version of the tool for Windows, though if you do some searching on the web you'll see that others have managed to get it working on other operating systems.

The other tool, which I'll discuss in my next blog post, is STM32 Workbench, which is a preconfigured Eclipse environment for STM32 development.

Can you see why my previous tutorial series is now obsolete?

Let's first take a look at STM32Cube. Here's an example of using the tool for a project I'm currently designing. Launching the tool, the user is given a couple of pretty obvious choices: create a new project, or load an existing project (as always, click on the thumbnail for fullsize graphics):

The STM32CubeMX Splash Screen

The STM32CubeMX Splash Screen

After clicking New Project, a parametric product selector is displayed. Check the onboard peripherals you want, select the chip series and package(s) you want, and the tool will tell you which parts meet your needs. Much easier than browsing Digi-Key or Mouser!

Choosing a part

Choosing a part

In my case, I'm designing a project that needs 3 UARTs, two I2C, one SPI, and has some EEPROM. I ended up selecting the STM32L051C6Tx chip:

The microcontrollers that are suitable for my application.

The microcontrollers that are suitable for my application.

(Note that even though my project requires 3 UARTs, I still had to juggle my requirements between UARTs, USARTs, and the LPUART. I suppose no tool is perfect.)

After highlighting the part and clicking OK, STM32CubeMX brings up an interface that allows you to configure the selected part. The four tabs are Pinout, Clock Configuration, Configuration, and Power Consumption Calculator. This is where STM32Cube gets really interesting.

Choosing a pinout from a blank slate.

Choosing a pinout from a blank slate.

From this blank slate, I made the following selections:

  • I expanded the FATFS node and checked the box to include this middleware in my project.
  • I enabled I2C1 and I2C2.
  • I set LPUART1 to Asynchronous mode.
  • In the RCC, I set both the HSE and LSE clocks to Crystal/Ceramic Resonator.
  • I enabled SPI1 in full-duplex master mode.
  • I checked the SWD debug function in the SYS node.
  • I set USART1 and USART2 to Asynchronous mode.

As you can see, the pin planner tells me which pins are connected to which peripherals. If I want to map a peripheral to a pin other than the one selected, I can CTRL-click on the pin and the tool will show me which other pins can be used for that function. Red X's indicate functions that cannot be used because another peripheral is already on the required pin(s). Yellow exclamation marks show peripherals that have one or more subfeatures that are not available because required pins are in use by other peripherals.

Pin Planning in STM32CubeMX.

Pin Planning in STM32CubeMX.

After placing the on-chip peripherals on pins, you can assign GPIO pins. Click on a pin to bring up a dropdown that lists the pin's available functions.

Selecting a use for PB5.

Selecting a use for PB5.

Here I've set PB3, PB4, PB5, and PA15 to digital outputs to drive LEDs, and PB8 and PB9 to digital inputs to accept signals from pushbuttons. Note that STM32CubeMX allows me to label the pins here as well. These labels will become symbols in the generated C code as well.

Pushpin icons show the manually placed pin functions.

Pushpin icons show the manually placed pin functions.

Once all the pins are assigned, we can look at the Clock Configuration tab. ST used to provide this tool as a rather inconvenient Excel spreadsheet. Now it's integrated into the code generation tool, which is nice. And given the complexity of the STM32 parts' clock systems, it saves a lot of headaches. Here, I've changed the clocking from the HSI (internal) clock to the HSE (external crystal) clock, and I've done the same for the low speed clock that drives the RTC. The system clock and most peripherals are running at 8MHz, which should be fine for my application.

Clock configuration.

Clock configuration.

After pins are mapped and clocking is done, the Configuration tab allows us to configure the selected peripherals and middleware. Here you can see that I have options for the FATFS filesystem, my UARTS, SPIs and I2Cs, the DMA controller, the GPIO pins, the NVIC, RCC and the RTC. (You'll find these terms defined in the STM32 reference manuals.)

Peripheral Configuration

Peripheral Configuration

For this project, I plan on using an SD card in SPI mode to store files in a FAT filesystem. The number of options that can be compiled in or excluded from FatFS are numerous:

Tweaking FATFS.

Tweaking FATFS.

I'm not going to show you all the screenshots for all the peripherals, but here I am putting a pullup resistor on my button inputs so that I don't need an external resistor:

Selecting GPIO options.

Selecting GPIO options.

Once the pins are mapped, the clocks are configured, and the peripherals are configured comes the really fun part: automatic code generation! With the click of a button, STM32CubeMX will automatically generate a project for you, after automatically downloading appropriate libraries for your target MCU if required. The generated project files look a lot like the sample projects I outlined in my earlier tutorial series.

One interesting thing about the generated code is that there are comments embedded in the code files, such as this set in the generated main() function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_I2C2_Init();
MX_LPUART1_UART_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_RTC_Init();
MX_SPI1_Init();
MX_FATFS_Init();

/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}
/* USER CODE END 3 */

}

Any code that you put between the USER CODE BEGIN and USER CODE END comments will be preserved if you go back and make changes in STM32CubeMX and re-generate your code.

Now, I haven't had a lot of time to play with the tool, but it looks very promising to me, and certainly a lot easier than the hoops I had to jump through in my previous tutorial series.

Next post, I'll look at STM32 Workbench.

 

February 12, 2014

Selecting Crystal Load Capacitors

When designing a circuit recently, I was faced with selecting appropriate load capacitors for the crystal oscillator on my microcontroller. While in the end this selection is rather straightforward, finding the relevant information can be a challenge. My Google searches weren't as helpful as I'd hoped they'd be, and I had to pull together information from several sources. I wrote this blog post to pull together all of the information I found into a single page that hopefully can serve as a reference for others.

So let's begin: what are load capacitors and why are they needed? (more…)

September 27, 2012

Yet Another Low-Cost Dev Board

Freescale joins the bevy of companies offering low-cost ARM dev boards with the Cortex-M0+ based "Freedom" dev platform.

Based on the Kinetis L series KL1 and KL2 chips, this $12 board offers the usual slew of peripherals, an onboard debugger, and various goodies including USB, an accelerometer, and a tri-color LED. A touch slider is included as well, and the chip supports updating firmware via a simple drag-and-drop USB mass storage interface, which is cool.

Interestingly, Freescale designed the board to be pin-compatible with Arduino shields. This is surprising news from a company that has been known to be very unfriendly to hackers/makers.

So I've got my STM32F0DISCOVERY, my STM32F4DISCOVERY, my LPCXpress board, my Stellaris M4F should be here soon, now there's the Freescale part (that I may or may not order), and I haven't even ordered a Raspberry Pi yet.

How many other low-cost ARM dev boards are there? How are manufacturers going to differentiate their products if this trend continues?

October 12, 2011

Free STM32F4DISCOVERY dev board

ST Micro just announced the STM32F4 series of processors and the STM32F4DISCOVERY kit. In fact, as I write this, ST is having a giveaway promo for the new discovery board. I have been thinking of an audio effects processor project for which this series of chips would be perfect. They have floating point processors, I2S interfaces, external memory interfaces, and high clock rates. (Yes, this is the same project idea I had for the Renesas RX600 contest. The two chips both have features that make them candidates for the project; I'll discuss the pros and cons of each in a later post.)

So, of course, I ordered one right away. (Especially when I found out it was free!) It was shipped remarkably quickly. Digi-Key is clearly the fulfillment house for ST based on the return address on the package. The board comes in clamshell packaging with little to no documentation.

I have 2 or 3 projects in my queue right now (and still have a wife, a job, and two kids) so it may be a while before I get to use this.

April 19, 2011

Capacitive Touch Booster Pack for Launchpad

Texas Instruments has released the Capacitive Touch Booster Pack for the Launchpad platform. This hardware/software combo demonstrates the use of touch sensitivity and proximity sensing with the Launchpad platform. Check out the video for an interesting demonstration!

While I've not been a big fan of touch sensing (which has been all the rage lately), I have to admit that the demo does look pretty cool. TI spent some effort in designing the hardware and software to make interesting apps, and it shows. I actually found myself thinking about things I could do with this platform rather than dismissing the product out of hand like I've done before when looking at 'touch sense' applications.

The launch price is, surprise surprise, $4.30 but the claim is that's a limited time price. As with the Launchpad itself, you can order up to 3 of them at once. Also like the Launchpad order itself, TI is not charging shipping.

So I have a couple of these on their way to me; maybe I'll find something cool and interesting to do with them.

LPCXpresso Board Arrived

On March 12, I blogged about the NXP LPCXPresso giveaway. I posted a video online of myself destroying some chips using the NXP "break your 8/16 bit habit" theme to qualify for a free board.

At the time, I was somewhat doubtful that I'd get a board. The eligibility requirements weren't clearly spelled out and the entry form requires a 'business' e-mail address.

Well, I'm happy to report that NXP sent me an LCP1114 XPresso board! I haven't had time to dive into it yet but I'm pleased to have the new hardware. The Cortex M0 platform looks like it's going to be a lot of fun.

March 12, 2011

NPC LPCXpresso Giveaway

NXP is giving away LPCXPresso boards to people who submit a video of themselves destroying an 8 or 16 bit micro. I'm not sure which board they're giving away or what the qualifications are for being eligible (the submission ominously requires a "Business" email address) but it's worth a try I suppose.

The Cortex M0 is positioned as an upgrade for existing 8 or 16 bit applications. Color me jaded, but the M0 specs are significantly more impressive than the typical 8/16 bit micro. The low-end LPC111x series tout the following features (datasheet):

  • System:
    • ARM Cortex-M0 processor, running at frequencies of up to 50 MHz.
    • ARM Cortex-M0 built-in Nested Vectored Interrupt Controller (NVIC).
    • Serial Wire Debug.
    • System tick timer.
  • Memory:
    • 32 kB (LPC1114), 24 kB (LPC1113), 16 kB (LPC1112), or 8 kB (LPC1111) on-chip flash programming memory.
    • 8 kB, 4 kB, or 2 kB SRAM
    • In-System Programming (ISP) and In-Application Programming (IAP) via on-chip bootloader software.
  • Digital peripherals:
    • Up to 42 General Purpose I/O (GPIO) pins with configurable pull-up/pull-down resistors.
    • GPIO pins can be used as edge and level sensitive interrupt sources.
    • High-current output driver (20 mA) on one pin.
    • High-current sink drivers (20 mA) on two I2C-bus pins in Fast-mode Plus.
    • Four general purpose counter/timers with a total of four capture inputs and 13 match outputs.
    • Programmable WatchDog Timer (WDT).
  • Analog peripherals:
    • 10-bit ADC with input multiplexing among 8 pins.
  • Serial interfaces:
    • UART with fractional baud rate generation, internal FIFO, and RS-485 support.
    • Two SPI controllers with SSP features and with FIFO and multi-protocol capabilities (second SPI on LQFP48 and PLCC44 packages only).
    • I2C-bus interface supporting full I2C-bus specification and Fast-mode Plus with a data rate of 1 Mbit/s with multiple address recognition and monitor mode.
  • Clock generation:
    • 12 MHz internal RC oscillator trimmed to 1 % accuracy that can optionally be used as a system clock.
    • Crystal oscillator with an operating range of 1 MHz to 25 MHz.
    • Programmable watchdog oscillator with a frequency range of 7.8 kHz to 1.8 MHz.
    • PLL allows CPU operation up to the maximum CPU rate without the need for a high-frequency crystal. May be run from the system oscillator or the internal RC oscillator.
    • Clock output function with divider that can reflect the system oscillator clock, IRC clock, CPU clock, and the Watchdog clock.
  • Power control:
    • Integrated PMU (Power Management Unit) to minimize power consumption during Sleep, Deep-sleep, and Deep power-down modes.
    • Power profiles residing in boot ROM allowing to optimize performance and minimize power consumption for any given application through one simple function call. (LPC1100L series, on LPC111x/102/202/302 only.)
    • Three reduced power modes: Sleep, Deep-sleep, and Deep power-down.
    • Processor wake-up from Deep-sleep mode via a dedicated start logic using up to 13 of the functional pins.
    • Power-On Reset (POR).
    • Brownout detect with four separate thresholds for interrupt and forced reset.
  • Unique device serial number for identification.
  • Single power supply (1.8 V to 3.6 V).
  • Available as 48-pin LQFP package, 33-pin HVQFN package, and 44-pin PLCC package.

That pretty much eclipses any 8/16 bit micro I've ever used. The LPC1111 is priced as low as $2.02 for one piece at Digi-Key. That's easily within the realm of hobbyist dollars! (The QFN packaging, though, could be a roadblock to many. You can get an LPC1100L in 48-LQFP for $2.80)

I think I'll head outside and take a few video clips of semiconductor destruction today.

March 10, 2011

Arduino Sketches on the Launchpad?

Chris Hulbert has created a header file for the TI MSP430 Launchpad that ports some of the Arduino functions to TI's platform.

Macros for setup(), loop(), delay(), pinMode(), pinBit(), digitalWrite(), and digitalRead() are included. Chris also disables the MSP430's watchdog timer, which will help a lot of newbies (and would have helped me on my first project).

It'll be interesting to see how "Arduino-like" the community can make the TI platform. TI is clearly going after the hobbyist market with this platform, but they certainly aren't providing the support or the ecosystem that's needed to really engage this audience. Tools like this one may make up the difference. (I doubt, however, that the MSP430 will ever approach the popularity of the Arduino. TI just doesn't seem to "get it" about supporting and engaging the hobbyist community.)

I still plan on creating some tutorials for the Launchpad, but it'll have to wait at least until the Renesas RX Design Contest ends on the 27th.