Nios Community Wiki > ExampleDesigns > Nios II MPU Usage (without an OS)

Nios II MPU Usage (without an OS)

Table of contents
  1. 1. Introduction
  2. 2. Example Hardware

[WORK IN PROGRESS!]

Introduction

This example walks you through making use of the Nios II's MPU in a HAL-based (no OS) environment.  The MPU is used to detect 3 commonly seen issues when debugging embedded software and systems.  These are:

  • Stack overflow detection
  • NULL pointer detection
  • "Wild" pointer detection

Stack overflow detection is achieved by creating a small high priority exclusion data region in the middle of a larger data region where both the stack and the heap reside.  Whenever the stack grows downwards or the heap grows upwards into this exclusion region, an exception is triggered and the software detects it.

NULL pointer detection is achieved by making sure that no regions include offset 0x0.  The example system is purposely designed such that no components (memory or otherwise) are located at this offset.  Whenever uninitialized data is accessed, this NULL pointer detection scheme triggers an exception and software is able to detect it.

"Wild" pointer detection is achieved by creating very large low priority exclusion regions covering the majority of the memory map.  In this way, if an instruction execution or data access outside of valid memory or peripheral I/O happens, the MPU triggers an exception and software can detect it.

Example Hardware

The example design is currently only for Nios II Embedded Evaluation Kits (NEEKs), but only uses onchip resources and can, therefore be easily ported to other development kits or your own board.

MPU_System (1).png

 


Tag page

Files 2

FileSizeDateAttached by 
 MPU_Designs.zip
Design examples for both "limit" and "mask" mode for region size determination.
218.66 kB20:01, 18 Aug 2009brankinActions
MPU_Usage.pdf
Updated to include instructions on how to properly disable MPU regions.
242.01 kB20:31, 18 Aug 2009brankinActions
Viewing 4 of 4 comments: view all
Ce tool est génial : léger, rapide simple efficace, avec toutes les options nécessaires et rien de superflu ! Pour tout dire, il ne m'a jamais quitté depuis que je le connais (10 ans?), même depuis quelques années que je suis sous xp64 puisque je le lançais manuellement pour faire certaines copies. graduate diploma | online masters degree | online business management degree
Posted 15:06, 11 Mar 2010
Problems with antiviruses and accounts without administrator rights should also be addressed. Consequently support of copies interception under Windows 95, 98 and Millennium will very likely disappear. computer science degree | CorllinsUniversity
Posted 15:06, 11 Mar 2010
Fyi the example system is purposely designed such that no components (memory or otherwise) are located at this offset. Matthew @ best muscle building supplements site.
Posted 15:35, 11 Mar 2010
Hello, I took the MPU usage example above as starting point for using the MPU. I adapted it to my hardware (DE1 board), using the 512K off chip SRAM and a 16K onchip ram in place of the instr_ram and stack_ram of the original example. I ran the test program and obtained the PASSED messages, everything's fine till now. After running this test I tried some modifications to the example code and problems started. I modified the program in the following way: after the original tests I disable the MPU (calling nios2_mpu_disable) and after this I repeat the tests (I enclose the modified code below). When running this code the first test after disabling the MPU fails as expected, but after this the program seems to restart, entering in an endless loop (a transcription of the nios console output is enclosed below). What's wrong? jpa ########## modified code // ... original test_null_data and test_wild_pointer calls // inserted code begin nios2_mpu_disable(); test_null_data( exc_info ); test_wild_pointer( exc_info ); // end of inserted code alt_putstr( "=====\n" ); alt_putstr( "\tException Tests ended.\n" ); alt_printf( "Now exiting program.\n%c", EOT ); ########## nios console output Hello from a simple MPU-Enabled Nios II System!. Starting some exceptions tests. ===== MPU NULL data pointer test. ...PASSED! MPU wild pointer test. ...PASSED! <<<<- after this line I disable MPU MPU NULL data pointer test. FAIL Hello from a simple MPU-Enabled Nios II System!. <<<<- UNEXPECTED RESTART, ENDLESS LOOP Starting some exceptions tests. ===== MPU NULL data pointer test. ...PASSED! .......
Posted 16:01, 11 Mar 2010
Viewing 4 of 4 comments: view all
You must login to post a comment.
SourceForge.net