Skip to content

Instantly share code, notes, and snippets.

View bgamari's full-sized avatar

Ben Gamari bgamari

View GitHub Profile
@bgamari
bgamari / gist:8796161
Created February 4, 2014 01:56
MC HCK bootloader protocol error
[2055 ben@ben-laptop usb-dfu(master)] $ make swd-flash MCHCKADAPTER=name=buspirate:dev=/dev/ttyUSB0 DEBUG=1
cd /home/ben/hardware/mchck/toolchain/.. && git submodule update --init programmer
ruby /home/ben/hardware/mchck/toolchain/../programmer/flash.rb name=buspirate:dev=/dev/ttyUSB0 dfu.bin 0
Attaching debugger...
PHYS: initializing bus pirate
PHYS: swd raw: 11111111111111111111111111111111111111111111111111111111
PHYS: swd raw: 1001111011100111
PHYS: swd raw: 11111111111111111111111111111111111111111111111111111111
PHYS: swd raw: 00000000
PHYS: transact 10100101
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32"
target triple = "arm-unknown-linux-gnueabi"
declare ccc i8* @memcpy(i8*, i8*, i32)
declare ccc i8* @memmove(i8*, i8*, i32)
declare ccc i8* @memset(i8*, i32, i32)
declare ccc i32 @newSpark(i8*, i8*)
!0 = metadata !{metadata !"top", i8* null}
!1 = metadata !{metadata !"stack", metadata !0}
!2 = metadata !{metadata !"heap", metadata !0}
!3 = metadata !{metadata !"rx", metadata !2}
@bgamari
bgamari / build-ghc-arm.sh
Last active August 29, 2015 13:57
A small helper script for building GHC 7.8 on ARM
#!/bin/bash -e
bindir=`pwd`/bin-tmp
mkdir -p $bindir
export PATH=$bindir:$PATH
function use_ld() {
rm -f $bindir/ld
ln -s $1 $bindir/ld
echo "Using $1 for ld"
}
@bgamari
bgamari / Check.hs
Created March 10, 2014 05:11
A quick script to check for overlaps in function, module, and variables namespaces in OpenSCAD code
{-# LANGUAGE OverloadedStrings, TupleSections #-}
import Language.OpenSCAD
import Control.Monad
import Data.Attoparsec.Char8
import Data.Attoparsec
import qualified Data.ByteString as BS
import System.Environment
import System.IO
import qualified Data.Map as M
Wrong exit code (expected 0 , actual 1 )
Stdout:
Int: Passed
Integer: Passed
Int8: Passed
Int16: Passed
Int32: Passed
Int64: Passed
Word: Passed
Word8: Passed
struct ListItem<T> {
value : T,
next : Option<*mut ListItem<T>>
}
struct List<T> (Option<*mut ListItem<T>>);
impl<T> List<T> {
fn prepend(&mut self, x : *mut ListItem<T>) {
match *self {
@bgamari
bgamari / fd
Last active August 29, 2015 13:58
[2043 bgamari@goldnerlab apache2] $ sudo -E gdb --args /usr/sbin/apache2 -k start
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
@bgamari
bgamari / I2C.rs
Created May 5, 2014 09:10
A skeleton interface for an embedded I2C peripheral written against Zinc
use os::mutex::Mutex;
use os::cond_var::CondVar;
enum Error {
Nack
}
enum State {
Idle,
Failed(Error),
$ RUST_BACKTRACE=1 rake PLATFORM=lpc17xx APP=app_sched
(in /opt/exp/zinc)
rustc -Z no-landing-pads -C relocation_model=static --target thumbv7m-linux-eabi -Ctarget-cpu=cortex-m3 --cfg mcu_lpc17xx --cfg arch_cortex_m3 --cfg cfg_tft_lcd --cfg cfg_multitasking --cfg cfg_mcu_has_spi --opt-level 2 -L ./build --out-dir ./build ./src/main.rs
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'expected item, found foreign item hal::k20::i2c::reg::I2C0::I2C0 (id=8188)', /opt/exp/rust/src/libsyntax/ast_map.rs:264
stack backtrace:
1: 0x7f2092732360 - rt::backtrace::imp::write::h0f7acf019ac1f7eeMwa::v0.11.pre
use ty::Unsafe;
use zinc::hal::cortex_m3::sched::CritSection;
pub struct Shared<T> {
value: Unsafe<T>
};
impl<T> Shared<T> {
pub fn new(value: T) -> Shared<T> {
Shared { Unsafe::new(value) }