Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: how can i program the processor memory management in teensy 3.5?

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    14

    how can i program the processor memory management in teensy 3.5?

    Hi all,

    I need to know how can i program the processor memory management in cortex m4 of this teensy 3.5?
    My main target is understand in a deep complete basis how cortex m4 works and what are the main and most important features.

    I made some research but i am a little confuse because there are not so much information to do that in these device.

    May be if i can get a deeper understanding of what are the layer beetween hardware and arduino base interface in teensy infrastructure, i'll be able to modify memory managment in this core processor.

    Please, if anyone could help me and give me at least a first steps to go into this amazing world, it would be amazing.

    Thank you in advance

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    All information is in the reference manual.

    But more important: WHY? and WHAT do you want to change? It would help to know that, and maybe we can help, then.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,985
    Quote Originally Posted by Spartan_001 View Post
    My main target is understand in a deep complete basis how cortex m4 works and what are the main and most important features.
    To learn everything in such detail is a huge undertaking. It could reasonably be expected to take years to cover it all in a "deep complete basis".

    So with that in mind, you could think of learning probably 6 broad categories.

    1: ARM hardware - get the "Definitive Guide" book by Joseph Yiu: https://www.amazon.com/dp/0124080820

    2: NXP hardware - the reference manual covers all the non-ARM hardware on the chip. https://www.pjrc.com/teensy/datasheets.html

    3: Communication protocols - some of the peripherals implement very complex protocols, like USB, which have their own documentation you need to read to really learn at a "deep complete basis".

    4: Toolchain - the software is all compiled by gcc. While gcc has tons of documentation, you probably only need to focus on reading about the linker and how linker scripts work.

    5: Teensyduino / Arduino abstraction layer - We mainly target Arduino's abstraction layer. The functions are documented on Arduino's website and elsewhere. They also have some documents on their github wiki about 3rd party hardware integration which explain how the Arduino IDE and toolchain work. Teensy has some moderate extensions, which you'll find some documented on the website, but to dive into how things really works can only be done by studying the source code.

    6: Libraries - the Teensyduino installer delivers about 90 libraries, and thousands more exist in the Arduino ecosystem. But a few key libraries like Wire and SPI are the basis for so many others. Understanding those protocols and the libraries & hardware which implement them at a deep level usually isn't necessary, as the whole point of the library is to let you use these protocols without diving deep into those details. But if you want everything on a "deep complete basis", those should be considered as important as the core library which provides most of the Arduino abstraction layer.

  4. #4
    Junior Member
    Join Date
    May 2018
    Posts
    14
    Thank you very much for your help.
    I will count this as a beginning on my journey.

    I want to clarify one more thing related to the core processor of this chip.
    There are any way to program the memory management in the chip of teenst 3.5 that is the chip i have?

    moreover, there are another way to program this chip with the objective to program at c language?
    I don't want to program in pseudo-C

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    First of all, you should think about what you actually mean by "memory management".
    Since you obviously know C, you know that there is at most new/malloc/free - and there is the stack, variables and pointers, RAM and Flash, etc.
    There is no "memory management". Microcontrollers don't have that.
    "Memory management is done by an operating system - but on microcontrollers there is no operating system in general. At least none which would be comparable with the one of the PC. With Arduino itself there is none. Arduino is not one either.
    The chip has also nothing what one could program there.
    There is a "Memory Protection Unit" - that would be something that comes closest to it - but has no real similarity
    So I assume you want to manage the memory of your C programs "somehow". For that there is the linker and the above mentioned techniques.
    By the way, the GCC compiler is used... the developers wouldn't be very happy if you called it a "pseudo C compiler" :-)
    Almost everything is compiled with GCC. The program that runs on your washing machine, your internet router, the TV, and if you use Linux you have almost inevitably run into this compiler.
    No, Arduino is regular C / C++, with a big runtime library (the "core") other libraries (as Paul calls it "abstraction layer" - which is totally right, too) and an admittedly strange build technology. (if you really want you can also use make files - but I wouldn't start with that).
    So, in sum - I can't tell you how you can program the "Memory Management". There is none. The instance that manages all that is you!

    It would still be helpful to know what you actually want to do, so we can help.

    Some documents:
    https://www.pjrc.com/teensy/K64P144M120SF5RM.pdf - the chip on the Teensy 3.5
    https://developer.arm.com/documentat.../0001/Preface- Arm Cortex M4+ Technical Manual
    https://static.docs.arm.com/ddi0403/...armv7m_arm.pdf Architecture Manual

    But a better Ide is to learn the basics - and to learn Arduino at first and don't spend too much time with these documents, at first. You may need them later - much later.
    Last edited by Frank B; 02-24-2021 at 06:08 PM.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,985
    I might be reading too much into your question, but it sure sounds like you have a misunderstanding how of how programming Teensy really works.

    The "Arduino language" really is just C++ which very minor preprocessing. You can avoid the preprocessing by just adding extra files / tabs and name them with .cpp extension instead of .ino. You can also add .c files, which are treated as pure C. As is always done with mixing C and C++ language, to share anything between C & C++ you need to use "extern C".

    Really, it is just standard C++ and C, not "pseudo-C".

    Likewise, the code you write really is "bare metal" which full access to all hardware registers and all memory. Of course there is plenty of default library code (called the "core library") which gets compiled together with your program. All the source code is sitting in a folder inside the Arduino folder, so if you want to change anything at all about how memory is managed, just edit the code.

    But I want to emphasize, from a perspective of getting help from other people, the more you alter the normal startup code, and especially if you create your own custom linker scripts, your code will be running with very different properties than everyone else uses. That's perfectly ok. All the code is published, so you can modify it any way you like. Just know that our ability to answer questions and help you resolve any problems become less the farther your environment diverges from the norm. You will need to resolve difficult technical issues yourself.

    From the nature of the questions you've asked so far, not even yet knowing the language really is C & C++, perhaps a wiser path might involve first using the system & memory layout as it is designed. Probably best to wait to make very low-level changes until you have learned much more.

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    You may have seen setup() and loop()
    Forget that.. they are just functions.

    its something like

    Code:
    void setup() { your code here }
    void loop() { your code here }
    
    void main() {
     setup();
      while (true) loop();
    }
    Then, you may have seen obscure things like "digitalWrite"... its just a ordinary C-library function, too:
    Code:
    void digitalWrite(uint8_t pin, uint8_t val)
    {
        if (pin >= CORE_NUM_DIGITAL) return;
        if (*portModeRegister(pin) & digitalPinToBitMask(pin)) {
            if (val) {
                *portSetRegister(pin) = digitalPinToBitMask(pin);
            } else {
                *portClearRegister(pin) = digitalPinToBitMask(pin);
            }
    
        } else {
            volatile uint32_t *config = portConfigRegister(pin);
            if (val) {
                *config |= (PORT_PCR_PE | PORT_PCR_PS);
            } else {
                *config &= ~(PORT_PCR_PE);
            }
        }
    
    }
    ... normal "C" (code above taken from the Teensy 3 core - cleaned up a little bit)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •