Skip to main content

Posts

Repurposing STLink of Nucleo64 boards

Most of the development kits from ST are equipped with on-board STLink-V2 debugger / programmers, use of which is not very convenient in Linux environment. Instead, Segger kindly provides a tool that allows you to reflash on-board STLink into JLink . Process takes only seconds. And you can enjoy most of the great features of JLink with no cost at least for STM32 devices. It keeps the UART port function, so you can use it as a serial monitor in addition to the JLink. If you have a Nucleo-64 board handy, you can make a nice stand-alone JLink debugger by reflashing the on-board STLink and snap it off. Note that the original pin headers are removed and some of them are replaced with right-angle type for the convenience. Two of the pins of ST-Link jumper are used to provide 3.3V power. And TX and RX pins of UART are soldered at the back not to interfere with the debug pins. Note the small changes in the solder bridges SB3 through SB10. Basically this allows the 3V3 line to b...

FatFs with FLASH memory

STM32Cube framework provides very similar interface for FatFS as USB MSC we have seen before. Again the same argument applies to this case about the basic unit of read/write operation on a flash memory. In this case, the sector size and the cluster size should be equal to the sector size of flash memory, namely 4KB. This can be set in the file ffconf.h , in which a lot of customization can be done by changing the definitions. In particular, following definitions should be set. In the file user_diskio.c, USER_read and USER_write functions can be implemented as the same way as before. Here we assume that the count is always one for the simplicity. In reality this can be bigger than one if you call f_read() with the buffer size larger than the sector size (4096). However given the limited memory capacity, that is not realistic. By similar token, pdrv variable can be ignored. If ioctl is to be used, then  FatFs allows users to not only read and write files but also to ...

STM32 USB MSC Device with FLASH memory

USB Mass Storage Class framework implements bulk-only-transfer (BOT) with SCSI protocol. USB packets from the host eventually converted SCSI transport commands by the middleware, in which data is exchanged (read / write) in the unit of logical block, typically 512 bytes. This SCSI commands works well with SD card system where a dedicated controller does the job of managing the actual memory elements. If you want to use a FLASH chip as a memory unit instead, you need to handle read / write operation directly. Fortunately, most of flash memory support 4KB block erase. This makes the 4096 bytes as a natural choice for the size of the logical block in the file usbd_storage_if.c. In this case, 8Mbit Flash memory was used. During initial enumeration, this information is registered to the host. The middleware maintains one logical block size of buffer and handles USB transaction where each payload is only 64 bytes. It then calls SCSI requests to store / retrieve data to / from physical...

STM32L052 Touch Sensing Controller

Some of STM32 MCUs are equipped with TSC (Touch Sensing Controller), whose hardware performance is not bad compared to ASIC solutions. It is a self-sufficient module supporting multi-touch. And you can lower the power consumption down to few tens of micro amps. Setting up the TSC requires to select one port for sampling for each group. One group consists of one sampling channel, where a sampling capacitor is connected, with one or more measurement channel, where a sensor pad is connected. Charge transfer happens from a measurement channel to the sampling channel. This is done independently from other groups. Thus channels belongs to each group are measured at the same time. In the same group, however measurement should be done sequentially among channels. A PCB touch panel (on the right) is connected to a STM32L052 MCU. The MCU is programmed to measure the touch sensor value at every 100 msec. It transfers the measurement to a PC via UART connection. On the PC side, a py...

A Simple wxPython Stopwatch

This is a very short wxPython script that helps to measure time interval during various testing. Initial screen shows a stock wxPython clock control. When clicked on the clock face, a list appears on the right, on which time stamp, lap time, and cumulative time are displayed. This list disappears when clicked on it. And all data is cleared. Finally, the transparency of the program can be adjusted with the mouse wheel button. <<source code>>

WS2812B (SK6812) Control with SPI and DMA

There are a couple of ways to control WS2812B and its clones. Among them, the method that uses SPI bus via DMA would be the easiest choice for the following reasons; Firstly SPI bus is ubiquitous. It is not easy to find a MCU that is not equipped with one. Secondly DMA minimizes the burden of the processor and handles timing with hardware. No code is involved in transferring data. Thus once proper SPI clock is chosen, operation is quite reliable as well. Only downside is that you have to dedicate one SPI port for the control of the LED, since you cannot share this line with any other SPI devices. The timing of SK6812 is shown below. There are slight variations in the actual timing between devices. But basically all use the same high/low ratio, namely 1:3 for logic zero and 2:2 for logic one. Thus set the SPI clock frequency to somewhere between 2.8hMHz and 4MHz, and use nibble (0x8) for logic zero, (0xc) for logic one. Then all should be good. Actually there are a few things t...

UART Data Communication in STM32Cube Framework

Sometimes implementation of UART communication is asymmetric. In general, Rx tasks are time critical and total size of the data is unknown, thus it is best to handle the task in an interrupt service routine where individual incoming bytes are checked without delay. While Tx tasks can be implemented rather relaxed manner. For example, you can use a blocking call inside the main loop. In this sense, UART HAL functions provided by STM32Cube framework is useful for Tx but not very much so for Rx task. Thus you may have to write your own UART interrupt handler using LL drivers while still using HAL UART Tx functions in Tx task. Use STM32Cube to generate all the chores of setting the UART module except the interrupt part. LL interrupt is activated after the UART port is initialized using LL functions: Source file 414 void SerialComm_Init () 415 { 416 LL_USART_EnableIT_RXNE ( huart1 . Instance ); 417 } Then write the interrupt handler to call Rx routine: ...