max32630fthr quad spi , unexpected spi behavior

Committer:
boonshen
Date:
Tue Mar 13 21:12:00 2018 +0000
Revision:
0:a35c40f49345
MAX32630FTHR QuadSPI test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boonshen 0:a35c40f49345 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
boonshen 0:a35c40f49345 2 *
boonshen 0:a35c40f49345 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
boonshen 0:a35c40f49345 4 * and associated documentation files (the "Software"), to deal in the Software without
boonshen 0:a35c40f49345 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
boonshen 0:a35c40f49345 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
boonshen 0:a35c40f49345 7 * Software is furnished to do so, subject to the following conditions:
boonshen 0:a35c40f49345 8 *
boonshen 0:a35c40f49345 9 * The above copyright notice and this permission notice shall be included in all copies or
boonshen 0:a35c40f49345 10 * substantial portions of the Software.
boonshen 0:a35c40f49345 11 *
boonshen 0:a35c40f49345 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
boonshen 0:a35c40f49345 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
boonshen 0:a35c40f49345 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
boonshen 0:a35c40f49345 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
boonshen 0:a35c40f49345 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
boonshen 0:a35c40f49345 17 */
boonshen 0:a35c40f49345 18
boonshen 0:a35c40f49345 19 #include "stdint.h"
boonshen 0:a35c40f49345 20 #include "USBSerial.h"
boonshen 0:a35c40f49345 21
boonshen 0:a35c40f49345 22 int USBSerial::_putc(int c) {
boonshen 0:a35c40f49345 23 if (!terminal_connected)
boonshen 0:a35c40f49345 24 return 0;
boonshen 0:a35c40f49345 25 send((uint8_t *)&c, 1);
boonshen 0:a35c40f49345 26 return 1;
boonshen 0:a35c40f49345 27 }
boonshen 0:a35c40f49345 28
boonshen 0:a35c40f49345 29 int USBSerial::_getc() {
boonshen 0:a35c40f49345 30 uint8_t c = 0;
boonshen 0:a35c40f49345 31 while (buf.isEmpty());
boonshen 0:a35c40f49345 32 buf.dequeue(&c);
boonshen 0:a35c40f49345 33 return c;
boonshen 0:a35c40f49345 34 }
boonshen 0:a35c40f49345 35
boonshen 0:a35c40f49345 36
boonshen 0:a35c40f49345 37 bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) {
boonshen 0:a35c40f49345 38 if(size > MAX_PACKET_SIZE_EPBULK) {
boonshen 0:a35c40f49345 39 return false;
boonshen 0:a35c40f49345 40 }
boonshen 0:a35c40f49345 41 if(!send(buf, size)) {
boonshen 0:a35c40f49345 42 return false;
boonshen 0:a35c40f49345 43 }
boonshen 0:a35c40f49345 44 return true;
boonshen 0:a35c40f49345 45 }
boonshen 0:a35c40f49345 46
boonshen 0:a35c40f49345 47
boonshen 0:a35c40f49345 48
boonshen 0:a35c40f49345 49 bool USBSerial::EPBULK_OUT_callback() {
boonshen 0:a35c40f49345 50 uint8_t c[65];
boonshen 0:a35c40f49345 51 uint32_t size = 0;
boonshen 0:a35c40f49345 52
boonshen 0:a35c40f49345 53 //we read the packet received and put it on the circular buffer
boonshen 0:a35c40f49345 54 readEP(c, &size);
boonshen 0:a35c40f49345 55 for (uint32_t i = 0; i < size; i++) {
boonshen 0:a35c40f49345 56 buf.queue(c[i]);
boonshen 0:a35c40f49345 57 }
boonshen 0:a35c40f49345 58
boonshen 0:a35c40f49345 59 //call a potential handler
boonshen 0:a35c40f49345 60 rx.call();
boonshen 0:a35c40f49345 61
boonshen 0:a35c40f49345 62 return true;
boonshen 0:a35c40f49345 63 }
boonshen 0:a35c40f49345 64
boonshen 0:a35c40f49345 65 uint8_t USBSerial::available() {
boonshen 0:a35c40f49345 66 return buf.available();
boonshen 0:a35c40f49345 67 }