Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: added pindbg module for direct control of debug pins #7352

Closed

Conversation

haukepetersen
Copy link
Contributor

The reason that we still have the direct controlled LED macros in RIOT is to have some means for controlling pins with the least possible amount of overhead for debugging and profiling purposes. This PR proposes a separate and optional module for this purpose.

So far, it only works for stm32 based boards. Use e.g. it like this:

USEMODULE+=pindbg CFLAGS="-DPINDBG1=GPIO_PIN\(0,1\) -DPINDBG0=GPIO_PIN\(2,17\)" BOARD=stm32f3discovery make

IMHO it makes sense to require the user of the pindbg module to explicitly define the pins he/she wants to use, as this is very specific to the application run on a board (i.e. which peripherals are use and which pins are actually free for debugging).

Putting this module in place could help with the discussion about cleaning up the LED interfaces (see #7321 and #7350).

@haukepetersen haukepetersen added Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Jul 11, 2017
@smlng
Copy link
Member

smlng commented Jul 12, 2017

what is the rational that this should go into sys rather than drivers?

@haukepetersen
Copy link
Contributor Author

I think this module is border line. IMHO it is not really a device driver, but rather a system module used for debugging that makes use of the periph/gpio driver... In the end, not everything that uses periph drivers has to be a device driver!?

@aabadie aabadie added this to the Release 2017.10 milestone Jul 12, 2017
@haukepetersen
Copy link
Contributor Author

Not in the code, yet: with this PR we can also very easily define default debug pins on a per-board basis: simply add something like this to the board.h:

#ifndef PINDBG0
#define PINDBG0    GPIO_PIN(PORT_A, 13)
#endif

So as default, we may simply map one or both debug pins to on-board LEDs, and they will behave exactly like the old LED_xx macros. But this way, they are more intuitive to define compared to the old LED macros, and also more easy to re-configure during compile time.

@OlegHahm: would this suffice as alternative to the existing LED macros in your opinion?

extern "C" {
#endif

#ifdef PINDBG0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it would be great to make this more generic, that is for arbitrary numbers of debug pins, and make the config consistent with other peripheral confs. So I was thinking about something like:

static const pindbg_cfg_t pindbg_config[] = {
    GPIO_PIN(0, 1),
    GPIO_PIN(0, 2),
}

#define PINDGB_NUMOF ( sizeof(pindbg_config) / sizeof(pindbg_config[0] )

and then also have MCU specific macros like

#define PINDBG_PORT(x)        ((GPIO_TypeDef *)(x & ~(0x0f)))
#define PINDBG_MASK(x)        (1 << (x & 0xf))
#define PINDBG_SET(x)         (PINDBG_PORT(x)->BSRR = PINDBG_MASK(x))
#define PINDBG_CLR(x)         (PINDBG_PORT(x)->BSRR = (PINDBG_MASK(x) << 16))
#define PINDBG_TGL(x)         (PINDBG_PORT(x)->ODR ^= PINDBG_MASK(x))

which then would turn pindbg_init() into a simple and generic for-loop.

@haukepetersen you think that's possible and handy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this I see two problems:

  • it is not possible to simply redefine a pin during compile time, e.g. DBGPIN0=GPIO_PIN\(0,2\) make ...
  • I am not sure, if the set/clr/tgl expressions will still evaluate to a single instruction as they do in the current code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the first:

#ifndef PINDBG0
#define PINDBG0 GPIO_PIN(0, 1)
#endif
#ifndef PINGDBG1
#define PINDBG0 GPIO_PIN(0, 2)
#endif 

static const pindbg_cfg_t pindbg_config[] = {
    PINDBG0,
    PINDBG1,
}

and for the second: its preprocessor text replacement, i.e, my example above should resolve to the same statement as you static defines where ever it is used in the code.

@kaspar030
Copy link
Contributor

To me "pindbg" as name feels the wrong way, "dbgpin" would make more sense. "pindbg" sounds like a module for debugging the pins. Do I make sense? :)

@smlng
Copy link
Member

smlng commented Aug 28, 2017

To me "pindbg" as name feels the wrong way, "dbgpin" would make more sense

yeah was thinking the same, but didn't got myself convinced that the latter variant is really more beautiful or comprehensive.

@kaspar030
Copy link
Contributor

Is it possible to just add "static pin init/set/clear/toggle"-functions/macros to periph/gpio? Having gpio.h, led.h and now pindbg.h seems to me like a statement that our gpio interface doesn't optimize optimally, as long as the latter two don't just wrap gpio.h.

@haukepetersen
Copy link
Contributor Author

"dbgpin" would make more sense

I agree, will change the name.

Is it possible to just add "static pin init/set/clear/toggle"-functions/macros to periph/gpio?

led.h does exactly that.

seems to me like a statement that our gpio interface doesn't optimize optimally

Optimization is at least not guaranteed -> as I found out using #7478, the gpio_set/clr/toggle are only properly optimized, when building with LTO. But as this is not the default case, I think there is no way around going the 'manual bit shovel way', if we want to guarantee 1-instruction operation, as we want/need for the debug pins.

@haukepetersen
Copy link
Contributor Author

@smlng will try your proposed solution and verify if the compiler does its job. If yes, I will adapt the code.

@haukepetersen
Copy link
Contributor Author

also changed the name to dbgpin and moved the module to drivers.

@smlng smlng removed this from the Release 2018.01 milestone Jan 12, 2018
@miri64
Copy link
Member

miri64 commented Feb 26, 2019

@haukepetersen any plans to work on this further? Otherwise I would close as archived.

@haukepetersen
Copy link
Contributor Author

yes, I still would like to have this PR merged. Though its hard to find time to work on this lately... I will give my best.

@haukepetersen haukepetersen added the State: don't stale State: Tell state-bot to ignore this issue label Aug 12, 2019
@tcschmidt tcschmidt requested a review from kaspar030 April 1, 2020 01:11
@haukepetersen
Copy link
Contributor Author

closing in favor of #14304

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: don't stale State: Tell state-bot to ignore this issue State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants