Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- #include "ch.h"
- #include "hal.h"
- #include "ff.h"
- #include "chprintf.h"
- #include "shell.h"
- // Some fast made debug and error macros
- #define debug(args ...) chprintf((BaseSequentialStream *)&SD1, args); chprintf((BaseSequentialStream *)&SD1, "\r\n")
- #define error(args ...) chThdSleepMilliseconds(100); debug(args); while(1)
- // Serial / UART config
- static SerialConfig uartCfg =
- {
- 115200, // bit rate
- 0,
- 0,
- 0
- };
- int main(void)
- {
- halInit();
- chSysInit();
- // Start the serial connection
- sdStart(&SD1, &uartCfg);
- // Clear the terminal screen
- char clear_data [7] = {27, '[', '2', 'J', 27, '[', 'H'};
- sdWrite(&SD1, (uint8_t *) clear_data, sizeof(clear_data));
- // Make alot of new lines
- chThdSleepMilliseconds(100);
- debug("\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ");
- chThdSleepMilliseconds(100);
- // init the SDC connection
- sdcStart(&SDCD1, NULL);
- sdcConnect(&SDCD1);
- // The variables to be used for the fat fs
- FATFS FatFs;
- FIL fp;
- // Mount the file system
- if(f_mount(&FatFs, "", 0) != FR_OK)
- {
- error("Couldn't mount fatfs");
- }
- // Open the file
- if(f_open(&fp, "test.txt", FA_READ) != FR_OK)
- {
- error("Couldnt open file!");
- }
- // Variables to read the print the data on the terminal
- char buf;
- uint16_t i;
- UINT read;
- // Read and print the first 800 chars of file
- for(i = 0 ; i < 800 ; i++)
- {
- f_read(&fp, &buf, 1, &read);
- debug("buf[%03i] = %c\t%02x\t%i", i, buf, buf, read);
- }
- while(true)
- {
- chThdSleepMilliseconds(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment