From 0c1e003e9d6aa58868c13de9618a9114181f921c Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 12 Sep 2014 02:21:15 +0300 Subject: [PATCH] working blinker with usb debug --- Makefile | 35 +++++++++++++++++++++++++++++++++++ main.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Makefile create mode 100644 main.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d934bba --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ +OBJCOPY = $(CROSS_COMPILE)objcopy +SIZE = $(CROSS_COMPILE)size + +TOOLSPATH = tools + +TARGET = test + +# CPPFLAGS += -DUSB_SERIAL -DLAYOUT_US_ENGLISH +CPPFLAGS += -D__MK20DX256__ -DF_CPU=48000000 +CPPFLAGS += -DUSB_RAWHID +CPPFLAGS += -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib # -MMD +CXXFLAGS += -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti +LDFLAGS = -Os -Wl,--gc-sections -mcpu=cortex-m4 -mthumb -Tteensy3/mk20dx256.ld +LDLIBS += -lm + +C_FILES := $(wildcard *.c) +CT_FILES := $(wildcard teensy3/*.c) +OBJS += $(C_FILES:.c=.o) $(CT_FILES:.c=.o) + +all: $(TARGET).hex + +$(TARGET).elf: $(OBJS) $(LDSCRIPT) + $(CC) $(LDFLAGS) -o "$@" $(OBJS) $(LDLIBS) + +%.hex: %.elf + $(SIZE) "$<" + $(OBJCOPY) -O ihex -R .eeprom "$<" "$@" + +clean: + $(RM) $(TARGET).hex $(TARGET).elf $(OBJS) + +up: $(TARGET).hex + teensy_loader_cli -mmcu=mk20dx128 -w $< diff --git a/main.c b/main.c new file mode 100644 index 0000000..511a599 --- /dev/null +++ b/main.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include "teensy3/core_pins.h" +#include "teensy3/usb_seremu.h" +#include "teensy3/usb_rawhid.h" + +ssize_t _write(int fd, const void *buf, size_t nbyte) +{ + char tbuf[64]; + int ret; + + if (fd != 1 && fd != 2) { + snprintf(tbuf, sizeof(tbuf), "write to fd %d\n", fd); + usb_seremu_write(tbuf, strlen(tbuf)); + } + + ret = usb_seremu_write(buf, nbyte); + return ret < 0 ? ret : nbyte; +} + +void yield(void) +{ +} + +int main(void) +{ + int ret; + + delay(1000); // wait for usb.. + + printf("starting, rawhid: %d\n", usb_rawhid_available()); + + // ret = usb_rawhid_recv(buf, 2000); + // ret = usb_rawhid_send(buf, 2000); + + pinMode(13, OUTPUT); + pinMode(14, OUTPUT); + while (1) { + CORE_PIN13_PORTSET = CORE_PIN13_BITMASK; + CORE_PIN14_PORTSET = CORE_PIN14_BITMASK; + delay(500*4); + CORE_PIN13_PORTCLEAR = CORE_PIN13_BITMASK; + CORE_PIN14_PORTCLEAR = CORE_PIN14_BITMASK; + delay(500*4); + } +} -- 2.39.5