Skip to content

Instantly share code, notes, and snippets.

View kaidokert's full-sized avatar

Kaido Kert kaidokert

View GitHub Profile
@kaidokert
kaidokert / cortex_m_stack_paint.rs
Created July 12, 2025 02:59
Quick and dirty cortex m stack watermarking
extern "C" {
static _stack_start: u32; // End of the stack (top of memory)
static _ram_length: u32; // Total RAM length (stack size in bytes)
}
const SAFE_ZONE_BYTES: usize = 256; // Reserve top and bottom bytes
#[inline(always)]
pub fn check_stack_high_water_mark() -> usize {
check_stack_high_water_mark_inner::<SAFE_ZONE_BYTES>()

Rust Interrupt Data Sharing Patterns

In embedded Rust, sharing data between the main thread and interrupt handlers requires careful consideration to ensure memory safety and avoid data races, particularly in single-core systems like Cortex-M. This document summarizes three common patterns—static Atomic<T>, static Option<T>, and Mutex<RefCell<Option<T>>>—comparing their use cases, safety, and complexity, and evaluates whether the "move to context" trick applies.

Comparison Table

Pattern Data Types Requires unsafe Synchronization Overhead Use Case Move to Context Trick
static Atomic Primitives (bool, u32) No Atomic op
@kaidokert
kaidokert / yts.exolist.json
Last active June 5, 2023 00:44
YTS test playlist file
[{
"name": "Youtube Test suite",
"samples": [{
"name": "Random first test",
"uri": "https://storage.googleapis.com/ytlr-cert.appspot.com/test-materials/media/high-bitrate/concat/sdr-fps-30/video10_137_h264_1920x1080_fps%3D30_bitrate_kbps%3D19021k.mp4"
},
{
"name": "A bit heavy test",
"uri": "https://storage.googleapis.com/ytlr-cert.appspot.com/test-materials/media/high-bitrate/sdr-drm/video10_h264_fps%3D30.0_bitrate_kbps%3D18994.589.enc"
}
@kaidokert
kaidokert / install-openssh.ps1
Last active May 2, 2023 02:09
Stub for testing provisioning
Add-WindowsCapability -Online -Name "OpenSSH.Server~~~~0.0.1.0"
# Dump in the key
echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCyFmcGw1DQhD7mns6lBQquepRf1p69ZjU/ml8bp3AA0RhDDwBYd4sjXfa/YgXS8A+5jDnivVvcqaB9jDWwGedLVYtPyObjp+OWZelGzx/hLI/E5LJ5iOh3Wu/AVJfaz+xdMEVNMq3fVNDgG72l9LlAxP8LC7tNWEGFsHESSg19RP61I8tOW5us/gjsAhwn+cZF8oURFx5daeLN7vjjXAMl6TOSvYxZR3Fcl+J/3FRTIQ0Iy5a463Jdc/lh/SMMWzwWNfTxOewm9Ay/KsA44ymcPTZOjSGfMRPeJ9KfQtbl2F/KYHkvtE5BFtwAZOVuFfrPSRWCQpPNvZp2U74/ffx2LZa8MvTIqOv1mzTeeR+/Ym6kc2CSmqkJ/STmXyj7b66gCuYfS9cwK+3Six6+8uYir1RGkjqM0WevH1V+EU0SSdyWqixK/R5GLPpwTpW3VBauEIdMZTXae4w67+EcocwiAtltZzrpizqGOE60WAHHrKPzRtGkqRo27Qor7u968kH4ir9i6Qy+4KeEiKgaZv+S0TNXIz+9tc8fpSDXw4WK0zm5Pmiu8rdRbwVLBSTFhPkvbkT4kVX2IGZtajUgP5Gw6abMGeuugeK2qYX+WsJMhXLBE6OinORTZIWsUGb5MZhPnQFCt66tcDkvuoTGYsNlujLufn99qvA8Ggo8U22/Uw== | Add-Content -Force -Path C:\ProgramData\ssh\administrators_authorized_keys
icacls 'C:\ProgramData\ssh\administrators_authorized_keys' /inheritance:r /grant 'Administrators:F' /grant 'SYSTEM:F'
Set-Service -N
@kaidokert
kaidokert / install-openssh.ps1
Created May 1, 2023 02:10
Install openssh on Windows
# OpenSSH
$capability = Get-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0"
if($capability.State -ne "Installed") {
WriteInfoHighlighted "`t Enabling OpensSH Client"
Add-WindowsCapability -Online -Name "OpenSSH.Client~~~~0.0.1.0"
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
}
@kaidokert
kaidokert / vms.tf
Created May 1, 2023 01:37
Azure Free VMs terraform snippet
# Create Windows VM
resource "azurerm_windows_virtual_machine" "windows_vm" {
size = "Standard_B1s"
name = "${var.prefix}-windows-vm"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
admin_username = "${var.adminname}"
admin_password = "${var.adminpwd}"
network_interface_ids = [
@kaidokert
kaidokert / Git Subtree basics.md
Created April 29, 2023 01:13 — forked from SKempin/Git Subtree basics.md
Git Subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

@kaidokert
kaidokert / cryptoparts.sql
Last active March 6, 2021 21:56
Query STM32 parts for security features
-- The SQLite database file is in STMCube installation, cube-finder-db.db
select * from (
select substr(rpn,1,length(rpn)-2) as rpn, --remove last 2 letters of RPN which are memory size
core, featurename, featureitemname
from (
select replace(replace(rpn,'-A',''),'-X','') as rpn, --squash minor variants
strValue as core, f.name featurename, fi.item featureitemname
from cpn
join cpn_has_attribute cha on cha.cpn_id=cpn.id
https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/windows-builder
https://github.com/search?q=gcr.io+ltsc2019&type=Code
@kaidokert
kaidokert / Vagrantfile
Last active June 29, 2020 02:21
Simple quick Win VM
Vagrant.configure("2") do |config|
config.vm.box = "gusztavvargadr/visual-studio"
config.vm.box_version = "2019.0.2006"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "8192"
vb.cpus = 6
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vb.customize ["setextradata", "global", "GUI/MaxGuestResolution", "any"]