-Wl,--start-group -lmbed -lc_s -lstdc++_s -Wl,--end-group
# Targets
-all: $(PROG).bin
+all: $(addsuffix .bin,$(PROG))
info: all
@echo "LS $(PROG).bin $(PROG).elf"
-f board/frdm-kl46z.cfg
clean:
- @echo "RM $(PROG).bin $(PROG).elf $(OBJS)"
- @rm -f $(PROG).bin $(PROG).elf $(OBJS)
+ @echo "RM *.bin *.elf *.o $(CLEAN)"
+ @rm -f *.bin *.elf *.o $(CLEAN)
+
+# Defaults
+$(PROG).elf: $(OJBS)
# Rules
%.o: %.c $(wildcard *.h) makefile ../common.mk ../config.mk
@echo "CXX $<"
@$(GXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
-$(PROG).elf: $(OBJS)
+%.elf:
@echo "LD $+"
@$(GLD) $(CFLAGS) -o $@ $^ $(LDFLAGS)
-$(PROG).bin: $(PROG).elf
+%.bin: %.elf
@echo "BIN $+"
@$(OBJCOPY) -O binary $< $@
exit 0
fi
-install "$1" /dev/sdb /mnt/mbed1 &
-install "$1" /dev/sdc /mnt/mbed2 &
+if [ "$2" ]; then
+ install "$1" "$2" "$3" &
+else
+ install "$1" /dev/sdb /mnt/mbed1 &
+ install "$1" /dev/sdc /mnt/mbed2 &
+fi
wait
-PROG = mbed
-UART0 = /dev/ttyACM0
-UART1 = /dev/ttyACM1
-OBJS = main.o serial_irq.o serial_dma.o timer_dma.o
+# Common settings
+UART0 = /dev/ttyACM0
+UART1 = /dev/ttyACM1
+CLEAN = control tags
CPPFLAGS =
LDFLAGS = -lm
-default: info run
+# Common rules
+default: all
-control: control.c messages.h
- gcc -Wall -o $@ $<
-
-run: all control install.sh
- @./install.sh $(PROG).bin
- @./control $(UART0) 1
- @./control $(UART1) 2 sync
+all: mbed.elf tester.elf control
terms:
- term /dev/ttyACM0 &
- term /dev/ttyACM1 &
+ test -c $(UART0) && term $(UART0) &
+ test -c $(UART1) && term $(UART1) &
dist:
zip mbed.zip makefile ../common.mk *.{c,cpp,h} */*.{cpp,.h}
+# Primary mbed (mbed1/mbed2)
+mbed.elf: main.o serial_irq.o serial_dma.o timer_dma.o
+
+mbed-run: mbed.bin control install.sh
+ @./install.sh $<
+ @./control $(UART0) 1
+ @./control $(UART1) 2 sync
+
+# Testing mbed (mbed3)
+tester.elf: tester.o
+
+tester-run: tester.bin install.sh
+ @./install.sh $< /dev/sdb /mnt/usb
+
+# Controls programs
+control: control.c messages.h
+ gcc -Wall -o $@ $<
+
-include ../config.mk
-include ../common.mk
--- /dev/null
+/* main.cpp
+ * mbed project: Simple_Square_Wave
+ * mbed board: FRDM-KL46Z
+ * Generate square waves using DigitalOut.
+ */
+
+#include "mbed.h"
+
+DigitalOut Square_Wave(PTD3); // Used PWM output is PTD3
+InterruptIn Control_Testing(PTC12); // SW3
+
+void Control_T(void);
+
+int START_STOP_FLAG = 0;
+float period_s = 0.0001;
+
+extern serial_t stdio_uart;
+
+int main(int arc, char **argv)
+{
+ serial_init(&stdio_uart, USBTX, USBRX);
+ serial_baud(&stdio_uart, 115200);
+ printf("starting\r\n");
+
+ Control_Testing.rise(&Control_T); // Enable getMode interrupt handler
+ __enable_irq();
+
+ while(1)
+ {
+ if(START_STOP_FLAG == 1)
+ {
+ Square_Wave.write(0);
+ wait(period_s/2);
+ Square_Wave.write(1);
+ wait(period_s/2);
+ }
+ else
+ Square_Wave.write(0);
+ }
+}
+
+void Control_T(void)
+{
+ if(START_STOP_FLAG == 0)
+ {
+ period_s = 1;
+ START_STOP_FLAG = 1;
+ }
+ else
+ {
+ START_STOP_FLAG = 0;
+ Square_Wave.write(0);
+ }
+}