实例介绍
【实例截图】
【文件目录】
SD卡文件读写
├── SD卡文件读写.pdf
└── Sd
├── Apps
│ ├── board.c
│ ├── board.h
│ ├── clock_config.c
│ ├── clock_config.h
│ ├── main.txt
│ ├── pin_mux.c
│ └── pin_mux.h
├── Drivers
│ ├── fsl_sdspi.h
│ ├── fsl_sdspi.txt
│ ├── fsl_sdspi_disk.c
│ ├── fsl_sdspi_disk.h
│ └── fsl_specification.h
├── LPC54114
│ ├── LPC54114_cm0plus.h
│ ├── LPC54114_cm0plus_features.h
│ ├── LPC54114_cm4.h
│ ├── LPC54114_cm4_features.h
│ ├── arm
│ │ ├── LPC54114J256_cm0plus.scf
│ │ ├── LPC54114J256_cm4.scf
│ │ ├── keil_lib_power.lib
│ │ ├── keil_lib_power_m0.lib
│ │ ├── startup_LPC54114_cm0plus.s
│ │ └── startup_LPC54114_cm4.s
│ ├── drivers
│ │ ├── fsl_adc.c
│ │ ├── fsl_adc.h
│ │ ├── fsl_clock.c
│ │ ├── fsl_clock.h
│ │ ├── fsl_common.c
│ │ ├── fsl_common.h
│ │ ├── fsl_crc.c
│ │ ├── fsl_crc.h
│ │ ├── fsl_ctimer.c
│ │ ├── fsl_ctimer.h
│ │ ├── fsl_dma.c
│ │ ├── fsl_dma.h
│ │ ├── fsl_dmic.c
│ │ ├── fsl_dmic.h
│ │ ├── fsl_dmic_dma.c
│ │ ├── fsl_dmic_dma.h
│ │ ├── fsl_flashiap.c
│ │ ├── fsl_flashiap.h
│ │ ├── fsl_flexcomm.c
│ │ ├── fsl_flexcomm.h
│ │ ├── fsl_fmeas.c
│ │ ├── fsl_fmeas.h
│ │ ├── fsl_gint.c
│ │ ├── fsl_gint.h
│ │ ├── fsl_gpio.c
│ │ ├── fsl_gpio.h
│ │ ├── fsl_i2c.c
│ │ ├── fsl_i2c.h
│ │ ├── fsl_i2c_dma.c
│ │ ├── fsl_i2c_dma.h
│ │ ├── fsl_i2c_freertos.c
│ │ ├── fsl_i2c_freertos.h
│ │ ├── fsl_i2s.c
│ │ ├── fsl_i2s.h
│ │ ├── fsl_i2s_dma.c
│ │ ├── fsl_i2s_dma.h
│ │ ├── fsl_inputmux.c
│ │ ├── fsl_inputmux.h
│ │ ├── fsl_inputmux_connections.h
│ │ ├── fsl_iocon.h
│ │ ├── fsl_mailbox.h
│ │ ├── fsl_mrt.c
│ │ ├── fsl_mrt.h
│ │ ├── fsl_pint.c
│ │ ├── fsl_pint.h
│ │ ├── fsl_power.c
│ │ ├── fsl_power.h
│ │ ├── fsl_reset.c
│ │ ├── fsl_reset.h
│ │ ├── fsl_rtc.c
│ │ ├── fsl_rtc.h
│ │ ├── fsl_sctimer.c
│ │ ├── fsl_sctimer.h
│ │ ├── fsl_spi.c
│ │ ├── fsl_spi.h
│ │ ├── fsl_spi_dma.c
│ │ ├── fsl_spi_dma.h
│ │ ├── fsl_spi_freertos.c
│ │ ├── fsl_spi_freertos.h
│ │ ├── fsl_usart.c
│ │ ├── fsl_usart.h
│ │ ├── fsl_usart_dma.c
│ │ ├── fsl_usart_dma.h
│ │ ├── fsl_usart_freertos.c
│ │ ├── fsl_usart_freertos.h
│ │ ├── fsl_utick.c
│ │ ├── fsl_utick.h
│ │ ├── fsl_wwdt.c
│ │ └── fsl_wwdt.h
│ ├── fsl_device_registers.h
│ ├── system_LPC54114_cm0plus.c
│ ├── system_LPC54114_cm0plus.h
│ ├── system_LPC54114_cm4.h
│ ├── system_LPC54114_cm4.txt
│ └── utilities
│ ├── fsl_debug_console.c
│ └── fsl_debug_console.h
├── Project
│ ├── Objects
│ │ ├── Sd.build_log.htm
│ │ ├── Sd_Target 1.dep
│ │ ├── board.d
│ │ ├── clock_config.d
│ │ ├── diskio.d
│ │ ├── ff.crf
│ │ ├── ff.d
│ │ ├── ff.o
│ │ ├── fsl_adc.d
│ │ ├── fsl_clock.d
│ │ ├── fsl_common.d
│ │ ├── fsl_crc.d
│ │ ├── fsl_ctimer.d
│ │ ├── fsl_debug_console.d
│ │ ├── fsl_dma.d
│ │ ├── fsl_dmic.d
│ │ ├── fsl_dmic_dma.d
│ │ ├── fsl_flashiap.d
│ │ ├── fsl_flexcomm.d
│ │ ├── fsl_fmeas.d
│ │ ├── fsl_gint.d
│ │ ├── fsl_gpio.d
│ │ ├── fsl_i2c.d
│ │ ├── fsl_i2c_dma.d
│ │ ├── fsl_i2s.d
│ │ ├── fsl_i2s_dma.d
│ │ ├── fsl_inputmux.d
│ │ ├── fsl_mrt.d
│ │ ├── fsl_pint.d
│ │ ├── fsl_power.d
│ │ ├── fsl_reset.d
│ │ ├── fsl_rtc.d
│ │ ├── fsl_sctimer.d
│ │ ├── fsl_sdspi.d
│ │ ├── fsl_sdspi_disk.d
│ │ ├── fsl_spi.d
│ │ ├── fsl_spi_dma.d
│ │ ├── fsl_usart.d
│ │ ├── fsl_usart_dma.d
│ │ ├── fsl_utick.d
│ │ ├── fsl_wwdt.d
│ │ ├── main.d
│ │ ├── pin_mux.d
│ │ ├── startup_lpc54114_cm4.d
│ │ ├── startup_lpc54114_cm4.lst
│ │ ├── startup_lpc54114_cm4.o
│ │ └── system_lpc54114_cm4.d
│ ├── Sd.uvgui.Administrator
│ ├── Sd.uvopt
│ ├── Sd.uvproj
│ ├── checksum.exe
│ └── firmware.bin
└── fatfs
├── diskio.c
├── diskio.h
├── ff.c
├── ff.h
├── ffconf.h
├── integer.h
└── option
├── cc932.c
├── cc936.c
├── cc949.c
├── cc950.c
├── ccsbcs.c
└── unicode.txt
11 directories, 163 files
【核心代码】
#include "board.h" #include "fsl_debug_console.h" #include "fsl_gpio.h" #include "pin_mux.h" #include "ff.h" #include "diskio.h" #include "fsl_sdspi_disk.h" uint8_t TestBuffer[2048]; __asm void Delay_ms(unsigned int nCount) { 0 ldr r1, =24000 // arm clock = 96000000hz 1 subs r1, r1, #1 bne %B1 subs r0, r0, #1 bne %B0 bx lr } void Gpio_Init(void) { /* Define the init structure for the output LED pin*/ gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0, }; /* Init output LED GPIO. */ GPIO_PinInit(GPIO, 0, 15, &led_config); GPIO_WritePinOutput(GPIO, 0, 15, 0); GPIO_PinInit(GPIO, 0, 19, &led_config); GPIO_WritePinOutput(GPIO, 0, 19, 0); GPIO_PinInit(GPIO, 0, 21, &led_config); GPIO_WritePinOutput(GPIO, 0, 21, 0); GPIO_PinInit(GPIO, 0, 22, &led_config); GPIO_WritePinOutput(GPIO, 0, 22, 0); GPIO_PinInit(GPIO, 0, 25, &led_config); GPIO_WritePinOutput(GPIO, 0, 25, 1); GPIO_PinInit(GPIO, 0, 26, &led_config); GPIO_WritePinOutput(GPIO, 0, 26, 1); GPIO_PinInit(GPIO, 0, 29, &led_config); GPIO_WritePinOutput(GPIO, 0, 29, 1); GPIO_PinInit(GPIO, 0, 30, &led_config); GPIO_WritePinOutput(GPIO, 0, 30, 1); } int main() { uint32_t i; FATFS fs; FIL file; FRESULT Res; uint32_t TimeCount; uint32_t ByteWrite, ByteRead; /* Board pin, clock, debug console init */ /* attach 12 MHz clock to FLEXCOMM0 (debug console) */ CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH); /* enable clock for GPIO*/ CLOCK_EnableClock(kCLOCK_Gpio0); CLOCK_EnableClock(kCLOCK_Gpio1); BOARD_InitPins(); BOARD_BootClockFROHF96M(); BOARD_InitDebugConsole(); Gpio_Init(); f_mount(&fs, "4:" , 0); /* Res = f_mkfs("", 0, 4096); if (Res != RES_OK) { PRINTF("f_mkfs error %d\r\n", Res); while(1); } */ PRINTF("Writing test.bin, file sise 10MB\r\n"); Res = f_open(&file, "4:test.bin", FA_WRITE | FA_CREATE_ALWAYS); if (Res != RES_OK) { PRINTF("Create file failed\r\n"); while(1) { GPIO_TogglePinsOutput(GPIO, 0, 1u << 15); Delay_ms(300); } } for (i=0; i<sizeof(TestBuffer); i ) { TestBuffer[i] = i; } TimeCount = timer_get_current_milliseconds(); for (i=0; i<10*1024*1024/sizeof(TestBuffer); i ) { Res = f_write(&file, &TestBuffer, sizeof(TestBuffer), &ByteWrite); if (Res != RES_OK) { f_close(&file); PRINTF("Write file error\r\n"); while(1) { GPIO_TogglePinsOutput(GPIO, 0, 1u << 15); Delay_ms(300); } } } f_close(&file); PRINTF("Sd write speed %d KB/s\r\n", 10*1024*1024/(timer_get_current_milliseconds()-TimeCount)); PRINTF("Reading test.bin, file sise 10MB\r\n"); Res = f_open(&file, "4:test.bin", FA_READ | FA_OPEN_EXISTING); if (Res != RES_OK) { PRINTF("Open file failed\r\n"); while(1) { GPIO_TogglePinsOutput(GPIO, 0, 1u << 15); Delay_ms(300); } } TimeCount = timer_get_current_milliseconds(); for (i=0; i<10*1024*1024/sizeof(TestBuffer); i ) { Res = f_read(&file, (unsigned char *)&TestBuffer, sizeof(TestBuffer), &ByteRead); if (Res != RES_OK) { f_close(&file); PRINTF("Read file error\r\n"); while(1) { GPIO_TogglePinsOutput(GPIO, 0, 1u << 15); Delay_ms(300); } } } f_close(&file); PRINTF("Sd read speed %d KB/s\r\n", 10*1024*1024/(timer_get_current_milliseconds()-TimeCount)); while(1) { GPIO_TogglePinsOutput(GPIO, 0, 1u << 15); Delay_ms(1000); } }
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论