From 4be63e9bf292129a3d9771025528d254646180fe Mon Sep 17 00:00:00 2001 From: batt Date: Thu, 18 Oct 2007 14:51:17 +0000 Subject: [PATCH] Add debug for ARM AT91. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@904 38d2e660-2303-0410-9eaa-f027e97ec537 --- cpu/arm/drv/kdebug_arm.c | 47 +++++++++++++++++ cpu/arm/drv/kdebug_at91.c | 102 ++++++++++++++++++++++++++++++++++++ cpu/arm/drv/kdebug_at91.h | 59 +++++++++++++++++++++ cpu/arm/io/at91_dbgu.h | 107 ++++++++++++++++++++++++++++++++++++++ cpu/arm/io/at91sam7s256.h | 12 +++-- 5 files changed, 322 insertions(+), 5 deletions(-) create mode 100644 cpu/arm/drv/kdebug_arm.c create mode 100644 cpu/arm/drv/kdebug_at91.c create mode 100644 cpu/arm/drv/kdebug_at91.h create mode 100644 cpu/arm/io/at91_dbgu.h diff --git a/cpu/arm/drv/kdebug_arm.c b/cpu/arm/drv/kdebug_arm.c new file mode 100644 index 00000000..9e16ba22 --- /dev/null +++ b/cpu/arm/drv/kdebug_arm.c @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Francesco Sacchi + * + * \brief Low-level kdebug module for ARM (inplementation). + */ + +#include + +#if CPU_ARM_AT91 + #include "kdebug_at91.c" +/*#elif Add other ARM families here */ +#else + #error Unknown CPU +#endif diff --git a/cpu/arm/drv/kdebug_at91.c b/cpu/arm/drv/kdebug_at91.c new file mode 100644 index 00000000..35261399 --- /dev/null +++ b/cpu/arm/drv/kdebug_at91.c @@ -0,0 +1,102 @@ +/** + * \file + * + * + * \brief ARM debug support (implementation). + * + * \version $Id$ + * \author Francesco Sacchi + */ + +#include "kdebug_at91.h" +#include +#include /* for BV() */ +#include +#include /* for CLOCK_FREQ */ +#include /* Required for bus macros overrides */ + +#include + +#if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU + #define KDBG_WAIT_READY() while (!(DBGU_SR & BV(US_TXRDY))) {} + #define KDBG_WAIT_TXDONE() while (!(DBGU_SR & BV(US_TXEMPTY))) {} + + #define KDBG_WRITE_CHAR(c) do { DBGU_THR = (c); } while(0) + + /* Debug unit is used only for debug purposes so does not generate interrupts. */ + #define KDBG_MASK_IRQ(old) do { (void)old; } while(0) + + /* Debug unit is used only for debug purposes so does not generate interrupts. */ + #define KDBG_RESTORE_IRQ(old) do { (void)old; } while(0) + + typedef uint32_t kdbg_irqsave_t; + +#else + #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU +#endif + + +INLINE void kdbg_hw_init(void) +{ + #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU + /* Disable all DBGU interrupts. */ + DBGU_IDR = 0xFFFFFFFF; + /* Reset DBGU */ + DBGU_CR = BV(US_RSTRX) | BV(US_RSTTX) | BV(US_RXDIS) | BV(US_TXDIS); + /* Set baudrate */ + DBGU_BRGR = (CLOCK_FREQ + (16 * CONFIG_KDEBUG_BAUDRATE) / 2) / (16 * CONFIG_KDEBUG_BAUDRATE); + /* Set DBGU mode to 8 data bits, no parity and 1 stop bit. */ + DBGU_MR = US_CHMODE_NORMAL | US_CHRL_8 | US_PAR_NO | US_NBSTOP_1; + /* Enable DBGU transmitter. */ + DBGU_CR = BV(US_TXEN); + /* Disable PIO on DGBU tx pin. */ + #if CPU_ARM_AT91SAM7S256 + PIOA_PDR = BV(10); + PIOA_ASR = BV(10); + #else + #warning Check Debug Unit AT91 pins on datasheet! + #endif + + #if 0 /* Disable Rx for now */ + /* Enable DBGU receiver. */ + DBGU_CR = BV(US_RXEN); + /* Disable PIO on DGBU rx pin. */ + #if CPU_ARM_AT91SAM7S256 + PIOA_PDR = BV(9); + PIOA_ASR = BV(9); + #else + #warning Check Debug pins on datasheet! + #endif + #endif + #else + #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU + #endif /* CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU */ +} diff --git a/cpu/arm/drv/kdebug_at91.h b/cpu/arm/drv/kdebug_at91.h new file mode 100644 index 00000000..24eb64e3 --- /dev/null +++ b/cpu/arm/drv/kdebug_at91.h @@ -0,0 +1,59 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Francesco Sacchi + * + * \brief ARM debug support (interface). + */ + +#ifndef DRV_KDEBUG_AT91_H +#define DRV_KDEBUG_AT91_H + +#include /* CONFIG_TIMER */ +#include /* uint8_t */ +#include /* CLOCK_FREQ */ + +/** + * \name Values for CONFIG_KDEBUG_PORT. + * + * Select which hardware UART to use for system debug. + * + * \{ + */ +#define KDEBUG_PORT_DBGU 0 ///< Debug on Debug Unit. + +#define KDEBUG_PORT_DEFAULT KDEBUG_PORT_DBGU ///< Default debug port. +/* \} */ + +#endif /* DRV_KDEBUG_AT91_H */ diff --git a/cpu/arm/io/at91_dbgu.h b/cpu/arm/io/at91_dbgu.h new file mode 100644 index 00000000..5fa700de --- /dev/null +++ b/cpu/arm/io/at91_dbgu.h @@ -0,0 +1,107 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Francesco Sacchi + * + * AT91 Debug unit. + * This file is based on NUT/OS implementation. See license below. + */ + +/* + * Copyright (C) 2005-2006 by egnite Software GmbH. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE + * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * For additional information see http://www.ethernut.de/ + */ +#ifndef AT91_DBGU_H +#define AT91_DBGU_H + +#define DBGU_CR (*((reg32_t *)(DBGU_BASE + US_CR_OFF))) ///