First SPI/SDcard & UART tests
Dependencies: SDFileSystem mbed-rtos mbed cmsis_rtos_demo_thread
Fork of cmsis_rtos_demo_thread by
main.cpp
- Committer:
- moxondesign
- Date:
- 2014-09-29
- Revision:
- 2:23757aa762a7
- Parent:
- 1:cbda4d713dc8
- Child:
- 3:9fa442c3fd27
File content as of revision 2:23757aa762a7:
#include "mbed.h" #include "cmsis_os.h" #include "SDFileSystem.h" DigitalOut led1(D7); DigitalOut led2(PD_2); Serial uart1(D8, D2); /* UART1: Modbus */ Serial uart2(D1, D0); /* UART2: pc(USBTX, USBRX) */ /* (i.e.) pc(D1, D0) */ SDFileSystem sd(D11, D12, D13, D10, "sd"); /* MOSI, MISO, SCK, CS */ FILE *fp; void led2_thread(void const *args){ while (true) { led2 = !led2; osDelay(1000); } } void uart1_thread(const void *args){ uart1.baud(9600); while(true){ uart1.putc(uart1.getc()); } } void uart2_thread(const void *args){ uart2.baud(9600); while(true){ uart2.putc(uart2.getc()); } } osThreadDef(uart1_thread, osPriorityNormal, DEFAULT_STACK_SIZE); osThreadDef(uart2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); int main() { osThreadCreate(osThread(led2_thread), NULL); osThreadCreate(osThread(uart1_thread), NULL); wait(1); uart2.printf("\r\n"); wait(1); uart2.printf("Initializing...\r\n"); fp = fopen("/sd/hello.txt", "r"); if (fp != NULL) { fclose(fp); remove("/sd/hello.txt"); uart2.printf("Remove an existing file with the same name\r\n"); } fp = fopen("/sd/hello.txt", "w"); if (fp == NULL) { uart2.printf("Unable to write the file\r\n"); } else { fprintf(fp, "mbed SDCard application!"); fclose(fp); uart2.printf("File successfully written!\r\n"); } osThreadCreate(osThread(uart2_thread), NULL); /* spin and spin */ while(true); }