Embedded

Using Arduino Leonardo as an USB/UART adapter

In contrasts to older designs like the Arduino Uno, the Arduino Leonardo features a separate connection Serial1 for TTLUART whereas Serial is used for the USB CDC UART interface.

This allows one to use the Leonardo as an USB/UART bridge without having to resort to more expensive boards like the Arduino Mega 2560. In order to do this, use this sketch which can also be modified to provide an intelligent UART bridge.

Remember to adjust the baudrate for your application. This version of the sketch does not support automatic baudrate selection via the CDC peripheral.

Continue reading →

Posted by Uli Köhler in C/C++, Embedded

Accessing lwIP struct netif instance in ChibiOS

Problem

You are using the ChibiOS lwIP binding to access the network your microcontroller application.

You need to access the lwIP struct netif structure, for example to get the current DHCP IP address assigned to the network interface. However, the default ChibiOS implementaton in lwipthread.c does not export the interface structure.
Continue reading →

Posted by Uli Köhler in C/C++, Embedded

Solving undefined symbol __main_stack_size__ in ChibiOS 3.x

Problem:

When trying to compile ChibiOS 3.x you get one of these error messages during the linking stage:

undefined symbol `__main_stack_size__' referenced in expression
undefined symbol `__process_stack_size__' referenced in expression

Continue reading →

Posted by Uli Köhler in C/C++, Embedded

Reading the STM32 unique device ID in C

All STM32 microcontrollers feature a 96-bit factory-programmed unique device ID. However, for me it was hard to find an adequately licensed example on how to read it in a manner compatible with different families and compilers.

Here’s a simple header that defines a macro for the device ID address. While I checked the address for both STM32F4 and STM32F0 families, other families might have slightly different addresses for the device ID. Check the reference manual corresponding to your STM32 family if errors occur.

Continue reading →

Posted by Uli Köhler in C/C++, Embedded

Reading STM32F0 internal temperature and voltage using ChibiOS

The STM32F0 series of 32-bit ARM Cortex M0 microcontrollers contain a huge number of internal peripherals despite their low price starting at 0,32€ @1pc. Amongst them is an internal, factory-calibrated temperature sensor and a supply voltage sensor (that specifically senses VDDA, the analog supply voltage rail) connect to channels 16 and 17 of the internal ADC.

While I usually like the STM32 documentation, it was quite hard to implement code that produced realistic values. While the STM32F0 reference manual contains both formulas and a short section of example code, I believe that some aspects of the calculation are understated in the computation:

Section 13.9 in RM0091 provides a formula for computing the temperature from the raw temperature sensor output and the factory calibration values. However it is not stated anywhere (at least in Rev7, the current RM0091 revision) that this formula is only correct for a VDDA of exactly 3.30V.

Continue reading →

Posted by Uli Köhler in C/C++, Embedded

Using the lwIP SNTP client with ChibiOS

A common task with embedded systems is to use the RTC to timestamp events. However, the system architect needs to find a way of synchronizing the devices RTC time with an external time source. Additionally, the designer needs to deal with the problem of drifting RTC clocks, especially for long-running devices. This article discusses an lwIP+SNTP-based approach for STM32 devices using the ChibiOS RTOS. The lwIP-specific part of this article is also applicable to other types of microcontrollers.

For high-accuracy or long-running applications, RTC clock drift also has to be taken into account. Depending on the clock source in use, the clock frequency can deviate significantly from the nominal value.

On the STM32F4 for example, you can derive the RTC clock from: The HSE/HSI main oscillator The LSI oscillator * The LSE oscillator, i.e. a 32.768 kHz external crystal.

Continue reading →

Posted by Uli Köhler in C/C++, Embedded

Enforcing debugger breakpoints in ChibiOS chDbgAssert()

ChibiOS provides a variety of debug functions that can be enabled or disabled using preprocessor definitions.

When debugging ARM-based microcontrollers like the STM32, it can be useful to hardcode

This post provides a simple method of improving the definition of chDbgAssert() in chdebug.h so that a breakpoint is enforced in case of assertion failures. By using the ARM BKPT instruction, the overhead is only a single assembler instruction.

Continue reading →

Posted by Uli Köhler in Embedded

Reading STM32 unique device ID using OpenOCD

When working with the STM32 family of microcontrollers, it can be useful to evaluate the factory-programmed 96-bit UUID using JTAG. On all major operating systems, OpenOCD provides a simple yet highly compatible and free solution in order to do this.

In this example, we’ll use a JLink adapter together with the Olimex E407 evalation board. Both the adapter and the board are interchangable, provided you have working OpenOCD configurations available.

Continue reading →

Posted by Uli Köhler in Embedded

Yet another Atom Arduino blinker

While experimenting with Atom I produced a minimal example for making my old Arduino Uno blink its LED periodically.

Although there are plenty of examples out there (some of them even work!) I didn’t want to introduce any dependency to the Arduino libraries. Besides making it harder to build (even if arscons is quite nice) it increases the object size and Arduino only supports a limited range of processors. I need the flexibility to use the code on controlles like the ATTiny45

Continue reading →

Posted by Uli Köhler in Allgemein, Embedded

Listing devices supported by OpenWRT

Problem:

You need a list of devices supported by OpenWRT.

Continue reading →

Posted by Uli Köhler in Embedded, Shell