Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various changes relating to zprobe and non-volatile data
1. Z-probing is now done in two stages: a fast stage at the configured home feed rate until within 10% of the target value, then a slow stage at 20% of that feed rate. 2. Provisional support for ultrasonic Z-probe. 3. Added calibration temperature and height temperature coefficient to Z probe parameters. 4. Z-probe parameters and Z-probe type are now saved to flash memory so that they survive power-off and reset cycles. Separate parameters are retained for IR and ultrasonic probes in case both are fitted. 5. Fixed issue with doing slow Z-moves immediately after Z-homing or probing.
- Loading branch information
Showing
15 changed files
with
3,496 additions
and
1,520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "DueFlashStorage.h" | ||
|
||
void DueFlashStorage::init() { | ||
/* Initialize flash: 6 wait states for flash writing. */ | ||
uint32_t retCode = flash_init(FLASH_ACCESS_MODE_128, 6); | ||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Flash init failed\n"); | ||
} | ||
} | ||
|
||
byte DueFlashStorage::read(uint32_t address) { | ||
return FLASH_START[address]; | ||
} | ||
|
||
void DueFlashStorage::read(uint32_t address, void *data, uint32_t dataLength) { | ||
memcpy(data, FLASH_START+address, dataLength); | ||
} | ||
|
||
bool DueFlashStorage::write(uint32_t address, byte value) { | ||
uint32_t byteLength = 1; | ||
uint32_t retCode = flash_unlock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + byteLength - 1, 0, 0); | ||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Failed to unlock flash for write\n"); | ||
return false; | ||
} | ||
|
||
// write data | ||
retCode = flash_write((uint32_t)FLASH_START+address, &value, byteLength, 1); | ||
|
||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Flash write failed\n"); | ||
return false; | ||
} | ||
|
||
// Lock page | ||
retCode = flash_lock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + byteLength - 1, 0, 0); | ||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Failed to lock flash page\n"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool DueFlashStorage::write(uint32_t address, const void *data, uint32_t dataLength) { | ||
if ((uint32_t)FLASH_START+address < IFLASH1_ADDR) { | ||
_FLASH_DEBUG("Flash write address too low\n"); | ||
return false; | ||
} | ||
|
||
if ((uint32_t)FLASH_START+address >= (IFLASH1_ADDR + IFLASH1_SIZE)) { | ||
_FLASH_DEBUG("Flash write address too high\n"); | ||
return false; | ||
} | ||
|
||
if (((uint32_t)FLASH_START+address & 3) != 0) { | ||
_FLASH_DEBUG("Flash start address must be on four byte boundary\n"); | ||
return false; | ||
} | ||
|
||
// Unlock page | ||
uint32_t retCode = flash_unlock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + dataLength - 1, 0, 0); | ||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Failed to unlock flash for write\n"); | ||
return false; | ||
} | ||
|
||
// write data | ||
retCode = flash_write((uint32_t)FLASH_START+address, data, dataLength, 1); | ||
|
||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Flash write failed\n"); | ||
return false; | ||
} | ||
|
||
// Lock page | ||
retCode = flash_lock((uint32_t)FLASH_START+address, (uint32_t)FLASH_START+address + dataLength - 1, 0, 0); | ||
if (retCode != FLASH_RC_OK) { | ||
_FLASH_DEBUG("Failed to lock flash page\n"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
DueFlashStorage saves non-volatile data for Arduino Due. | ||
The library is made to be similar to EEPROM library | ||
Uses flash block 1 per default. | ||
Note: uploading new software will erase all flash so data written to flash | ||
using this library will not survive a new software upload. | ||
Inspiration from Pansenti at https://github.com/Pansenti/DueFlash | ||
Rewritten and modified by Sebastian Nilsson | ||
Further modified up by David Crocker | ||
*/ | ||
|
||
|
||
#ifndef DUEFLASHSTORAGE_H | ||
#define DUEFLASHSTORAGE_H | ||
|
||
#include <Arduino.h> | ||
#include "flash_efc.h" | ||
#include "efc.h" | ||
|
||
// 1Kb of data | ||
#define DATA_LENGTH ((IFLASH1_PAGE_SIZE/sizeof(byte))*4) | ||
|
||
// Choose a start address close to the top of the Flash 1 memory space | ||
#define FLASH_START ((byte *)(IFLASH1_ADDR + IFLASH1_SIZE - DATA_LENGTH)) | ||
|
||
// FLASH_DEBUG can be enabled to get debugging information displayed. | ||
//#define FLASH_DEBUG | ||
|
||
#ifdef FLASH_DEBUG | ||
#define _FLASH_DEBUG(x) Serial.print(x); | ||
#else | ||
#define _FLASH_DEBUG(x) | ||
#endif | ||
|
||
// DueFlash is the main namespace for flash functions | ||
namespace DueFlashStorage { | ||
void init(); | ||
|
||
// write() writes the specified amount of data into flash. | ||
// flashStart is the address in memory where the write should start | ||
// data is a pointer to the data to be written | ||
// dataLength is length of data in bytes | ||
|
||
byte read(uint32_t address); | ||
void read(uint32_t address, void *data, uint32_t dataLength); | ||
bool write(uint32_t address, byte value); | ||
bool write(uint32_t address, const void *data, uint32_t dataLength); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.