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 /* mbed Microcontroller Library
boonshen 0:a35c40f49345 2 * Copyright (c) 2006-2013 ARM Limited
boonshen 0:a35c40f49345 3 *
boonshen 0:a35c40f49345 4 * Licensed under the Apache License, Version 2.0 (the "License");
boonshen 0:a35c40f49345 5 * you may not use this file except in compliance with the License.
boonshen 0:a35c40f49345 6 * You may obtain a copy of the License at
boonshen 0:a35c40f49345 7 *
boonshen 0:a35c40f49345 8 * http://www.apache.org/licenses/LICENSE-2.0
boonshen 0:a35c40f49345 9 *
boonshen 0:a35c40f49345 10 * Unless required by applicable law or agreed to in writing, software
boonshen 0:a35c40f49345 11 * distributed under the License is distributed on an "AS IS" BASIS,
boonshen 0:a35c40f49345 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
boonshen 0:a35c40f49345 13 * See the License for the specific language governing permissions and
boonshen 0:a35c40f49345 14 * limitations under the License.
boonshen 0:a35c40f49345 15 */
boonshen 0:a35c40f49345 16 #include "drivers/RawSerial.h"
boonshen 0:a35c40f49345 17 #include "platform/mbed_wait_api.h"
boonshen 0:a35c40f49345 18 #include <stdio.h>
boonshen 0:a35c40f49345 19 #include <cstdarg>
boonshen 0:a35c40f49345 20
boonshen 0:a35c40f49345 21
boonshen 0:a35c40f49345 22 #if DEVICE_SERIAL
boonshen 0:a35c40f49345 23
boonshen 0:a35c40f49345 24 #define STRING_STACK_LIMIT 120
boonshen 0:a35c40f49345 25
boonshen 0:a35c40f49345 26 namespace mbed {
boonshen 0:a35c40f49345 27
boonshen 0:a35c40f49345 28 RawSerial::RawSerial(PinName tx, PinName rx, int baud) : SerialBase(tx, rx, baud) {
boonshen 0:a35c40f49345 29 // No lock needed in the constructor
boonshen 0:a35c40f49345 30 }
boonshen 0:a35c40f49345 31
boonshen 0:a35c40f49345 32 int RawSerial::getc() {
boonshen 0:a35c40f49345 33 lock();
boonshen 0:a35c40f49345 34 int ret = _base_getc();
boonshen 0:a35c40f49345 35 unlock();
boonshen 0:a35c40f49345 36 return ret;
boonshen 0:a35c40f49345 37 }
boonshen 0:a35c40f49345 38
boonshen 0:a35c40f49345 39 int RawSerial::putc(int c) {
boonshen 0:a35c40f49345 40 lock();
boonshen 0:a35c40f49345 41 int ret = _base_putc(c);
boonshen 0:a35c40f49345 42 unlock();
boonshen 0:a35c40f49345 43 return ret;
boonshen 0:a35c40f49345 44 }
boonshen 0:a35c40f49345 45
boonshen 0:a35c40f49345 46 int RawSerial::puts(const char *str) {
boonshen 0:a35c40f49345 47 lock();
boonshen 0:a35c40f49345 48 while (*str)
boonshen 0:a35c40f49345 49 putc(*str ++);
boonshen 0:a35c40f49345 50 unlock();
boonshen 0:a35c40f49345 51 return 0;
boonshen 0:a35c40f49345 52 }
boonshen 0:a35c40f49345 53
boonshen 0:a35c40f49345 54 // Experimental support for printf in RawSerial. No Stream inheritance
boonshen 0:a35c40f49345 55 // means we can't call printf() directly, so we use sprintf() instead.
boonshen 0:a35c40f49345 56 // We only call malloc() for the sprintf() buffer if the buffer
boonshen 0:a35c40f49345 57 // length is above a certain threshold, otherwise we use just the stack.
boonshen 0:a35c40f49345 58 int RawSerial::printf(const char *format, ...) {
boonshen 0:a35c40f49345 59 lock();
boonshen 0:a35c40f49345 60 std::va_list arg;
boonshen 0:a35c40f49345 61 va_start(arg, format);
boonshen 0:a35c40f49345 62 // ARMCC microlib does not properly handle a size of 0.
boonshen 0:a35c40f49345 63 // As a workaround supply a dummy buffer with a size of 1.
boonshen 0:a35c40f49345 64 char dummy_buf[1];
boonshen 0:a35c40f49345 65 int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg);
boonshen 0:a35c40f49345 66 if (len < STRING_STACK_LIMIT) {
boonshen 0:a35c40f49345 67 char temp[STRING_STACK_LIMIT];
boonshen 0:a35c40f49345 68 vsprintf(temp, format, arg);
boonshen 0:a35c40f49345 69 puts(temp);
boonshen 0:a35c40f49345 70 } else {
boonshen 0:a35c40f49345 71 char *temp = new char[len + 1];
boonshen 0:a35c40f49345 72 vsprintf(temp, format, arg);
boonshen 0:a35c40f49345 73 puts(temp);
boonshen 0:a35c40f49345 74 delete[] temp;
boonshen 0:a35c40f49345 75 }
boonshen 0:a35c40f49345 76 va_end(arg);
boonshen 0:a35c40f49345 77 unlock();
boonshen 0:a35c40f49345 78 return len;
boonshen 0:a35c40f49345 79 }
boonshen 0:a35c40f49345 80
boonshen 0:a35c40f49345 81 /** Acquire exclusive access to this serial port
boonshen 0:a35c40f49345 82 */
boonshen 0:a35c40f49345 83 void RawSerial::lock() {
boonshen 0:a35c40f49345 84 // No lock used - external synchronization required
boonshen 0:a35c40f49345 85 }
boonshen 0:a35c40f49345 86
boonshen 0:a35c40f49345 87 /** Release exclusive access to this serial port
boonshen 0:a35c40f49345 88 */
boonshen 0:a35c40f49345 89 void RawSerial::unlock() {
boonshen 0:a35c40f49345 90 // No lock used - external synchronization required
boonshen 0:a35c40f49345 91 }
boonshen 0:a35c40f49345 92
boonshen 0:a35c40f49345 93 } // namespace mbed
boonshen 0:a35c40f49345 94
boonshen 0:a35c40f49345 95 #endif