From 121974ff5ddad5d116c31031aa5639664be0cbf3 Mon Sep 17 00:00:00 2001 From: Michal Demin Date: Fri, 9 Aug 2024 21:11:24 +0200 Subject: [PATCH 1/4] add support for sam 5x mcu trace --- Support/gdbtrace.init | 88 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/Support/gdbtrace.init b/Support/gdbtrace.init index 6f643862..5054ba81 100644 --- a/Support/gdbtrace.init +++ b/Support/gdbtrace.init @@ -20,6 +20,7 @@ IMXRT; SAM5X; enableSAMD5XSWD : Enable SWO on SAM5X output pin on SAM5X + enableSAMD5XTRACE : Enable TRACE on SAM5x pins NRF; enableNRF52TRACE : Start TRACE on NRF52 (not nrf52833 or nrf52840) pins @@ -88,6 +89,7 @@ set $CPU_TM4C=5 set $CPU_S32K344=6 set $CPU_IMXRT117X=7 set $CPU_KINETIS=8 +set $CPU_SAMD5x=9 # ==================================================================== set $CDBBASE=0xE000EDF0 @@ -923,7 +925,6 @@ end document enableSAMD5XSWD enableSAMD5XSWD Configure output pin on SAM5X for SWO use. end - # ==================================================================== define enableEFR32MG12SWO #set language c @@ -1488,7 +1489,92 @@ document enableLPC176xTRACE enableLPC176xTRACE Enable TRACE on LPC176x pins. : Number of bits wide (1,2 or 4 only) end +# ==================================================================== +define enableSAMD5XTRACE + #set language c + + set $bits=4 + set $drive=1 + + if $argc >= 1 + set $bits = $arg0 + end + if (($bits<1) || ($bits==3) || ($bits>4)) + help enableSAMD5XTRACE + end + + if $argc >= 2 + set $drive = $arg1 + end + + if ($drive > 1) + help enableSAMD5XTRACE + end + + set $bits = $bits-1 + set $CPU=$CPU_STM32 + + # Enable peripheral channel clock on GCLK#0 + # GCLK->PHCTRL[47] = GCLK_PCHCTRL_GEN(0) + set *(unsigned char *)0x40001D3C = 0 + # GCLK->PHCTRL[47] |= GCLK_PCHCTRL_CHEN + set *(unsigned char *)0x40001D3C |= 0x40 + + # Configure PINMUX for GPIOB.30. '7' is SWO. + set *(unsigned char *)0x410080BF |= 0x07 + set *(unsigned char *)0x410080DE = 0x01 + + # Setup PC28 - pmux 7 + set *(unsigned char *)(0x41008000+0x80*2+0x30+28/2) &= ~0x0f + set *(unsigned char *)(0x41008000+0x80*2+0x30+28/2) |= 0x07 + set *(unsigned char *)(0x41008000+0x80*2+0x40+28) = (($drive) << 6) | 1 + + # Setup PC27 - pmux 7 + set *(unsigned char *)(0x41008000+0x80*2+0x30+27/2) &= ~0xf0 + set *(unsigned char *)(0x41008000+0x80*2+0x30+27/2) |= 0x70 + set *(unsigned char *)(0x41008000+0x80*2+0x40+27) = (($drive) << 6) | 1 + if ($bits>0) + # Setup PC26 - pmux 7 + set *(unsigned char *)(0x41008000+0x80*2+0x30+26/2) &= ~0x0f + set *(unsigned char *)(0x41008000+0x80*2+0x30+26/2) |= 0x07 + set *(unsigned char *)(0x41008000+0x80*2+0x40+26) = (($drive) << 6) | 1 + end + + if ($bits>1) + # Setup PC25 - pmux 7 + set *(unsigned char *)(0x41008000+0x80*2+0x30+25/2) &= ~0xf0 + set *(unsigned char *)(0x41008000+0x80*2+0x30+25/2) |= 0x70 + set *(unsigned char *)(0x41008000+0x80*2+0x40+25) = (($drive) << 6) | 1 + # + # Setup PC24 - pmux 7 + set *(unsigned char *)(0x41008000+0x80*2+0x30+24/2) &= ~0x0f + set *(unsigned char *)(0x41008000+0x80*2+0x30+24/2) |= 0x07 + set *(unsigned char *)(0x41008000+0x80*2+0x40+24) = (($drive) << 6) | 1 + end + + # Set number of bits in DBGMCU_CR + set *0xE0042004 &= ~(3<<6) + + if ($bits<3) + set *0xE0042004 |= ((($bits+1)<<6) | (1<<5)) + else + set *0xE0042004 |= ((3<<6) | (1<<5)) + end + + # Enable Trace TRCENA (DCB DEMCR) + set *($CDBBASE+0xC)=(1<<24) + + # Finally start the trace output + _doTRACE + + #set language auto +end +document enableSAMD5XTRACE +enableSAMD5XTRACE : Enable TRACE on SAM5x pins + : Number of bits wide (1,2 or 4 only) + : Drive strength (0=normal, 1=strong) +end # ==================================================================== define dwtPOSTCNT #set language c From 2e9fdc8b9992aa2aee8e729784ebb986c415a844 Mon Sep 17 00:00:00 2001 From: Michal Demin Date: Fri, 9 Aug 2024 21:14:26 +0200 Subject: [PATCH 2/4] fix small typo --- Support/gdbtrace.init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Support/gdbtrace.init b/Support/gdbtrace.init index 5054ba81..0a708bb9 100644 --- a/Support/gdbtrace.init +++ b/Support/gdbtrace.init @@ -1512,7 +1512,7 @@ define enableSAMD5XTRACE end set $bits = $bits-1 - set $CPU=$CPU_STM32 + set $CPU=$CPU_SAMD5x # Enable peripheral channel clock on GCLK#0 # GCLK->PHCTRL[47] = GCLK_PCHCTRL_GEN(0) From 8680b161cf6cf745c98a6be3f770eba5fc88f452 Mon Sep 17 00:00:00 2001 From: Michal Demin Date: Fri, 9 Aug 2024 21:36:18 +0200 Subject: [PATCH 3/4] fix indentation --- Support/gdbtrace.init | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Support/gdbtrace.init b/Support/gdbtrace.init index 0a708bb9..5a2cd618 100644 --- a/Support/gdbtrace.init +++ b/Support/gdbtrace.init @@ -1536,20 +1536,20 @@ define enableSAMD5XTRACE if ($bits>0) # Setup PC26 - pmux 7 - set *(unsigned char *)(0x41008000+0x80*2+0x30+26/2) &= ~0x0f - set *(unsigned char *)(0x41008000+0x80*2+0x30+26/2) |= 0x07 + set *(unsigned char *)(0x41008000+0x80*2+0x30+26/2) &= ~0x0f + set *(unsigned char *)(0x41008000+0x80*2+0x30+26/2) |= 0x07 set *(unsigned char *)(0x41008000+0x80*2+0x40+26) = (($drive) << 6) | 1 end if ($bits>1) # Setup PC25 - pmux 7 - set *(unsigned char *)(0x41008000+0x80*2+0x30+25/2) &= ~0xf0 - set *(unsigned char *)(0x41008000+0x80*2+0x30+25/2) |= 0x70 + set *(unsigned char *)(0x41008000+0x80*2+0x30+25/2) &= ~0xf0 + set *(unsigned char *)(0x41008000+0x80*2+0x30+25/2) |= 0x70 set *(unsigned char *)(0x41008000+0x80*2+0x40+25) = (($drive) << 6) | 1 - # + # Setup PC24 - pmux 7 - set *(unsigned char *)(0x41008000+0x80*2+0x30+24/2) &= ~0x0f - set *(unsigned char *)(0x41008000+0x80*2+0x30+24/2) |= 0x07 + set *(unsigned char *)(0x41008000+0x80*2+0x30+24/2) &= ~0x0f + set *(unsigned char *)(0x41008000+0x80*2+0x30+24/2) |= 0x07 set *(unsigned char *)(0x41008000+0x80*2+0x40+24) = (($drive) << 6) | 1 end From ff7339cef88cc8fe62715ed3754647a0e3f49de2 Mon Sep 17 00:00:00 2001 From: Michal Demin Date: Sun, 11 Aug 2024 11:40:29 +0200 Subject: [PATCH 4/4] remove unneeded gpiuoB30 init in trace --- Support/gdbtrace.init | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Support/gdbtrace.init b/Support/gdbtrace.init index 5a2cd618..d2ed8961 100644 --- a/Support/gdbtrace.init +++ b/Support/gdbtrace.init @@ -1520,10 +1520,6 @@ define enableSAMD5XTRACE # GCLK->PHCTRL[47] |= GCLK_PCHCTRL_CHEN set *(unsigned char *)0x40001D3C |= 0x40 - # Configure PINMUX for GPIOB.30. '7' is SWO. - set *(unsigned char *)0x410080BF |= 0x07 - set *(unsigned char *)0x410080DE = 0x01 - # Setup PC28 - pmux 7 set *(unsigned char *)(0x41008000+0x80*2+0x30+28/2) &= ~0x0f set *(unsigned char *)(0x41008000+0x80*2+0x30+28/2) |= 0x07