To use mbed or not to use?

30 Jun 2014

A big hello to everybody

I'm just about to implement a software platform for the new CPU family (STM32) which we are going to use in my company and so just got across mbed. The descriptions seem very promising as well as a short look into the structures. Yet….. After having some 'hello world' stuff working pretty quick on my Hardware, I made a first step into importing a project into our environment. For that chose a Hello World using ADC. Now I've spent so much time fetching bugs out of the library code and trying to understand what the undocumented part of the code does that I have now my doubts about using mbed as such is the right way. So this was just one piece of code I checked. But I wonder if the code that has been placed on the mbed Platform has ever really been tested (the part I got surely was not). Can anyone here share his or hers experience in order to make me more confident about using mbed (or make me think that it would be wiser to wait)?

30 Jun 2014

Hi,

What library did you use (and found bugs in)? Is it the mbed.lib or a user supplied one?

regards Wim

30 Jun 2014

Hello Wim

I downloaded the Nucleo_Printf example for the Keil Environment 6 days ago mbed Revision 78:ed8466a608b4 But then I also used code from the Nucleo_read_analog_value example. The bug is from the adc part.

Regards

Nico

30 Jun 2014

Hi

I'm still using the original lpc1768 (before they expanded to more platforms) and did not find that many bugs (the one most striking where the spikes, they seemed to be silicon/design).

I also use the online platform to compile (or the free LCPXpresso). I noticed that the compilers are different and cause other warnings and generated code. I have no experience with Keil on arm.

Btw can you give some example of the bugs you found?

regards Wim

30 Jun 2014

Hi Wim

The one think that makes me think the code was never really tested is the omission of assigning AdcHanle.Instance a valid pointer before using it. See file 'analogin_api.c' function 'analogin_init()'. It calls function 'HAL_ADC_Init()' which then uses the .Instance pointer without that ever being initialised.

Regards

Nico

30 Jun 2014

@Nico,

can you be more specific? What target and which bugs did you find ? All mbed official libraries have bug issue tracker where you can create a bug report. I personally want to know more about those bugs.

If you look at the workspace tools at github mbed repository, you will find there tests scripts which a user can run on supported platforms. Sources for tests are located inside mbed/libraries folder. They test basic functionality, coverage currently is not ideal, but progress ongoing.

If you have any questions, don't hesitate to ask.

Regards,
0xc0170

30 Jun 2014

@Nico, I haven't seen a reply above... Here's an implementation from mbed HAL for 401RE platform:

void analogin_init(analogin_t *obj, PinName pin) {
    // Get the peripheral name from the pin and assign it to the object
    obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
    MBED_ASSERT(obj->adc != (ADCName)NC);

    // Configure GPIO
    pinmap_pinout(pin, PinMap_ADC);

    // Save pin number for the read function
    obj->pin = pin;

    // The ADC initialization is done once
    if (adc_inited == 0) {
        adc_inited = 1;

        // Enable ADC clock
        __ADC1_CLK_ENABLE();

        // Configure ADC
        AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
        AdcHandle.Init.ClockPrescaler        = ADC_CLOCKPRESCALER_PCLK_DIV2;
        AdcHandle.Init.Resolution            = ADC_RESOLUTION12b;
        AdcHandle.Init.ScanConvMode          = DISABLE;
        AdcHandle.Init.ContinuousConvMode    = DISABLE;
        AdcHandle.Init.DiscontinuousConvMode = DISABLE;
        AdcHandle.Init.NbrOfDiscConversion   = 0;
        AdcHandle.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE;
        AdcHandle.Init.ExternalTrigConv      = ADC_EXTERNALTRIGCONV_T1_CC1;
        AdcHandle.Init.DataAlign             = ADC_DATAALIGN_RIGHT;
        AdcHandle.Init.NbrOfConversion       = 1;
        AdcHandle.Init.DMAContinuousRequests = DISABLE;
        AdcHandle.Init.EOCSelection          = DISABLE;
        HAL_ADC_Init(&AdcHandle);
    }
}

Instance pointer is initialized, if not MBED_ASSERT should be triggered.

One side note, mbed ports are done by community, mbed team or mbed partners. As an example, the most of nucleo boards were ported ST.

30 Jun 2014

Mbed revision 78 is over 4 months old. It is 4 days younger than mbed revision 77, in which the Nucleo targets were added (I assume you got one of those?). Since 78 didn't change anything for those, it is essentially the first revision of the lib with Nucleo targets. And to be fair, although I didn't use it myself but from what I saw here, the first revision was pretty bad. Better not look up the clock speed your device is running at, it will make you sad ;).

However the good news, we are currently at revision 85, and again just from what I see passing by on the site, it seems to be fairly mature currently. Sure it can happen that for example there is a typo in a pinout, so not the correct ADC channel is used with a certain pin, but really something like AnalogIn should function fine now. Easy way to get it is opening a project in the online compiler, updating the mbed lib (click on it, right side is update button if you don't have latest version), and exporting it to whatever offline compiler you want to use.

By the way which target are you using? I checked in the F401 code, simply because that one is the most popular, and I don't see what you describe at the older revision:

AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);

Which was previously defined as:

obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
30 Jun 2014

@Erik +1 for revision, I completely overlooked he was referring to 78.

Please always use the newest revision, mainly for new boards which gets update more regularly than olders. Thanks.

30 Jun 2014

The mbed lib is at revision 85. If you're working offline you should be able to update by running hg update (-C if you made changes) from the command line at the mbed directory in your program. Prerequisite: need mercurial installed on your PC.

30 Jun 2014

Hello everybody

Well, one good thing about mbed are the quick responses here :)

Well I used the said version, because it was the one that was current when I started with my tests.

Then: No MBED_ASSERT will only trigger if 'obj_adc' is not initialised.

What is missing (also in the sample provided by Martin is the assignment of that to .Instance.

My code started to work when I added following line to 'analogin_init()' AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);

(There was something else too that needed correction, but that will maybe be another post)

Cheers

Nico (leaving now the office for the day)

30 Jun 2014

You started months ago with your tests? Because it really is an old version. In general it makes sense to verify you still got a recent version, and if newer versions solve bugs you might have problems with.

In Martin's example the line you are missing is already present at line 20. It is virtually impossible something like AnalogIn would have such a global error (ie: not relevant for only a single pin), since it would have been noticed long ago by users. Not saying there aren't bugs left, I can pretty much assure you there are somewhere still bugs hiding, but they can't be that large.

01 Jul 2014

Thanks Erik

Obviously something went wrong exporting the things for Keil. I downloaded everything 7 days ago, and I had started with the samples two, three days before that. So, no I did not do it months ago. And the line of code mentioned is really missing in the file that I downloaded.

Could it be that the 'error' is somewhere within the 'export' functionality?

Greetings

Nico

01 Jul 2014

Check mbed library revision if you are using the online IDE.. Update to the latest one.

01 Jul 2014

Which method did you use to export it? If you downloaded it directly from the site you will have the version used during which the example was made. While this has advantages (it should always stay working, even when libraries are modified), it does mean you won't have the latest version. If you use the online compiler to export the project you can first update all libs (It currently even asks when importing if you want to do so, although that might still only be for beta version users), but pressing right mouse button on for example the mbed lib, update. It would be really weird if a line randomly disapeared when exporting, which target are you currently using?

In the end if you want to use it as your default environment using offline compilers you probably want something which can for example pull new versions from the github, but thats a bit outside my area of expertise :).