ISP example program.
Dependencies: SLCD mbed USBLocalFileSystem
FRDM-KL46Z | LPC810 | |
---|---|---|
UART RXD | PTE23 | p2(P0_4) |
UART TXD | PTE22 | p8(P0_0) |
nRESET | D6 | p1(P0_5) |
nISP | D8 | p5(P0_1) |
GND | GND | p7 |
3.3V | P3V3 | p6 |
Copy binary image to the disk called LPC81ISP.
Push sw1 or sw3, start write to LPC810 flash.
USBMSD2/USB_CDC.h@1:cccfc461c61f, 2014-02-16 (annotated)
- Committer:
- va009039
- Date:
- Sun Feb 16 12:56:12 2014 +0000
- Revision:
- 1:cccfc461c61f
add virtual COM.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:cccfc461c61f | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
va009039 | 1:cccfc461c61f | 2 | * |
va009039 | 1:cccfc461c61f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
va009039 | 1:cccfc461c61f | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
va009039 | 1:cccfc461c61f | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
va009039 | 1:cccfc461c61f | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
va009039 | 1:cccfc461c61f | 7 | * Software is furnished to do so, subject to the following conditions: |
va009039 | 1:cccfc461c61f | 8 | * |
va009039 | 1:cccfc461c61f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
va009039 | 1:cccfc461c61f | 10 | * substantial portions of the Software. |
va009039 | 1:cccfc461c61f | 11 | * |
va009039 | 1:cccfc461c61f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
va009039 | 1:cccfc461c61f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
va009039 | 1:cccfc461c61f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
va009039 | 1:cccfc461c61f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
va009039 | 1:cccfc461c61f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
va009039 | 1:cccfc461c61f | 17 | */ |
va009039 | 1:cccfc461c61f | 18 | |
va009039 | 1:cccfc461c61f | 19 | #pragma once |
va009039 | 1:cccfc461c61f | 20 | |
va009039 | 1:cccfc461c61f | 21 | #include "USBDevice.h" |
va009039 | 1:cccfc461c61f | 22 | #include "CircBuffer.h" |
va009039 | 1:cccfc461c61f | 23 | |
va009039 | 1:cccfc461c61f | 24 | #if defined(TARGET_LPC1768) |
va009039 | 1:cccfc461c61f | 25 | #define CDC_EPINT_IN EP1IN |
va009039 | 1:cccfc461c61f | 26 | #define CDC_EPBULK_IN EP5IN |
va009039 | 1:cccfc461c61f | 27 | #define CDC_EPBULK_OUT EP5OUT |
va009039 | 1:cccfc461c61f | 28 | #elif defined(TARGET_LPC1347) |
va009039 | 1:cccfc461c61f | 29 | #define CDC_EPINT_IN EP1IN |
va009039 | 1:cccfc461c61f | 30 | #define CDC_EPBULK_IN EP3IN |
va009039 | 1:cccfc461c61f | 31 | #define CDC_EPBULK_OUT EP3OUT |
va009039 | 1:cccfc461c61f | 32 | #elif defined(TARGET_KL25Z)||defined(TARGET_KL46Z) |
va009039 | 1:cccfc461c61f | 33 | #define CDC_EPINT_IN EP1IN |
va009039 | 1:cccfc461c61f | 34 | #define CDC_EPBULK_IN EP5IN |
va009039 | 1:cccfc461c61f | 35 | #define CDC_EPBULK_OUT EP5OUT |
va009039 | 1:cccfc461c61f | 36 | #else |
va009039 | 1:cccfc461c61f | 37 | #error "target type error" |
va009039 | 1:cccfc461c61f | 38 | #endif |
va009039 | 1:cccfc461c61f | 39 | |
va009039 | 1:cccfc461c61f | 40 | class USB_CDC { |
va009039 | 1:cccfc461c61f | 41 | public: |
va009039 | 1:cccfc461c61f | 42 | USB_CDC(USBDevice* device); |
va009039 | 1:cccfc461c61f | 43 | |
va009039 | 1:cccfc461c61f | 44 | /** target to virtual COM |
va009039 | 1:cccfc461c61f | 45 | */ |
va009039 | 1:cccfc461c61f | 46 | void putc(int c); |
va009039 | 1:cccfc461c61f | 47 | |
va009039 | 1:cccfc461c61f | 48 | /** virtial COM to target |
va009039 | 1:cccfc461c61f | 49 | */ |
va009039 | 1:cccfc461c61f | 50 | int getc(); |
va009039 | 1:cccfc461c61f | 51 | |
va009039 | 1:cccfc461c61f | 52 | int readable(); |
va009039 | 1:cccfc461c61f | 53 | |
va009039 | 1:cccfc461c61f | 54 | int writeable(); |
va009039 | 1:cccfc461c61f | 55 | |
va009039 | 1:cccfc461c61f | 56 | void baud_callback(int baudrate); |
va009039 | 1:cccfc461c61f | 57 | void send_break_callback(uint16_t duration); |
va009039 | 1:cccfc461c61f | 58 | void control_line_callback(int rts, int dtr); |
va009039 | 1:cccfc461c61f | 59 | |
va009039 | 1:cccfc461c61f | 60 | /* |
va009039 | 1:cccfc461c61f | 61 | * Send a buffer |
va009039 | 1:cccfc461c61f | 62 | * |
va009039 | 1:cccfc461c61f | 63 | * @param endpoint endpoint which will be sent the buffer |
va009039 | 1:cccfc461c61f | 64 | * @param buffer buffer to be sent |
va009039 | 1:cccfc461c61f | 65 | * @param size length of the buffer |
va009039 | 1:cccfc461c61f | 66 | * @returns true if successful |
va009039 | 1:cccfc461c61f | 67 | */ |
va009039 | 1:cccfc461c61f | 68 | bool send(uint8_t * buffer, uint32_t size); |
va009039 | 1:cccfc461c61f | 69 | |
va009039 | 1:cccfc461c61f | 70 | /* |
va009039 | 1:cccfc461c61f | 71 | * Read a buffer from a certain endpoint. Warning: blocking |
va009039 | 1:cccfc461c61f | 72 | * |
va009039 | 1:cccfc461c61f | 73 | * @param endpoint endpoint to read |
va009039 | 1:cccfc461c61f | 74 | * @param buffer buffer where will be stored bytes |
va009039 | 1:cccfc461c61f | 75 | * @param size the number of bytes read will be stored in *size |
va009039 | 1:cccfc461c61f | 76 | * @param maxSize the maximum length that can be read |
va009039 | 1:cccfc461c61f | 77 | * @returns true if successful |
va009039 | 1:cccfc461c61f | 78 | */ |
va009039 | 1:cccfc461c61f | 79 | bool readEP(uint8_t * buffer, uint32_t * size); |
va009039 | 1:cccfc461c61f | 80 | |
va009039 | 1:cccfc461c61f | 81 | /* |
va009039 | 1:cccfc461c61f | 82 | * Read a buffer from a certain endpoint. Warning: non blocking |
va009039 | 1:cccfc461c61f | 83 | * |
va009039 | 1:cccfc461c61f | 84 | * @param endpoint endpoint to read |
va009039 | 1:cccfc461c61f | 85 | * @param buffer buffer where will be stored bytes |
va009039 | 1:cccfc461c61f | 86 | * @param size the number of bytes read will be stored in *size |
va009039 | 1:cccfc461c61f | 87 | * @param maxSize the maximum length that can be read |
va009039 | 1:cccfc461c61f | 88 | * @returns true if successful |
va009039 | 1:cccfc461c61f | 89 | */ |
va009039 | 1:cccfc461c61f | 90 | bool readEP_NB(uint8_t * buffer, uint32_t * size); |
va009039 | 1:cccfc461c61f | 91 | |
va009039 | 1:cccfc461c61f | 92 | bool Request_callback(CONTROL_TRANSFER* transfer); |
va009039 | 1:cccfc461c61f | 93 | bool RequestCompleted_callback(CONTROL_TRANSFER* transfer, uint8_t* buf, int length); |
va009039 | 1:cccfc461c61f | 94 | bool EPBULK_OUT_callback(); |
va009039 | 1:cccfc461c61f | 95 | |
va009039 | 1:cccfc461c61f | 96 | private: |
va009039 | 1:cccfc461c61f | 97 | USBDevice* _device; |
va009039 | 1:cccfc461c61f | 98 | CircBuffer<uint8_t> _rx_buf; |
va009039 | 1:cccfc461c61f | 99 | volatile bool terminal_connected; |
va009039 | 1:cccfc461c61f | 100 | }; |