Skip to content

How to extend basic functionality of the MBED API? #2181

Closed
@hesolium

Description

@hesolium

I need to generate a signal (PWM) with high frequency. The minimum (standard) period for PWM is 1 uS. How to modify the API to obtain a shorter period?
My board (Nucleo-F401/84 MHz) has the ability to generate a PWM with shorter periods.
Of course, I do not want to program the device (STM32 TIMx)) from the beginning.
I think a better solution would be a slight modification behaviour of the existing API.

For this purpose, I have modified HAL for STMF4 (pwmout_api.c) as follows:

  1. I added and exposed additional variable 'short TIMadditionalPrescaler'
  2. I added 3 lines in ''pwmout_period_us' function for conditionally increase the standard (1000000) prescaler for 1 uS period.
    In my application before call method 'period_us' I can set suitable value for TIMadditionalPrescaler.
    For example if I need 250 ns PWM period I can set my additional prescaler to 4.

In a similar (easy:) way, we can expand behavior AnalogIn class to add the ability to trigger the measurement via an external GPIO pin.

Now it's time for a general question.

How should we design an MBED API that such minor changes will be possible for the implementation for specific targets? Maybe definitions of each (PMW,AnalogIn, ...) class should contain some elements that enable smooth and easy implementation of additional functionality specific for some target boards. How it should be done from a theoretical point of view?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions