Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Nov 9, 2017
1 parent fbc5eb5 commit d9b91ed
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cpu/cortexm_common/vectors_cortexm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "panic.h"
#include "vectors_cortexm.h"

#ifdef MODULE_PINDBG
#include "pindbg.h"
#endif

#ifndef SRAM_BASE
#define SRAM_BASE 0
#endif
Expand Down Expand Up @@ -113,6 +117,11 @@ void reset_handler_default(void)

post_startup();

#ifdef MODULE_PINDBG
/* initialize debug pins if configured */
pindbg_init();
#endif

/* initialize the board (which also initiates CPU initialization) */
board_init();

Expand Down
49 changes: 49 additions & 0 deletions cpu/stm32_common/include/pindbg_cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2017 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_stm32_common
*
* @{
* @file
* @brief CPU specific handlers for direct control of debug pins
*
* @author Hauke Petersen <[email protected]>
*/

#ifndef PINDBG_CPU_H
#define PINDBG_CPU_H

#include "cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef PINDBG0
#define PINDBG0_PORT ((GPIO_TypeDef *)(PINDBG0 & ~(0x0f)))
#define PINDBG0_MASK (1 << (PINDBG0 & 0xf))
#define PINDBG0_SET (PINDBG0_PORT->BSRR = PINDBG0_MASK)
#define PINDBG0_CLR (PINDBG0_PORT->BSRR = (PINDBG0_MASK << 16))
#define PINDBG0_TGL (PINDBG0_PORT->ODR ^= PINDBG0_MASK)
#endif

#ifdef PINDBG1
#define PINDBG1_PORT ((GPIO_TypeDef *)(PINDBG1 & ~(0x0f)))
#define PINDBG1_MASK (1 << (PINDBG1 & 0xf))
#define PINDBG1_SET (PINDBG1_PORT->BSRR = PINDBG1_MASK)
#define PINDBG1_CLR (PINDBG1_PORT->BSRR = (PINDBG1_MASK << 16))
#define PINDBG1_TGL (PINDBG1_PORT->ODR ^= PINDBG1_MASK)
#endif

#ifdef __cplusplus
}
#endif

#endif /* PINDBG_CPU_H */
/** @} */
59 changes: 59 additions & 0 deletions sys/include/pindbg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2017 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup sys_pindbg Direct pin control for debugging/profiling
* @ingroup sys
*
* This module gives the possibility to directly control a number of GPIO pins
* without the least possible overhead for debugging and profiling purposes. For
* this, the module provides a number of macros for setting, clearing, and
* toggling some defined pins: `PINDBG[\d]_[SET|CLR|TGL]`, for example
* `PINDBG0_SET` or `PINDBG1_TGL`.
*
* To use this module, you have to do two things:
* 1. the module has to be selected in your project: `USEMODULE += pindbg`
* 2. you have to define the pins you want to use for debugging, e.g.:
* `CFLAGS += -DPINDBG0=GPIO_PIN\(0,15\) -DPINDBG1=GPIO_PIN\(1,24\)`
*
* It is of course up to you to add these settings to your application Makefile
* for the duration of debugging/profiling or to set them through environment
* variables in your host systems shell.
*
* The initialization function is automatically called as early as possible
* during the system initialization so the debug pins can be used already during
* e.g. auto_init and so on.
*
* @{
* @file
* @brief Module for direct pin control for debugging/profiling purposes
*
* @author Hauke Petersen <[email protected]>
*/

#ifndef PINDBG_H
#define PINDBG_H

#include "pindbg_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialize all configured debug pins
*/
void pindbg_init(void);

#ifdef __cplusplus
}
#endif

#endif /* PINDBG_H */
/** @} */

1 change: 1 addition & 0 deletions sys/pindbg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
32 changes: 32 additions & 0 deletions sys/pindbg/pindbg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup sys_pindbg
* @{
*
* @file
* @brief Initialization of configured direct controlled debug pins
*
* @author Hauke Petersen <[email protected]>
*
* @}
*/

#include "pindbg.h"
#include "periph/gpio.h"

void pindbg_init(void)
{
#ifdef PINDBG0
gpio_init(PINDBG0, GPIO_OUT);
#endif
#ifdef PINDBG1
gpio_init(PINDBG1, GPIO_OUT);
#endif
}

0 comments on commit d9b91ed

Please sign in to comment.