Skip to content

How can dynamically sized Vec<T> be using on STM32? #335

Closed

Description

@johnthagen

Cross post from rust-lang/rfcs#2480 (comment)

When evaluating using Rust for an embedded project at work, not having dynamic containers was a big drawback at the time compared with C++11/14 where the gcc-arm-embedded toolchain had versions of std::string and std::vector<T>. (C++ has it's own set of drawbacks, like exception-based error handling APIs, but in this one, fundamental case, it had a leg up).

Is there a way (even it's nightly) to use Vec<T> on something like the STM32F3DISCOVERY? It was a hard sell to recommend Rust over C++ without being able to safely use the heap.

Edit: We used heapless in some tutorials but we wanted to have true heap access available like is available for C++11/14 and the gcc-arm-embedded toolchain.

Activity

  1. therealprof commented on Mar 19, 2019

    @therealprof
    Contributor
  2. changed the title [-]How can Vec<T> be using on STM32?[/-] [+]How can dynamically resizable Vec<T> be using on STM32?[/+] on Mar 19, 2019
  3. johnthagen commented on Mar 19, 2019

    @johnthagen
    ContributorAuthor

    @therealprof Thanks, yeah I had seen heapless and I changed the title to be more clear that we'd like to actually use the heap for true dynamically sized containers. heapless requires a fixed size up front.

  4. changed the title [-]How can dynamically resizable Vec<T> be using on STM32?[/-] [+]How can dynamically sized Vec<T> be using on STM32?[/+] on Mar 19, 2019
  5. therealprof commented on Mar 19, 2019

    @therealprof
    Contributor

    You can use alloc-cortex-m to create a heap and combine it with heapless.

  6. japaric commented on Mar 19, 2019

    @japaric
    Member
  7. japaric commented on Mar 19, 2019

    @japaric
    Member

    (you don't need to specifically use alloc-cortex-m; any global_allocator will do)

  8. johnthagen commented on Mar 19, 2019

    @johnthagen
    ContributorAuthor

    @japaric Is this mentioned in the Discovery Book? And if not, would you accept a PR to add it? I think this would be a really great addition!

  9. johnthagen commented on Mar 19, 2019

    @johnthagen
    ContributorAuthor

    (For anyone else finding this issue in the future, the embedded book has some discussion on this as well.)

  10. therealprof commented on Mar 19, 2019

    @therealprof
    Contributor

    I think this would be more appropriate for the book and/or the embeddonomicon with a reference in the discovery book. Any contributions in that directions would certainly be welcome.

  11. jamesmunns commented on Mar 19, 2019

    @jamesmunns
    Member

    I think we should also note (last time I checked) that alloc-cortex-m requires nightly rust to operate.

  12. johnthagen commented on Mar 19, 2019

    @johnthagen
    ContributorAuthor

    I think we should also note (last time I checked) that alloc-cortex-m requires nightly rust to operate.

    Correct, this RFC is currently being discussed to potentially stabilize alloc: rust-lang/rfcs#2480

  13. johnthagen commented on Apr 22, 2019

    @johnthagen
    ContributorAuthor

    alloc is on track to stabilize for Rust 1.36.0: rust-lang/rust#59675

  14. marcoieni commented on Jun 14, 2020

    @marcoieni

    So:

    • The answer to the question is to use the alloc crate.
    • This issue was opened in order to mention this fact in the discovery book.

    I think that no action is required here anymore and this issue could be closed.

  15. jonas-schievink commented on Jun 14, 2020

    @jonas-schievink
    Contributor

    Yup, closing then. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions