Skip to content
Snippets Groups Projects
Commit 824cef85 authored by Erik Strand's avatar Erik Strand
Browse files

Update the blink example

OUTSET and OUTCLR should use =, not |=. Their purpose is to avoid
read-modify-write operations.

Also there's no reason to make the hello world sketch blink too fast for
the eye to see without waving the board around.
parent d1e271bc
Branches
No related tags found
No related merge requests found
...@@ -131,6 +131,4 @@ Info : Listening on port 3333 for gdb connections ...@@ -131,6 +131,4 @@ Info : Listening on port 3333 for gdb connections
``` ```
If you see `Error: unable to open CMSIS-DAP device 0x3eb:0x2141`, it probably means openocd needs root privileges to access the programmer. You could run `sudo openocd`, but a better solution is to follow the instructions [here](https://forgge.github.io/theCore/guides/running-openocd-without-sudo.html) to create a new rule. Don't forget to restart `udev` after doing this with `sudo udevadm trigger`. If you see `Error: unable to open CMSIS-DAP device 0x3eb:0x2141`, it probably means openocd needs root privileges to access the programmer. You could run `sudo openocd`, but a better solution is to follow the instructions [here](https://forgge.github.io/theCore/guides/running-openocd-without-sudo.html) to create a new rule. Don't forget to restart `udev` after doing this with `sudo udevadm trigger`.
Fifth, now that openocd is running, open a second terminal window and type `arm-none-eabi-gdb main.elf`. When gdb opens, type `tar ext :3333` (a shortcut for `target extended-remote :3333`), then `load`. This should flash the microcontroller with the new code, at which point you can exit gdb with `quit` and `y`. In the openocd window, close the connection with `Ctrl-C`. If you're flashing one of Jake's [moduleboards](https://gitlab.cba.mit.edu/squidworks/moduleboard-atsamd51/tree/master), the red and green LEDs should alternate fast enough to create a line of dashes when you wave the board around: Fifth, now that openocd is running, open a second terminal window and type `arm-none-eabi-gdb main.elf`. When gdb opens, type `tar ext :3333` (a shortcut for `target extended-remote :3333`), then `load`. This should flash the microcontroller with the new code, at which point you can exit gdb with `quit` and `y`. In the openocd window, close the connection with `Ctrl-C`. If you're flashing one of Jake's [moduleboards](https://gitlab.cba.mit.edu/squidworks/moduleboard-atsamd51/tree/master), the red and green LEDs should blink.
![example-blinks](baremetal/example-blinks.jpg)
baremetal/example-blinks.jpg

174 KiB

...@@ -2,17 +2,21 @@ ...@@ -2,17 +2,21 @@
int main (void) { int main (void) {
int i; int i;
REG_PORT_DIR0 |= (1<<17);
REG_PORT_DIR0 |= (1<<19); // on a squidworks module board, the red LED is 17, and the green is 19
REG_PORT_DIR0 = (1u << 17) | (1u << 19);
// setting these high turns the LEDs off
REG_PORT_OUTSET0 = (1u << 17) | (1u << 19);
while(1) { while(1) {
REG_PORT_OUTSET0 |= (1<<17); REG_PORT_OUTSET0 = (1u << 17) | (1u << 19);
REG_PORT_OUTCLR0 |= (1<<19); for (i=0; i<1000000; i++) {
for (i=0;i<10000;i++) {
__asm("nop"); __asm("nop");
} }
REG_PORT_OUTCLR0 |= (1<<17);
REG_PORT_OUTSET0 |= (1<<19); REG_PORT_OUTCLR0 = (1u << 17) | (1u << 19);
for (i=0;i<10000;i++) { for (i=0; i<1000000; i++) {
__asm("nop"); __asm("nop");
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment