Memory management unit in pic32mz

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Jul 8, 2016.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi guys

    I was looking at a pic32mz today and noticed that they have a MMU, and you can add ram or flash through SQI or EBI module.

    This maybe a silly question, is that mean I can add extra memory on a pic with EBI/SQI, and my code can use those extra memory like native ram/flash?

    Say I have a pic32mz with 2MB flash and 512K ram, can I add a 2MB flash and write code up to 4MB? Or add another 512K ram and my code can use up to 1MB ram?

    Thanks guys
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,166
    The Memory Organization section of the FRM says "External serial and or parallel memory can be mapped into virtual memory space for data access or code execution using the Serial Quad Interface (SQI) or External Bus Interface (EBI)".

    So yes, but not exactly in a linear address space. EBI/SQI memory will be mapped into KSEG2/3 by the linker. Expect it to be slow.


    Section 3.3 MEMORY LAYOUT
    http://ww1.microchip.com/downloads/en/DeviceDoc/60001115H.pdf
     
  3. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    After I set it up properly, do I use those extra memory like native memory in a pic? Or do I need dedicated function to access those memory.

    Say I have a pic with EBI and MMU, and the pic have 1K ram and I added another 1K ram through EBI, and if I declare a variable like this:

    uint8_t dummy[1025];

    Will the pic use all 1k ram plus 1byte on the addition ram?

    Thanks
     
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,166
    http://ww1.microchip.com/downloads/en/DeviceDoc/61192A.pdf 50.17

    The MMU can map the external physical address to the processors virtual address space that can be used like native memory but that's something normally used with a OS instead of an embedded program because of the paging overhead.

    Some MZ defaults for a OS kernel/user address space configuration.
    https://github.com/sergev/LiteBSD/wiki/PIC32MZ memory map
     
  5. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    This EBI thing is very new to me, and those docs you linked in look like a foreign language for me, so please bear with me. (I did googled a tutorial or some sort, but come up with nothing so far)

    I am more interested in an embedded program (for now). Will the xc32 compiler handle this process automatically? For my personal experience with xc8, if I use more ram than the target pic, the xc8 will throw an error.

    Thanks
     
  6. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,166
    The 1.42-full-release-notes has this.

    Application-Defined Memory Regions -- This new feature allows you to add a new memory region to your application in C/C++ source code using a new region pragma. You can then allocate variables and functions to your region by using the new region attribute.

    • #pragma region name=name origin=address size=bytes
      Define an application-defined memory region, with the origin and the size in bytes using the region pragma. The argument name is a quoted string containing the name of the region, address is the starting address of the region, and bytes is the size in bytes of the region.
      Example:
      #pragma region name="ext_mem" origin=0xC0000000 size=0x1000

    • __attribute__((region("region_name")))
      Allocate the variable or function in the previously defined region. The region must be previously defined with the region pragma.
      Example:
      int ext_array[256] __attribute__((region("ext_mem")));
      signed int ea1 __attribute__((region("ext_mem")));
      unsigned int ea2 __attribute__((region("ext_mem")));

    • void _on_reset(void)
      The default runtime start-up code provides an _on_reset() weak hook. This routine is called after initializing a minimum 'C' context but before data initialization. You can provide your memory-interface configuration code in this hook. This allows you to ensure that your memory interface is properly initialized before the startup code attempts to initialize your variables.
      Example:
      /* The _on_reset() function will be called by the default
      runtime start-up code prior to data initialization. */
      void _on_reset (void)
      {
      /* Call a function that configures the EBI control
      registers for the target board. */
      configure_ebi_sram();
      }
      ...
    • Device-specific startup code -- The C/C++ runtime startup code is now device specific. The xc32-gcc and xc32-g++ compilation drivers will select the appropriate startup code when linking using the -mprocessor=deviceoption.
      • The startup code initializes the L1 cache when available.
      • It enables the DSPr2 engine when available.
      • It also initializes the Translation Lookaside Buffer (TLB) of the Memory Management Unit (MMU) for the External Bus Interface (EBI) or Serial Quad Interface (SQI) when available. The device-specific linker script creates a table of TLB initialization values that the startup code then uses to initialize the TLB at startup.
    • ...
    • XC32-447
      The default linker scripts and startup code for the PIC32MZ devices now create 16-MB pages for the SQI and EBI memory ranges in the TLB. Previously, the code incorrectly created 32-MB pages.

    These default mappings correspond to the memory map in the data sheet.
     
    JohnInTX likes this.
  7. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi nsaspook

    Thank you for all your help, I am still not sure, but your replies help me to start to get some basic idea around this. I think I will have something fundamental that I need to learn first before I can get a better understand of this. (Although my OP question is answered, yes I can use those memory like they are native memory)

    Also, do you have first hand experience with pic32mz? Form my googling, there are people in Microchip forum complaining the chip is not yer ready and the support form Harmony is buggy. But those post are from 2014 and 2015, maybe Microchip has fixed this by now??

    Thanks
     
  8. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,166
    I've only looked at the improved specs for the MZ. All my current PIC32 projects use the MX. After all the bugs in the original MZEC stepping I decided to wait for the EF (out now) and later versions before playing with MZ hardware so maybe it's time to play.

    Harmony is another can of worms but it's getting better.
     
    JohnInTX likes this.
  9. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    It sounds like I should avoid this for now, do you usually use PIC32 with RTOS, Linux or no OS? How's the pic32MX working with harmony? Is that any good? I usually just use pic18f, but recently I want to learn about embedded https server. That leads me to look into this pic32.

    I saw the marking demo on the pic32mz, it show how easy to make a embedded https server. But from what you said and other people on the Microchip forum, this pic32mz is still buggy and this harmony is not delivering what it should be delivering.

    I like the concept of Harmony tho.
     
  10. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,166
    The latest versions of the MZ (EF version) are fine so if I were just starting that would be my choice. I don't use Harmony as you can still get the old PLIB and applications library code (with no OS) to run on the MX easily.
     
  11. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    That's good to know, I thought Microchip stop supporting the PLIB in the new complier, so I can still find the PLIB and add to my project and use it like before? Anyway I will try, it's good to know.
     
Loading...