Skip to content

Commit e6070c6

Browse files
committed
SAMA5D3: Hal fixes, add DBGU, enable ARM_ASM
1 parent c124702 commit e6070c6

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

config/examples/sama5d3.config

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ HASH?=SHA256
55
DEBUG?=0
66
VTOR?=1
77
CORTEX_M0?=0
8-
NO_ASM?=0
98
EXT_FLASH?=1
109
NAND_FLASH?=1
1110
SPI_FLASH?=0
1211
V?=0
1312
SPMATH?=1
14-
WOLFBOOT_PARTITION_SIZE?=0x1000000
13+
WOLFBOOT_PARTITION_SIZE?=0x8000000
1514
WOLFBOOT_NO_PARTITIONS=0
1615
WOLFBOOT_SECTOR_SIZE?=0x1000
17-
WOLFBOOT_LOAD_ADDRESS=0x20100800
18-
WOLFBOOT_LOAD_DTS_ADDRESS=0x21100800
16+
WOLFBOOT_LOAD_ADDRESS=0x20100000
17+
WOLFBOOT_LOAD_DTS_ADDRESS=0x21100000
1918
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x400000
2019
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x800000
2120
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x0

hal/sama5d3.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)
666666
return len;
667667
}
668668

669-
void pit_init(void)
669+
static void pit_init(void)
670670
{
671671
uint32_t pmc_pcr;
672672

@@ -697,6 +697,29 @@ void sleep_us(uint32_t usec)
697697
} while (current < delay);
698698
}
699699

700+
/* Set up DBGU.
701+
* Assume baud rate is correcly set by RomBoot
702+
*/
703+
static void dbgu_init(void) {
704+
/* Set up pins */
705+
PMC_CLOCK_EN(GPIOB_PMCID);
706+
707+
/* Disable Pull */
708+
GPIO_PPUDR(DBGU_GPIO) = (1 << DBGU_PIN_TX) | (1 << DBGU_PIN_RX);
709+
GPIO_PPDDR(DBGU_GPIO) = (1 << DBGU_PIN_TX) | (1 << DBGU_PIN_RX);
710+
711+
/* Set "Peripheral A" */
712+
GPIO_ASR(DBGU_GPIO) = (1 << DBGU_PIN_TX) | (1 << DBGU_PIN_RX);
713+
714+
/* Enable the peripheral clock for the DBGU */
715+
PMC_CLOCK_EN(DBGU_PMCID);
716+
717+
/* Enable the transmitter and receiver */
718+
DBGU_CR = DBGU_CR_TXEN | DBGU_CR_RXEN;
719+
}
720+
721+
722+
700723
int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
701724
{
702725
/* TODO */
@@ -742,6 +765,7 @@ void hal_init(void)
742765
pit_init();
743766
watchdog_disable();
744767
ddr_init();
768+
dbgu_init();
745769
nand_read_info();
746770
}
747771

hal/sama5d3.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393
#define PMC_PCR_DIV_SHIFT 13
9494
#define PMC_PCR_DIV_MASK (0x3 << PMC_PCR_DIV_SHIFT)
9595

96-
97-
9896
/* Specific configuration for 264/132/12 MHz */
9997

10098
#define PLL_PCK (((CRYSTAL_FREQ * (PLLA_MULA + 1)) / 2))
@@ -110,23 +108,33 @@
110108

111109
#define PLLICPR_CONFIG (0x0 << PMC_PLLICPR_ICPPLLA_SHIFT | 0x3 << PMC_PLLICPR_IPLLA_SHIFT)
112110

111+
/* DBGU
112+
*
113+
*/
114+
#define DBGU_BASE 0xFFFFEE00
115+
#define DBGU_CR *(volatile uint32_t *)(DBGU_BASE + 0x00)
116+
#define DBGU_BRGR *(volatile uint32_t *)(DBGU_BASE + 0x20)
117+
#define DBGU_CR_RXEN (1 << 4)
118+
#define DBGU_CR_TXEN (1 << 6)
119+
#define DBGU_PMCID 0x02 /* dec: 2 for SAMA5D3 */
120+
121+
/* Associated pins : GPIOB 30 - 31*/
122+
#define DBGU_PIN_RX 30
123+
#define DBGU_PIN_TX 31
124+
#define DBGU_GPIO GPIOB
113125

114126
/* PIT
115127
*
116128
*/
117-
118129
#define PIT_BASE 0xFFFFFE30
119130
#define PIT_MR *(volatile uint32_t *)(PIT_BASE + 0x00)
120131
#define PIT_SR *(volatile uint32_t *)(PIT_BASE + 0x04)
121132
#define PIT_PIVR *(volatile uint32_t *)(PIT_BASE + 0x08)
122133
#define PIT_PIIR *(volatile uint32_t *)(PIT_BASE + 0x0C)
123134

124-
125-
126-
127135
/* DRAM setup
136+
*
128137
*/
129-
130138
#define MPDDRC_BASE 0xFFFFEA00
131139
#define MPDDRC_MR *(volatile uint32_t *)(MPDDRC_BASE + 0x00) /* Mode Register */
132140
#define MPDDRC_RTR *(volatile uint32_t *)(MPDDRC_BASE + 0x04) /* Refresh Timer Register */
@@ -159,7 +167,6 @@
159167
#define MPDDRC_WPMR *(volatile uint32_t *)(MPDDRC_BASE + 0xE4) /* Write Protection Mode Register */
160168
#define MPDDRC_WPSR *(volatile uint32_t *)(MPDDRC_BASE + 0xE8) /* Write Protection Status Register */
161169

162-
163170
/* MPDDRC_CR: shift, mask, values */
164171
#define MPDDRC_NC_SHIFT 0 /* Number of Column Bits */
165172
#define MPDDRC_NC_MASK (0x3 << MPDDRC_NC_SHIFT)
@@ -285,8 +292,6 @@
285292
#define GPIOD_PMCID 0x09
286293
#define GPIOE_PMCID 0x0A
287294

288-
289-
290295
struct dram {
291296
struct dram_timing {
292297
uint32_t tras;
@@ -310,6 +315,7 @@ struct dram {
310315
};
311316

312317
/* Watchdog
318+
*
313319
*/
314320
#define WDT_BASE 0xFFFFFD40
315321
#define WDT_CR *(volatile uint32_t *)(WDT_BASE + 0x00)
@@ -435,7 +441,6 @@ extern void *kernel_addr, *update_addr, *dts_addr;
435441
#define MAX_ECC_BYTES 8
436442
#endif
437443

438-
439444
#define GPIOB 0xFFFFF400
440445
#define GPIOC 0xFFFFF600
441446
#define GPIOE 0xFFFFFA00
@@ -454,6 +459,7 @@ extern void *kernel_addr, *update_addr, *dts_addr;
454459
#define GPIO_MDDR(base) *(volatile uint32_t *)(base + 0x54)
455460
#define GPIO_PPUDR(base) *(volatile uint32_t *)(base + 0x60)
456461
#define GPIO_PPUER(base) *(volatile uint32_t *)(base + 0x64)
462+
#define GPIO_ASR(base) *(volatile uint32_t *)(base + 0x70)
457463
#define GPIO_PPDDR(base) *(volatile uint32_t *)(base + 0x90)
458464

459465

test-app/ARM-sama5d3.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ OUTPUT_ARCH(arm)
33

44
MEMORY
55
{
6-
DDR_MEM(rwx): ORIGIN = 0x20100800, LENGTH = 0x100000
6+
DDR_MEM(rwx): ORIGIN = 0x20100000, LENGTH = 0x100000
77
STACK_MEM(rw): ORIGIN = 0x20000000, LENGTH = 0x00100000
88
}
99

0 commit comments

Comments
 (0)