Skip to content

extmod/modopenamp: Add support for building Open-AMP on device side. #15450

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

Closed

Conversation

iabdalkader
Copy link
Contributor

@iabdalkader iabdalkader commented Jul 11, 2024

Adds support for building Open-AMP in device mode, in addition to a couple of misc fixes. This was tested with two VMs each running on a different core. To build for device:

make -j<n> BOARD=my_board CORE=M4 MICROPY_PY_OPENAMP_DEVICE=1

Of course, whichever port you use, it must support building for a second core. For example, the main core will initialize USB, but the second one will not and so on.

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.43%. Comparing base (55b2720) to head (2813f18).
Report is 51 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15450   +/-   ##
=======================================
  Coverage   98.43%   98.43%           
=======================================
  Files         161      161           
  Lines       21281    21281           
=======================================
  Hits        20948    20948           
  Misses        333      333           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Jul 11, 2024
@iabdalkader iabdalkader force-pushed the openamp_build_fixes branch 2 times, most recently from 9d2a57c to 5b73e04 Compare July 17, 2024 13:31
@@ -411,6 +422,6 @@ const mp_obj_module_t openamp_module = {
};

MP_REGISTER_ROOT_POINTER(struct _virtio_dev_obj_t *virtio_device);
MP_REGISTER_MODULE(MP_QSTR_openamp, openamp_module);
MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_openamp, openamp_module);
Copy link
Member

Choose a reason for hiding this comment

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

Why do you want to make this module extensible? In general, this feature is only used to support CPython modules that we don't fully support in C, so they can be extended in Python.

For the openamp module we define it ourselves, so there's nothing missing that needs adding.

Copy link
Contributor Author

@iabdalkader iabdalkader Jul 20, 2024

Choose a reason for hiding this comment

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

I extend in Python to add utils and classes that can be accessed with openamp.x. For example I have an EndpointIO class which is a subclass of IOBase that you can use for dupterm. Note that there's an openamp.Endpoint in the C-module, so openamp.EndpointIO belongs there too but as an extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm I guess my EndpointIO class would not be needed if #14181 is merged but I still have other extensions.

Copy link
Member

Choose a reason for hiding this comment

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

Note that there's an openamp.Endpoint in the C-module, so openamp.EndpointIO belongs there too but as an extension.

I don't think it's a good idea to add things to this module outside this repo. We should fully define the openamp module here, and have the docs here. Any extensions that work with openamp but are outside this repo (which would be third-party extensions, relative to this repo) should be placed in a separate module, eg openamp_ext, with separate docs. Otherwise it will get confusing what functions/classes are available in this module.

Eventually we want to get rid of this extensible module stuff (it's a backwards compatible way to support the old u-module naming scheme), so I don't want to add more modules that use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually we want to get rid of this extensible module stuff (it's a backwards compatible way to support the old u-module naming scheme), so I don't want to add more modules that use this.

Whoa that will be a very breaking change. We heavily depend on extending modules for adding missing functionality or for portability. For example, we extend machine to add an LED that's used throughout or examples. We'll also extend it to mask missing machine.PWM for stm32 port. Can this feature be kept for such uses cases ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's important additional C functionality then it should be added in this repo, with docs, so it's available on all ports. Or if that functionality is best implemented in Python, and it makes more sense to have it in openamp rather than a separate module, then it should go in micropython-lib and then, yes, the module would be extensible

I think this is all subjective. For example, I think we can all? agree that something like EndpointIO is useful to have, whether it's an extension or native (as implemented in #14181). However, the rest of the extensions, which BTW are Not yet ready for sharing, may or may not be welcome by the maintainers. However we'd still like to have them as an extension as they [in my opinion] logically belong to the same module, and as an extension we won't have to maintain or document a new module, and the users won't have to learn about a new module.

The point is, it's hard to agree on what's useful and what's not and what should be C or extension. The maintainers are of course free to decide on that, but I think they should not block others from extending the module if they want to, to best fit their needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is all subjective

This is a tricky topic for sure, but I suggest the measurable aspect of what Damien is talking about is consistency. The extension mechanism is used to ensure consistency between MicroPython and CPython (i.e. extending os with os.path), or between different MP ports (i.e. extending machine.Pin to the unix port). In both cases there are docs for those modules already, and the extensions mechanism keeps the implementation (and therefore user experience) as consistent with those docs as possible.

However, the rest of the extensions, which BTW are Not yet ready for sharing, may or may not be welcome by the maintainers.

Either way, I think the preferred path for MicroPython and user experience would be to have a separate module here:

  • If the additional Python-based functionality gets merged to micropython-lib, then this sounds like it fits well with the common pattern Damien already mentioned of bluetooth/aioble, machine.USBDevice/usb-device, etc.
  • If the additional Python functionality is not merged to micropython-lib, then using the same module name would cause the MicroPython docs for the openamp module to be inconsistent with the docs for the external extended openamp module. Using a different name removes the ambiguity and improves the user experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the additional Python functionality is not merged to micropython-lib, then using the same module name would cause the MicroPython docs for the openamp module to be inconsistent with the docs

But what if we don't want to push our extensions to micropython-lib even if they are in line with the upstream policy and will be merged ? Maybe we'd want to maintain them privately, or push them somewhere else, like arduino-lib and then we could also maintain our own docs for the module.
The reason for sending work like this upstream, in addition to contributing something useful, is to Not have fork and maintain it ourselves, but if we still have to fork and change the code that we ourselves put upstream just to be able to extend it, then what's the point of pushing it upstream in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that you can drop the extensible commit (it's in its own commit) if you don't want it, if this is ready to be merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

then we could also maintain our own docs for the module.

It's of course your choice if you want to do that. I'd note that if there are two modules called openamp with different functions in them, and different docs for that module in two places, then this can easily lead to a bad user experience. i.e. Finding the docs for openamp (even openamp docs for the matching MP version) won't necessarily find the correct docs, because there will be two different implementations with the same name.

Sometimes that's unavoidable because of external constraints (and the history of MP has plenty of confusing incidents arising from those unavoidable name clashes). In this case it seems like it is avoidable, by giving different modules different names. Maybe I don't understand the use case here, though.

Note that you can drop the extensible commit (it's in its own commit) if you don't want it, if this is ready to be merged.

👍

@iabdalkader
Copy link
Contributor Author

iabdalkader commented Jul 20, 2024

I pushed one more commit for stm32 to define the last used MPU region number. This macro allows custom/outside code to find a free MPU region to use. For example you can start at the max (H7 that's 15) loop down to the MPU_REGION_LAST or start from MPU_REGION_LAST+1 knowing that it will not clash with regions used by MicroPython. Note that there are no more free regions on F7, but I guess that's fine because it doesn't use Open-AMP.

@iabdalkader iabdalkader force-pushed the openamp_build_fixes branch from 9b54be6 to c04e875 Compare July 20, 2024 07:54
@iabdalkader iabdalkader force-pushed the openamp_build_fixes branch 3 times, most recently from 21d10af to f1ec7cf Compare August 1, 2024 14:30
This causes multiple definition of symbols on some builds.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Tested with two VMs each running on a different core.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
The callback arg is not actually required.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
The reason for this change is that it makes allows custom code,
that needs to use an MPU region, to find a free one by using
this macro or starting from the max number and downwards, without
concern that it might change in the future.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
@iabdalkader iabdalkader force-pushed the openamp_build_fixes branch from f1ec7cf to 2813f18 Compare August 7, 2024 15:42
@dpgeorge
Copy link
Member

dpgeorge commented Aug 8, 2024

Thanks for updating. I've now merged this in 1216f2c through 91f4a6b, all commits here in this PR except the commit that makes the openamp module extensible. That needs further discussion.

@iabdalkader iabdalkader deleted the openamp_build_fixes branch August 24, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants