Skip to content

Instantly share code, notes, and snippets.

@technobly
Created January 9, 2014 21:36
Show Gist options
  • Save technobly/8342518 to your computer and use it in GitHub Desktop.
Save technobly/8342518 to your computer and use it in GitHub Desktop.
Intro to Inline Assembly on the Spark Core #1
//--------------------------------------------------
// Intro to Inline Assembly on the Spark Core (WIP)
//==================================================
// Copy this into a new application at:
// https://www.spark.io/build and go nuts!
//--------------------------------------------------
// Technobly / BDub - Jan 2014
//==================================================
uint16_t pin = D0;
void setup() {
pinMode(pin,OUTPUT);
}
void loop() {
// Bit-Bang Digital Output D7 at 18MHz = System Clock 72MHz / 4
// HIGH time = 27.7ns
// LOW time = 27.7ns
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin; // HIGH
asm volatile(
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
);
PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin; // LOW
asm volatile(
"nop" "\n\t"
"nop" "\n\t"
"nop" "\n\t"
);
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin; // HIGH
asm volatile(
"nop" "\n\t"
"nop" "\n\t"
);
PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin; // LOW
asm volatile(
"nop" "\n\t"
"nop" "\n\t"
);
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin; // HIGH
asm volatile("nop\n\t");
PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin; // LOW
asm volatile("nop\n\t");
PIN_MAP[pin].gpio_peripheral->BSRR = PIN_MAP[pin].gpio_pin; // HIGH
asm volatile("nop\n\t");
PIN_MAP[pin].gpio_peripheral->BRR = PIN_MAP[pin].gpio_pin; // LOW
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment