Skip to content

Instantly share code, notes, and snippets.

# inspired from http://nathanhoad.net/how-to-meld-for-git-diffs-in-ubuntu-hardy
# and http://gitguru.com/2009/02/22/integrating-git-with-a-visual-merge-tool/
sudo apt-get install meld
# create a python script with the below content and name it diff.py
#!/usr/bin/python
@mofosyne
mofosyne / gittag2C.py
Created November 17, 2019 17:38
This is a sketch of a python3 script that checks git tag written in a modified semantic version format and returns a C file with the parsed version code and the git hash
#!/usr/bin/env python3
# This script checks git tag written in a modified semantic version format
# and returns a C file with the parsed version code and the git hash
# The git tag MUST conform to this format v<major>.<minor>.<patch>-<rcX>
import subprocess
import sys, os
import re
tagname = subprocess.check_output(["git", "describe", "--tags"]).strip().decode("utf-8") ;
/***********************
SEMIHOSTING
************************/
#define SEMIHOSTING
#ifdef SEMIHOSTING
#include <stdarg.h>
#include <ctype.h> //isprint
/*
Note: This semihost printing utility functions is targeted towards STM32 based chips
// This allows you to easily monitor change to registers that you care about
#define PRINTREG(X, MSG) printf("%15s = %08lX : %s\r\n", (char*) #X, (long unsigned) X, (char*) MSG);
#define PRINTREG_MON(X, MSG) \
{\
static int count = 0;\
static long unsigned prev = 0;\
if (!count) \
{ printf("%4d: %40s = %08lX : %s", (int) count, (char*) #X, (long unsigned) X, (char*) MSG); count++;}\
else if (prev != X) \
{ printf("%4d: %40s = (%08lX --> %08lX) : %s", (int) count, (char*) #X, (long unsigned) prev, (long unsigned) X, (char*) MSG); count++;}\
@mofosyne
mofosyne / STM32H7_SWO_Output_Solution.py
Last active October 12, 2020 15:23
This generates codes that enables SWO output for STM32H7 and was tested on NUCLEO-H743ZI2. This is required because stm32h7 changed the registers that OpenOCD expects for SWO output.
#!/usr/bin/env python3
"""
# STM32H7 SWO Output Solution
Author: Brian Khuu 2020
Main Copy: https://gist.github.com/mofosyne/178ad947fdff0f357eb0e03a42bcef5c
This generates codes that enables SWO output for STM32H7 and was tested on NUCLEO-H743ZI2.
This is required because stm32h7 changed the registers that OpenOCD expects for SWO output.
Best to use 400Mhz, tried lower... but had issue with getting stable uart output
@mofosyne
mofosyne / circularBuffer_uint8.h
Last active June 12, 2023 16:00
Circular Byte Buffer For Embedded Applications (Index Based)
// # Circular Byte Buffer For Embedded Applications (Index Based)
// Author: Brian Khuu (July 2020) (briankhuu.com) (mofosyne@gmail.com)
// Reason: Malloc free, minimum overhead implementation of a circular buffer.
// Static inlined handlers for speed and ease of usage in various projects.
// Index based implementation diverges from harshkn's version, since it is
// easier for me to grok. However may come at cost of speed and optimisation.
// Also uses byte based rather than item based for easier understability
// when used for simpler byte array circular buffers.
// I have also written an pointer based circular buffer version.
// Based on harshkn's circular buffer: https://gist.github.com/harshkn/909546
@mofosyne
mofosyne / circularBuffer_uint8.h
Last active July 7, 2021 10:09
Circular Byte Buffer For Embedded Applications (Pointer Based)
// # Circular Byte Buffer For Embedded Applications (Pointer Based)
// Author: Brian Khuu (July 2020) (briankhuu.com) (mofosyne@gmail.com)
// Reason: Malloc free, minimum overhead implementation of a circular buffer.
// Static inlined handlers for speed and ease of usage in various projects.
// Pointer based implementation approach kept from harshkn's version
// as it may be faster than index deferencing approach.
// Also uses byte based rather than item based for easier understability
// when used for simpler byte array circular buffers.
// I have also written an index based circular buffer version.
// Based on harshkn's circular buffer: https://gist.github.com/harshkn/909546
@mofosyne
mofosyne / ecma48.h
Last active January 8, 2022 17:25
Simple method for adding color in embedded C serial terminal (e.g. VT100 emulated serial terminal with color output)
/*
Title: ECMA-48 ANSI ESC CODE (e.g. VT100)
Author: Brian Khuu 2021
About: Simple header files for inclusion in embedded system for serial interfaces
Applications: Adding colors to VT100 serial terminal emulators.
Tips: This headerfile also contains some code that you can use to test/preview all the codes
Ref: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
Ref: http://osr507doc.sco.com/man/html.HW/screen.HW.html
Ref: SO/IEC 6429 https://www.ecma-international.org/publications-and-standards/standards/ecma-48/
@mofosyne
mofosyne / ipv4ToStrbuff.c
Last active January 8, 2022 17:25
minimal ipv4 string print
#include <stdio.h>
void ipv4ToStrbuff(char ipStr[], const unsigned char ipaddr[])
{
// assumes that char *ipStr = "XXX.XXX.XXX.XXX";
const char *nibblesToDigits = "0123456789";
int i = 0;
for (i = 0 ; i < 4 ; i++)
{
const unsigned char h = ipaddr[i];
@mofosyne
mofosyne / gist:0dceb2485dd384e2eb9e2f85cccfd774
Created March 14, 2021 14:07
Cleaning Up Empty folders in linux bash and windows batchfiles
# Tips in cleaning up empty folders
* https://stackoverflow.com/questions/30345690/git-how-to-remove-only-empty-directoriesnot-un-tracked-files-in-a-git-repo
* https://superuser.com/questions/444474/how-to-delete-empty-folders-from-a-given-directory-in-windows-with-a-script
In Linux bash
```
find . -empty -type d -delete
```