Skip to content

Instantly share code, notes, and snippets.

@denizzzka
Last active January 23, 2020 12:04
Show Gist options
  • Select an option

  • Save denizzzka/1e31d3cf275403ae50768eca613fb1c6 to your computer and use it in GitHub Desktop.

Select an option

Save denizzzka/1e31d3cf275403ae50768eca613fb1c6 to your computer and use it in GitHub Desktop.
Bare metal Dlang ARM
// https://github.com/ldc-developers/ldc/issues/3290
import ldc.attributes;
@llvmAttr("nounwind"):
import ldc.llvmasm;
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
static void gpio_setup()
{
rcc_periph_clock_enable(RCC_GPIOB);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
}
import ldc.attributes;
extern(C) void main()
{
int i;
gpio_setup();
while (1) {
gpio_toggle(GPIOB, GPIO1); /* LED on/off */
for (i = 0; i < 800000; i++) /* Wait a bit. */
__asm("nop", "");
}
}
@denizzzka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment