View previous topic :: View next topic |
Author |
Message |
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sun Mar 11, 2018 7:37 pm Post subject: EDMA on E Series XMEGA - Need advice! |
|
|
Dear Forum,
Having been successful with implementing DMA on the Series A XMEGA, https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14077
I then tried to implement EDMA in E Series - BUT only with limited success.
I found the following problems:
1. BASCOM v2.0.8.1 does not accept Config EDMA definition of the Channel Mode (CHM) as described in the Help.
2. Cannot set ANY of the registers manually - after Disabling EDMA_CTRL.7 = 0.
3. Channel Priority Mode (CPM) register is always set to RoundRobin regardless of the parameters used in Config EDMA
4. The Channel Repeat variable is not recognized in the Config EDMACHx command. But is available in register EDMA_CHx_CTRLA Bit 5.
5. Register EDMA_CHx_SRCADDRCTRL as described in Datasheet is not available.
6. Register EDMA_CHx_DESTADDRCTRL is available and always &B00000000.
Most importantly, when using USART as Source/Destination:
7. The first call to the EDMA produces garbled message.
8. The message send to RX is ALWAYS echoed to TX. I do not know if this is a flaw in my code, BASCOM or the E Series XMega. Unless this can be eliminated, this flaw makes using EDMA on USART impractical.
9. Data received by USARTxy_DATA is NOT stored in the Destination Array.
Any help re: items 7-9 would be greatly appreciated.
E
[PS: USART Trigger Addresses are different between A and E Series XMEGA. This is described in the datasheet.]
Code: | $regfile = "xm32e5def.dat"
$hwstack = 200
$swstack = 200
$framesize = 200
Osc_dfllctrl.0 = 1
Dfllrc32m_ctrl.0 = 1 'enable CALIBRATION
$crystal = 48000000
Config Osc = Enabled , 32mhzosc = Disabled
Osc_pllctrl = &B00_0_11000
Set Osc_ctrl.4 ' PLL enable
Bitwait Osc_status.4 , Set 'Check if PLL is ready
Config Sysclock = Pll , Prescalea = 1 , Prescalebc = 1_1 ' configure the systemclock ---> use PLL
Waitms 2
'COM1 - Uart_C0 PORTC.3 PORTC.2 SERIALIN or SERIALIN0
'COM3 - UART_D0 PORTD.3 PORTD.2 SERIALIN2
'Trigsrc Base Value Group Configuration Description
'0x4C Usartc0 Usart C0 EDMA Triggers Base Value
'0x6C Usartd0 Usart D0 EDMA Triggers Base Value
'*********************************************************************
'UART Trigger Source - NOTE: THESE ARE DIFFERENT FROM "A" - Series XMEGA *********
'*********************************************************************
'TRGSRC offset value Group Configuration Description
'0x00 RXC Receive complete
'0x01 DRE Data Register Empty
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled
Declare Sub Dump_regs()
'====Dummy Data ====
'&123456789012345678901234567890123456789012345678901234567890 Sample message sent from Terminal
'====Config USART ====
Config Serialin = Buffered , Size = 3 , Bytematch = &H26 '&
'uses _rs232inbuf0(size) SRAM space
Config Com1 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #2
Dim Payload(60) As Byte 'At _rs232inbuf7(1) Overlay
Dim I As Byte , Uart_rx As Byte , Uart_tx As Byte 'Host TX Payload
'====Config DMA ====
Config Edma = Enabled , Doublebuf = Disabled , Cpm = Ch0123
'TX
Config Edmach1 = Enabled , Burstlen = 1 , Chanrpt = Enabled , Tci = Med , Eil = Off , Singleshot = Enabled , Trigger = &H4D , Btc = 6 , Sar = Transaction , Sam = Inc , Sadr = Varptr(payload(1)) , Dar = Burst , Dam = Fixed , Dadr = Varptr(usartc0_data)
'Repeat = 1
On Edma_ch1 Edmach_tx_isr 'Interrupt MUST be cleared in ISR!!!!!
'RX
Config Edmach0 = Enabled , Burstlen = 1 , Chanrpt = Enabled , Tci = Med , Eil = Off , Singleshot = Enabled , Trigger = &H4C , Btc = 6 , Dar = Transaction , Dam = Inc , Dadr = Varptr(payload(1)) , Sar = Burst , Sam = Fixed , Sadr = Varptr(usartc0_data)
'Repeat = 1
On Edma_ch0 Edmach_rx_isr 'Inrerrupt MUST be cleared in ISR!!!!!
Edma_intflags.0 = 1
'show initial config
Call Dump_regs() 'as defined by Config
Edma_ch0_ctrla.7 = 0
Edma_ch1_ctrla.7 = 0
'==================
'Config EDMA
'==================
'EDMA_CTRL = 10000000
'RoundRobin, Double Buffer Disabled, 4 Peripherals
'Note that CHM is not recognized by BASCOM
'Define Standard Channels 0 and 2:
Edma_ctrl.7 = 0 'Deactivate
'CHMode = PER0123
' Edma_ctrl.4 = 0
' Edma_ctrl.5 = 0
'CHMode = STD0
' Edma_ctrl.4 = 1
' Edma_ctrl.5 = 0
'CHMode = STD2
' Edma_ctrl.4 = 0
' Edma_ctrl.5 = 1
'CHMode = STD02
' Edma_ctrl.4 = 1
' Edma_ctrl.5 = 1
'==================
'Config Channel 0
'==================
'EDMA_CH0_CTRLA = 10100100 - Seems OK as is
'Burstlen = 1 byte, Single-Shot, Repeat = 1, Channel Enabled
'Note that Repeat is not recognized by BASCOM Config EDMACHx
'EDMA_CH0_ADDRCTRL = 00100000 - Seems OK as is [used as Source]
'Reload = Burst, Dir = Fixed
'EDMA_CH0_TRIGSRC = &H4C - Note E Series XMega is different from A Series!!!
'SRC and DEST ADDRCTRL are only used by Standard Channels
'EDMA_CH0_SRCADDRCTRL - Register shown in Datasheet not available in Bascom
'EDMA_CH0_DESTADDRCTRL = 00000000 - Appears not to have been set properly by Config
'DestReload = None, DestAddrMode = Fixed
'Should be:
'DestReload = Transaction
Edma_ch0_destaddrctrl.4 = 1
Edma_ch0_destaddrctrl.5 = 0
'DestAddrMode = Inc
Edma_ch0_destaddrctrl.2 = 0
Edma_ch0_destaddrctrl.1 = 0
Edma_ch0_destaddrctrl.0 = 1
'==================
'Config Channel 1/2
'==================
'EDMA_CHx_CTRLA = 00000100 - This appears incorrect
'Burstlen = 1 byte, Single-Shot, Repeat = 0, Channel Disabled
'Note that Repeat is not recognized by BASCOM Config EDMACHx
'Should be:
'Repeat = 1
Edma_ch1_ctrla.5 = 1
'Channel Enable
'EDMA_CH1_CTRLA = 1 - Enable when needed
'EDMA_CHx_ADDRCTRL = 00110001 - Seems OK as is [used as Source]
'Reload = Transaction, Dir = Inc
'EDMA_CHx_TRIGSRC = &H4D - Note E Series XMega is different from A Series!!!
'SRC and DEST ADDRCTRL are only used by Standard Channels
'EDMA_CHx_SRCADDRCTRL - Register shown in Datasheet not available in Bascom
'EDMA_CHx_DESTADDRCTRL = 00000000 - Appears not to have been set properly by Config
'DestReload = None, DestAddrMode = Fixed
'Should be:
'DestReload = Burst
Edma_ch1_destaddrctrl.4 = 0
Edma_ch1_destaddrctrl.5 = 1
'DestAddrMode = Fixed
Edma_ch1_destaddrctrl.2 = 0
Edma_ch1_destaddrctrl.1 = 0
Edma_ch1_destaddrctrl.0 = 0
Edma_ctrl.7 = 1 'Activate
Call Dump_regs() 'as modified
'Intialize first message to see if EDMA receives new message
Payload(1) = &H36
Payload(2) = &H35
Payload(3) = &H34
Payload(4) = &H33
Payload(5) = &H32
Payload(6) = &H31
Enable Interrupts
'====M a i n ====
Do
Config Powermode = Idle 'DMA will continue to receive UART Data while in Idle mode
If Uart_rx = 1 Then
Print #2 , Chr(13) ; "Serial Buffer Msg Rcvd: " ;
For I = 1 To 3 : Print #2 , Hex(_rs232inbuf0(i)) ; " " ; : Next
Print #2 , Chr(13) ; Chr(10) ; "EDMA Msg Rcvd: ";
Edma_ch1_ctrla.7 = 1 'DMA TX to Terminal
Waitms 100
If Uart_tx = 1 Then
Print #2 , " TX OK" ; Chr(13)
Else
Print #2 , " TX Fail" ; Chr(13)
End If
Enable Usartc0_rxc 'Restart Bytematch
Uart_rx = 0
Clear Serialin 'Clear Buffer
For I = 1 To 3 : _rs232inbuf0(i) = 0 : Next
End If
Loop
End
Sub Dump_regs()
Print #2 , Chr(13) ; "XMega E Series"
Print #2 , "EDMA_CTRL: " ; Bin(edma_ctrl)
Print #2 , Chr(13) ; "EDMA Channel 0"
Print #2 , "EDMA_CH0_CTRLA: " ; Bin(edma_ch0_ctrla)
Print #2 , "EDMA_CH0_ADDRCTRL: " ; Bin(edma_ch0_addrctrl)
Print #2 , "EDMA_CH0_TRIGSRC: $" ; Hex(edma_ch0_trigsrc)
' Print #2 , "EDMA_CH0_SRCADDRCTRL: " ; Bin(edma_ch0_srcaddrctrl) 'NOT AVAILABLE
Print #2 , "EDMA_CH0_DESTADDRCTRL: " ; Bin(edma_ch0_destaddrctrl)
Print #2 , Chr(13) ; "EDMA Channel 2"
Print #2 , "EDMA_CH1_CTRLA: " ; Bin(edma_ch1_ctrla)
Print #2 , "EDMA_CH1_ADDRCTRL: " ; Bin(edma_ch1_addrctrl)
Print #2 , "EDMA_CH1_TRIGSRC: $" ; Hex(edma_ch1_trigsrc)
' Print #2 , "EDMA_CH1_SRCADDRCTRL: " ; Bin(edma_ch1_srcaddrctrl) 'NOT AVAILABLE
Print #2 , "EDMA_CH1_DESTADDRCTRL: " ; Bin(edma_ch1_destaddrctrl)
End Sub
Serial0charmatch:
'Pushall
Edma_ch0_ctrla.7 = 1
Disable Usartc0_rxc 'Disable UART RX, and let DMA receive rest of message
'Popall
Return
Edmach_rx_isr:
If Edma_intflags.0 = 1 Then 'DMA Channel 0 Transaction Interrupt
Edma_intflags.0 = 1 'Clear Interrupt
Uart_rx = 1 'set flag
End If
Return
Edmach_tx_isr:
If Edma_intflags.1 = 1 Then 'DMA Channel 1 Transaction Interrupt
Edma_intflags.1 = 1 'Clear interrupt
Uart_tx = 1 'set flag
End If
Return |
(BASCOM-AVR version : 2.0.8.1 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Mar 11, 2018 9:39 pm Post subject: |
|
|
That looks like a voluntary extra task.
And it looks the one who needs it, will be in charge of this extra task.
Luckily I don't need it.
Alas simulation for that controller does not work on the AVR Studio 6.2 - the newest version I have here on my old system. It would be good to read the settings also in clear text.
Maybe you are luckier with a newer version of Studio.
What however works, is to use Bascom's simulator, I would suggest to add $noramclear, as otherwise you have to wait to get SRam cleared, which slows down start of simulation.
Basics of every check is to compare the register settings of what should be against the simulated values and these against the dump.
As said: voluntary extra task
Quote: | 8. The message send to RX is ALWAYS echoed to TX | Did you try:
Have you proof/experience with other ATXMegas that this tautology actually works?
I mean, you trigger an RX-interrupt for buffered serial at every incoming char, while in the same you want EDMA to fetch the same data.
Don't you think you should disable buffered serial for testing the DMA stuff?
Same with Config Powermode = Idle, it's not advisable at roadworks to dig hundreds of holes and try to fix them all the same, instead I'd go step by step, begin from basics and advance to more sophisticated solutions. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sun Mar 11, 2018 10:37 pm Post subject: |
|
|
Thanks MWS.
If you take a quick look at the example (linked in the Share Working Code section of the Forum) - it is nearly the exact same code working on a XMEGA 192A.
Maybe, as a favor, can you give me a simple way to write values directly to the registers by using ASM?
I can then configure them directly and continue with my development.
E |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Mar 11, 2018 11:12 pm Post subject: |
|
|
What do you want to achieve by using asm?
You write to Edma_ch1_ctrla already, don't you believe this is executed well?
Absolutely write to a register:
Code: | !LDI R18, &B00000011
!STS {Edma_ch1_ctrla}, R18 |
Set bits (7, 0):
Code: | !LDS R18, {Edma_ch1_ctrla}
!ORI R18, &B10000001
!STS {Edma_ch1_ctrla}, R18 |
Clear bits (3, 2):
Code: | !LDS R18, {Edma_ch1_ctrla}
!ANDI R18, &B11110011
!STS {Edma_ch1_ctrla}, R18 |
It will work also - in case you don't want use the register-name as defined within the dat-file - to replace {registername} with the number of the register from the data sheet.
I doubt it will behave different in asm. As well there are some reasons why registers do not accept a value, I see none of them here.
Last edited by MWS on Mon Mar 12, 2018 7:10 am; edited 1 time in total |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sun Mar 11, 2018 11:39 pm Post subject: |
|
|
Perfect. Thank you.
One register, SRCADDCTRL, is not defined so will need direct access.
Also, according to datasheet, Disabling EDMA_CTRL should allow changing the registers.
E
Last edited by enniom on Mon Mar 12, 2018 9:43 am; edited 1 time in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Mar 12, 2018 7:32 am Post subject: |
|
|
Be aware that reading and writing 16 bit registers has to be done in special order of low and high byte, read ' Accessing 16-bit Registers' in the data sheet. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Mon Mar 12, 2018 9:41 am Post subject: |
|
|
Yes, thanks MWS.
BTW, it was this statement that helped greatly in helping understand what was happening ....
Quote: | ... in case you don't want use the register-name as defined within the dat-file - to replace {registername} with the number of the register from the data sheet. |
Here is an update to my findings (in the order of my first post):
1. It appears as if the Bascom Help is not correct. The parameter is not CHM but CHMODE.
Code: | '====Config DMA ====
Config Edma = Enabled , Doublebuf = Disabled , Cpm = Rr , Chmode = Std02
|
2-4. Still working on this.
5. Seems as if EDMA_CHx_ADDRCTRL (for Peripheral Channel) is used as EDMA_CHx_SRCADDCTRL (for Standard Channel).
6. Seems as if EDMA_CHx_DESTADDRCTRL is available only when Standard Channels are defined.
7. The first call to the EDMA produces garbled message. This continues to be a problem.
8. The message send to RX is ALWAYS echoed to TX when the EDMA channel is defined as a Peripheral Channel.
9. Data received by USARTxy_DATA is NOT stored in the Destination Array when the EDMA channel is defined as a Peripheral Channel.
E |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|