Skip to content

Improve management handling of multiple instances of analogin ojects #4623

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

Merged
merged 5 commits into from
Jul 31, 2017

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented Jun 23, 2017

Description

Few reports has raised issue related to multiple instances of analogin objects:
https://developer.mbed.org/questions/67841/Multiple-analogIn-not-working/

This PR solves the issue by replacing usage of a single global variable to store the adc handle by a new handle members in the analogin_s object.

Status

READY

Tests

CI shield tests PASSED OK. (no regression found)

image

@theotherjimmy
Copy link
Contributor

@LMESTM Does this also reduce the amount of static RAM allocated when an AnalogIn object is not constructed? Does it increase the size of an AnalogIn object?

@theotherjimmy
Copy link
Contributor

@LMESTM It looks like Travis CI failed.
The error is reproduced below:

In file included from /home/travis/build/ARMmbed/mbed-os/BUILD/mbed/TARGET_DISCO_F413ZH/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/objects.h:63:0,

                 from /home/travis/build/ARMmbed/mbed-os/BUILD/mbed/TARGET_DISCO_F413ZH/TARGET_STM/TARGET_STM32F4/device.h:38,

                 from /home/travis/build/ARMmbed/mbed-os/BUILD/mbed/hal/analogin_api.h:22,

                 from /home/travis/build/ARMmbed/mbed-os/targets/TARGET_STM/TARGET_STM32F4/analogin_api.c:29:

/home/travis/build/ARMmbed/mbed-os/BUILD/mbed/TARGET_DISCO_F413ZH/TARGET_STM/TARGET_STM32F4/common_objects.h:113:8: error: redefinition of 'struct analogin_s'

 struct analogin_s {

        ^

In file included from /home/travis/build/ARMmbed/mbed-os/BUILD/mbed/TARGET_DISCO_F413ZH/TARGET_STM/TARGET_STM32F4/device.h:38:0,

                 from /home/travis/build/ARMmbed/mbed-os/BUILD/mbed/hal/analogin_api.h:22,

                 from /home/travis/build/ARMmbed/mbed-os/targets/TARGET_STM/TARGET_STM32F4/analogin_api.c:29:

/home/travis/build/ARMmbed/mbed-os/BUILD/mbed/TARGET_DISCO_F413ZH/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/objects.h:43:8: note: originally defined here

 struct analogin_s {

Please fix this compile error.

@LMESTM
Copy link
Contributor Author

LMESTM commented Jun 26, 2017

@LMESTM Does this also reduce the amount of static RAM allocated when an AnalogIn object is not constructed? Does it increase the size of an AnalogIn object?

Yes and yes as a direct consequence of moving from global to object

@LMESTM
Copy link
Contributor Author

LMESTM commented Jun 26, 2017

Will check the build failure and update RP

@LMESTM LMESTM force-pushed the analogin_handle branch from aa8d35e to 2c7eef1 Compare June 26, 2017 09:07
@LMESTM
Copy link
Contributor Author

LMESTM commented Jun 26, 2017

@theotherjimmy - error reproduced after rebase, then fixed. should be fine now

@theotherjimmy
Copy link
Contributor

@LMESTM Thanks for getting on that!

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 29, 2017

retest uvisor

@theotherjimmy
Copy link
Contributor

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 3, 2017

@LMESTM Can you please look at the conflicts?

@LMESTM LMESTM force-pushed the analogin_handle branch from 2c7eef1 to c529ecb Compare July 3, 2017 11:51
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 3, 2017

@0xc0170 rebased and conflicts solved

@LMESTM LMESTM force-pushed the analogin_handle branch from c529ecb to 32f5184 Compare July 4, 2017 13:31
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 4, 2017

I made a conflict resolution error during last rebase - solved now

@studavekar
Copy link
Contributor

/morph test

@mbed-bot
Copy link

mbed-bot commented Jul 5, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 736

Test failed!

@ohagendorf
Copy link
Contributor

Maybe a minor thing was overseen in targets/TARGET_STM/TARGET_STM32F2/objects.h

struct analogin_s {
  ADCName adc;
  ADC_HandleTypeDef handle;
  PinName pin;
  uint8_t channel;
 };

In comparison to all other familiies is contains the line:

ADCName adc;

@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 6, 2017

@ohagendorf good catch - will post update

@theotherjimmy
Copy link
Contributor

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

@LMESTM LMESTM force-pushed the analogin_handle branch from c5a5868 to 87c1b79 Compare July 11, 2017 06:50
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 11, 2017

Rebased - so conflicts resolved

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 11, 2017

/morph test

LMESTM added 3 commits July 17, 2017 13:23
In this commit, the analogin_s structure is moved to commonn_objects.h file
to limit the duplicaion.

The ADC handle is moved from a global variable to a struct member of the
analogin object. This allows multiple ADC instances to work correctly.

Note that State needs to be explicitely set to HAL_ADC_STATE_RESET
because the object is not zero initialized.
The adc in analogin_t has the same value as the Instance member of
ADC_HandleTypeDef. So we can only rely on the later one.
Same as other families applied here
@LMESTM LMESTM force-pushed the analogin_handle branch from 87c1b79 to ea33f8b Compare July 17, 2017 11:28
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 17, 2017

@0xc0170 There were conflicts due to another merged PR - rebased and conflicts solved

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 17, 2017

@LMESTM thanks, please look at travis failure

/home/travis/build/ARMmbed/mbed-os/targets/TARGET_STM/TARGET_STM32L0/analogin_api.c:44:8: error: 'analogin_t' has no member named 'adc'
     obj->adc = (ADCName)NC;

@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 17, 2017

@0xc0170 oops - this was also introduced by the conflicting PR and I missed it during rebase. I was too confident ... compiles fine now.

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 17, 2017

Still fails for Travis?

@LMESTM LMESTM force-pushed the analogin_handle branch from a7e435d to b9d801f Compare July 17, 2017 14:29
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 17, 2017

good job travis !

// Get the functions (adc channel) from the pin and assign it to the object
function = pinmap_function(pin, PinMap_ADC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);
} else {
// Internal channels
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC_Internal);
obj->handle.Instance = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry Laurent,
This should be PinMap_ADC_Internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

// Get the functions (adc channel) from the pin and assign it to the object
function = pinmap_function(pin, PinMap_ADC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);
} else {
// Internal channels
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC_Internal);
obj->handle.Instance = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, this should be PinMap_ADC_Internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

// Get the functions (adc channel) from the pin and assign it to the object
function = pinmap_function(pin, PinMap_ADC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);
} else {
// Internal channels
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC_Internal);
obj->handle.Instance = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, PinMap_ADC_Internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

function = pinmap_function(pin, PinMap_ADC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);
} else {
// Internal channels
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC_Internal);
obj->handle.Instance = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same, PinMap_ADC_Internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

The instance needs to be searched in PinMap_ADC_Internal, not PinMap_ADC.
This was a copy paste error...
@LMESTM
Copy link
Contributor Author

LMESTM commented Jul 20, 2017

@jeromecoutant Thanks !
Too many errors in this PR, about time to take a summer break ;-) !

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 21, 2017

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 861

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 24, 2017

@jeromecoutant happy with the update?

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 31, 2017

@jeromecoutant happy with the update?

@LMESTM @jeromecoutant - we assume yes, as no voice against this changeset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants