Skip to main content

Posts

Showing posts from September, 2018

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 crea

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