Comments (18)
from dxcore.
Any pointers to how I might solve this myself ? I don't see any relevant appnotes and the one AS Start example isn't helpful either. I've read the NVMCTRL section of the datasheet but I don't know how to convert this to code.
from dxcore.
Hold your horses, it's a 5-minute fix from my end...
from dxcore.
Wait wait wait - the avr-libc routines don't work? Ugh... Okay, that will be a bit longer :-(
from dxcore.
Need to implement those macros, in that case...
from dxcore.
What's in there now is definitely totally hosed though
from dxcore.
I just pushed a version of EEPROM that I would expect to work (in github repo - obv. not in a board manager release).
Does that not work?
from dxcore.
If it doesn't work, please describe how it doesn't work...
from dxcore.
Thanks. I copied that straight over the file in /Users/xxx/Documents/Arduino/hardware/DxCore/megaavr/libraries/EEPROM/src.
Compilation output: [eeprom_test_compile_v1.txt]. I restarted the IDE just to make sure there wasn't anything cached. (https://github.com/SpenceKonde/DxCore/files/5359825/eeprom_test_compile_v1.txt)
Same result - whatever value or address I write reads back as 255, e.g.
EEPROM[0] = 22;
Serial.println(EEPROM[0]);
EEPROM.write(1, 22);
Serial.println(EEPROM.read(1));
But, if it's calling eeprom_read_byte() surely that's resolved from avr-libc ?
from dxcore.
Check NVMCTRL.STATUS after attempting a write, see if there are any error flags.
I suspect read is working correctly, and write is not.
It's easy enough to verify read by just directly reading from the address of the mapped EEPROM
from dxcore.
After a write, NVMCTRL.STATUS is 16. Per the datasheet (sec 10.5.3), that's the LSB of the error code, which translates to 0x1 INVALIDCMD (The selected command is not supported).
from dxcore.
Yup, I had a feeling that was what you'd see....
Yeah, eeprom_write_byte needs to be reimplemented....
from dxcore.
I installed MPLABX and used the mcc to generate some code, but I don't know how to implement this correctly. Maybe this will be a helpful pointer ?
/**
* \brief Read a byte from eeprom
*
* \param[in] eeprom_adr The byte-address in eeprom to read from
*
* \return The read byte
*/
uint8_t DA_ReadEepromByte(eeprom_adr_t eeprom_adr)
{
// Read operation will be stalled by hardware if any write is in progress
return *(uint8_t *)(EEPROM_START + eeprom_adr);
}
/**
* \brief Write a byte to eeprom
*
* \param[in] eeprom_adr The byte-address in eeprom to write to
* \param[in] data The byte to write
*
* \return Status of write operation
*/
nvmctrl_status_t DA_WriteEepromByte(eeprom_adr_t eeprom_adr, uint8_t data)
{
/* Wait for completion of previous write */
while (NVMCTRL.STATUS & (NVMCTRL_EEBUSY_bm|NVMCTRL_FBUSY_bm));
/* Program the EEPROM with desired value(s) */
ccp_write_spm((void *)&NVMCTRL.CTRLA, NVMCTRL_CMD_EEERWR_gc);
/* Write byte to EEPROM */
*(uint8_t *)(EEPROM_START + eeprom_adr) = data;
/* Clear the current command */
ccp_write_spm((void *)&NVMCTRL.CTRLA, NVMCTRL_CMD_NONE_gc);
return NVM_OK;
}
static inline void ccp_write_spm(void *addr, uint8_t value)
{
protected_write_io(addr, CCP_SPM_gc, value);
}
There is no implementation provided for protected_write_io() so I assume it's buried somewhere in some library ?
from dxcore.
Ok, this seems to work. Again, cobbled together from disparate MCP sources.
...
#include <avr/xmega.h>
...
/** Datatype for return status of NVMCTRL operations */
typedef enum {
NVM_OK = 0, ///< NVMCTRL free, no write ongoing.
NVM_ERROR = 1, ///< NVMCTRL operation retsulted in error
NVM_BUSY = 2, ///< NVMCTRL busy, write ongoing.
} nvmctrl_status_t;
uint8_t da_eeprom_read_byte(uint8_t * index) {
return *(uint8_t *)(EEPROM_START + index);
}
nvmctrl_status_t da_eeprom_write_byte(uint8_t *index, uint8_t in) {
/* Wait for completion of previous write */
while (NVMCTRL.STATUS & (NVMCTRL_EEBUSY_bm|NVMCTRL_FBUSY_bm));
/* Program the EEPROM with desired value(s) */
_PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_EEERWR_gc);
/* Write byte to EEPROM */
*(uint8_t *)(EEPROM_START + index) = in;
/* Clear the current command */
_PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_NONE_gc);
return NVM_OK;
}
from dxcore.
5403512 .... but yeah your approach is better if that works, somehow I thought (looks like incorrectly) that you weren't supposed to change the command while it was busy....
from dxcore.
I was hoping you'd know better than me ! As I said, it was hacked together using MCC, a couple of app notes and some googling.
Works fine using your changes. Thanks.
from dxcore.
I had a similar problem when I tried to do it in the past defining a macro like that. I was as baffled as you were. That's why I didn't do it like that this time - I'd tripped over it before. No clue why the include guards don't do their job here...
from dxcore.
https://github.com/SpenceKonde/DxCore/blob/master/megaavr/libraries/EEPROM/src/EEPROM.h#L38
Oops :) index needs to be wider than 8 bits to address 512 bytes. Wondered why I was getting strange overwrites.
from dxcore.
Related Issues (20)
- EEPROM with new AVR EA CPU HOT 3
- millis/micros timer disabled wedges DD part HOT 10
- Comparator Reference Voltages Incorrect? HOT 3
- Optiboot_dx build fails on various alternative baud rates HOT 4
- TWI name classification not perfect. (Information Request) HOT 22
- DD series: Error in digitalPinToAnalogInput macro in pins_arduino.h HOT 3
- 10bit DAC with analogWrite give have only 8bit resolution (DD series and other?) HOT 1
- Add DXCORE AVR128DB64 to Library HOT 2
- Menu with optimization level. HOT 1
- D7 LED not blinking after burning bootloader into 32DD14 configured for Serial on D4/D5 (Serial0, Swap3) HOT 11
- On AVR-DD Parts can't configure MVIO for Single Supply via Tools MVIO Option in Arduino IDE HOT 1
- EVENT AND COMPARATOR ISSUES WITH EA and EB parts HOT 5
- How to do OTA? AVR128DB64 HOT 2
- Wrong timer for millis() on 14-pin DD part HOT 1
- HV programmer for DD series (and newer)
- Board Manager SSH Certificate Expired HOT 2
- AVR128DB48 unexpected behaviour HOT 5
- linking error: section .bss' is not within region data' HOT 1
- program avr128da28 chip using arduino uno as a programmer HOT 3
- error when burning the bootloader for avr128DA28 and arduino uno as updi HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dxcore.