How to fix GCC error: unknown type name ‘size_t’ (STM32)

Problem:

When you try to compile your C/C++ project (typically a STM32 project):

C:/Users/User/MyProject/MyHeader.h:9:7: error: unknown type name 'size_t'
    9 | const size_t MySize = 15;
      |       ^~~~~~

Solution:

At the top of the file where this error occurs, add the following line:

#include <stddef.h>

 

Posted by Uli Köhler in C/C++, GCC errors, STM32

PySerial minimal RFC2217 example: Copy data received from serial port to stdout

Also see the same example for a local serial port: PySerial minimal example: Copy data received from serial port to stdout

This example connects to the RFC2217 remote serial port on 10.1.2.3 port 1234. It does not send data to the serial port but only copies data received from the serial port to stdout.

#!/usr/bin/env python3
import serial
with serial.serial_for_url("rfc2217://10.1.2.3:1234", baudrate=115200) as ser:
    try:
        while True:
            response = ser.read()
            if response:
                print(response.decode("iso-8859-1"), end="")
    finally:
        ser.close()

 

By using iso-8859-1   decoding, we ensure that even binary bytes are decoded in some way and do not cause an exception.

Posted by Uli Köhler in Embedded, Python

How to generate human-readable description of git commit

The following command assumes that you have at least one previous tag in the repository:

git describe --long --tags --dirty

Example output:

v0.1.0-9-g68066f4-dirty

This means that we’re on the 9th commit after the v0.1.0 tag with commit ID g68066f4 and the working tree is dirty, i.e. there are uncommited changes.

Posted by Uli Köhler in git, Version management

How to install .NET Core SDK on Ubuntu 22.04

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0

Source for these commands: Microsoft documentation

Posted by Uli Köhler in C#, Linux

LumenPnP: Always assign the same serial port number on Linux

It is certainly a hassle when you always have to re-configure OpenPnP to open the correct serial device for LumenPnP.

In order to fix, this, we’ll create an alias /dev/lumenpnp that points to /dev/ttyACM0 or /dev/ttyACM1 or any other port that gets assigned to LumenPnP. Create /etc/udev/rules.d/99-lumenpnp.rules:

ACTION=="add", ENV{ID_VENDOR_ID}=="0483", ENV{ID_MODEL_ID}=="5740", SYMLINK+="lumenpnp"

Now, reload udev to activate the rule:

sudo udevadm control --reload-rules && sudo udevadm trigger

Now, open ~/.openpnp2/machine.xml, find this line:

<serial line-ending-type="LF" port-name="ttyACM0" baud="115200" ...

and set port-name to lumenpnp:

<serial line-ending-type="LF" port-name="lumenpnp" baud="115200" ...

After this, you need to restart OpenPnP. Typically, it works without reconnecting the device (due to udevadm trigger). If it doesn’t work, unplug and re-plug the mainboard USB connector.

Posted by Uli Köhler in Linux, LumenPnP

How to enable SSH public key authentication on Teltonika RUTX/TRB series

First, generate a SSH key:

ssh-keygen -t ed25519 -f id_teltonika.pub

Now copy the content of id_teltonika.pub which should look like this:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfPyvgFaANpm+vjEcbQSHkmXe27DqLanlB++5+muI7H uli@uli-desktop

and open the Teltonika web interface and open System -> Administration -> Access Control

On that page, set Enable key-based authentication  to On. Furthermore, paste the content of id_teltonika.pub into the Public Keys field.

After that remember to click Save & Apply at the bottom of the page!

Now you can login using the public key, e.g.:

ssh -i id_teltonika [email protected]

 

Posted by Uli Köhler in Networking, OpenWRT

How to install pip (Python) on Teltonika RUTX/TRB (OpenWRT)

You can just install pipon OpenWRT such as on the Teltonika RUTX10/RUTX11 or TRB series using opkg:

opkg update
opkg install python3-pip

Tested on firmware TRB1_R_00.07.02.6.

Posted by Uli Köhler in OpenWRT

How to add route to local network in Linux even if VPN is active

If you route all your traffic via a VPN on Linux, you will typically not be able to access local networks except for the network which you are directly connected to via L2.

In order to fix this, you can simply add a route, which typically takes precedence over the VPN route even with additional options.

The following example will add a route to 10.1.2.0/24 (local network) via the gateway=local router we’re connected via L2 to (192.168.1.1)

sudo ip route add 10.1.2.0/24 via 192.168.1.1

 

Posted by Uli Köhler in Linux, Networking

How to recursively move all .ics files to a single folder on the Linux command line

This command will move all *.ics files from the current directory and

mkdir -p ICS
find . -name "*.ics" -type f -exec mv --backup=numbered -v {} ICS/ \;

Due to --backup=numbered, files with the same name won’t overwrite anything but instead mv will append a number such as ~2~ to the filename.

Posted by Uli Köhler in Linux

How to recursively sha256sum a directory

This command will run sha256sum recursively on all files in a directory:

find . -type f -print0 | xargs -0 sha256sum

You can also pipe it into a file

find . -type f -print0 | xargs -0 sha256sum > recursive-sha256sum.txt

 

Posted by Uli Köhler in Linux

Where to find cheap SMD ferrite beads?

Generally, SMD ferrites of a given size are characterized by:

  • The RF impedance (typically specified @100 MHz)
    • Low impedance (e.g. 100 Ω @ 100 MHz) do not filter EMI that well, but also distort your data signals less. Use them for high speed signals above 1 MHz
    • High impedance ferrites, e.g. 1kΩ @ 100 MHz, filter EMI really well but will distort any high speed signal. Use them for low speed signals below 1 MHz
  • The current rating
    • For data signals, you don’t need any form of high current rating. Generally, I would recommend to require at least 0.1A of current rating to be able to handle soft short circuits
    • For power lines, use whatever power rating is suitable (the specified current + 20% is typically fine)
  • The DC resistance. This mostly only matters for power lines.
    • Keep in mind to keep the ferrite cool by choosing the DC resistance so that the

As with most passive parts, LCSC generally has the lowest pricing if you buy a bunch of parts.

Keep in mind the expensive shipping, but since they are often 50 times cheaper (!) than other distributors, it might be worth it even if just ordering a reel of ferrites.

Signal ferrites

This section contains cheap SMD ferrite beads for < 1A current rating.

Low impedance (<= 500Ω):

  • LCSC 0603 100Ω 200mA CBG160808U101T @ 0.0019€/pc@4000pc = 7.60€/reel

High impedance (>= 500Ω):

  • LCSC 0805 600Ω 300mA CBG201209U601T @ 0.0026€/pc@4000pcs = 10.40€/reel
  • LCSC 0603 1kΩ 400mA FCM1608KF-102T04 @ 0.0027€/pc@4000pc = 10.80€/reel
  • LCSC 0805 1kΩ 800mA CBW201209U102T @ 0.0044€/pc@4000pc = 17.60€/reel
  • DigiKey 0603 1kΩ 400mA 2506031027Y0 @ 0.01264€/pc@4000pc = 50.56€/reel
  • TME 0805 1kΩ 200mA LCCB-102 @ 0.0181€/pc = 72.40€/reel

Power ferrites

This section contains cheap SMD ferrite beads for > 1A current rating.

Low impedance (<= 500Ω):

  • LCSC 1206 120Ω 3A CBW321609U122T @ 0.006€/pc@4000pc = 24. 00€/reel
  • LCSC 1206 120Ω 4A CBM321609U121T @ 0.0086€/pc@4000pc = 34.40€/reel

High impedance (>= 500Ω):

  • LCSC 1206 1.2kΩ 1A CBW321609U122T @ 0.0088€/pc@4000pc = 35.20€/reel
  • LCSC 1206 1kΩ 2A CBW321609U102T @ 0.0095€/pc@4000pc = 38.00€/reel
Posted by Uli Köhler in Components, Electronics

Where to find cheap general purpose SMD optocouplers?

I generally use the LTV-356T optocoupler (phototransistor output) for general purpose applications. It has a smaller footprint than most DIP-derived SMD optocouplers and a thinner package. Its pin pitch is 2.54mm whereas the center-distance between the pads is 6.5mm. It it rated

It is available:

Even cheaper?

The LTV-356T has the advantage of being available from different sources in large quantities. However, you can get a pin-compatible variant LTV-356T-C which is only rated for 35V on the output:

Even smaller?

At LCSC, you can also get the half-width OR-3H7B-TP-Gwith a pin pitch of only 1.27mm for 0,0424€/pc@1kpc

 

Posted by Uli Köhler in Components, Electronics

Where to find cheap general purpose resistors?

Typically, 1% thick film resistors are used as general purpose SMD resistors. Most of these are spec’d with a 100ppm/°C temperature coefficient.

From all the “normal” distributors, in my experience LCSC has by far the cheapest resistors – around 3€ per reel (5000pcs) of 0603 resistors. Note, however, that they charge around 35€ of shipping to Germany. So you have to buy a lot of resistors in order to compensate for the expensive shipping. However, you can also order other components on LCSC (they’re usually quite cheap, especially for passives and other standard components).

0603 resistors

 

Posted by Uli Köhler in Components, Electronics

How to fix dji_irp: error while loading shared libraries: libdirp.so: cannot open shared object file: No such file or directory

Problem:

When you try to run dji_irp from the DJI thermal SDK on Linux, you see the following error message:

./utility/bin/linux/release_x64/dji_irp: error while loading shared libraries: libdirp.so: cannot open shared object file: No such file or directory

Solution:

The libdirp.so library is included with the SDK but it is in a subfolder (the same subfolder where dji_irp is located) where the shell can’t find it.

In order to fix the issue, prefix the command you’re using with

LD_LIBRARY_PATH=./utility/bin/linux/release_x64/

For example:

LD_LIBRARY_PATH=./utility/bin/linux/release_x64/ ./utility/bin/linux/release_x64/dji_irp

 

 

Posted by Uli Köhler in Audio/Video, Linux

How to remove all lines from file, starting from a known line, using sed

This command will look for a line starting with volumes: and remove all lines after said line from the file (including the line starting with volumes: itself).

sed -i -e '/^volumes:/,$d' myfile

The command edits the file in-place (-i), no copy (or backup) of the file will be created.

Posted by Uli Köhler in Linux

How to download forum pages to HTML using Python & requests

This will download page 1000 … page 1 in descending order and save the HTML to 1000.html up to 1.html

import requests
for i in range(1000, 0, -1):
    with open(f"{i}.html", "w") as outfile:
        outfile.write(requests.get(f"https://forum.my-domain.com/showthread.php?123456-my-thread/page{i}").text)

With progress bar

import requests
from tqdm import tqdm
for i in tqdm(range(1000, 0, -1)):
    with open(f"{i}.html", "w") as outfile:
        outfile.write(requests.get(f"https://forum.my-domain.com/showthread.php?123456-my-thread/page{i}").text)

 

Posted by Uli Köhler in Python

How to fix ESP32 FreeRTOS error: too few arguments to function ‘void vPortEnterCritical(portMUX_TYPE*)’

Problem:

On FreeRTOS on the ESP32, you want to use a critical zone like this:

portENTER_CRITICAL();
// Your critical code goes here!
portEXIT_CRITICAL();

but while compiling the procject, you see an error message like

src/main.cpp: In function 'void MyFunc(size_t, int16_t)':
/home/uli/.platformio/packages/framework-arduinoespressif32@src-f2ea83e2545300b10a69ff44ef9dc6cd/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h:476:75: error: too few arguments to function 'void vPortEnterCritical(portMUX_TYPE*)'
 #define portENTER_CRITICAL(mux)                     vPortEnterCritical(mux)

Solution:

You need to use portENTER_CRITICAL() and portEXIT_CRITICAL() with a spinlock, i.e.

portENTER_CRITICAL(&mySpinlock);
// TODO Your critical code goes here!
portEXIT_CRITICAL(&mySpinlock);

In order to see a full example on how to initialize a spinlock in FreeRTOS and use it for critical zones, see our previous post ESP32 critical zone example using FreeRTOS / PlatformIO

Posted by Uli Köhler in Arduino, ESP8266/ESP32, FreeRTOS, PlatformIO

ESP32 critical zone example using FreeRTOS / PlatformIO

In order to enter a critical zone on the ESP32 using FreeRTOS, you have to do the following:

Globally declare a spinlock:

portMUX_TYPE mySpinlock;

In setup(), initialize the spinlock:

spinlock_initialize(&mySpinlock);

Now, wherever you want to enter a critical zone, run:

portENTER_CRITICAL(&mySpinlock);
// TODO Your critical code goes here!
portEXIT_CRITICAL(&mySpinlock);

When using this in an interrupt handler, use this instead:

portENTER_CRITICAL_ISR(&mySpinlock);
// TODO Your critical code goes here!
portEXIT_CRITICAL_ISR(&mySpinlock);

 

FreeRTOS will ensure that no two threads using mySpinlock are run at the same time.

Posted by Uli Köhler in Arduino, ESP8266/ESP32, FreeRTOS, PlatformIO

How I fixed PlatformIO Arduino portGET_ARGUMENT_COUNT() result does not match for 0 arguments

Problem:

When trying to compile your Arduino PlatformIO project, you see multiple error messages like the following.

In file included from /home/uli/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/sys-include/stdlib.h:19,
                 from /home/uli/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/cstdlib:75,
                 from /home/uli/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/stdlib.h:36,
                 from /home/uli/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:26,
                 from /home/uli/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.h:26,
                 from /home/uli/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:27,
                 from /home/uli/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.cpp:24:
/home/uli/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h:717:41: error: static assertion failed: portGET_ARGUMENT_COUNT() result does not match for 0 arguments
 _Static_assert(portGET_ARGUMENT_COUNT() == 0, "portGET_ARGUMENT_COUNT() result does not match for 0 arguments");

Solution:

For me, the solution was as follows. I had

build_flags = --std=c++17

in my platformio.ini. Replacing it by

build_flags = --std=gnu++17

fixed the issue for me.

Posted by Uli Köhler in Arduino, C/C++, PlatformIO
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPTPrivacy &amp; Cookies Policy