Skip to content

Instantly share code, notes, and snippets.

@ivand58
ivand58 / flash-kb.fs
Last active May 30, 2018 11:51
get the flash size in real-time (only for STM32F103C8T6)
: flash-size@ ( -- x )
dup
[
$4900 h, \ ldr r1, [pc, #0]
$e001 h, \ b.n
$1ffff7e0 , \ .word 0x1ffff7e0
$8809 h, \ ldrh r1, [r1, #0]
$028e h, \ lsls r6, r1, #10
]
;
@ivand58
ivand58 / 2swap.fs
Created July 19, 2018 06:10
2swap
: 2swap >R -rot R> -rot ;
: test2swap 1 2 3 4 5 cr .s 2swap cr .s cr ;
#!/bin/bash
TARGET=mecrisp-stellaris-hackaday-edition.bin
arm-none-eabi-objcopy -O elf32-littlearm -B arm --adjust-vma 0x8000000 --rename-section .data=.text -I binary $TARGET blob.o
arm-none-eabi-gdb -b 115200 -ex 'target extended-remote /dev/ttyACM0' -ex 'set confirm off' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'set mem inaccessible-by-default off' -ex 'monitor erase_mass' -ex 'kill' -ex 'quit'
arm-none-eabi-gdb -b 115200 -ex 'target extended-remote /dev/ttyACM0' -ex 'set confirm off' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'set mem inaccessible-by-default off' -ex 'load' -ex 'kill' -ex 'quit' blob.o
#connect: folie-linux64 -r -p "/dev/ttyACM1"
#! /bin/bash
if [[ $BASH_SOURCE == $0 ]] ; then
printf '?ERROR %s run it sourced ...\n' "$BASH_SOURCE" ;
exit 1 ;
fi
echo -n "remove_from_history "
if [ "$(type -t remove_from_history)" = 'function' ]; then
echo "redefined "
else
@ivand58
ivand58 / dectest.py
Created September 4, 2018 11:48
Make Your Python Prettier With Decorators
import datetime
import time
import logging
log = logging.getLogger(__name__)
def log_performance(func):
def wrapper():
datetime_now = datetime.datetime.now()
# log.debug(f"Function {func.__name__} being called at {datetime_now}")
@ivand58
ivand58 / code.c
Created September 12, 2018 10:16
#define MY_MAPPING(ENTRY) \
ENTRY(a, (0x10,0x01,0x01,0x00), foo) \
ENTRY(b, (0x10,0x01,0x02,0x00), boo)
#define BRACIFY(...) { __VA_ARGS__ }
#define MAKE_SOME_INT_ARRAY_THINGY(ID, INIT, X) int ID[] = BRACIFY INIT;
MY_MAPPING(MAKE_SOME_INT_ARRAY_THINGY)
@ivand58
ivand58 / a-gdb.py
Last active September 13, 2018 07:47
autoloaded by GDB py file
GDB_C_INT = gdb.lookup_type("int")
class Bpout (gdb.Breakpoint):
def stop (self):
pout = gdb.parse_and_eval ("port_out")
mychar = chr(int(pout.cast(GDB_C_INT)))
if mychar != '\0':
sys.stdout.write(mychar)
return False #Continue
bpout = Bpout ("port_out", gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)
@ivand58
ivand58 / newdir.sh
Last active September 25, 2018 12:11
create new folder and make it current
#! /bin/bash
if [[ $BASH_SOURCE == $0 ]] ; then
printf '?ERROR %s: run it sourced ...\n' "$BASH_SOURCE" ;
exit 1 ;
fi
echo -n "newdir "
if [ "$(type -t newdir)" = 'function' ]; then
echo "redefined "
else
@ivand58
ivand58 / sensor.py
Created September 26, 2018 13:28
opensensemap POST
import httplib, urllib
sensor1_id = "XX"
sensor2_id = "XX"
sensebox_id = "XX"
host = "ingress.opensensemap.org"
url = '/boxes/%s/%s' % (sensebox_id, sensor2_id)
mkfifo /tmp/board;
wireshark -k -i /tmp/board &
ssh root@10.7.6.5 "tcpdump -s 0 -U -n -w - -i lo not port 22" > /tmp/board;