I think the TINY USART/TIMERs ...etc, are the same as the MEGA peripherals except for the number of USART/TIMERs. The Tinys have TCD and a DAC too. The setup and operation are nearly the same. Pretty much all of the code will be universal in AVR-0/1. Anyway... i hope that's the case.
I noticed AVRDUDE 8 has been released. It seems to communicate with my USB to Serial converter which will make life easier for those with raw chips and a serial device.
AVRDUDE 7 probably works fine as SerialUPDI, but more features have been added. Studying that to get up to speed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For the life of me... I cannot get PWM working at 38Hz using main clock as the primary clock source. So, this is not using the 32k as the main OSC but something between 2 to 20 mHz. Can you have a look? I tried MPLAB... failed to do anything!
So, I am now working on EEPROM operations.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The EEPROM operations of EPWRITE() and EPREAD() are now support. Same syntax as legacy AVR, PIC etc.
I have written a demo program to write and read the EEPROM. This program write 256 EEPROM bytes - select from Random number, a fixed number, or a range ( 255 to 0 )
The program will output the results on a serial terminal as follows - this is a range
The TCB can only do a main clock of div 2, It is not like TCA. If You divide the Main Clock(OSC20M) by 64 then You can get the TCB PWM down to about 612 Hz, but then it may affect Millis() on TCA . TCA is the champion in the 4809 as far as PWM. TCB is a good interval counter.
I'm having anomalous issues with MICROCHIP( AKA.ATMEL) STUDIO 7 simulator. I have no debugger so I have to debug with USART and LEDs to verify that hardware works. Rumor has it that Microchip is not doing any bug fixes on microchip/atmel studio 7 software any longer. The Simulator will get no attention. I guess MPLAB X is the future.
Congrats on the EE R/W!
I'm working on flash write. The BOOTEND/APPEND fuses play a role in this. Figuring out what works. Got USERROW EEwrite coded, was having issues with simulator anomalies ... going to MPLAB X to see if it will work better.
Thanks for the update.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The methods EPWRITE ( EEAddress , EEDataValue) and EEPREAD ( EEAddress ) { a function}. Are relatively simple.
Write the data to correct address, handled the interrupt ( in this case there is no interrupt defined so the compiler optimises that code .. by removing it ), then set the protect and execute the write. I even left your comments in!
Still have to figure out an erase routine for USERROW ... probably just writing 0xFF.
The Flash Write needs the BOOTEND/ APPEND fuses specifically set. A default BOOTEND 0 : APPEND 0, turns the entire Flash into the BOOT section and no section can write to itself.
The code controlling the main prescaler/OSC select was changing the division values intermittently. it may or may not have caused you some problems. Here's a new Routine.
I think the EPWRITE will work fine with the 0x1300 offset in USERROW... That's essentially what the routine is, But it doesn't have an erase routine specific to it( Like EEER, EEPROM Erase) and it is persistent through Chip_Erase. Maybe I'll try the EEER EEPROM Erase on USERROW.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You Have to write 0xFF to USERROW to erase it, you can erase the entire page of 64 bytes, or a byte at a time... the code is attached above as MEGA4809_USER_ROW_EEP_RW.asm along with the flash page write code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But, essentially Hugh never implemented any EEPROM operations and he never implemented creation of an EEP file from GCASM.
So, I have resolved. A lot of work but basically a case of changing the datamodel to support AVR EE data, and then using the data model throughout the compiler.
Along the way I hit lots of issues but all seems to be resolved.
The following with now correctly generate an EEP, there a lots of ways but these are the two typlical methods.
EEPROMmyEEDataBlock// [ EE address ]1,2,3,4// etcENDEEPROM
Working Read Progmem and Data Block(s). Write Progmem after I have resolved/implemented Read Progmem/Block.
Lots needed to be resolved. But, now able to compile in GCASM and using the ASM produced by GCBASIC get same results with AVRASM2. Issue remaining are counting progmem used and a proper implementation of PROGREAD() Currently, the ASM is in my program not a library.
I will post a video soon. Lots to do!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can now read Program Memory ( PROGMEM ) and create Data Block in PROGMEM. Very simple to read PROGMEM with ProgramRead ( ) - pass the address and you will get the word returned. In terms of DATA BLOCK define a block as WORD ( default ) or BYTE and the compiler will handle strings, numbers, constants etc.
DATAmyLoremasByte"Lorem ipsum dolor sit amet, consectetur adipiscing elit.""\&013123"0xFFFFENDDAT
The program below shows the fullprogram to read a DATA BLOCK that is treated as an ASCII string ( you can treat the data anyway you like ). Use ProgramRead() to get the data.
/* This program uses DATA blocks to create data sets in PROGMEM, then, use PROGREAD() to show a DATA block on a serial terminal. You may want to increase the Seral BPS.....*/#chipmega4809//DeclaretheTargetProcessorandSpeed#optionexplicit//RequireExplicitdeclarationofVariables#DEFINEUSART3_BAUD_RATE9600#DEFINEUSART3_TX_BLOCKING#DEFINEUSART3_DELAYOFF'*****************************************************************************************************'Mainprogramcommenceshere..everythingbeforethisissetupfortheboard.'NowassumesSerialTerminalisoperationalHserPrintCRLF2wait1sHSerPrintStringCRLF"Dump byte DATABLOCK to terminal - commencing"Wait1sDimValue,DataOffset,AddressasWord//InitialdataoffsetvalueDataOffset=0//LoopthroughuntilthedatablockendsDo//Addressesneedtobetwicereportedvalues-thatisthewayAVRswork.Address=@MYLOREM*2//GetbaseaddressAddress=Address+DataOffset//CalcualatenextaddressProgramRead(Address,value)//Getthewordvalueofthenexttwobytes//ShowbytesasASCII,donotshow0x00,andexiton0xFF//~Donotshowlastcharwhichis0xFF,0xFF,so,exitIfValue_H=0xFFor[BYTE]Value=0xFFThen//~ExittheloopandendExitDoEndif//The0x00couldbeapadbyte,so,donotprintIf[BYTE]Value<>0x00OR[BYTE]Value_H<>0x00ThenHSerPrintChr([BYTE]Value)EndIf//IndextonextwordDataOffset=DataOffset+2LoopHserPrintCRLF2HSerPrintStringCRLF"Dump DATABLOCK to Terminal - ended"End
Technical Review of changes
This change was specifially hard as compiler did not support AVR for DATABLOCKS or PROGREAD().
The first challenge was to get the GCBASIC compiler to produce ASM that that was 100% compatible with AVRASM2. Specifically, the correct format for Byte and Word data. AVR ASM is STRICT and there the GCBASIC has to be correct.
Assembly instructions also had to AVRASM2 strict. Z+ is not valid, when Z and z+ is. GCBASIC needs to be strict also.
To support Byte DATABLOCK where the WORD in program contains two bytes required many changes - padding when only one byte is used, counting Bytes rather than Words to provide the correct PROGMEM usage number, isolation of PIC operations and AVR operations ( they are very different in terms of ASM!) and other tweaks.
Greg had provided ASM example of the read operations so this part was easy! This meant the extending of the method PROGREAD() to support AVR using a mix of GCBASIC and ASM.
I am learning more and more about AVR ASM but I am learning how good Hugh was in creating the base compiler. For this change the architecture really helps.
GCBASIC Language changes - none, As PROGREAD() and DATA BLOCK is already there.
Preprocessor - no changes as the context of handling DATA BLOCKs has not changed.
DATA BLOCK handling - isolation of PIC and AVR operations adding the strict AVR ASM controls. I also added a check for duplicate naming of DATABLOCKs
GCASM - add support for .DB - data bytes.
Next, ProgramWrite..
I have ASM, from Greg, I have methods to see the changes on terminal... What can go wrong?
Once ProgramWrite is done I will complete Write UserRow, PageWrite and then I2C and SPI.
I need some here completing the [interrupt] section of the DAT file.
What I need is rather simple .... I need for each interrupt the interrupt enable bit and the clear interrupt bit. As you can see below I have done this for a few - but they are all needed.
Ok, I will switch gears and work on the [interrupt] section of the DAT file. Currently trying to figure out TWI / i2c protocol for the m4809.
I imagined that the compiler side would be difficult. I don't envy your job... it's a big one!
From what I understand the AVR-0/1 processors have similar syntax as the X-mega chips so that may help us in the future.
As far as what's missing?... These new processors are feature rich. Now that some of the big chunks are out of the way, we will have to re-assess our progress to determine what's left and how in-depth we want to get.
Some of this is new to me and I'm having to research it, but I am learning .
G
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not sure in what context I'm dealing with in the .DAT files. There are interrupts with Multiple sources using a single vector as well as configuration group bits... not sure what to do there. Anyway, pls check this and see if any of it is useable.
I am stumped. I need some input to crack this issue.
The PROGRAMWrite is just not working. Tried for a few days but no joy yet.
Here is the state of play. The write operation returns NVMCTRL_STATUS.2 = 1. This bit will read '1' when a write error has happened. A write error could be writing to different sections before doing a page write or writing to a protected area. This bit is valid for the last operation.
To call the test sub the following is used:
Address=FnLSL(@WORDNUMBERS,1)// Get base address// This is tad complex but this, for this test, returns the base address for a page of PROGMEM.// CHIPMAPPED_PROGMEM_START = 0x4000// address = the address of the stuff we want to overwrite// CHIPPROGMEM_PAGE_SIZE = 128// So, for any address this will set the address to the page address 0 byte.Address=(CHIPMAPPED_PROGMEM_START+Address)ANDNOT(CHIPPROGMEM_PAGE_SIZE-1)PROGRAMWRITE(Address,0x1234)
The SUB code is relatively simple.
SubPROGRAMWRITE(InSYSSTRINGAasWord,InxMemDataasWord)// SYSSTRINGA is a word aliased to R26 & R27 therefore the X register.DimxMemDataAsWordINTOFFdimccountforccount=0to63// just write 128 words for this test// SYSTEMP1 is .R1 SYSTEMP1=xMemData_H// write Hi BytestX+,SYSTEMP1SYSTEMP1=xMemData// Write Lo BytestX+,SYSTEMP1nextwaitwhileNVMCTRL_STATUS.1=1orNVMCTRL_STATUS.0=1CPU_CCP=CPU_CCP_SPM_gc;unlockCCPchangeprotectionforNVMcommandregisterNVMCTRL_CTRLA=NVMCTRL_CMD_PAGEERASEWRITE_gc;executeNVMerase/writeEndSub
I have tried settings fuse BOOT=0xC0 and APPEND=0xC0. And, many other numbers... No joy.
Any thoughts?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Re: millis() indeed great news!
I think the TINY USART/TIMERs ...etc, are the same as the MEGA peripherals except for the number of USART/TIMERs. The Tinys have TCD and a DAC too. The setup and operation are nearly the same. Pretty much all of the code will be universal in AVR-0/1. Anyway... i hope that's the case.
I noticed AVRDUDE 8 has been released. It seems to communicate with my USB to Serial converter which will make life easier for those with raw chips and a serial device.
AVRDUDE 7 probably works fine as SerialUPDI, but more features have been added. Studying that to get up to speed.
AVRDUDE is causing no end of issues. They are nor regression testing - they seem to forget to test.
We have had to backout the current AVRDUDE release and it cannot program LGTs and has acquired case sensitivity.
Great news on Timers and Millis.
Weekend off for me!
Millis () seems to run fine on my hardware. Have a good weekend, I'd have to say you've earned it.
Updated RAR ( I have moved from ZIP to RAR ).
https://1drv.ms/f/s!Ase-PX_n_4cvhP9oJsliPl4v9tm3Cg?e=dFDhsJ
The folders match you build, so, can drag and drop the contents now.
In the RAR is a set of demos for millis. I tested across a range of chips. All passed.
I have ported your ASM for:
100_MEGA4809_Set_Clock_Out.gcb
110_MEGA4809_Set_PWM.gcb
For the life of me... I cannot get PWM working at 38Hz using main clock as the primary clock source. So, this is not using the 32k as the main OSC but something between 2 to 20 mHz. Can you have a look? I tried MPLAB... failed to do anything!
So, I am now working on EEPROM operations.
EEPROM read and write of AVRDX
The EEPROM operations of EPWRITE() and EPREAD() are now support. Same syntax as legacy AVR, PIC etc.
I have written a demo program to write and read the EEPROM. This program write 256 EEPROM bytes - select from Random number, a fixed number, or a range ( 255 to 0 )
The program will output the results on a serial terminal as follows - this is a range
Updated EEPROM.H is in the latest RAR, along with the demo.
Enjoy
The TCB can only do a main clock of div 2, It is not like TCA. If You divide the Main Clock(OSC20M) by 64 then You can get the TCB PWM down to about 612 Hz, but then it may affect Millis() on TCA . TCA is the champion in the 4809 as far as PWM. TCB is a good interval counter.
I'm having anomalous issues with MICROCHIP( AKA.ATMEL) STUDIO 7 simulator. I have no debugger so I have to debug with USART and LEDs to verify that hardware works. Rumor has it that Microchip is not doing any bug fixes on microchip/atmel studio 7 software any longer. The Simulator will get no attention. I guess MPLAB X is the future.
Congrats on the EE R/W!
I'm working on flash write. The BOOTEND/APPEND fuses play a role in this. Figuring out what works. Got USERROW EEwrite coded, was having issues with simulator anomalies ... going to MPLAB X to see if it will work better.
Thanks for the update.
EE R/W is totally based on your work.
The methods EPWRITE ( EEAddress , EEDataValue) and EEPREAD ( EEAddress ) { a function}. Are relatively simple.
Write the data to correct address, handled the interrupt ( in this case there is no interrupt defined so the compiler optimises that code .. by removing it ), then set the protect and execute the write. I even left your comments in!
I do need you full name to attribute this work to you. :-)
Still have to figure out an erase routine for USERROW ... probably just writing 0xFF.
The Flash Write needs the BOOTEND/ APPEND fuses specifically set. A default BOOTEND 0 : APPEND 0, turns the entire Flash into the BOOT section and no section can write to itself.
This is the config of a CNANO board. Just so you know.
PERIOD = OFF
WINDOW = OFF
SLEEP = DIS
ACTIVE = DIS
SAMPFREQ = 1KHZ
LVL = BODLEVEL0
FREQSEL = 20MHZ
OSCLOCK = [ ]
EESAVE = [X]
RSTPINCFG = GPIO
CRCSRC = NOCRC
SUT = 64MS
WDTCFG = 0x00 (valid)
BODCFG = 0x00 (valid)
OSCCFG = 0x02 (valid)
SYSCFG0 = 0xC1 (valid)
SYSCFG1 = 0x07 (valid)
APPEND = 0x00 (valid)
BOOTEND = 0x00 (valid)
Let me know when you have user row operating.
But, a thought. Why wont EPWRITE just work with a different offset? EE offset is 0x1400. What is USERROW? Cannot we just change the offset?
The code controlling the main prescaler/OSC select was changing the division values intermittently. it may or may not have caused you some problems. Here's a new Routine.
I think the EPWRITE will work fine with the 0x1300 offset in USERROW... That's essentially what the routine is, But it doesn't have an erase routine specific to it( Like EEER, EEPROM Erase) and it is persistent through Chip_Erase. Maybe I'll try the EEER EEPROM Erase on USERROW.
You Have to write 0xFF to USERROW to erase it, you can erase the entire page of 64 bytes, or a byte at a time... the code is attached above as MEGA4809_USER_ROW_EEP_RW.asm along with the flash page write code.
Don't think you need this demo code, but here it is just in case.
See https://sourceforge.net/p/gcbasic/discussion/579125/thread/7fb3c8422f/?limit=250#1280
But, essentially Hugh never implemented any EEPROM operations and he never implemented creation of an EEP file from GCASM.
So, I have resolved. A lot of work but basically a case of changing the datamodel to support AVR EE data, and then using the data model throughout the compiler.
Along the way I hit lots of issues but all seems to be resolved.
The following with now correctly generate an EEP, there a lots of ways but these are the two typlical methods.
or
I also sorted a new programming interface using UPDI to program the PROGMEM and EEPROM. It is fast and easy to use.
Now I will sort the FLASH write etc. and, resolve the DATA blocks. Onwards and upwards.
That's awesome, Keep up the good work!
Progress is ok.
Working Read Progmem and Data Block(s). Write Progmem after I have resolved/implemented Read Progmem/Block.
Lots needed to be resolved. But, now able to compile in GCASM and using the ASM produced by GCBASIC get same results with AVRASM2. Issue remaining are counting progmem used and a proper implementation of PROGREAD() Currently, the ASM is in my program not a library.
I will post a video soon. Lots to do!
Program Read and Data Blocks supported
You can now read Program Memory ( PROGMEM ) and create Data Block in PROGMEM. Very simple to read PROGMEM with ProgramRead ( ) - pass the address and you will get the word returned. In terms of DATA BLOCK define a block as WORD ( default ) or BYTE and the compiler will handle strings, numbers, constants etc.
The program below shows the fullprogram to read a DATA BLOCK that is treated as an ASCII string ( you can treat the data anyway you like ). Use ProgramRead() to get the data.
Build 1425 has this capability. Downlodad and apply https://1drv.ms/u/s!Ase-PX_n_4cvhYJj_acYp33tuKbuEQ?e=kzTUK4
Program to read DATA BLOCK using ProgramRead()
Technical Review of changes
This change was specifially hard as compiler did not support AVR for DATABLOCKS or PROGREAD().
The first challenge was to get the GCBASIC compiler to produce ASM that that was 100% compatible with AVRASM2. Specifically, the correct format for Byte and Word data. AVR ASM is STRICT and there the GCBASIC has to be correct.
Assembly instructions also had to AVRASM2 strict. Z+ is not valid, when Z and z+ is. GCBASIC needs to be strict also.
To support Byte DATABLOCK where the WORD in program contains two bytes required many changes - padding when only one byte is used, counting Bytes rather than Words to provide the correct PROGMEM usage number, isolation of PIC operations and AVR operations ( they are very different in terms of ASM!) and other tweaks.
Greg had provided ASM example of the read operations so this part was easy! This meant the extending of the method PROGREAD() to support AVR using a mix of GCBASIC and ASM.
I am learning more and more about AVR ASM but I am learning how good Hugh was in creating the base compiler. For this change the architecture really helps.
Next, ProgramWrite..
I have ASM, from Greg, I have methods to see the changes on terminal... What can go wrong?
Once ProgramWrite is done I will complete Write UserRow, PageWrite and then I2C and SPI.
What is missing then?
@cribcat
I need some here completing the [interrupt] section of the DAT file.
What I need is rather simple .... I need for each interrupt the interrupt enable bit and the clear interrupt bit. As you can see below I have done this for a few - but they are all needed.
Looks at an example
RTCOverflow:RTC_CNT,6,RTC_INTCTRL.RTC_OVF_bp,RTC_INTFLAGS.RTC_OVF_bp
The enable bit is
RTC_INTCTRL.RTC_OVF_bp
and the clear bit isRTC_INTFLAGS.RTC_OVF_bp
.We need the rest that are shown as
,,
No rush but this is needed.
Thank you!
Evan
It would be best to edit an existing DAT and send it to me.
Ok, I will switch gears and work on the [interrupt] section of the DAT file. Currently trying to figure out TWI / i2c protocol for the m4809.
I imagined that the compiler side would be difficult. I don't envy your job... it's a big one!
From what I understand the AVR-0/1 processors have similar syntax as the X-mega chips so that may help us in the future.
As far as what's missing?... These new processors are feature rich. Now that some of the big chunks are out of the way, we will have to re-assess our progress to determine what's left and how in-depth we want to get.
Some of this is new to me and I'm having to research it, but I am learning .
G
Thanks re Interrupts.
TWI will be need. I have written a state engine for the newer PICs. Is that what is needed? Meanwhile folks can use software I2C/TWI.
You are correct. Assess where are next week as a number of features we may decide to leave as ASM demos.
And, we are learning!!
Not sure in what context I'm dealing with in the .DAT files. There are interrupts with Multiple sources using a single vector as well as configuration group bits... not sure what to do there. Anyway, pls check this and see if any of it is useable.
I am stumped. I need some input to crack this issue.
The PROGRAMWrite is just not working. Tried for a few days but no joy yet.
Here is the state of play. The write operation returns NVMCTRL_STATUS.2 = 1. This bit will read '1' when a write error has happened. A write error could be writing to different sections before doing a page write or writing to a protected area. This bit is valid for the last operation.
To call the test sub the following is used:
The SUB code is relatively simple.
I have tried settings fuse BOOT=0xC0 and APPEND=0xC0. And, many other numbers... No joy.
Any thoughts?
Hello Anobium,
Do these new chip still require the $55 - $AA sequence for EE memory ?
Geoffrey Younger
These chips are very different. The PICs need the 55-AA sequence.
The issue was ... incorrect Constant usage by me.
All resolved now.