一、第一阶段,无修改
二、第二阶段
u-boot-1.3.4\lib_arm\board.c
1.增加头文件
2.增加版本号
3.start_armboot中初始化部分
板级初始化部分init_sequence->board_init
3.1创建新单板资源头文件include\asm-arm\arch-at91sam9\at91sam9m10g45ek.h(地址与中断号)
文件书写思路:
1.参考同系列芯片的at91sam9263.h文件
2.外设标识符
3.用户外围物理基地址
4.系统外设物理基地址(基于系统控制寄存器)
5.内部存储基地址
参照图表:
附上源代码:
#ifndef AT91SAM9G45_H
#define AT91SAM9G45_H /*
* Peripheral identifiers/interrupts.
*/
#define AT91_ID_FIQ 0 /* Advanced Interrupt Controller (FIQ) */
#define AT91_ID_SYS 1 /* System Controller Interrupt */
#define AT91SAM9G45_ID_PIOA 2 /* Parallel I/O Controller A */
#define AT91SAM9G45_ID_PIOB 3 /* Parallel I/O Controller B */
#define AT91SAM9G45_ID_PIOC 4 /* Parallel I/O Controller C */
#define AT91SAM9G45_ID_PIODE 5 /* Parallel I/O Controller D and E */
#define AT91SAM9G45_ID_TRNG 6 /* True Random Number Generator */
#define AT91SAM9G45_ID_US0 7 /* USART 0 */
#define AT91SAM9G45_ID_US1 8 /* USART 1 */
#define AT91SAM9G45_ID_US2 9 /* USART 2 */
#define AT91SAM9G45_ID_US3 10 /* USART 3 */
#define AT91SAM9G45_ID_MCI0 11 /* High Speed Multimedia Card Interface 0 */
#define AT91SAM9G45_ID_TWI0 12 /* Two-Wire Interface 0 */
#define AT91SAM9G45_ID_TWI1 13 /* Two-Wire Interface 1 */
#define AT91SAM9G45_ID_SPI0 14 /* Serial Peripheral Interface 0 */
#define AT91SAM9G45_ID_SPI1 15 /* Serial Peripheral Interface 1 */
#define AT91SAM9G45_ID_SSC0 16 /* Synchronous Serial Controller 0 */
#define AT91SAM9G45_ID_SSC1 17 /* Synchronous Serial Controller 1 */
#define AT91SAM9G45_ID_TCB 18 /* Timer Counter 0, 1, 2, 3, 4 and 5 */
#define AT91SAM9G45_ID_PWMC 19 /* Pulse Width Modulation Controller */
#define AT91SAM9G45_ID_TSC 20 /* Touch Screen ADC Controller */
#define AT91SAM9G45_ID_DMA 21 /* DMA Controller */
#define AT91SAM9G45_ID_UHPHS 22 /* USB Host High Speed */
#define AT91SAM9G45_ID_LCDC 23 /* LCD Controller */
#define AT91SAM9G45_ID_AC97C 24 /* AC97 Controller */
#define AT91SAM9G45_ID_EMAC 25 /* Ethernet MAC */
#define AT91SAM9G45_ID_ISI 26 /* Image Sensor Interface */
#define AT91SAM9G45_ID_UDPHS 27 /* USB Device High Speed */
#define AT91SAM9G45_ID_AESTDESSHA 28 /* AES + T-DES + SHA */
#define AT91SAM9G45_ID_MCI1 29 /* High Speed Multimedia Card Interface 1 */
#define AT91SAM9G45_ID_VDEC 30 /* Video Decoder */
#define AT91SAM9G45_ID_IRQ0 31 /* Advanced Interrupt Controller */ /*
* User Peripheral physical base addresses.
*/
#define AT91SAM9G45_BASE_UDPHS 0xfff78000
#define AT91SAM9G45_BASE_TC0 0xfff7c000
#define AT91SAM9G45_BASE_TC1 0xfff7c040
#define AT91SAM9G45_BASE_TC2 0xfff7c080
#define AT91SAM9G45_BASE_MCI0 0xfff80000
#define AT91SAM9G45_BASE_TWI0 0xfff84000
#define AT91SAM9G45_BASE_TWI1 0xfff88000
#define AT91SAM9G45_BASE_US0 0xfff8c000
#define AT91SAM9G45_BASE_US1 0xfff90000
#define AT91SAM9G45_BASE_US2 0xfff94000
#define AT91SAM9G45_BASE_US3 0xfff98000
#define AT91SAM9G45_BASE_SSC0 0xfff9c000
#define AT91SAM9G45_BASE_SSC1 0xfffa0000
#define AT91SAM9G45_BASE_SPI0 0xfffa4000
#define AT91SAM9G45_BASE_SPI1 0xfffa8000
#define AT91SAM9G45_BASE_AC97C 0xfffac000
#define AT91SAM9G45_BASE_TSC 0xfffb0000
#define AT91SAM9G45_BASE_ISI 0xfffb4000
#define AT91SAM9G45_BASE_PWMC 0xfffb8000
#define AT91SAM9G45_BASE_EMAC 0xfffbc000
#define AT91SAM9G45_BASE_AES 0xfffc0000
#define AT91SAM9G45_BASE_TDES 0xfffc4000
#define AT91SAM9G45_BASE_SHA 0xfffc8000
#define AT91SAM9G45_BASE_TRNG 0xfffcc000
#define AT91SAM9G45_BASE_MCI1 0xfffd0000
#define AT91SAM9G45_BASE_TC3 0xfffd4000
#define AT91SAM9G45_BASE_TC4 0xfffd4040
#define AT91SAM9G45_BASE_TC5 0xfffd4080
#define AT91_BASE_SYS 0xffffe200 /*
* System Peripherals (offset from AT91_BASE_SYS)
*/
#define AT91_ECC (0xffffe200 - AT91_BASE_SYS)
#define AT91_DDRSDRC1 (0xffffe400 - AT91_BASE_SYS)
#define AT91_DDRSDRC0 (0xffffe600 - AT91_BASE_SYS)
#define AT91_SMC (0xffffe800 - AT91_BASE_SYS)
#define AT91_MATRIX (0xffffea00 - AT91_BASE_SYS)
#define AT91_DMA (0xffffec00 - AT91_BASE_SYS)
#define AT91_DBGU (0xffffee00 - AT91_BASE_SYS)
#define AT91_AIC (0xfffff000 - AT91_BASE_SYS)
#define AT91_PIOA (0xfffff200 - AT91_BASE_SYS)
#define AT91_PIOB (0xfffff400 - AT91_BASE_SYS)
#define AT91_PIOC (0xfffff600 - AT91_BASE_SYS)
#define AT91_PIOD (0xfffff800 - AT91_BASE_SYS)
#define AT91_PIOE (0xfffffa00 - AT91_BASE_SYS)
#define AT91_PMC (0xfffffc00 - AT91_BASE_SYS)
#define AT91_RSTC (0xfffffd00 - AT91_BASE_SYS)
#define AT91_SHDWC (0xfffffd10 - AT91_BASE_SYS)
#define AT91_RTT (0xfffffd20 - AT91_BASE_SYS)
#define AT91_PIT (0xfffffd30 - AT91_BASE_SYS)
#define AT91_WDT (0xfffffd40 - AT91_BASE_SYS)
#define AT91_GPBR (0xfffffd60 - AT91_BASE_SYS)
#define AT91_RTC (0xfffffdb0 - AT91_BASE_SYS) #define AT91_USART0 AT91SAM9G45_BASE_US0
#define AT91_USART1 AT91SAM9G45_BASE_US1
#define AT91_USART2 AT91SAM9G45_BASE_US2
#define AT91_USART3 AT91SAM9G45_BASE_US3 /*
* Internal Memory.
*/
#define AT91SAM9G45_SRAM_BASE 0x00300000 /* Internal SRAM base address */
#define AT91SAM9G45_SRAM_SIZE SZ_64K /* Internal SRAM size (64Kb) */ #define AT91SAM9G45_ROM_BASE 0x00400000 /* Internal ROM base address */
#define AT91SAM9G45_ROM_SIZE SZ_64K /* Internal ROM size (64Kb) */ #define AT91SAM9G45_LCDC_BASE 0x00500000 /* LCD Controller */
#define AT91SAM9G45_UDPHS_FIFO 0x00600000 /* USB Device HS controller */
#define AT91SAM9G45_HCI_BASE 0x00700000 /* USB Host controller (OHCI) */
#define AT91SAM9G45_EHCI_BASE 0x00800000 /* USB Host controller (EHCI) */
#define AT91SAM9G45_VDEC_BASE 0x00900000 /* Video Decoder Controller */ #define CONFIG_DRAM_BASE AT91_CHIPSELECT_6 #endif
at91sam9m10g45ek.h
3.2 创建单板总线矩阵头文件include\asm-arm\arch-at91sam9\at91sam9g45_matrix.h(地址)
文件书写思路:
1.参考同系列芯片的at91sam9263_matrix.h文件
2.寄存器映射表
参照图表:
附上源代码:
#ifndef AT91SAM9G45_MATRIX_H
#define AT91SAM9G45_MATRIX_H #define AT91_MATRIX_MCFG0 (AT91_MATRIX + 0x00) /* Master Configuration Register 0 */
#define AT91_MATRIX_MCFG1 (AT91_MATRIX + 0x04) /* Master Configuration Register 1 */
#define AT91_MATRIX_MCFG2 (AT91_MATRIX + 0x08) /* Master Configuration Register 2 */
#define AT91_MATRIX_MCFG3 (AT91_MATRIX + 0x0C) /* Master Configuration Register 3 */
#define AT91_MATRIX_MCFG4 (AT91_MATRIX + 0x10) /* Master Configuration Register 4 */
#define AT91_MATRIX_MCFG5 (AT91_MATRIX + 0x14) /* Master Configuration Register 5 */
#define AT91_MATRIX_MCFG6 (AT91_MATRIX + 0x18) /* Master Configuration Register 6 */
#define AT91_MATRIX_MCFG7 (AT91_MATRIX + 0x1C) /* Master Configuration Register 7 */
#define AT91_MATRIX_MCFG8 (AT91_MATRIX + 0x20) /* Master Configuration Register 8 */
#define AT91_MATRIX_MCFG9 (AT91_MATRIX + 0x24) /* Master Configuration Register 9 */
#define AT91_MATRIX_MCFG10 (AT91_MATRIX + 0x28) /* Master Configuration Register 10 */
#define AT91_MATRIX_MCFG11 (AT91_MATRIX + 0x2C) /* Master Configuration Register 11 */
#define AT91_MATRIX_ULBT (7 << 0) /* Undefined Length Burst Type */
#define AT91_MATRIX_ULBT_INFINITE (0 << 0)
#define AT91_MATRIX_ULBT_SINGLE (1 << 0)
#define AT91_MATRIX_ULBT_FOUR (2 << 0)
#define AT91_MATRIX_ULBT_EIGHT (3 << 0)
#define AT91_MATRIX_ULBT_SIXTEEN (4 << 0)
#define AT91_MATRIX_ULBT_THIRTYTWO (5 << 0)
#define AT91_MATRIX_ULBT_SIXTYFOUR (6 << 0)
#define AT91_MATRIX_ULBT_128 (7 << 0) #define AT91_MATRIX_SCFG0 (AT91_MATRIX + 0x40) /* Slave Configuration Register 0 */
#define AT91_MATRIX_SCFG1 (AT91_MATRIX + 0x44) /* Slave Configuration Register 1 */
#define AT91_MATRIX_SCFG2 (AT91_MATRIX + 0x48) /* Slave Configuration Register 2 */
#define AT91_MATRIX_SCFG3 (AT91_MATRIX + 0x4C) /* Slave Configuration Register 3 */
#define AT91_MATRIX_SCFG4 (AT91_MATRIX + 0x50) /* Slave Configuration Register 4 */
#define AT91_MATRIX_SCFG5 (AT91_MATRIX + 0x54) /* Slave Configuration Register 5 */
#define AT91_MATRIX_SCFG6 (AT91_MATRIX + 0x58) /* Slave Configuration Register 6 */
#define AT91_MATRIX_SCFG7 (AT91_MATRIX + 0x5C) /* Slave Configuration Register 7 */
#define AT91_MATRIX_SLOT_CYCLE (0x1ff << 0) /* Maximum Number of Allowed Cycles for a Burst */
#define AT91_MATRIX_DEFMSTR_TYPE (3 << 16) /* Default Master Type */
#define AT91_MATRIX_DEFMSTR_TYPE_NONE (0 << 16)
#define AT91_MATRIX_DEFMSTR_TYPE_LAST (1 << 16)
#define AT91_MATRIX_DEFMSTR_TYPE_FIXED (2 << 16)
#define AT91_MATRIX_FIXED_DEFMSTR (0xf << 18) /* Fixed Index of Default Master */ #define AT91_MATRIX_PRAS0 (AT91_MATRIX + 0x80) /* Priority Register A for Slave 0 */
#define AT91_MATRIX_PRBS0 (AT91_MATRIX + 0x84) /* Priority Register B for Slave 0 */
#define AT91_MATRIX_PRAS1 (AT91_MATRIX + 0x88) /* Priority Register A for Slave 1 */
#define AT91_MATRIX_PRBS1 (AT91_MATRIX + 0x8C) /* Priority Register B for Slave 1 */
#define AT91_MATRIX_PRAS2 (AT91_MATRIX + 0x90) /* Priority Register A for Slave 2 */
#define AT91_MATRIX_PRBS2 (AT91_MATRIX + 0x94) /* Priority Register B for Slave 2 */
#define AT91_MATRIX_PRAS3 (AT91_MATRIX + 0x98) /* Priority Register A for Slave 3 */
#define AT91_MATRIX_PRBS3 (AT91_MATRIX + 0x9C) /* Priority Register B for Slave 3 */
#define AT91_MATRIX_PRAS4 (AT91_MATRIX + 0xA0) /* Priority Register A for Slave 4 */
#define AT91_MATRIX_PRBS4 (AT91_MATRIX + 0xA4) /* Priority Register B for Slave 4 */
#define AT91_MATRIX_PRAS5 (AT91_MATRIX + 0xA8) /* Priority Register A for Slave 5 */
#define AT91_MATRIX_PRBS5 (AT91_MATRIX + 0xAC) /* Priority Register B for Slave 5 */
#define AT91_MATRIX_PRAS6 (AT91_MATRIX + 0xB0) /* Priority Register A for Slave 6 */
#define AT91_MATRIX_PRBS6 (AT91_MATRIX + 0xB4) /* Priority Register B for Slave 6 */
#define AT91_MATRIX_PRAS7 (AT91_MATRIX + 0xB8) /* Priority Register A for Slave 7 */
#define AT91_MATRIX_PRBS7 (AT91_MATRIX + 0xBC) /* Priority Register B for Slave 7 */
#define AT91_MATRIX_M0PR (3 << 0) /* Master 0 Priority */
#define AT91_MATRIX_M1PR (3 << 4) /* Master 1 Priority */
#define AT91_MATRIX_M2PR (3 << 8) /* Master 2 Priority */
#define AT91_MATRIX_M3PR (3 << 12) /* Master 3 Priority */
#define AT91_MATRIX_M4PR (3 << 16) /* Master 4 Priority */
#define AT91_MATRIX_M5PR (3 << 20) /* Master 5 Priority */
#define AT91_MATRIX_M6PR (3 << 24) /* Master 6 Priority */
#define AT91_MATRIX_M7PR (3 << 28) /* Master 7 Priority */
#define AT91_MATRIX_M8PR (3 << 0) /* Master 8 Priority (in Register B) */
#define AT91_MATRIX_M9PR (3 << 4) /* Master 9 Priority (in Register B) */
#define AT91_MATRIX_M10PR (3 << 8) /* Master 10 Priority (in Register B) */
#define AT91_MATRIX_M11PR (3 << 12) /* Master 11 Priority (in Register B) */ #define AT91_MATRIX_MRCR (AT91_MATRIX + 0x100) /* Master Remap Control Register */
#define AT91_MATRIX_RCB0 (1 << 0) /* Remap Command for AHB Master 0 (ARM926EJ-S Instruction Master) */
#define AT91_MATRIX_RCB1 (1 << 1) /* Remap Command for AHB Master 1 (ARM926EJ-S Data Master) */
#define AT91_MATRIX_RCB2 (1 << 2)
#define AT91_MATRIX_RCB3 (1 << 3)
#define AT91_MATRIX_RCB4 (1 << 4)
#define AT91_MATRIX_RCB5 (1 << 5)
#define AT91_MATRIX_RCB6 (1 << 6)
#define AT91_MATRIX_RCB7 (1 << 7)
#define AT91_MATRIX_RCB8 (1 << 8)
#define AT91_MATRIX_RCB9 (1 << 9)
#define AT91_MATRIX_RCB10 (1 << 10)
#define AT91_MATRIX_RCB11 (1 << 11) #define AT91_MATRIX_TCMR (AT91_MATRIX + 0x110) /* TCM Configuration Register */
#define AT91_MATRIX_ITCM_SIZE (0xf << 0) /* Size of ITCM enabled memory block */
#define AT91_MATRIX_ITCM_0 (0 << 0)
#define AT91_MATRIX_ITCM_32 (6 << 0)
#define AT91_MATRIX_DTCM_SIZE (0xf << 4) /* Size of DTCM enabled memory block */
#define AT91_MATRIX_DTCM_0 (0 << 4)
#define AT91_MATRIX_DTCM_32 (6 << 4)
#define AT91_MATRIX_DTCM_64 (7 << 4)
#define AT91_MATRIX_TCM_NWS (0x1 << 11) /* Wait state TCM register */
#define AT91_MATRIX_TCM_NO_WS (0x0 << 11)
#define AT91_MATRIX_TCM_ONE_WS (0x1 << 11) #define AT91_MATRIX_VIDEO (AT91_MATRIX + 0x118) /* Video Mode Configuration Register */
#define AT91C_VDEC_SEL (0x1 << 0) /* Video Mode Selection */
#define AT91C_VDEC_SEL_OFF (0 << 0)
#define AT91C_VDEC_SEL_ON (1 << 0) #define AT91_MATRIX_EBICSA (AT91_MATRIX + 0x128) /* EBI Chip Select Assignment Register */
#define AT91_MATRIX_EBI_CS1A (1 << 1) /* Chip Select 1 Assignment */
#define AT91_MATRIX_EBI_CS1A_SMC (0 << 1)
#define AT91_MATRIX_EBI_CS1A_SDRAMC (1 << 1)
#define AT91_MATRIX_EBI_CS3A (1 << 3) /* Chip Select 3 Assignment */
#define AT91_MATRIX_EBI_CS3A_SMC (0 << 3)
#define AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA (1 << 3)
#define AT91_MATRIX_EBI_CS4A (1 << 4) /* Chip Select 4 Assignment */
#define AT91_MATRIX_EBI_CS4A_SMC (0 << 4)
#define AT91_MATRIX_EBI_CS4A_SMC_CF0 (1 << 4)
#define AT91_MATRIX_EBI_CS5A (1 << 5) /* Chip Select 5 Assignment */
#define AT91_MATRIX_EBI_CS5A_SMC (0 << 5)
#define AT91_MATRIX_EBI_CS5A_SMC_CF1 (1 << 5)
#define AT91_MATRIX_EBI_DBPUC (1 << 8) /* Data Bus Pull-up Configuration */
#define AT91_MATRIX_EBI_DBPU_ON (0 << 8)
#define AT91_MATRIX_EBI_DBPU_OFF (1 << 8)
#define AT91_MATRIX_EBI_VDDIOMSEL (1 << 16) /* Memory voltage selection */
#define AT91_MATRIX_EBI_VDDIOMSEL_1_8V (0 << 16)
#define AT91_MATRIX_EBI_VDDIOMSEL_3_3V (1 << 16)
#define AT91_MATRIX_EBI_EBI_IOSR (1 << 17) /* EBI I/O slew rate selection */
#define AT91_MATRIX_EBI_EBI_IOSR_REDUCED (0 << 17)
#define AT91_MATRIX_EBI_EBI_IOSR_NORMAL (1 << 17)
#define AT91_MATRIX_EBI_DDR_IOSR (1 << 18) /* DDR2 dedicated port I/O slew rate selection */
#define AT91_MATRIX_EBI_DDR_IOSR_REDUCED (0 << 18)
#define AT91_MATRIX_EBI_DDR_IOSR_NORMAL (1 << 18) #define AT91_MATRIX_WPMR (AT91_MATRIX + 0x1E4) /* Write Protect Mode Register */
#define AT91_MATRIX_WPMR_WPEN (1 << 0) /* Write Protect ENable */
#define AT91_MATRIX_WPMR_WP_WPDIS (0 << 0)
#define AT91_MATRIX_WPMR_WP_WPEN (1 << 0)
#define AT91_MATRIX_WPMR_WPKEY (0xFFFFFF << 8) /* Write Protect KEY */ #define AT91_MATRIX_WPSR (AT91_MATRIX + 0x1E8) /* Write Protect Status Register */
#define AT91_MATRIX_WPSR_WPVS (1 << 0) /* Write Protect Violation Status */
#define AT91_MATRIX_WPSR_NO_WPV (0 << 0)
#define AT91_MATRIX_WPSR_WPV (1 << 0)
#define AT91_MATRIX_WPSR_WPVSRC (0xFFFF << 8) /* Write Protect Violation Source */ #endif
at91sam9g45_matrix.h
3.3 创建单板初始化文件u-boot-1.3.4/board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
文件书写思路:
1)参考同系列芯片的at91sam9263ek.c文件
2)初始化队列中board_init()
2.1)控制台初始化
2.2)机器ID初始化
2.3)启动参数存储地址初始化
2.4)串口硬件初始化
2.4.1)设置复用GPIO口为A设备
2.4.2)写寄存器,使能时钟开启(参数是外设标识符)
2.5)nandflash硬件初始化
2.5.1) 读取片选寄存器
2.5.2) 设置EBI片选3分配给静态存储控制器
2.5.3) 设置静态存储控制器
2.5.4) 外设时钟开启寄存器,并行IO控制器C
2.5.5) C8初始化为输入
2.5.6) C14初始化为输出
2.6)spi硬件初始化
2.6.1) 设置B3为复用GPIO口B设备,用作NPCS0
2.6.2) 设置B0为复用GPIO口B设备,用作MISO0
2.6.3) 设置B1为复用GPIO口B设备,用作MOSI0
2.6.4) 设置B2为复用GPIO口B设备,用作SPCK0
2.6.5) 写寄存器,使能时钟开启(参数是外设标识符SPI0)
2.7)macb硬件初始化
2.7.1) 禁止上拉A15 A12 A13
2.7.2) 读取复位寄存模式寄存器
2.7.3) 设置复位寄存器周期,允许复位
2.7.4) 设置外部复位
2.7.5) 等待硬件复位结束
2.7.6) 设置允许复位
2.7.7) 使能上拉A15 A12 A13
2.7.8) 复用IO A10-19 为A设备 功能:ETXCK_EREFCK、ERXDV、ERX0、ERX1、ERXER、ETXEN、ETX0、ETX1、EMDIO、EMDC
2.7.9) 复用IO A6-9 A27-30 为B设备 功能:ECRS、ECOL、ERX2、ERX3、ERXCK、ETX2、ETX3、ETXER
2.7.10) D5引脚复位
2.8)lcd硬件初始化
2.8.1) 复用IO E0 E4-30 为A设备 功能:LCDDPWR、LCDHSYNC、LCDDOTCK、LCDDEN、LCDD0-23
2.8.1) 外设时钟开启寄存器,LCD
3) 初始化队列中dram_init()
3.1) 初始化RAM起始地址0x70000000
3.2) 初始化RAM大小0x08000000
附上源码:
#include <common.h>
#include <asm/sizes.h>
#include <asm/arch/at91sam9g45.h>
#include <asm/arch/at91sam9g45_matrix.h>
#include <asm/arch/at91sam9_smc.h>
#include <asm/arch/at91_pmc.h>
#include <asm/arch/at91_rstc.h>
#include <asm/arch/gpio.h>
#include <asm/arch/io.h>
#include <lcd.h>
//#include <asm_blackfin/delay.h> //have udelay()
#include <atmel_lcdc.h>
#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
#include <net.h>
#endif DECLARE_GLOBAL_DATA_PTR; /* ------------------------------------------------------------------------- */
/*
* Miscelaneous platform dependent initialisations
*/ static void at91samm10g45ek_serial_hw_init(void)
{
#ifdef CONFIG_USART0
at91_set_A_periph(AT91_PIN_PB19, ); /* TXD0 */
at91_set_A_periph(AT91_PIN_PB18, ); /* RXD0 */
at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_US0);
#endif #ifdef CONFIG_USART1
at91_set_A_periph(AT91_PIN_PB4, ); /* TXD1 */
at91_set_A_periph(AT91_PIN_PB5, ); /* RXD1 */
at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_US1);
#endif #ifdef CONFIG_USART2
at91_set_A_periph(AT91_PIN_PD6, ); /* TXD2 */
at91_set_A_periph(AT91_PIN_PD7, ); /* RXD2 */
at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_US2);
#endif #ifdef CONFIG_USART3 /* DBGU */
at91_set_A_periph(AT91_PIN_PB12, ); /* DRXD */
at91_set_A_periph(AT91_PIN_PB13, ); /* DTXD */
at91_sys_write(AT91_PMC_PCER, << AT91_ID_SYS);
#endif
} #ifdef CONFIG_CMD_NAND
static void at91samm10g45ek_nand_hw_init(void)
{
unsigned long csa; /* Enable CS3 */
//EBI 片选 3 分配给静态存储控制器
csa = at91_sys_read(AT91_MATRIX_EBICSA);
at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA); /* Configure SMC CS3 for NAND/SmartMedia */
//NWE 建立时长=(128 X NWE_SETUP[5] + NWE_SETUP[4:0])时钟周期
//NCS 建立时长=(128 X NCS_WR_SETUP[5] + NCS_WR_SETUP[4:0])时钟周期
//NRD 建立时长=(128 X NRD_SETUP[5] + NRD_SETUP[4:0])时钟周期
//NCS 建立时长=(128 X NCS_RD_SETUP[5] + NCS_RD_SETUP[4:0])时钟周期
at91_sys_write(AT91_SMC_SETUP(),
AT91_SMC_NWESETUP_() | AT91_SMC_NCS_WRSETUP_() |
AT91_SMC_NRDSETUP_() | AT91_SMC_NCS_RDSETUP_());
//NWE 脉宽=(256 X NWE_PULSE[6] + NWE_PULSE[5:0])时钟周期
//NCS 脉宽=(256 X NCS_WR_PULSE[6] + NCS_WR_PULSE[5:0])时钟周期
//NRD 脉宽=(256 X NRD_PULSE[6] + NRD_PULSE[5:0])时钟周期
//NCS 脉宽=(256 X NCS_RD_PULSE[6] + NCS_RD_PULSE[5:0])时钟周期
at91_sys_write(AT91_SMC_PULSE(),
AT91_SMC_NWEPULSE_() | AT91_SMC_NCS_WRPULSE_() |
AT91_SMC_NRDPULSE_() | AT91_SMC_NCS_RDPULSE_());
//写周期长度=(NWE_CYCLE[8:7] X 256 + NWE_CYCLE[6:0])时钟周期
//读周期长度=(NRD_CYCLE[8:7] X 256 + NRD_CYCLE[6:0])时钟周期
at91_sys_write(AT91_SMC_CYCLE(),
AT91_SMC_NWECYCLE_() | AT91_SMC_NRDCYCLE_());
//读操作是由 NRD 信号来控制的。
//写操作是由 NWE 信号控制的
//NWAIT 是用来扩展当前的读或写信号的,它只在读和写控制信号的脉宽才会被考虑。如果NWAIT 启用了,在读和写控制信号中必须设置至少一个周期。
//数据总线宽度8-位总线
//数据浮动时间: 外部设备在读控制信号上升沿后释放数据的整数个周期时间
at91_sys_write(AT91_SMC_MODE(),
AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
AT91_SMC_EXNWMODE_DISABLE |
#ifdef CFG_NAND_DBW_16
AT91_SMC_DBW_16 |
#else /* CFG_NAND_DBW_8 */
AT91_SMC_DBW_8 |
#endif
AT91_SMC_TDF_());
//外设时钟开启寄存器 并行IO控制器C
at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_PIOC); /* Configure RDY/BSY */
//输入初始化
at91_set_gpio_input(AT91_PIN_PC8, ); /* Enable NandFlash */
//输出初始化
at91_set_gpio_output(AT91_PIN_PC14, );
}
#endif #ifdef CONFIG_HAS_DATAFLASH
static void at91samm10g45ek_spi_hw_init(void)
{
at91_set_B_periph(AT91_PIN_PB3, ); /* SPI0_NPCS0 */ at91_set_B_periph(AT91_PIN_PB0, ); /* SPI0_MISO */
at91_set_B_periph(AT91_PIN_PB1, ); /* SPI0_MOSI */
at91_set_B_periph(AT91_PIN_PB2, ); /* SPI0_SPCK */ /* Enable clock */
at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_SPI0);
}
#endif #ifdef CONFIG_MACB
/***********md9161 reset test****************/
//D5脚复位网卡
static void macb_reset(void)
{
int i; at91_set_gpio_output(AT91_PIN_PD5,); //puts("macb_reset... \n");
for(i=;i<;i++)
{
;
} // udelay(200*1000); at91_set_gpio_output(AT91_PIN_PD5,); } /***************************************/
static void at91samm10g45ek_macb_hw_init(void)
{
unsigned long rstc; // macb_reset();//reset dm9161 /* Enable clock */
at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_EMAC); /*
* Disable pull-up on:
* RXDV (PA15) => PHY normal mode (not Test mode)
* ERX0 (PA12) => PHY ADDR0
* ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
*
* PHY has internal pull-down
*/ /*AC97*/
//at91_set_A_periph(AT91_PIN_PD8, 0); /* AC97FS */
//at91_set_A_periph(AT91_PIN_PD7, 0); /* AC97TX */
//禁止上拉 A15 A12 A13
writel(pin_to_mask(AT91_PIN_PA15) |
pin_to_mask(AT91_PIN_PA12) |
pin_to_mask(AT91_PIN_PA13),
pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
//读取复位寄存模式寄存器
rstc = at91_sys_read(AT91_RSTC_MR); /* Need to reset PHY -> 500ms reset */
//KEY:应该设为 0xA5。如果设成其他值,会中止写操作
//外部复位的时长,这个值为 2 (ERSTL+1) 个低速时钟周期。所以这个值的范围
//检测到 NRST (复位)引脚一个 low 电平,触发一个用户复位
at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
(AT91_RSTC_ERSTL & (0x0D << )) |
AT91_RSTC_URSTEN);
// 复位控制器控制寄存器
//外部复位:如果 KEY 正确,插入 NRST (复位)引脚
at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST); //复位控制器状态寄存器
//读取以主控制器时钟频率(MCK)锁存 NRST (复位)引脚的电平 目的:等待硬件复位结束
while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL)); /* Restore NRST value */
//如果检测到 NRST (复位)引脚一个 low 电平,触发一个用户复位
at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
(rstc) |
AT91_RSTC_URSTEN);
//使能上拉 A15 A12 A13
/* Re-enable pull-up */
writel(pin_to_mask(AT91_PIN_PA15) |
pin_to_mask(AT91_PIN_PA12) |
pin_to_mask(AT91_PIN_PA13),
pin_to_controller(AT91_PIN_PA0) + PIO_PUER); //at91_set_gpio_output(AT91_PIN_PA30,1); //pull up PA30
//复用IO A10-19 为A设备
at91_set_A_periph(AT91_PIN_PA17, ); /* ETXCK_EREFCK */
at91_set_A_periph(AT91_PIN_PA15, ); /* ERXDV */
at91_set_A_periph(AT91_PIN_PA12, ); /* ERX0 */
at91_set_A_periph(AT91_PIN_PA13, ); /* ERX1 */
at91_set_A_periph(AT91_PIN_PA16, ); /* ERXER */
at91_set_A_periph(AT91_PIN_PA14, ); /* ETXEN */
at91_set_A_periph(AT91_PIN_PA10, ); /* ETX0 */
at91_set_A_periph(AT91_PIN_PA11, ); /* ETX1 */
at91_set_A_periph(AT91_PIN_PA19, ); /* EMDIO */
at91_set_A_periph(AT91_PIN_PA18, ); /* EMDC */ #ifndef CONFIG_RMII
//复用IO A6-9 A27-30 为B设备
at91_set_B_periph(AT91_PIN_PA29, ); /* ECRS */
at91_set_B_periph(AT91_PIN_PA30, ); /* ECOL */
at91_set_B_periph(AT91_PIN_PA8, ); /* ERX2 */
at91_set_B_periph(AT91_PIN_PA9, ); /* ERX3 */
at91_set_B_periph(AT91_PIN_PA28, ); /* ERXCK */
at91_set_B_periph(AT91_PIN_PA6, ); /* ETX2 */
at91_set_B_periph(AT91_PIN_PA7, ); /* ETX3 */
at91_set_B_periph(AT91_PIN_PA27, ); /* ETXER */
#endif
macb_reset();//reset dm9161
//printf("macb_reset...\n");
}
#endif #ifdef CONFIG_LCD
vidinfo_t panel_info = {
vl_col: ,
vl_row: ,
vl_clk: ,
vl_sync: ATMEL_LCDC_INVLINE_NORMAL |
ATMEL_LCDC_INVFRAME_NORMAL,
vl_bpix: ,
vl_tft: ,
vl_hsync_len: ,
vl_left_margin: ,
vl_right_margin:,
vl_vsync_len: ,
vl_upper_margin:,
vl_lower_margin:,
mmio: AT91SAM9G45_LCDC_BASE,
}; void lcd_enable(void)
{
at91_set_gpio_value(AT91_PIN_PE6, ); /* power up */
} void lcd_disable(void)
{
at91_set_gpio_value(AT91_PIN_PE6, ); /* power down */
} static void at91samm10g45ek_lcd_hw_init(void)
{
at91_set_A_periph(AT91_PIN_PE0, ); /* LCDDPWR */ at91_set_A_periph(AT91_PIN_PE4, ); /* LCDHSYNC */
at91_set_A_periph(AT91_PIN_PE5, ); /* LCDDOTCK */ at91_set_gpio_input(AT91_PIN_PE6, ); /* LCDDEN */ at91_set_A_periph(AT91_PIN_PE7, ); /* LCDD0 */
at91_set_A_periph(AT91_PIN_PE8, ); /* LCDD1 */
at91_set_A_periph(AT91_PIN_PE9, ); /* LCDD2 */
at91_set_A_periph(AT91_PIN_PE10, ); /* LCDD3 */
at91_set_A_periph(AT91_PIN_PE11, ); /* LCDD4 */
at91_set_A_periph(AT91_PIN_PE12, ); /* LCDD5 */
at91_set_A_periph(AT91_PIN_PE13, ); /* LCDD6 */
at91_set_A_periph(AT91_PIN_PE14, ); /* LCDD7 */
at91_set_A_periph(AT91_PIN_PE15, ); /* LCDD8 */
at91_set_A_periph(AT91_PIN_PE16, ); /* LCDD9 */
at91_set_A_periph(AT91_PIN_PE17, ); /* LCDD10 */
at91_set_A_periph(AT91_PIN_PE18, ); /* LCDD11 */
at91_set_A_periph(AT91_PIN_PE19, ); /* LCDD12 */
at91_set_B_periph(AT91_PIN_PE20, ); /* LCDD13 */
at91_set_A_periph(AT91_PIN_PE21, ); /* LCDD14 */
at91_set_A_periph(AT91_PIN_PE22, ); /* LCDD15 */
at91_set_A_periph(AT91_PIN_PE23, ); /* LCDD16 */
at91_set_A_periph(AT91_PIN_PE24, ); /* LCDD17 */
at91_set_A_periph(AT91_PIN_PE25, ); /* LCDD18 */
at91_set_A_periph(AT91_PIN_PE26, ); /* LCDD19 */
at91_set_A_periph(AT91_PIN_PE27, ); /* LCDD20 */
at91_set_B_periph(AT91_PIN_PE28, ); /* LCDD21 */
at91_set_A_periph(AT91_PIN_PE29, ); /* LCDD22 */
at91_set_A_periph(AT91_PIN_PE30, ); /* LCDD23 */ at91_sys_write(AT91_PMC_PCER, << AT91SAM9G45_ID_LCDC); gd->fb_base = AT91SAM9G45_SRAM_BASE;
}
#endif #if defined(CONFIG_MACB) && defined(CONFIG_CMD_NET)
extern int macb_eth_initialize(int id, void *regs, unsigned int phy_addr); int board_eth_init(bd_t *bis)
{
macb_eth_initialize(, (void *)AT91SAM9G45_BASE_EMAC, 0x00);
}
#endif int board_init(void)
{
/* Enable Ctrlc */
console_init_f();
/* arch number of AT91SAM9M10G45EK-Board */
#ifdef CONFIG_AT91SAM9M10G45EK
gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10G45EK;
#elif defined CONFIG_AT91SAM9G45EKES
gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9G45EKES;
#elif defined CONFIG_AT91SAM9M10EKES
gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9M10EKES;
#endif
/* adress of boot parameters */
gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;//启动参数地址,DDR内存位置 at91samm10g45ek_serial_hw_init();
#ifdef CONFIG_CMD_NAND
at91samm10g45ek_nand_hw_init();
#endif
#ifdef CONFIG_HAS_DATAFLASH
at91samm10g45ek_spi_hw_init();
#endif
#ifdef CONFIG_MACB
at91samm10g45ek_macb_hw_init();
#endif #ifdef CONFIG_LCD
at91samm10g45ek_lcd_hw_init();
#endif
return ;
} int dram_init(void)
{
gd->bd->bi_dram[].start = PHYS_SDRAM;
gd->bd->bi_dram[].size = PHYS_SDRAM_SIZE;
printf("\n++++++++++++++++++++++++++++++++++++++++++++\n");
return ;
} #ifdef CONFIG_RESET_PHY_R
void reset_phy(void)
{
#ifdef CONFIG_MACB
/*
* Initialize ethernet HW addr prior to starting Linux,
* needed for nfsroot
*/
//puts("reset_phy \n");
eth_init(gd->bd);
#endif
}
#endif
board\atmel\at91sam9m10g45ek\at91sam9m10g45ek.c
3.4 board.c中NAND初始化
1) drivers\mtd\nand\nand.c标准函数nand_init->nand_init_chip->board_nand_init
2) 增加nand文件board\atmel\at91sam9m10g45ek\nand.c
2.1) board_nand_init初始化函数
2.1.1) 初始化eccmode 软件ECC对应字节数
2.1.2) 初始化options 总线宽度
2.1.3) 初始化hwcontrol 硬件控制函数
2.1.4) 初始化dev_ready 准备就绪函数
2.1.5) 初始化chip_delay 芯片时序延迟参数
2.2) hwcontrol 硬件控制函数
2.3) dev_ready 准备就绪函数
3.5 board.c中NOR初始化 使用的AT45DB161 2M NOR Flash
1) drivers\mtd\dataflash.c标准函数AT91F_DataflashInit->AT91F_SpiInit->AT91F_DataflashProbe 得到ID=c2 即AT45DB161
2) 依据ID初始化页数量、页大小、页偏移、基地址