From ecc8db0cd66413eec9231c80c4b51456007ecc45 Mon Sep 17 00:00:00 2001 From: weety Date: Sat, 21 Oct 2017 17:37:10 +0800 Subject: [PATCH 1/2] [BSP][at91sam9260] Cleanup Code. --- bsp/at91sam9260/applications/application.c | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/bsp/at91sam9260/applications/application.c b/bsp/at91sam9260/applications/application.c index 50373d89fd..cbb1899ad0 100644 --- a/bsp/at91sam9260/applications/application.c +++ b/bsp/at91sam9260/applications/application.c @@ -48,6 +48,8 @@ static int rt_led_app_init(void); int main(void) { + int timeout = 0; + /* Filesystem Initialization */ #ifdef RT_USING_DFS { @@ -74,21 +76,27 @@ int main(void) rt_mmcsd_core_init(); rt_mmcsd_blk_init(); at91_mci_init(); - rt_thread_delay(RT_TICK_PER_SECOND*2); - /* mount sd card fat partition 1 as root directory */ + timeout = 0; + while ((rt_device_find("sd0") == RT_NULL) && (timeout++ < RT_TICK_PER_SECOND*2)) + { + rt_thread_delay(1); + } + + if (timeout < RT_TICK_PER_SECOND*2) + { + /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("File System initialized!\n"); } else - rt_kprintf("File System initialzation failed!\n"); -#endif + rt_kprintf("File System initialzation failed!%d\n", rt_get_errno()); + } + else + { + rt_kprintf("No SD card found.\n"); } #endif - -#ifdef RT_USING_I2C - { - rt_i2c_core_init(); } #endif From ab7d4fd6653f5a4d31f4fd7aa47be3459a8f51e0 Mon Sep 17 00:00:00 2001 From: weety Date: Sat, 21 Oct 2017 17:38:22 +0800 Subject: [PATCH 2/2] [BSP][at91sam9260] Support rt_hw_console_output function. --- bsp/at91sam9260/drivers/board.c | 98 +++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/bsp/at91sam9260/drivers/board.c b/bsp/at91sam9260/drivers/board.c index c45a2e6b2b..d058c30935 100644 --- a/bsp/at91sam9260/drivers/board.c +++ b/bsp/at91sam9260/drivers/board.c @@ -150,18 +150,108 @@ static void at91sam926x_pit_init(void) writel(0xffff, AT91SAM9260_BASE_TC0 + AT91_TC_CV); } +#define RXRDY 0x01 +#define TXRDY (1 << 1) +#define BPS 115200 /* serial baudrate */ + +typedef struct uartport +{ + volatile rt_uint32_t CR; + volatile rt_uint32_t MR; + volatile rt_uint32_t IER; + volatile rt_uint32_t IDR; + volatile rt_uint32_t IMR; + volatile rt_uint32_t CSR; + volatile rt_uint32_t RHR; + volatile rt_uint32_t THR; + volatile rt_uint32_t BRGR; + volatile rt_uint32_t RTOR; + volatile rt_uint32_t TTGR; + volatile rt_uint32_t reserved0[5]; + volatile rt_uint32_t FIDI; + volatile rt_uint32_t NER; + volatile rt_uint32_t reserved1; + volatile rt_uint32_t IFR; + volatile rt_uint32_t reserved2[44]; + volatile rt_uint32_t RPR; + volatile rt_uint32_t RCR; + volatile rt_uint32_t TPR; + volatile rt_uint32_t TCR; + volatile rt_uint32_t RNPR; + volatile rt_uint32_t RNCR; + volatile rt_uint32_t TNPR; + volatile rt_uint32_t TNCR; + volatile rt_uint32_t PTCR; + volatile rt_uint32_t PTSR; +}uartport; + +#define CIDR FIDI +#define EXID NER +#define FNR reserved1 + +#define DBGU ((struct uartport *)AT91SAM9260_BASE_DBGU) + +static void at91_usart_putc(char c) +{ + while (!(DBGU->CSR & TXRDY)); + DBGU->THR = c; +} + +/** + * This function is used to display a string on console, normally, it's + * invoked by rt_kprintf + * + * @param str the displayed string + */ +void rt_hw_console_output(const char* str) +{ + while (*str) + { + if (*str=='\n') + { + at91_usart_putc('\r'); + } + + at91_usart_putc(*str++); + } +} + +static void rt_hw_console_init(void) +{ + int div; + int mode = 0; + + DBGU->CR = AT91_US_RSTTX | AT91_US_RSTRX | + AT91_US_RXDIS | AT91_US_TXDIS; + mode |= AT91_US_USMODE_NORMAL | AT91_US_USCLKS_MCK | + AT91_US_CHMODE_NORMAL; + mode |= AT91_US_CHRL_8; + mode |= AT91_US_NBSTOP_1; + mode |= AT91_US_PAR_NONE; + DBGU->MR = mode; + div = (clk_get_rate(clk_get("mck")) / 16 + BPS/2) / BPS; + DBGU->BRGR = div; + DBGU->CR = AT91_US_RXEN | AT91_US_TXEN; +} + + /** * This function will init at91sam9260 board */ void rt_hw_board_init() { - /* initialize mmu */ - rt_hw_mmu_init(at91_mem_desc, sizeof(at91_mem_desc)/sizeof(at91_mem_desc[0])); - /* initialize hardware interrupt */ - rt_hw_interrupt_init(); /* initialize the system clock */ rt_hw_clock_init(); + /* initialize console */ + rt_hw_console_init(); + + /* initialize mmu */ + rt_hw_mmu_init(at91_mem_desc, sizeof(at91_mem_desc)/sizeof(at91_mem_desc[0])); + + /* initialize hardware interrupt */ + rt_hw_interrupt_init(); + /* initialize early device */ #ifdef RT_USING_COMPONENTS_INIT rt_components_board_init();