Mikroelektronika MIKROE-724 データシート

ページ / 726
338
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Flash Memory Library
This library provides routines for accessing microcontroller’s (internal) Flash memory.
On the dsPIC30/33 and PIC24, Flash memory is mapped to address space 3:2, which means that every 3 consecutive 
bytes of Flash have 2 consecutive address locations available. That is why mikroE’s library allows data to be written to 
flash in two ways: “regular” and “compact”. In the “regular” mode, which is used for word(16-bit) variables, the 3rd (un-
addressable) flash memory byte remains unused. In the “compact” mode, which can be used for 1 byte-sized variables/
arrays, all flash bytes are being used.
All dsPIC30/33 and PIC24 MCUs use the RTSP module to perform Read/Erase/Write operations on Flash memory. 
This, together with the internal structure of the Flash, imposes certain rules to be followed when working with Flash 
memory:
dsPIC30: 
 
- Erasing can be done only in 32-instructions (64 addresses, 96 bytes) memory blocks. This means that the  
 
  block start address should be a multiply of 64 (i.e. have 6 lower bits set to zero). 
 
- Data is read and written in 4-instructions (8 addresses, 12 bytes) blocks.This means that the block start  
 
  address should be a multiply of 8 (i.e. have 3 lower bits set to zero). 
 
- On the dsPIC30s, 2 address locations are assigned on every 3 bytes of (flash) program memory. Due to  
 
  this specific and non-one-to-one address mapping, the mikroBasic PRO for dsPIC30/33 and PIC24 offers  
 
  two sets of Flash handling functions: “regular” and “compact”. 
 
  Using the “regular” set, the user can write one byte of data to a single address, which means that each  
 
  byte of written data has its own address, but on every 2 written bytes one byte of Flash memory remains  
 
  empty. 
 
  Using the “compact” set, every byte of Flash memory, including those non-addressable, is filled with data;  
 
  this method can only be used for data organized in bytes. 
 
  The “compact” functions have 
_Compact
 as name suffix. 
 
- For run-time FLASH read/write, the dsPIC30’s RTSP module is being used. It organizes data into rows  
 
  and panels. Each row contains write latches that can hold 4 instructions (12 bytes). The number of panels  
 
  varies from one dsPIC30 MCU model to another. Because of that, the flash write sequence has been split  
 
  into several operations (
_Write_Init(), _Write_LoadLatch4(), _Write_DoWrite()
), in order to  
 
  be usable on all dsPICs. 
PIC24 and dsPIC33: 
 
- Erasing can be done only in 512-instructions (1024 addresses, 1536 bytes) memory blocks, which means  
 
  that the block start address should be a multiply of 1024 (i.e. have 10 lower bits set to zero). 
 
- Data is read and written in 64-instructions (128 addresses, 192 bytes) blocks.This means that the block  
 
  start address should be a multiply of 128 (i.e. have 7 lower bits set to zero). 
 
- On the dsPIC33 and PIC24s, 2 address locations are assigned on every 3 bytes of (flash) program  
    
  memory. Due to this specific and non-one-to-one address mapping, the mikroBasic PRO for dsPIC30/33  
 
  and PIC24 offers two sets of Flash handling functions: “regular” and “compact”. 
 
  Using the “regular” set, the user can write one byte of data to a single address, which means that each  
 
  byte of written data has its own address, but on every 2 written bytes one byte of Flash memory remains  
 
  empty. 
 
  Using the “compact” set, every byte of Flash memory, including those non-addressable, is filled with data;  
 
  this method can only be used for data organized in bytes. 
 
  The “compact” functions have 
_Compact
 as name suffix.