Skip to content

Instantly share code, notes, and snippets.

View nebelgrau77's full-sized avatar
👾

Michal Lasak nebelgrau77

👾
View GitHub Profile
@nebelgrau77
nebelgrau77 / MicroPython on STM32F4xx.md
Last active March 12, 2024 16:11
how to install MicroPython on cheap STM32F4xx boards ("black pill", "black F407")

Installing MicroPython on inexpensive STM32F4xx boards

This tutorial will explain step by step how to build and deploy MicroPython on STM32F407xx and STM32F411CEU boards, using both DFU mode over USB, as well as SWD with ST-Link and OpenOCD in case you can't get the board into DFU mode (happened to me with the "black pill").

It should be applicable to other boards, such as the other "black pill" STM32F401, Nucleo boards etc., provided you can find an appropriate board definition to build.

1. clone the MicroPython repo:

'''
Reading and decoding temperature values over BLE from Arduino BLE Sense
'''
import asyncio
from bleak import BleakClient
from bleak.backends.characteristic import BleakGATTCharacteristic
ADDRESS = "E6:A3:44:CD:9C:4F" # BLE sense
@nebelgrau77
nebelgrau77 / struct_vs_enum.md
Last active April 11, 2021 10:13
Struct vs enum to hold register addresses in a Rust hardware driver

What are, if any, pros or cons of using a struct vs using an enum to hold register addresses for a device driver? Different authors of such drivers seem to approach it differently. At first sight the struct seems to make more sense, as there is no need to add the function that will return actual u8 values required by the functions. Is there some good reason to use enum here?

struct Register;
impl Register {
    const CTRL_STATUS_2     : u8 = 0x01;
}

/// Clear the timer flag.
pub fn clear_timer_flag(&mut self) -> Result<(), Error> {
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
  # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
  try:
    tf.config.experimental.set_virtual_device_configuration(
        gpus[0],
        [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
    logical_gpus = tf.config.experimental.list_logical_devices('GPU')
 print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
@nebelgrau77
nebelgrau77 / tinyML_sound_converter.md
Last active December 30, 2020 11:48
Convert WAV files to a selected sample rate and/or mix down to mono.
import scipy.io.wavfile as wavfile
import librosa

def wave_converter(filename, resampled_sr=16000, prefix="resampled_", mix2mono = False):

    '''
    Resample WAV soundfile to a different sample rate.
    
        Input: original sound file
@nebelgrau77
nebelgrau77 / bootstrap_flask.md
Created October 5, 2020 11:42
bootstrap base for Flask app
{% extends "bootstrap/base.html" %}

{% block title %}cars{% endblock %}

{% block navbar %}

<div class="navbar  navbar-inverse" role="navigation">
    <div class="container">
        <div class="navbar-header">
use arduino_nano33iot as hal;

use hal::clock::GenericClockController;
use hal::prelude::*;
use rtic::app;
use core::fmt::Write;
use hal::adc::Adc;

#[app(device = crate::hal::pac, peripherals = true)]
def add(*args):
    
    if len(set([tuple([len(item) for item in arg]) for arg in args])) == 1:
    
        return [[sum(b) for *b, in zip(*item,)] for item in [b for *b, in zip(*args,)]]
        
    else:
 
@nebelgrau77
nebelgrau77 / bubble_sort.md
Last active July 18, 2020 15:24
bubble sort algorithm
@nebelgrau77
nebelgrau77 / sorenson-dice.md
Last active July 8, 2020 09:51
the Sørenson–Dice coefficient