![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test CAN bus on Stm32F746nG
Dependencies: F746_GUI mbed CANMsg
main.cpp@1:68083f9dd39d, 2020-08-30 (annotated)
- Committer:
- 38domo
- Date:
- Sun Aug 30 14:42:53 2020 +0000
- Revision:
- 1:68083f9dd39d
- Parent:
- 0:77e62347e7c9
test bus can avec stm32f746
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
38domo | 0:77e62347e7c9 | 1 | /* |
38domo | 0:77e62347e7c9 | 2 | programme test sur carte stm32F746ng-discovery |
38domo | 0:77e62347e7c9 | 3 | |
38domo | 0:77e62347e7c9 | 4 | update 30/07/2019 : display datas on lcd ok |
38domo | 0:77e62347e7c9 | 5 | update 29/07/2020 : send can ok ( after received), receive can ok |
38domo | 0:77e62347e7c9 | 6 | update 29/07/2020 : remove touch screen |
38domo | 0:77e62347e7c9 | 7 | update 28/07/2020 : add serial and CAN |
38domo | 0:77e62347e7c9 | 8 | update 21/07/2020 : test buttons |
38domo | 0:77e62347e7c9 | 9 | update 20/07/2020 : display buttons |
38domo | 0:77e62347e7c9 | 10 | update 17/07/2020 GC : change colors |
38domo | 0:77e62347e7c9 | 11 | */ |
38domo | 0:77e62347e7c9 | 12 | |
38domo | 0:77e62347e7c9 | 13 | #include "mbed.h" |
38domo | 0:77e62347e7c9 | 14 | #include "stm32746g_discovery_lcd.h" |
38domo | 0:77e62347e7c9 | 15 | #include "stm32746g_discovery_ts.h" |
38domo | 0:77e62347e7c9 | 16 | #include <string> |
38domo | 0:77e62347e7c9 | 17 | #include "CANMsg.h" |
38domo | 0:77e62347e7c9 | 18 | #include <stdio.h> |
38domo | 0:77e62347e7c9 | 19 | #include <errno.h> |
38domo | 0:77e62347e7c9 | 20 | |
38domo | 0:77e62347e7c9 | 21 | // serial port sur connecteur arduino (D0,D1)-------------------- |
38domo | 0:77e62347e7c9 | 22 | Serial serial2(PC_6, PC_7); // TX, RX for udp bridge |
38domo | 0:77e62347e7c9 | 23 | Serial pc(USBTX, USBRX); // serial on usb connector |
38domo | 0:77e62347e7c9 | 24 | // CAN ------------------------------------------------------------ |
38domo | 0:77e62347e7c9 | 25 | CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name |
38domo | 0:77e62347e7c9 | 26 | CANMsg rxMsg; |
38domo | 0:77e62347e7c9 | 27 | CANMsg txMsg; |
38domo | 0:77e62347e7c9 | 28 | |
38domo | 0:77e62347e7c9 | 29 | uint8_t counter = 0; |
38domo | 0:77e62347e7c9 | 30 | float voltage; |
38domo | 0:77e62347e7c9 | 31 | Timer timer; |
38domo | 0:77e62347e7c9 | 32 | volatile bool msgAvailable = false; |
38domo | 0:77e62347e7c9 | 33 | AnalogIn analogIn(A0); |
38domo | 0:77e62347e7c9 | 34 | CircularBuffer<char, 1024> rxbuf; // PC receiving Buffer |
38domo | 0:77e62347e7c9 | 35 | uint8_t text2[30]; |
38domo | 0:77e62347e7c9 | 36 | char s2; |
38domo | 0:77e62347e7c9 | 37 | char buffer[128]; |
38domo | 0:77e62347e7c9 | 38 | #define LED_PIN PC_13 |
38domo | 0:77e62347e7c9 | 39 | DigitalOut led(LED_PIN); |
38domo | 0:77e62347e7c9 | 40 | |
38domo | 0:77e62347e7c9 | 41 | //#define TARGET_STM32F103C8T6 1 // uncomment this line to use STM32F103C8T6 boards |
38domo | 0:77e62347e7c9 | 42 | #define BOARD1 1 // comment out this line when compiling for board #2 |
38domo | 0:77e62347e7c9 | 43 | #if defined(BOARD1) |
38domo | 0:77e62347e7c9 | 44 | const unsigned int RX_ID = 0x100; |
38domo | 0:77e62347e7c9 | 45 | const unsigned int TX_ID = 0x101; |
38domo | 0:77e62347e7c9 | 46 | #else |
38domo | 0:77e62347e7c9 | 47 | const unsigned int RX_ID = 0x101; |
38domo | 0:77e62347e7c9 | 48 | const unsigned int TX_ID = 0x100; |
38domo | 0:77e62347e7c9 | 49 | #endif |
38domo | 0:77e62347e7c9 | 50 | |
38domo | 0:77e62347e7c9 | 51 | /** |
38domo | 0:77e62347e7c9 | 52 | * @brief Prints CAN message to PC's serial terminal |
38domo | 0:77e62347e7c9 | 53 | * @param CANMessage to print |
38domo | 0:77e62347e7c9 | 54 | */ |
38domo | 0:77e62347e7c9 | 55 | void printMsg(CANMessage& msg, int dir) |
38domo | 0:77e62347e7c9 | 56 | { if (dir ==0) |
38domo | 0:77e62347e7c9 | 57 | { BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE); |
38domo | 0:77e62347e7c9 | 58 | } |
38domo | 0:77e62347e7c9 | 59 | else |
38domo | 0:77e62347e7c9 | 60 | { BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message received", LEFT_MODE); |
38domo | 0:77e62347e7c9 | 61 | } |
38domo | 0:77e62347e7c9 | 62 | pc.printf(" ID = 0x%.3x\r\n", msg.id); |
38domo | 0:77e62347e7c9 | 63 | pc.printf(" Type = %d\r\n", msg.type); |
38domo | 0:77e62347e7c9 | 64 | pc.printf(" Format = %d\r\n", msg.format); |
38domo | 0:77e62347e7c9 | 65 | pc.printf(" Length = %d\r\n", msg.len); |
38domo | 0:77e62347e7c9 | 66 | pc.printf(" Data ="); |
38domo | 0:77e62347e7c9 | 67 | for(int i = 0; i < msg.len; i++) |
38domo | 0:77e62347e7c9 | 68 | pc.printf(" 0x%.2X", msg.data[i]); |
38domo | 0:77e62347e7c9 | 69 | pc.printf("\r\n"); |
38domo | 0:77e62347e7c9 | 70 | |
38domo | 0:77e62347e7c9 | 71 | sprintf((char*)text2, "ID: %d", msg.id); |
38domo | 0:77e62347e7c9 | 72 | BSP_LCD_DisplayStringAt(2, LINE(7), (uint8_t *)&text2, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 73 | sprintf((char*)text2, "Type: %d", msg.type); |
38domo | 0:77e62347e7c9 | 74 | BSP_LCD_DisplayStringAt(2, LINE(8), (uint8_t *)&text2, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 75 | sprintf((char*)text2, "Format: %d", msg.format); |
38domo | 0:77e62347e7c9 | 76 | BSP_LCD_DisplayStringAt(2, LINE(9), (uint8_t *)&text2, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 77 | sprintf((char*)text2, "Length: %d", msg.len); |
38domo | 0:77e62347e7c9 | 78 | BSP_LCD_DisplayStringAt(2, LINE(10), (uint8_t *)&text2, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 79 | sprintf((char*)text2, "Data: %d", msg.data[0]); |
38domo | 0:77e62347e7c9 | 80 | BSP_LCD_DisplayStringAt(2, LINE(11), (uint8_t *)&text2, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 81 | } |
38domo | 0:77e62347e7c9 | 82 | |
38domo | 0:77e62347e7c9 | 83 | /** |
38domo | 0:77e62347e7c9 | 84 | * @brief Handles received CAN messages |
38domo | 0:77e62347e7c9 | 85 | * @note Called on 'CAN message received' interrupt. |
38domo | 0:77e62347e7c9 | 86 | */ |
38domo | 0:77e62347e7c9 | 87 | void onCanReceived(void) |
38domo | 0:77e62347e7c9 | 88 | { can.read(rxMsg); |
38domo | 0:77e62347e7c9 | 89 | pc.printf("-------------------------------------\r\n"); |
38domo | 0:77e62347e7c9 | 90 | pc.printf("CAN message received\r\n"); |
38domo | 0:77e62347e7c9 | 91 | serial2.printf("CAN message received\r\n"); |
38domo | 0:77e62347e7c9 | 92 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 93 | //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 94 | printMsg(rxMsg,1); |
38domo | 0:77e62347e7c9 | 95 | //serial2.printf("%d\n",rxMsg); |
38domo | 0:77e62347e7c9 | 96 | //serial2.printf("ID: "); |
38domo | 0:77e62347e7c9 | 97 | serial2.printf("ID: 0x%.3x ", rxMsg.id); |
38domo | 0:77e62347e7c9 | 98 | serial2.printf("D: "); |
38domo | 0:77e62347e7c9 | 99 | for(int i = 0; i < rxMsg.len; i++) |
38domo | 0:77e62347e7c9 | 100 | serial2.printf(" 0x%.2X", rxMsg.data[i]); |
38domo | 0:77e62347e7c9 | 101 | serial2.printf("\r\n"); |
38domo | 0:77e62347e7c9 | 102 | if (rxMsg.id == RX_ID) { |
38domo | 0:77e62347e7c9 | 103 | // extract data from the received CAN message |
38domo | 0:77e62347e7c9 | 104 | // in the same order as it was added on the transmitter side |
38domo | 0:77e62347e7c9 | 105 | rxMsg >> counter; |
38domo | 0:77e62347e7c9 | 106 | rxMsg >> voltage; |
38domo | 0:77e62347e7c9 | 107 | pc.printf(" counter = %d\r\n", counter); |
38domo | 0:77e62347e7c9 | 108 | pc.printf(" voltage = %e V\r\n", voltage); |
38domo | 0:77e62347e7c9 | 109 | } |
38domo | 0:77e62347e7c9 | 110 | timer.start(); // to transmit next message in main |
38domo | 0:77e62347e7c9 | 111 | } |
38domo | 0:77e62347e7c9 | 112 | |
38domo | 0:77e62347e7c9 | 113 | // ------------------------------------------------------------------------------------------------------ |
38domo | 0:77e62347e7c9 | 114 | int main() |
38domo | 0:77e62347e7c9 | 115 | { TS_StateTypeDef TS_State; |
38domo | 0:77e62347e7c9 | 116 | uint16_t x, y; |
38domo | 0:77e62347e7c9 | 117 | uint8_t text[30]; |
38domo | 0:77e62347e7c9 | 118 | uint8_t status; |
38domo | 0:77e62347e7c9 | 119 | uint8_t idx; |
38domo | 0:77e62347e7c9 | 120 | uint8_t cleared = 0; |
38domo | 0:77e62347e7c9 | 121 | uint8_t menu_level = 0; |
38domo | 0:77e62347e7c9 | 122 | uint8_t prev_nb_touches = 0; |
38domo | 0:77e62347e7c9 | 123 | uint8_t touche_appuyee = 99; |
38domo | 0:77e62347e7c9 | 124 | string touche_appuyee_s = "%"; |
38domo | 0:77e62347e7c9 | 125 | string text_display1 ("Memorisation Touches "); |
38domo | 0:77e62347e7c9 | 126 | char buffer_touche[50]; |
38domo | 0:77e62347e7c9 | 127 | // set serial speed |
38domo | 0:77e62347e7c9 | 128 | pc.baud(57600); |
38domo | 0:77e62347e7c9 | 129 | serial2.baud(57600); |
38domo | 0:77e62347e7c9 | 130 | // config can -------------------------------------- |
38domo | 0:77e62347e7c9 | 131 | //jpa can = new CAN(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name |
38domo | 0:77e62347e7c9 | 132 | can.frequency(125000); // set CAN bit rate to 125 kbps |
38domo | 0:77e62347e7c9 | 133 | //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID |
38domo | 0:77e62347e7c9 | 134 | can.attach(onCanReceived); // attach ISR to handle received messages |
38domo | 0:77e62347e7c9 | 135 | //can->attach(&onMsgReceived); //msgAvailable = true; // attach the 'CAN receive-complete' interrupt service routine (ISR) |
38domo | 0:77e62347e7c9 | 136 | #if defined(BOARD1) |
38domo | 0:77e62347e7c9 | 137 | timer.start(); // start timer |
38domo | 0:77e62347e7c9 | 138 | pc.printf("CAN_Hello board #1\r\n"); |
38domo | 0:77e62347e7c9 | 139 | #else |
38domo | 0:77e62347e7c9 | 140 | pc.printf("CAN_Hello board #2\r\n"); |
38domo | 0:77e62347e7c9 | 141 | #endif |
38domo | 0:77e62347e7c9 | 142 | pc.printf("\nStart Prog\n"); |
38domo | 0:77e62347e7c9 | 143 | serial2.printf("\nStart Prog\n"); |
38domo | 0:77e62347e7c9 | 144 | BSP_LCD_Init(); |
38domo | 0:77e62347e7c9 | 145 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
38domo | 0:77e62347e7c9 | 146 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
38domo | 0:77e62347e7c9 | 147 | //BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 148 | //HAL_Delay(1000); |
38domo | 0:77e62347e7c9 | 149 | status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); |
38domo | 0:77e62347e7c9 | 150 | if (status != TS_OK) { |
38domo | 0:77e62347e7c9 | 151 | BSP_LCD_Clear(LCD_COLOR_RED); |
38domo | 0:77e62347e7c9 | 152 | BSP_LCD_SetBackColor(LCD_COLOR_RED); |
38domo | 0:77e62347e7c9 | 153 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 0:77e62347e7c9 | 154 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 155 | } else { |
38domo | 0:77e62347e7c9 | 156 | BSP_LCD_Clear(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 157 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 158 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 0:77e62347e7c9 | 159 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 160 | } |
38domo | 0:77e62347e7c9 | 161 | pc.printf("\nInit Display\n"); |
38domo | 0:77e62347e7c9 | 162 | HAL_Delay(1000); |
38domo | 0:77e62347e7c9 | 163 | BSP_LCD_Clear(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 164 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 165 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 0:77e62347e7c9 | 166 | BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)"STM32F746 Disco Appli", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 167 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
38domo | 0:77e62347e7c9 | 168 | BSP_LCD_DrawRect(10, 100, 200, 50); |
38domo | 0:77e62347e7c9 | 169 | BSP_LCD_DrawRect(10, 180, 200, 50); |
38domo | 0:77e62347e7c9 | 170 | BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); |
38domo | 0:77e62347e7c9 | 171 | BSP_LCD_DisplayStringAt(25, LINE(5), (uint8_t *)"Setup", LEFT_MODE); |
38domo | 0:77e62347e7c9 | 172 | BSP_LCD_DisplayStringAt(25, 200, (uint8_t *)"Run", LEFT_MODE); |
38domo | 0:77e62347e7c9 | 173 | BSP_LCD_SetFont(&Font12); |
38domo | 0:77e62347e7c9 | 174 | |
38domo | 0:77e62347e7c9 | 175 | BSP_LCD_Clear(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 176 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 177 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 0:77e62347e7c9 | 178 | BSP_LCD_SetFont(&Font16); |
38domo | 0:77e62347e7c9 | 179 | BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)"Mode Run", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 180 | |
38domo | 0:77e62347e7c9 | 181 | |
38domo | 0:77e62347e7c9 | 182 | //HAL_Delay(1000); |
38domo | 0:77e62347e7c9 | 183 | BSP_LCD_SetFont(&Font12); |
38domo | 0:77e62347e7c9 | 184 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 185 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
38domo | 0:77e62347e7c9 | 186 | |
38domo | 0:77e62347e7c9 | 187 | while(1) //menu_level == 1) |
38domo | 0:77e62347e7c9 | 188 | { // timer send can |
38domo | 0:77e62347e7c9 | 189 | if(timer.read_ms() >= 1000) // check for timeout |
38domo | 0:77e62347e7c9 | 190 | { timer.stop(); // stop the timer |
38domo | 0:77e62347e7c9 | 191 | timer.reset(); // reset the timer |
38domo | 0:77e62347e7c9 | 192 | counter++; // increment the counter |
38domo | 0:77e62347e7c9 | 193 | voltage = (analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input |
38domo | 0:77e62347e7c9 | 194 | txMsg.clear(); // clear the Tx message storage |
38domo | 0:77e62347e7c9 | 195 | //txMsg.id = TX_ID; // set ID |
38domo | 0:77e62347e7c9 | 196 | txMsg.id = 0x18881001;//TX_ID; // set the message ID |
38domo | 0:77e62347e7c9 | 197 | txMsg.format = CANExtended ; //extended |
38domo | 0:77e62347e7c9 | 198 | // We are about to transmit two data items to the CAN bus. |
38domo | 0:77e62347e7c9 | 199 | // counter: uint_8 (unsigned eight bits int) value (one byte). |
38domo | 0:77e62347e7c9 | 200 | // voltage: floating point value (four bytes). |
38domo | 0:77e62347e7c9 | 201 | // So the total length of payload data is five bytes. |
38domo | 0:77e62347e7c9 | 202 | // We'll use the "<<" (append) operator to add data to the CAN message. |
38domo | 0:77e62347e7c9 | 203 | // The usage is same as of the similar C++ io-stream operators. |
38domo | 0:77e62347e7c9 | 204 | // NOTE: The data length of CAN message is automatically updated when using "<<" operators. |
38domo | 0:77e62347e7c9 | 205 | txMsg << counter << voltage; // append data (total data length must be <= 8 bytes!) |
38domo | 0:77e62347e7c9 | 206 | |
38domo | 0:77e62347e7c9 | 207 | if(can.write(txMsg)) // transmit message |
38domo | 0:77e62347e7c9 | 208 | { //if(can->write(txMsg)) { // transmit the CAN message |
38domo | 0:77e62347e7c9 | 209 | //led = OFF; // turn the LED off |
38domo | 0:77e62347e7c9 | 210 | pc.printf("-------------------------------------\r\n"); |
38domo | 0:77e62347e7c9 | 211 | pc.printf("CAN message sent\r\n"); |
38domo | 0:77e62347e7c9 | 212 | printMsg(txMsg,0); |
38domo | 0:77e62347e7c9 | 213 | pc.printf(" counter = %d\r\n", counter); |
38domo | 0:77e62347e7c9 | 214 | pc.printf(" voltage = %e V\r\n", voltage); |
38domo | 0:77e62347e7c9 | 215 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 216 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 217 | } |
38domo | 0:77e62347e7c9 | 218 | else |
38domo | 0:77e62347e7c9 | 219 | { pc.printf("Transmission error\r\n"); |
38domo | 0:77e62347e7c9 | 220 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 221 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 222 | } |
38domo | 0:77e62347e7c9 | 223 | //timer.start(); // insert transmission lag |
38domo | 0:77e62347e7c9 | 224 | } // end if timer |
38domo | 1:68083f9dd39d | 225 | // read can |
38domo | 1:68083f9dd39d | 226 | if (can.read(rxMsg)); |
38domo | 1:68083f9dd39d | 227 | { |
38domo | 1:68083f9dd39d | 228 | pc.printf("-------------------------------------\r\n"); |
38domo | 1:68083f9dd39d | 229 | pc.printf("CAN message received\r\n"); |
38domo | 1:68083f9dd39d | 230 | serial2.printf("CAN message received\r\n"); |
38domo | 1:68083f9dd39d | 231 | |
38domo | 1:68083f9dd39d | 232 | printMsg(rxMsg,1); |
38domo | 1:68083f9dd39d | 233 | serial2.printf("%d\n",rxMsg); |
38domo | 1:68083f9dd39d | 234 | serial2.printf("ID: "); |
38domo | 1:68083f9dd39d | 235 | serial2.printf("ID: 0x%.3x ", rxMsg.id); |
38domo | 1:68083f9dd39d | 236 | serial2.printf("D: "); |
38domo | 1:68083f9dd39d | 237 | for(int i = 0; i < rxMsg.len; i++) |
38domo | 1:68083f9dd39d | 238 | serial2.printf(" 0x%.2X", rxMsg.data[i]); |
38domo | 1:68083f9dd39d | 239 | serial2.printf("\r\n"); |
38domo | 1:68083f9dd39d | 240 | } |
38domo | 1:68083f9dd39d | 241 | |
38domo | 1:68083f9dd39d | 242 | |
38domo | 1:68083f9dd39d | 243 | |
38domo | 0:77e62347e7c9 | 244 | // read serial port |
38domo | 0:77e62347e7c9 | 245 | // get serial 2 |
38domo | 0:77e62347e7c9 | 246 | //serial2.gets(buffer, 4); |
38domo | 0:77e62347e7c9 | 247 | //pc.printf("I got '%s'\n", buffer); |
38domo | 0:77e62347e7c9 | 248 | char c = pc.getc(); |
38domo | 0:77e62347e7c9 | 249 | |
38domo | 0:77e62347e7c9 | 250 | if((c == 's') ) |
38domo | 0:77e62347e7c9 | 251 | { // send trame CAN |
38domo | 0:77e62347e7c9 | 252 | if(can.write(txMsg)) // transmit message |
38domo | 0:77e62347e7c9 | 253 | { //if(can->write(txMsg)) { // transmit the CAN message |
38domo | 0:77e62347e7c9 | 254 | //led = OFF; // turn the LED off |
38domo | 0:77e62347e7c9 | 255 | pc.printf("-------------------------------------\r\n"); |
38domo | 0:77e62347e7c9 | 256 | pc.printf("CAN message sent\r\n"); |
38domo | 0:77e62347e7c9 | 257 | printMsg(txMsg,0); |
38domo | 0:77e62347e7c9 | 258 | pc.printf(" counter = %d\r\n", counter); |
38domo | 0:77e62347e7c9 | 259 | pc.printf(" voltage = %e V\r\n", voltage); |
38domo | 0:77e62347e7c9 | 260 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 261 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 262 | } |
38domo | 0:77e62347e7c9 | 263 | else |
38domo | 0:77e62347e7c9 | 264 | { pc.printf("Transmission error\r\n"); |
38domo | 0:77e62347e7c9 | 265 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 266 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 267 | } |
38domo | 0:77e62347e7c9 | 268 | } |
38domo | 0:77e62347e7c9 | 269 | |
38domo | 0:77e62347e7c9 | 270 | char ser2 = serial2.getc(); |
38domo | 0:77e62347e7c9 | 271 | if( (ser2 = 's') ) |
38domo | 0:77e62347e7c9 | 272 | { // send trame CAN |
38domo | 0:77e62347e7c9 | 273 | if(can.write(txMsg)) // transmit message |
38domo | 0:77e62347e7c9 | 274 | { //if(can->write(txMsg)) { // transmit the CAN message |
38domo | 0:77e62347e7c9 | 275 | //led = OFF; // turn the LED off |
38domo | 0:77e62347e7c9 | 276 | pc.printf("-------------------------------------\r\n"); |
38domo | 0:77e62347e7c9 | 277 | pc.printf("CAN message sent\r\n"); |
38domo | 0:77e62347e7c9 | 278 | printMsg(txMsg,0); |
38domo | 0:77e62347e7c9 | 279 | pc.printf(" counter = %d\r\n", counter); |
38domo | 0:77e62347e7c9 | 280 | pc.printf(" voltage = %e V\r\n", voltage); |
38domo | 0:77e62347e7c9 | 281 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 282 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 283 | } |
38domo | 0:77e62347e7c9 | 284 | else |
38domo | 0:77e62347e7c9 | 285 | { pc.printf("Transmission error\r\n"); |
38domo | 0:77e62347e7c9 | 286 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 287 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:77e62347e7c9 | 288 | } |
38domo | 0:77e62347e7c9 | 289 | } |
38domo | 0:77e62347e7c9 | 290 | |
38domo | 0:77e62347e7c9 | 291 | // gestion touches appuyees |
38domo | 0:77e62347e7c9 | 292 | BSP_TS_GetState(&TS_State); |
38domo | 0:77e62347e7c9 | 293 | if (TS_State.touchDetected) { |
38domo | 0:77e62347e7c9 | 294 | // Clear lines corresponding to old touches coordinates |
38domo | 0:77e62347e7c9 | 295 | if (TS_State.touchDetected < prev_nb_touches) { |
38domo | 0:77e62347e7c9 | 296 | for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { |
38domo | 0:77e62347e7c9 | 297 | BSP_LCD_ClearStringLine(idx); |
38domo | 0:77e62347e7c9 | 298 | } |
38domo | 0:77e62347e7c9 | 299 | } |
38domo | 0:77e62347e7c9 | 300 | prev_nb_touches = TS_State.touchDetected; |
38domo | 0:77e62347e7c9 | 301 | cleared = 0; |
38domo | 0:77e62347e7c9 | 302 | sprintf((char*)text, "Touches: %d", TS_State.touchDetected); |
38domo | 0:77e62347e7c9 | 303 | BSP_LCD_DisplayStringAt(2, LINE(1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 304 | |
38domo | 0:77e62347e7c9 | 305 | for (idx = 0; idx < TS_State.touchDetected; idx++) { |
38domo | 0:77e62347e7c9 | 306 | x = TS_State.touchX[idx]; |
38domo | 0:77e62347e7c9 | 307 | y = TS_State.touchY[idx]; |
38domo | 0:77e62347e7c9 | 308 | sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); |
38domo | 0:77e62347e7c9 | 309 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 310 | } |
38domo | 0:77e62347e7c9 | 311 | BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); |
38domo | 0:77e62347e7c9 | 312 | |
38domo | 0:77e62347e7c9 | 313 | // rajouter test touche appuyée |
38domo | 0:77e62347e7c9 | 314 | if ((y>100)& (y<150)) |
38domo | 0:77e62347e7c9 | 315 | { // touches 0 a 5 appuyées |
38domo | 0:77e62347e7c9 | 316 | if ((x>10)&(x<60)) |
38domo | 0:77e62347e7c9 | 317 | { // touche 0 appuyée) |
38domo | 0:77e62347e7c9 | 318 | sprintf((char*)text, "Touche 0 appuyée"); |
38domo | 0:77e62347e7c9 | 319 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 320 | touche_appuyee = 0;touche_appuyee_s = "0"; |
38domo | 0:77e62347e7c9 | 321 | } |
38domo | 0:77e62347e7c9 | 322 | if ((x>90)&(x<130)) |
38domo | 0:77e62347e7c9 | 323 | { // touche 1 appuyée) |
38domo | 0:77e62347e7c9 | 324 | sprintf((char*)text, "Touche 1 appuyée"); |
38domo | 0:77e62347e7c9 | 325 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 326 | touche_appuyee = 1;touche_appuyee_s = "1"; |
38domo | 0:77e62347e7c9 | 327 | } |
38domo | 0:77e62347e7c9 | 328 | if ((x>180)&(x<230)) |
38domo | 0:77e62347e7c9 | 329 | { // touche 2 appuyée) |
38domo | 0:77e62347e7c9 | 330 | sprintf((char*)text, "Touche 2 appuyée"); |
38domo | 0:77e62347e7c9 | 331 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 332 | touche_appuyee = 2;touche_appuyee_s = "2"; |
38domo | 0:77e62347e7c9 | 333 | } |
38domo | 0:77e62347e7c9 | 334 | if ((x>260)&(x<310)) |
38domo | 0:77e62347e7c9 | 335 | { // touche 3 appuyée) |
38domo | 0:77e62347e7c9 | 336 | sprintf((char*)text, "Touche 3 appuyée"); |
38domo | 0:77e62347e7c9 | 337 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 338 | touche_appuyee = 3;touche_appuyee_s = "3"; |
38domo | 0:77e62347e7c9 | 339 | } |
38domo | 0:77e62347e7c9 | 340 | if ((x>340)&(x<390)) |
38domo | 0:77e62347e7c9 | 341 | { // touche 4 appuyée) |
38domo | 0:77e62347e7c9 | 342 | sprintf((char*)text, "Touche 4 appuyée"); |
38domo | 0:77e62347e7c9 | 343 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 344 | touche_appuyee = 4;touche_appuyee_s = "4"; |
38domo | 0:77e62347e7c9 | 345 | } |
38domo | 0:77e62347e7c9 | 346 | if ((x>420)&(x<470)) |
38domo | 0:77e62347e7c9 | 347 | { // touche 5 appuyée) |
38domo | 0:77e62347e7c9 | 348 | sprintf((char*)text, "Touche 5 appuyée"); |
38domo | 0:77e62347e7c9 | 349 | BSP_LCD_DisplayStringAt(2, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 350 | touche_appuyee = 5;touche_appuyee_s = "5"; |
38domo | 0:77e62347e7c9 | 351 | } |
38domo | 0:77e62347e7c9 | 352 | text_display1 = text_display1 + touche_appuyee_s; |
38domo | 0:77e62347e7c9 | 353 | sprintf(buffer_touche, "text_display1 %d", touche_appuyee); |
38domo | 0:77e62347e7c9 | 354 | BSP_LCD_DisplayStringAt(2, 3, (uint8_t *)&buffer_touche, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 355 | } |
38domo | 0:77e62347e7c9 | 356 | |
38domo | 0:77e62347e7c9 | 357 | } else { |
38domo | 0:77e62347e7c9 | 358 | if (!cleared) |
38domo | 0:77e62347e7c9 | 359 | { //BSP_LCD_Clear(LCD_COLOR_BLUE); |
38domo | 0:77e62347e7c9 | 360 | // sprintf((char*)text, "Touches: 0"); |
38domo | 0:77e62347e7c9 | 361 | // BSP_LCD_DisplayStringAt(2, LINE(2), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:77e62347e7c9 | 362 | cleared = 1; |
38domo | 0:77e62347e7c9 | 363 | } |
38domo | 0:77e62347e7c9 | 364 | } |
38domo | 0:77e62347e7c9 | 365 | } |
38domo | 0:77e62347e7c9 | 366 | } |
38domo | 0:77e62347e7c9 | 367 | |
38domo | 0:77e62347e7c9 | 368 | //int main() { |
38domo | 0:77e62347e7c9 | 369 | // pc.printf("Hello World!\n\r"); |
38domo | 0:77e62347e7c9 | 370 | // while(1) { |
38domo | 0:77e62347e7c9 | 371 | // pc.putc(pc.getc() + 1); // echo input back to terminal |
38domo | 0:77e62347e7c9 | 372 | // }// |
38domo | 0:77e62347e7c9 | 373 | //} |
38domo | 0:77e62347e7c9 | 374 | /* |
38domo | 0:77e62347e7c9 | 375 | int main() { |
38domo | 0:77e62347e7c9 | 376 | while(1) { |
38domo | 0:77e62347e7c9 | 377 | if(pc.readable()) { |
38domo | 0:77e62347e7c9 | 378 | device.putc(pc.getc()); |
38domo | 0:77e62347e7c9 | 379 | } |
38domo | 0:77e62347e7c9 | 380 | if(device.readable()) { |
38domo | 0:77e62347e7c9 | 381 | pc.putc(device.getc()); |
38domo | 0:77e62347e7c9 | 382 | } |
38domo | 0:77e62347e7c9 | 383 | } |
38domo | 0:77e62347e7c9 | 384 | } |
38domo | 0:77e62347e7c9 | 385 | */ |
38domo | 0:77e62347e7c9 | 386 | /* |
38domo | 0:77e62347e7c9 | 387 | #include "mbed.h" |
38domo | 0:77e62347e7c9 | 388 | |
38domo | 0:77e62347e7c9 | 389 | Serial pc(USBTX, USBRX); // tx, rx |
38domo | 0:77e62347e7c9 | 390 | PwmOut led(LED1); |
38domo | 0:77e62347e7c9 | 391 | |
38domo | 0:77e62347e7c9 | 392 | float brightness = 0.0; |
38domo | 0:77e62347e7c9 | 393 | |
38domo | 0:77e62347e7c9 | 394 | int main() { |
38domo | 0:77e62347e7c9 | 395 | pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); |
38domo | 0:77e62347e7c9 | 396 | |
38domo | 0:77e62347e7c9 | 397 | while(1) { |
38domo | 0:77e62347e7c9 | 398 | char c = pc.getc(); |
38domo | 0:77e62347e7c9 | 399 | if((c == 'u') && (brightness < 0.5)) { |
38domo | 0:77e62347e7c9 | 400 | brightness += 0.01; |
38domo | 0:77e62347e7c9 | 401 | led = brightness; |
38domo | 0:77e62347e7c9 | 402 | } |
38domo | 0:77e62347e7c9 | 403 | if((c == 'd') && (brightness > 0.0)) { |
38domo | 0:77e62347e7c9 | 404 | brightness -= 0.01; |
38domo | 0:77e62347e7c9 | 405 | led = brightness; |
38domo | 0:77e62347e7c9 | 406 | } |
38domo | 0:77e62347e7c9 | 407 | |
38domo | 0:77e62347e7c9 | 408 | } |
38domo | 0:77e62347e7c9 | 409 | } |
38domo | 0:77e62347e7c9 | 410 | */ |
38domo | 0:77e62347e7c9 | 411 | /* |
38domo | 0:77e62347e7c9 | 412 | #include "mbed.h" |
38domo | 0:77e62347e7c9 | 413 | |
38domo | 0:77e62347e7c9 | 414 | Serial pc(USBTX, USBRX); |
38domo | 0:77e62347e7c9 | 415 | Serial uart(p28, p27); |
38domo | 0:77e62347e7c9 | 416 | |
38domo | 0:77e62347e7c9 | 417 | DigitalOut pc_activity(LED1); |
38domo | 0:77e62347e7c9 | 418 | DigitalOut uart_activity(LED2); |
38domo | 0:77e62347e7c9 | 419 | |
38domo | 0:77e62347e7c9 | 420 | int main() { |
38domo | 0:77e62347e7c9 | 421 | while(1) { |
38domo | 0:77e62347e7c9 | 422 | if(pc.readable()) { |
38domo | 0:77e62347e7c9 | 423 | uart.putc(pc.getc()); |
38domo | 0:77e62347e7c9 | 424 | pc_activity = !pc_activity; |
38domo | 0:77e62347e7c9 | 425 | } |
38domo | 0:77e62347e7c9 | 426 | if(uart.readable()) { |
38domo | 0:77e62347e7c9 | 427 | pc.putc(uart.getc()); |
38domo | 0:77e62347e7c9 | 428 | uart_activity = !uart_activity; |
38domo | 0:77e62347e7c9 | 429 | } |
38domo | 0:77e62347e7c9 | 430 | } |
38domo | 0:77e62347e7c9 | 431 | } |
38domo | 0:77e62347e7c9 | 432 | */ |
38domo | 0:77e62347e7c9 | 433 | /* |
38domo | 0:77e62347e7c9 | 434 | #include "mbed.h" |
38domo | 0:77e62347e7c9 | 435 | |
38domo | 0:77e62347e7c9 | 436 | DigitalOut myled(LED1); |
38domo | 0:77e62347e7c9 | 437 | Serial pc(USBTX, USBRX); |
38domo | 0:77e62347e7c9 | 438 | |
38domo | 0:77e62347e7c9 | 439 | int main() { |
38domo | 0:77e62347e7c9 | 440 | char c; |
38domo | 0:77e62347e7c9 | 441 | char buffer[128]; |
38domo | 0:77e62347e7c9 | 442 | |
38domo | 0:77e62347e7c9 | 443 | pc.gets(buffer, 4); |
38domo | 0:77e62347e7c9 | 444 | |
38domo | 0:77e62347e7c9 | 445 | pc.printf("I got '%s'\n", buffer); |
38domo | 0:77e62347e7c9 | 446 | } |
38domo | 0:77e62347e7c9 | 447 | */ |
38domo | 0:77e62347e7c9 | 448 | /* |
38domo | 0:77e62347e7c9 | 449 | sd card filesystem |
38domo | 0:77e62347e7c9 | 450 | /* Example file of using SD/MMC Block device Library for MBED-OS |
38domo | 0:77e62347e7c9 | 451 | * Copyright 2017 Roy Krikke |
38domo | 0:77e62347e7c9 | 452 | * Licensed under the Apache License, Version 2.0 (the "License"); |
38domo | 0:77e62347e7c9 | 453 | * you may not use this file except in compliance with the License. |
38domo | 0:77e62347e7c9 | 454 | * You may obtain a copy of the License at |
38domo | 0:77e62347e7c9 | 455 | * http://www.apache.org/licenses/LICENSE-2.0 |
38domo | 0:77e62347e7c9 | 456 | * Unless required by applicable law or agreed to in writing, software |
38domo | 0:77e62347e7c9 | 457 | * distributed under the License is distributed on an "AS IS" BASIS, |
38domo | 0:77e62347e7c9 | 458 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
38domo | 0:77e62347e7c9 | 459 | * See the License for the specific language governing permissions and |
38domo | 0:77e62347e7c9 | 460 | * limitations under the License. |
38domo | 0:77e62347e7c9 | 461 | |
38domo | 0:77e62347e7c9 | 462 | #include "mbed.h" |
38domo | 0:77e62347e7c9 | 463 | #include "FATFileSystem.h" |
38domo | 0:77e62347e7c9 | 464 | #include "SDBlockDeviceDISCOF746NG.h" |
38domo | 0:77e62347e7c9 | 465 | #include <stdio.h> |
38domo | 0:77e62347e7c9 | 466 | #include <errno.h> |
38domo | 0:77e62347e7c9 | 467 | |
38domo | 0:77e62347e7c9 | 468 | DigitalOut led (LED1); |
38domo | 0:77e62347e7c9 | 469 | |
38domo | 0:77e62347e7c9 | 470 | // Instantiate the Block Device for sd card on DISCO-F746NG |
38domo | 0:77e62347e7c9 | 471 | SDBlockDeviceDISCOF746NG bd; |
38domo | 0:77e62347e7c9 | 472 | FATFileSystem fs ("fs"); |
38domo | 0:77e62347e7c9 | 473 | |
38domo | 0:77e62347e7c9 | 474 | void |
38domo | 0:77e62347e7c9 | 475 | return_error (int ret_val) |
38domo | 0:77e62347e7c9 | 476 | { if(ret_val) |
38domo | 0:77e62347e7c9 | 477 | printf ("Failure. %d\r\n", ret_val); |
38domo | 0:77e62347e7c9 | 478 | else |
38domo | 0:77e62347e7c9 | 479 | printf ("done.\r\n"); |
38domo | 0:77e62347e7c9 | 480 | } |
38domo | 0:77e62347e7c9 | 481 | |
38domo | 0:77e62347e7c9 | 482 | void |
38domo | 0:77e62347e7c9 | 483 | errno_error (void* ret_val) |
38domo | 0:77e62347e7c9 | 484 | { if(ret_val == NULL) |
38domo | 0:77e62347e7c9 | 485 | printf (" Failure. %d \r\n", errno); |
38domo | 0:77e62347e7c9 | 486 | else |
38domo | 0:77e62347e7c9 | 487 | printf (" done.\r\n"); |
38domo | 0:77e62347e7c9 | 488 | } |
38domo | 0:77e62347e7c9 | 489 | |
38domo | 0:77e62347e7c9 | 490 | int |
38domo | 0:77e62347e7c9 | 491 | main () |
38domo | 0:77e62347e7c9 | 492 | { |
38domo | 0:77e62347e7c9 | 493 | Serial pc (SERIAL_TX, SERIAL_RX); |
38domo | 0:77e62347e7c9 | 494 | pc.baud(115200); |
38domo | 0:77e62347e7c9 | 495 | printf("Start\n"); |
38domo | 0:77e62347e7c9 | 496 | |
38domo | 0:77e62347e7c9 | 497 | int error = 0; |
38domo | 0:77e62347e7c9 | 498 | printf("Welcome to the filesystem example.\r\n" |
38domo | 0:77e62347e7c9 | 499 | "Formatting a FAT, RAM-backed filesystem. "); |
38domo | 0:77e62347e7c9 | 500 | error = FATFileSystem::format(&bd); |
38domo | 0:77e62347e7c9 | 501 | return_error(error); |
38domo | 0:77e62347e7c9 | 502 | |
38domo | 0:77e62347e7c9 | 503 | printf("Mounting the filesystem on \"/fs\". "); |
38domo | 0:77e62347e7c9 | 504 | error = fs.mount(&bd); |
38domo | 0:77e62347e7c9 | 505 | return_error(error); |
38domo | 0:77e62347e7c9 | 506 | |
38domo | 0:77e62347e7c9 | 507 | printf("Opening a new file, numbers.txt."); |
38domo | 0:77e62347e7c9 | 508 | FILE* fd = fopen("/fs/numbers.txt", "w"); |
38domo | 0:77e62347e7c9 | 509 | errno_error(fd); |
38domo | 0:77e62347e7c9 | 510 | |
38domo | 0:77e62347e7c9 | 511 | for (int i = 0; i < 20; i++) { |
38domo | 0:77e62347e7c9 | 512 | printf("Writing decimal numbers to a file (%d/20)\r", i); |
38domo | 0:77e62347e7c9 | 513 | fprintf(fd, "%d\r\n", i); |
38domo | 0:77e62347e7c9 | 514 | } |
38domo | 0:77e62347e7c9 | 515 | printf("Writing decimal numbers to a file (20/20) done.\r\n"); |
38domo | 0:77e62347e7c9 | 516 | |
38domo | 0:77e62347e7c9 | 517 | printf("Closing file."); |
38domo | 0:77e62347e7c9 | 518 | fclose(fd); |
38domo | 0:77e62347e7c9 | 519 | printf(" done.\r\n"); |
38domo | 0:77e62347e7c9 | 520 | |
38domo | 0:77e62347e7c9 | 521 | printf("Re-opening file read-only."); |
38domo | 0:77e62347e7c9 | 522 | fd = fopen("/fs/numbers.txt", "r"); |
38domo | 0:77e62347e7c9 | 523 | errno_error(fd); |
38domo | 0:77e62347e7c9 | 524 | |
38domo | 0:77e62347e7c9 | 525 | printf("Dumping file to screen.\r\n"); |
38domo | 0:77e62347e7c9 | 526 | char buff[16] = { 0 }; |
38domo | 0:77e62347e7c9 | 527 | while(!feof (fd)) { |
38domo | 0:77e62347e7c9 | 528 | int size = fread(&buff[0], 1, 15, fd); |
38domo | 0:77e62347e7c9 | 529 | fwrite(&buff[0], 1, size, stdout); |
38domo | 0:77e62347e7c9 | 530 | } |
38domo | 0:77e62347e7c9 | 531 | printf("EOF.\r\n"); |
38domo | 0:77e62347e7c9 | 532 | |
38domo | 0:77e62347e7c9 | 533 | printf("Closing file."); |
38domo | 0:77e62347e7c9 | 534 | fclose(fd); |
38domo | 0:77e62347e7c9 | 535 | printf(" done.\r\n"); |
38domo | 0:77e62347e7c9 | 536 | |
38domo | 0:77e62347e7c9 | 537 | printf("Opening root directory."); |
38domo | 0:77e62347e7c9 | 538 | DIR* dir = opendir("/fs/"); |
38domo | 0:77e62347e7c9 | 539 | errno_error(fd); |
38domo | 0:77e62347e7c9 | 540 | |
38domo | 0:77e62347e7c9 | 541 | struct dirent* de; |
38domo | 0:77e62347e7c9 | 542 | printf("Printing all filenames:\r\n"); |
38domo | 0:77e62347e7c9 | 543 | while((de = readdir (dir)) != NULL) { |
38domo | 0:77e62347e7c9 | 544 | printf(" %s\r\n", &(de->d_name)[0]); |
38domo | 0:77e62347e7c9 | 545 | } |
38domo | 0:77e62347e7c9 | 546 | |
38domo | 0:77e62347e7c9 | 547 | printf("Closeing root directory. "); |
38domo | 0:77e62347e7c9 | 548 | error = closedir(dir); |
38domo | 0:77e62347e7c9 | 549 | return_error(error); |
38domo | 0:77e62347e7c9 | 550 | printf("Filesystem Demo complete.\r\n"); |
38domo | 0:77e62347e7c9 | 551 | |
38domo | 0:77e62347e7c9 | 552 | // Blink led with 2 Hz |
38domo | 0:77e62347e7c9 | 553 | while(true) { |
38domo | 0:77e62347e7c9 | 554 | led = !led; |
38domo | 0:77e62347e7c9 | 555 | wait (0.5); |
38domo | 0:77e62347e7c9 | 556 | } |
38domo | 0:77e62347e7c9 | 557 | } |
38domo | 0:77e62347e7c9 | 558 | */ |