void init_thread(void* parameter) { rt_thread_t tid; rt_system_comonent_init(); rt_hw_uart_init("uart0", 0); rt_console_set_device("uart0"); rt_hw_sd_init("sd0"); rt_hw_rtc_init(); rt_hw_spi_init(); rt_hw_pin_init("gpio"); rt_hw_i2c_bit_ops_bus_init("i2c0"); at24cxx_init("at24c02", "i2c0"); rt_hw_ads7843_init("ads7843", "spi20"); w25qxx_init("sf0", "spi21"); rt_hw_lcd_init("lcd0"); finsh_system_init(); // tid = rt_thread_create("usb", usb_thread_entry, RT_NULL, 1024, 9, 20); // rt_thread_startup(tid); if((*(uint32_t*)0x60000) != 0xFFFFFFFF) { tid = rt_thread_create("init", (void*)(0x60000), RT_NULL, 1024, 8, 20); rt_thread_startup(tid); } else { printf("addr:0x%X has no application\r\n", 0x60000); } rt_hw_enet_phy_init(); tid = rt_thread_self(); rt_thread_delete(tid); }
static int DO_SPI_FLASH(int argc, char * const argv[]) { uint32_t i; int x,y; #define SPI_FLASH_TEST_LEN (1024*512) volatile uint8_t* buf_test = SRAM_START_ADDRESS; uint32_t ret; static struct spi_bus bus; ret = kinetis_spi_bus_init(&bus, HW_SPI2); ret = ads7843_init(&bus, 0); ret = w25qxx_init(&bus, 1); for(i=0;i<100;i++) { ads7843_readX(&x); ads7843_readY(&y); printf("X:%04d Y:%04d\r", x, y); DelayMs(10); } /* probe w25qxx */ if(w25qxx_probe()) { printf("no w25qxx deived found\r\n"); return 1; } printf("%s detected!\r\n", w25qxx_get_name()); /* for(i=0;i<SPI_FLASH_TEST_LEN;i++) { buf_test[i] = i; } if(w25qxx_write(0, (uint8_t*)buf_test, SPI_FLASH_TEST_LEN)) { printf("w25qxx write failed\r\n"); return 1; } memset((uint8_t*)buf_test,0, SPI_FLASH_TEST_LEN); if(w25qxx_read(0, (uint8_t*)buf_test, SPI_FLASH_TEST_LEN)) { printf("w25qxx read failed\r\n"); return 1; } for(i=0;i<SPI_FLASH_TEST_LEN;i++) { if(buf_test[i] != i%256) { printf("error:[0x%X]:%d\r\n", i, buf_test[i]); } } */ printf("spi flash test finish!\r\n"); return 0; }
void rt_init_thread_entry(void* parameter) { platform_init(); #ifdef RT_USING_SPI { w25qxx_init("flash0", "spi20"); } #endif /* do some thing here. */ }
int cmd_spi(int argc, char * const argv[]) { struct w25qxx_init_t init; uint32_t i, buf_size; static uint8_t buf[256]; struct w25qxx_attr_t w25qxx; init.delayms = DelayMs; init.get_reamin = _get_reamin; init.xfer = xfer; SPI_QuickInit(SPI0_MOSI_PA7_MISO_PA6, kSPI_CPOL1_CPHA1, 100*1000);//配置PTA7为MOSI PTA6为MISO, 波特率为100K,但是实际波特率要根据匹配出来的寄存器值算,有些误差 GPIO_QuickInit(HW_GPIOA, 5, kGPIO_Mode_OPP); //PTA5 SS GPIO_WriteBit(HW_GPIOA, 5, 1); PORT_PinMuxConfig(HW_GPIOB,0,kPinAlt3); //PTB0 SCK w25qxx_init(&init); //外部flash初始化 w25qxx_get_attr(&w25qxx); buf_size = sizeof(buf); /*读取外部flash256个字节*/ printf("reading page...\n"); w25qxx_read(0, buf, buf_size); print_buf(buf,PAGE_SIZE); /*擦除整个外部flash芯片*/ printf("erase all chips...\r\n"); w25qxx_erase_chip(); printf("erase complete\r\n"); /*读取外部flash256个字节*/ printf("reading page...\n"); w25qxx_read(0, buf, buf_size); print_buf(buf,PAGE_SIZE); /*编程外部flash256个字节*/ printf("programing a page...\n"); for(i=0;i<256;i++) buf[i] = i; w25qxx_write(0, buf, buf_size); printf("clearing buffer..\n"); for(i=0;i<256;i++) buf[i] = 0; /*读取外部flash256个字节*/ printf("reading page...\n"); w25qxx_read(0, buf, buf_size); print_buf(buf,PAGE_SIZE); printf("demo end.\n"); return 0; }
void rt_platform_init(void) { #ifdef RT_USING_SPI rt_hw_spi2_init(); #ifdef RT_USING_DFS w25qxx_init("flash0", "spi20"); #endif /* RT_USING_DFS */ #ifdef RT_USING_RTGUI /* initilize touch panel */ rtgui_touch_hw_init("spi21"); #endif /* RT_USING_RTGUI */ #endif /* RT_USING_SPI */ #ifdef RT_USING_USB_HOST /* register stm32 usb host controller driver */ rt_hw_susb_init(); #endif #ifdef RT_USING_DFS /* initilize sd card */ #ifdef RT_USING_SDIO rt_mmcsd_core_init(); rt_mmcsd_blk_init(); stm32f4xx_sdio_init(); rt_thread_delay(RT_TICK_PER_SECOND); #else rt_hw_sdcard_init(); #endif #endif /* RT_USING_DFS */ #ifdef RT_USING_RTGUI /* initilize ra8875 lcd controller */ ra8875_init(); /* initilize key module */ rt_hw_key_init(); #endif /* RT_USING_RTGUI */ #ifdef RT_USING_RTC rt_hw_rtc_init(); #endif /* RT_USING_RTC */ rt_thread_delay(50); rt_device_init_all(); }
int rt_hw_spi_flash_init(void) { DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__); return w25qxx_init(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME); }
void spi_flash_init(void) { rt_spi_bus_attach_device(&spi_flash,"cs_d11","spi2",&flash_cs); w25qxx_init("flash0","cs_d11"); }
static int rt_hw_spi_flash_init(void) { return w25qxx_init(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME); }
void rt_platform_init(void) { #ifdef RT_USING_RTC rt_hw_rtc_init(); #ifdef RT_USING_ALARM rt_alarm_system_init(); #endif /* 放在finsh中去设置初始时间 set_date(2013,4,28); set_time(10,8,24); */ list_date(); #endif /* RT_USING_RTC */ #ifdef RT_USING_SPI { extern void rt_hw_spi1_init(void); rt_hw_spi1_init(); } #ifdef RT_USING_DFS w25qxx_init("flash0", "spi10"); #endif /* RT_USING_DFS */ #ifdef RT_USING_RTGUI /* initilize touch panel */ //rtgui_touch_hw_init("spi11"); #endif /* RT_USING_RTGUI */ #endif /* RT_USING_SPI */ #ifdef RT_USING_USB_HOST /* register stm32 usb host controller driver */ //rt_hw_susb_init(); #endif #ifdef RT_USING_DFS /* initilize sd card */ #ifdef RT_USING_SDIO rt_mmcsd_core_init(); rt_mmcsd_blk_init(); { extern rt_int32_t stm32f1xx_sdio_init(void); stm32f1xx_sdio_init(); } rt_thread_delay(RT_TICK_PER_SECOND); #else rt_hw_sdcard_init(); #endif #endif /* RT_USING_DFS */ #ifdef RT_USING_RTGUI /* initilize ili9320 lcd controller */ //lcd_9320_init(); /* initilize key module */ //rt_hw_key_init(); #endif /* RT_USING_RTGUI */ rt_thread_delay(50); rt_device_init_all(); }