Skip to content

Instantly share code, notes, and snippets.

View wdwalker's full-sized avatar

Willie Walker wdwalker

  • Hollis, NH
View GitHub Profile
@wdwalker
wdwalker / LPC1768.ld.diff
Last active March 12, 2017 17:08
Diffs from CMSIS_5/Device/ARM/ARMCM3/Source/GCC/gcc_arm.ld to set the MEMORY section for the NXP LPC1768
*** ../CMSIS_5/Device/ARM/ARMCM3/Source/GCC/gcc_arm.ld 2017-03-09 18:07:02.000000000 -0500
--- LPC1768.ld 2017-03-09 18:53:18.000000000 -0500
***************
*** 2,8 ****
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K
! RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
}
@wdwalker
wdwalker / main.c
Last active March 11, 2017 14:43
PINSEL3 for LED1-4 on LPC1768
#define P1_18_SEL (1 << 5) | (1 << 4) /* Pin 1.18 = LED1 */
#define P1_20_SEL (1 << 9) | (1 << 8) /* Pin 1.20 = LED2 */
#define P1_21_SEL (1 << 11) | (1 << 10) /* Pin 1.21 = LED3 */
#define P1_23_SEL (1 << 15) | (1 << 14) /* Pin 1.23 = LED4 */
...
/* Set the pins to GPIO by setting the associated bits to 00 (p119)
*/
LPC_PINCON->PINSEL3 &= (unsigned) ~(P1_18_SEL | P1_20_SEL | P1_21_SEL | P1_23_SEL);
@wdwalker
wdwalker / main.c
Last active March 11, 2017 14:46
Set FIODIR of pins to output for LED1-4
#define P18 (1 << 18)
#define P20 (1 << 20)
#define P21 (1 << 21)
#define P23 (1 << 23)
#define ALL (P18 | P20 | P21 | P23)
...
/* Set the direction as output by setting the associated bits
@wdwalker
wdwalker / main.c
Last active March 11, 2017 15:03
Toggle LED1-4 on and off
/* Turn the LEDs on and off at roughly 1Hz.
*/
while (1) {
LPC_GPIO1->FIOSET |= ALL; /* p132 */
delay_ms(500);
LPC_GPIO1->FIOCLR |= ALL; /* p132 */
delay_ms(500);
}
@wdwalker
wdwalker / makefile
Created March 11, 2017 15:21
ARM_FLAGS
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/ARM-Options.html
ARM_FLAGS = \
-mthumb \
-mcpu=cortex-m3
@wdwalker
wdwalker / makefile
Created March 11, 2017 15:25
WARNING_FLAGS
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Warning-Options.html
WARNING_FLAGS = \
-Wall \
-Wextra \
-pedantic \
-Wbad-function-cast \
-Wconversion \
-Wfloat-equal \
-Wlogical-op \
-Wmissing-declarations \
@wdwalker
wdwalker / makefile
Created March 11, 2017 15:28
CPP_FLAGS
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Preprocessor-Options.html
CPPFLAGS = \
-MMD \
-MF"$(@:%.o=%.d)" \
-MT"$(@)"
@wdwalker
wdwalker / makefile
Created March 11, 2017 15:39
DEBUG
# Define DEBUG to anything if you want debug enabled.
#
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Optimize-Options.html#Optimize-Options
# http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0205g/Bgbjjgij.html
# https://mcuoneclipse.com/2015/05/27/semihosting-for-kinetis-design-studio-v3-0-0-and-gnu-arm-embedded-launchpad/
DEBUG=
ifdef DEBUG
OPTIMIZE=-Os -g -DDEBUG
RDIMONSPECS = --specs=rdimon.specs
RDIMONLIB = -lrdimon
@wdwalker
wdwalker / makefile
Created March 11, 2017 15:54
Other Flags
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Diagnostic-Message-Formatting-Options.html
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/C-Dialect-Options.html#C-Dialect-Options
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Code-Gen-Options.html
ASFLAGS = \
$(ARM_FLAGS) \
$(WARNING_FLAGS) \
-fmessage-length=0 \
$(OPTIMIZE) \
-ffunction-sections \
-fdata-sections \
@wdwalker
wdwalker / makefile
Created March 11, 2017 17:00
LD_FLAGS
# https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Link-Options.html
LDFLAGS = \
-nodefaultlibs \
-T "LPC1768.ld" \
-Wl,--gc-sections \
-Wl,-Map,"BBB.map" \
-Wl,--start-group -lgcc -lc -lm $(RDIMONLIB) -Wl,--end-group