Skip to main content

Posts

Showing posts from December, 2017

A Simple STM32 Example Project

Most of the embedded projects share certain initial steps. You need to confirm the clock settings before doing anything, then you want to have debug connection via a UART channel since it is cheap  but still it can provide useful information for debugging. Let us start with CubeMX. You select a device/board of your choice, set up the pinouts for one GPIO output and one UART port. Configure the clock if necessary then create a project. Clock Checking using SysTick The sanity of the clock setting can be done by checking the SysTick interval. All Cortex-M series core have SysTick timer by default, which should fire at 1msec interval while the MCU is active. In the STM32Cube, the SysTick is initialized by HAL_Init() call, which in turn calls SysTick_Config() in CMSIS. Once the SysTick is initialized, it generates 1 msec interrupt and this interrupt is handled by SysTick_Handler() according to the Cube framework. Source file 1 /** 2 * @brief This function handles

Makefile Based STM32 Development Environment

The development environment discussed here is minimal, terminal based, and cross platform. This configuration assumes that a terminal based text editor such as vim  and the  make utility are the primary tools for programming. It consists of following components: GNU ARM Embedded Toolchain Makefile Utility STM32CubeMX Flash Tool (JLink or OpenOCD) Hardware The most recent version of the compiler suite can be found  here . The toolchain is self-sufficient. Thus you can simply unzip the archive into any directory of choice then you are good to go. In Linux, make  utility is included in a package such as  build-essential . If you have C/C++ compiler installed on your system then you already have it. In Windows, preferred way to get the utility is to install cygwin first, then to install make from there. Alternatively, you can use the one comes with MinGW system or you can find one of the precompiled version . However you may need to choose 32bit version of make , since the

Data Plotting in wxPython

wx.lib.plot wxPython has its own plotting library, which provides simple way of drawing large number of data on a canvas. It is convenient to use and it is fast. However you have only one axis per canvas and you can plot 2D graphs only. To plot a line graph like above, you create line objects using numpy Source file 214 x = np . linspace ( 0 , 10 , 500 ) 215 y = np . sin ( x ) 216 217 # create lines 218 line1 = wxplot . PolyLine ( list ( zip ( x , np . sin ( x ))), 219 colour = 'red' , width = 3 , style = wx . PENSTYLE_DOT_DASH ) 220 line2 = wxplot . PolyLine ( list ( zip ( x , - np . sin ( x ))), 221 colour = 'blue' , width = 3 , style = wx . PENSTYLE_LONG_DASH ) Then generate a graphics object and render it on the canvas Source file 223 # create a graphics 224

About the Python Environment

Python programs introduced in this blog are tested with  Python 3.6 . Although most of those should run with Python 2.7 with minor modification, there is not much reason to use v2.7 any more. GUI is based on wxPython v.4 (a.k.a wxPython Phoenix). Other frequently used packages are: numpy and scpiy for mathematical data processing matploltlib for data plotting PIL and OpenCv for image processing sounddevice, soundfile, pyserial, etc. 32bit vs. 64bit Most of the Linux distributions include Python as a standard component, frequently both v2.7 and v3.x. And 32bit applications are quite rare these days. Thus you are not likely to have compatibility issue when installing a new package. In Windows, things are a bit more complicated. Still large percentage of programs are released in 32bit architecture. This is particularly true in engineering software. Thus it is still highly recommended to install 32bit version of Python if your have any chance to interface wit

wxPython Highlight Frontend

Highlight is a source code syntax highlighter that convert source code into HTML and other formats with syntax highlighting. It comes with a nice GUI as well as a command-line executable. The program implemented here utilizes the command-line version of Highlight as its backend. It exposes only limited number of features of the original program. However you may find it convenient in certain situations. The program has three main windows: one for the source code, one for the HTML view and one for the HTML code. In the HTML view you can check the result rendered by the HTML engine. In the HTML code page, you can see its actual HTML code. The HTML view window and the HTML code window are embedded in the notebook window as separate pages under the source code window. The upper window (a text control) and the lower window (a notebook) are two client areas of a wx.SplitterWindow. So you can resize them by moving the sash in the middle. On the right, you have several options to choo

wxPython COM Terminal

PySerial provides a convenient way to handle data transfer over COM ports. It works on most of the platforms. The program is written using wxPython to create a simple terminal emulator. It is pretty much similar to the example presented by PySerial itself.  However in this case, the UI is built on wx.Panel instead of wx.Frame, thus it is easy to embed the terminal emulator into any wxPython GUI. All GUI components are populated on a single panel inherited from the wx.Panel. On the left a wx.TextCtrl is located as a terminal window. On the right, handful controls are added for for basic setup and control of the terminal window and the COM port. The controls on the right side can be hidden or shown at any time.This terminal supports ASCII mode and Hexadecimal mode. You can also save data to a disk file. Since all the features are implemented on a wx.Panel (TermPanel), it can be embedded into any window including main frame window simply by creating an instance and passing a PySer