-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new board blinky example, nRF52840
- Loading branch information
1 parent
00c96aa
commit d1a6197
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/**/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CFLAGS ?= -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -Wformat-truncation -fno-common | ||
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections -Wno-shadow | ||
CFLAGS += -mcpu=cortex-m4 | ||
SOURCES = main.c | ||
|
||
build: | ||
mkdir build | ||
arm-none-eabi-gcc $(SOURCES) -c $(CFLAGS) -o ./build/main.o | ||
arm-none-eabi-gcc -T link.ld -nostdlib ./build/main.o -o ./build/firmware.elf | ||
arm-none-eabi-objcopy -Oihex ./build/firmware.elf ./build/firmware.hex | ||
|
||
flash: | ||
nrfjprog -f NRF52 --program ./build/firmware.hex --recover --verify | ||
nrfjprog -f NRF52 --reset | ||
|
||
clean: | ||
rm -rf ./build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#define P0 ((struct gpio *) 0x50000000) | ||
#define P1 ((struct gpio *) 0x50000300) | ||
#define BUILD_IN_LED_1 13 | ||
|
||
enum { GPIO_MODE_INPUT, GPIO_MODE_OUTPUT }; | ||
enum { LOW, HIGH }; | ||
|
||
struct gpio { | ||
volatile uint32_t RESERVED[321], OUT, OUTSET, OUTCLR, IN, DIR, DIRSET, DIRCLR, LATCH, DETECTMODE, PIN_CNF[32]; | ||
}; | ||
|
||
void set_gpio_mode(struct gpio * port, int pin, int mode) { | ||
port->DIR |= mode << pin; | ||
} | ||
|
||
void gpio_write(struct gpio * port, int pin, int value) { | ||
if (value == 1) | ||
port->OUTSET |= 1 << pin; | ||
else | ||
port->OUTCLR |= 1 << pin; | ||
} | ||
|
||
static inline void spin(volatile uint32_t count) { | ||
while (count--) (void) 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
ENTRY(_reset); | ||
|
||
MEMORY { | ||
flash(rx) : ORIGIN = 0x00000000, LENGTH = 1M | ||
sram(rwx) : ORIGIN = 0x20000000, LENGTH = 256k | ||
} | ||
_estack = ORIGIN(sram) + LENGTH(sram); | ||
|
||
SECTIONS { | ||
.vectors : { KEEP(*(.vectors)) } > flash | ||
.text : { *(.text*) } > flash | ||
.rodata : { *(.rodata*) } > flash | ||
|
||
.data : { | ||
_sdata = .; /* .data section start */ | ||
*(.first_data) | ||
*(.data SORT(.data.*)) | ||
_edata = .; /* .data section end */ | ||
} > sram AT > flash | ||
_sidata = LOADADDR(.data); | ||
|
||
.bss : { | ||
_sbss = .; /* .bss section start */ | ||
*(.bss SORT(.bss.*) COMMON) | ||
_ebss = .; /* .bss section end */ | ||
} > sram | ||
|
||
. = ALIGN(8); | ||
_end = .; /* for cmsis_gcc.h */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdint.h> | ||
#include "hal.h" | ||
|
||
int main(void) { | ||
set_gpio_mode(P0, BUILD_IN_LED_1, GPIO_MODE_OUTPUT); | ||
|
||
while (1) { | ||
gpio_write(P0, BUILD_IN_LED_1, HIGH); | ||
spin(9999999); | ||
gpio_write(P0, BUILD_IN_LED_1, LOW); | ||
spin(9999999); | ||
} | ||
} | ||
|
||
// Startup code | ||
__attribute__((naked, noreturn)) void _reset(void) { | ||
// memset .bss to zero, and copy .data section to RAM region | ||
extern long _sbss, _ebss, _sdata, _edata, _sidata; | ||
for (long *dst = &_sbss; dst < &_ebss; dst++) *dst = 0; | ||
for (long *dst = &_sdata, *src = &_sidata; dst < &_edata;) *dst++ = *src++; | ||
|
||
main(); // Call main() | ||
for (;;) (void) 0; // Infinite loop in the case if main() returns | ||
} | ||
|
||
extern void _estack(void); // Defined in link.ld | ||
|
||
// 16 standard and 42 nRF52-specific handlers | ||
__attribute__((section(".vectors"))) void (*const tab[16 + 42])(void) = { | ||
_estack, _reset}; | ||
|