From patchwork Mon Sep 11 11:58:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Filzmaier X-Patchwork-Id: 9947283 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4C2B603F3 for ; Mon, 11 Sep 2017 11:59:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D898828B53 for ; Mon, 11 Sep 2017 11:59:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD51728BC4; Mon, 11 Sep 2017 11:59:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BFE028B53 for ; Mon, 11 Sep 2017 11:59:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751599AbdIKL7l (ORCPT ); Mon, 11 Sep 2017 07:59:41 -0400 Received: from mout.gmx.net ([212.227.15.19]:50275 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751393AbdIKL7k (ORCPT ); Mon, 11 Sep 2017 07:59:40 -0400 Received: from hella-laptop.8.8.4.4 ([178.191.35.178]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0LnxxQ-1dG5cR1824-00fzsi; Mon, 11 Sep 2017 13:59:39 +0200 From: Josef Filzmaier To: linux-wpan@vger.kernel.org Cc: Josef Filzmaier Subject: [PATCH atusb/fw v2 1/2] atusb/fw: Introduce DEBUG flag Date: Mon, 11 Sep 2017 13:58:32 +0200 Message-Id: <20170911115833.24957-2-j.filzmaier@gmx.at> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170911115833.24957-1-j.filzmaier@gmx.at> References: <20170911115833.24957-1-j.filzmaier@gmx.at> X-Provags-ID: V03:K0:nkmVyH/Q3jpwSGAN2Q54ATCS8BnY5OOdhdVJdcACz9xK60WGpXe d+i573Bu8OE+T9i+RqtbA3ZKxYbiKWKVpmQf/CKcDVpOSdNUllV+VszuvXimdOZsGgM6Dn9 6xbRpBEr1M8CVEJGFOa/MJmPgYhwi27eDFtxjsvaoVD0sJz1qDD4w0EKLr4mBs9veHEO651 PjD+mxmehvfR4Sx7oO7xQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Ww5b6/SdJJg=:vOU19FsCo+pR0xBpEm8vAs K9nGyfSrwONmgW8WmzlD2GAOPr8Y3ucLbHwE+aB2x0pKqjtlh6aoKm59yMU6j+5qmZ9NseN44 0zPU1E1spF3L293nkLl86QE7O5SegG0jULocObJayfQFmDHWFVkQ4VoChGjczIFOC/wKNXvgE H31GeI/+mtuWW6rEkFaZIkYHMbdXHfyrkCfhFzEkU8EiraKzoybrBsx2U3sZywsf/QX2to1bf f6u3LN8hqz5tj3NlWAnfcr/hTwr97/XSqC19BHukYmD9nAiXg6GLbn7bTe5xDLOfJL4SqW2oU 5Rw+jBdI9HP6cUc7kimBijs3wSS2GKQkRRzr9uwFTNhOwQhQuhImcs60SV7z4uh3C2rKKXEMl GaBP/Ai7kAYluKTPdOYuZTW0Y7vMfrH5glgLmXBh72irtLPTvkfv1gQjLfSz+OqQBrv9Rd+Rb RBWGjf2UQDkVhwRRxrVAGJkXfJ8eO3aJq7290yz+gtiRuD62PIe/4hJNbD5SjAgLqLnUNYjeX jkQZGNU55JGYo4xtB/j936BTeTpqGqcKCxE+cw7eUO4EPM5mxC0qALnkrz90x55TuZwK4xK98 B3CrhE1A9Gwu/pchOll+Wa2+2/06ZJu7T3g7LLk/CJcZEO4qkexa6/gA+HevuHpkpHm2DHtQ9 3vFlGzbJ4L/6gOwWPfGnRlCl5xlT/PfS+67xzOh++dtfrmCKom8I2C70fpNr0oQJh3z4SCdN2 F0gWx+UIH67zNU9K9YFoVLwAseN74KdowxMRKZt0S2VOiHo/vfUSBJhUly46zifZHO350UPpv d6tBt/Scly8ifuCcozI4XYhILU/hw== Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This flag can be used to enable debugging over uart. Currently only available for boards with the at90usb1287 chip. Signed-off-by: Josef Filzmaier --- atusb/fw/Makefile | 10 ++++++++- atusb/fw/atusb.c | 11 ++++++++++ atusb/fw/ep0.c | 7 ++++++ atusb/fw/uart.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ atusb/fw/uart.h | 25 ++++++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 atusb/fw/uart.c create mode 100644 atusb/fw/uart.h diff --git a/atusb/fw/Makefile b/atusb/fw/Makefile index c1c68d7..4cc749c 100644 --- a/atusb/fw/Makefile +++ b/atusb/fw/Makefile @@ -1,5 +1,5 @@ # -# Makefile - Makefile of the ATUSB firmware +# Makefile - Makefile of the ATUSB firmware # # Written 2010-2011, 2013 by Werner Almesberger # Copyright 2010-2011, 2013 by Werner Almesberger @@ -13,11 +13,16 @@ SHELL = /bin/bash NAME = atusb +DEBUG = false CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes +ifeq ($(DEBUG),true) +CFLAGS += -DDEBUG +endif + ifeq ($(NAME),rzusb) CHIP=at90usb1287 CFLAGS += -DRZUSB -DAT86RF230 @@ -46,6 +51,9 @@ OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o \ BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \ dfu_common.o usb.o boot-atu2.o +ifeq ($(DEBUG),true) +OBJS += uart.o +endif ifeq ($(NAME),rzusb) OBJS += board_rzusb.o diff --git a/atusb/fw/atusb.c b/atusb/fw/atusb.c index 1f65d53..28faf40 100644 --- a/atusb/fw/atusb.c +++ b/atusb/fw/atusb.c @@ -24,6 +24,10 @@ #include "spi.h" #include "atusb/ep0.h" +#ifdef DEBUG +#include "uart.h" +#endif + int main(void) { @@ -35,6 +39,13 @@ int main(void) /* now we should be at 8 MHz */ +#ifdef DEBUG + uart_init(); + static FILE atben_stdout = FDEV_SETUP_STREAM(uart_write_char, NULL, + _FDEV_SETUP_WRITE); + stdout = &atben_stdout; +#endif + usb_init(); ep0_init(); #ifdef ATUSB diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c index 2b92f6d..674f9de 100644 --- a/atusb/fw/ep0.c +++ b/atusb/fw/ep0.c @@ -45,8 +45,15 @@ #define HW_TYPE HW_TYPE_RZUSB #endif +#ifdef DEBUG +#include "uart.h" +#include +#define debug(FORMAT,args...) printf(FORMAT,##args) +#define error(FORMAT,args...) printf(FORMAT,##args) +#else #define debug(...) #define error(...) +#endif static const uint8_t id[] = { EP0ATUSB_MAJOR, EP0ATUSB_MINOR, HW_TYPE }; diff --git a/atusb/fw/uart.c b/atusb/fw/uart.c new file mode 100644 index 0000000..44bec27 --- /dev/null +++ b/atusb/fw/uart.c @@ -0,0 +1,64 @@ +/* + * fw/uart.h - Functions needed for debugging over uart + * + * Code adapted from http://www.roboternetz.de/wissen/index.php/UART_mit_avr-gcc + * and http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial + * + * Published under the Creative Commons Share-Alike licence + * https://creativecommons.org/licenses/by-sa/2.0/de/ + * + * S. Salewski 2007 + * + * Adapted by + * Josef Filzmaier 2017 + */ + +#include +#include "uart.h" + +#define USART_BAUD 38400UL +#define F_CPU 8000000UL + +#define Wait_USART_Ready() while (!(UCSR1A & (1< + +void uart_init(void); +int uart_write_char(char c, FILE* stream); +void uart_new_line(void); + +#endif /* UART_H_ */