Fork of mbed-dev with the NUCLEO-L152RE target modified for use with the STM32L151RB (128 kB flash, 16 kB RAM).

Fork of mbed-dev by mbed official

To use this, remove the default "mbed" library and import this one instead. Target must be NUCLEO_L152RE.

Committer:
Jim Paris
Date:
Thu Feb 11 15:22:33 2016 -0500
Revision:
28:a132a70c6c08
Parent:
0:9b334a45a8ff
Merge to get rid of old heads

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 /* mbed Microcontroller Library
bogdanm 0:9b334a45a8ff 2 * Copyright (c) 2006-2013 ARM Limited
bogdanm 0:9b334a45a8ff 3 *
bogdanm 0:9b334a45a8ff 4 * Licensed under the Apache License, Version 2.0 (the "License");
bogdanm 0:9b334a45a8ff 5 * you may not use this file except in compliance with the License.
bogdanm 0:9b334a45a8ff 6 * You may obtain a copy of the License at
bogdanm 0:9b334a45a8ff 7 *
bogdanm 0:9b334a45a8ff 8 * http://www.apache.org/licenses/LICENSE-2.0
bogdanm 0:9b334a45a8ff 9 *
bogdanm 0:9b334a45a8ff 10 * Unless required by applicable law or agreed to in writing, software
bogdanm 0:9b334a45a8ff 11 * distributed under the License is distributed on an "AS IS" BASIS,
bogdanm 0:9b334a45a8ff 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bogdanm 0:9b334a45a8ff 13 * See the License for the specific language governing permissions and
bogdanm 0:9b334a45a8ff 14 * limitations under the License.
bogdanm 0:9b334a45a8ff 15 */
bogdanm 0:9b334a45a8ff 16 #include <stdio.h>
bogdanm 0:9b334a45a8ff 17 #include "mbed_interface.h"
bogdanm 0:9b334a45a8ff 18
bogdanm 0:9b334a45a8ff 19 #include "gpio_api.h"
bogdanm 0:9b334a45a8ff 20 #include "wait_api.h"
bogdanm 0:9b334a45a8ff 21 #include "semihost_api.h"
bogdanm 0:9b334a45a8ff 22 #include "mbed_error.h"
bogdanm 0:9b334a45a8ff 23 #include "toolchain.h"
bogdanm 0:9b334a45a8ff 24
bogdanm 0:9b334a45a8ff 25 #if DEVICE_SEMIHOST
bogdanm 0:9b334a45a8ff 26
bogdanm 0:9b334a45a8ff 27 // return true if a debugger is attached, indicating mbed interface is connected
bogdanm 0:9b334a45a8ff 28 int mbed_interface_connected(void) {
bogdanm 0:9b334a45a8ff 29 return semihost_connected();
bogdanm 0:9b334a45a8ff 30 }
bogdanm 0:9b334a45a8ff 31
bogdanm 0:9b334a45a8ff 32 int mbed_interface_reset(void) {
bogdanm 0:9b334a45a8ff 33 if (mbed_interface_connected()) {
bogdanm 0:9b334a45a8ff 34 semihost_reset();
bogdanm 0:9b334a45a8ff 35 return 0;
bogdanm 0:9b334a45a8ff 36 } else {
bogdanm 0:9b334a45a8ff 37 return -1;
bogdanm 0:9b334a45a8ff 38 }
bogdanm 0:9b334a45a8ff 39 }
bogdanm 0:9b334a45a8ff 40
bogdanm 0:9b334a45a8ff 41 WEAK int mbed_interface_uid(char *uid) {
bogdanm 0:9b334a45a8ff 42 if (mbed_interface_connected()) {
bogdanm 0:9b334a45a8ff 43 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
bogdanm 0:9b334a45a8ff 44 } else {
bogdanm 0:9b334a45a8ff 45 uid[0] = 0;
bogdanm 0:9b334a45a8ff 46 return -1;
bogdanm 0:9b334a45a8ff 47 }
bogdanm 0:9b334a45a8ff 48 }
bogdanm 0:9b334a45a8ff 49
bogdanm 0:9b334a45a8ff 50 int mbed_interface_disconnect(void) {
bogdanm 0:9b334a45a8ff 51 int res;
bogdanm 0:9b334a45a8ff 52 if (mbed_interface_connected()) {
bogdanm 0:9b334a45a8ff 53 if ((res = semihost_disabledebug()) != 0)
bogdanm 0:9b334a45a8ff 54 return res;
bogdanm 0:9b334a45a8ff 55 while (mbed_interface_connected());
bogdanm 0:9b334a45a8ff 56 return 0;
bogdanm 0:9b334a45a8ff 57 } else {
bogdanm 0:9b334a45a8ff 58 return -1;
bogdanm 0:9b334a45a8ff 59 }
bogdanm 0:9b334a45a8ff 60 }
bogdanm 0:9b334a45a8ff 61
bogdanm 0:9b334a45a8ff 62 int mbed_interface_powerdown(void) {
bogdanm 0:9b334a45a8ff 63 int res;
bogdanm 0:9b334a45a8ff 64 if (mbed_interface_connected()) {
bogdanm 0:9b334a45a8ff 65 if ((res = semihost_powerdown()) != 0)
bogdanm 0:9b334a45a8ff 66 return res;
bogdanm 0:9b334a45a8ff 67 while (mbed_interface_connected());
bogdanm 0:9b334a45a8ff 68 return 0;
bogdanm 0:9b334a45a8ff 69 } else {
bogdanm 0:9b334a45a8ff 70 return -1;
bogdanm 0:9b334a45a8ff 71 }
bogdanm 0:9b334a45a8ff 72 }
bogdanm 0:9b334a45a8ff 73
bogdanm 0:9b334a45a8ff 74 // for backward compatibility
bogdanm 0:9b334a45a8ff 75 void mbed_reset(void) {
bogdanm 0:9b334a45a8ff 76 mbed_interface_reset();
bogdanm 0:9b334a45a8ff 77 }
bogdanm 0:9b334a45a8ff 78
bogdanm 0:9b334a45a8ff 79 WEAK int mbed_uid(char *uid) {
bogdanm 0:9b334a45a8ff 80 return mbed_interface_uid(uid);
bogdanm 0:9b334a45a8ff 81 }
bogdanm 0:9b334a45a8ff 82 #endif
bogdanm 0:9b334a45a8ff 83
bogdanm 0:9b334a45a8ff 84 WEAK void mbed_mac_address(char *mac) {
bogdanm 0:9b334a45a8ff 85 #if DEVICE_SEMIHOST
bogdanm 0:9b334a45a8ff 86 char uid[DEVICE_ID_LENGTH + 1];
bogdanm 0:9b334a45a8ff 87 int i;
bogdanm 0:9b334a45a8ff 88
bogdanm 0:9b334a45a8ff 89 // if we have a UID, extract the MAC
bogdanm 0:9b334a45a8ff 90 if (mbed_interface_uid(uid) == 0) {
bogdanm 0:9b334a45a8ff 91 char *p = uid;
bogdanm 0:9b334a45a8ff 92 #if defined(DEVICE_MAC_OFFSET)
bogdanm 0:9b334a45a8ff 93 p += DEVICE_MAC_OFFSET;
bogdanm 0:9b334a45a8ff 94 #endif
bogdanm 0:9b334a45a8ff 95 for (i=0; i<6; i++) {
bogdanm 0:9b334a45a8ff 96 int byte;
bogdanm 0:9b334a45a8ff 97 sscanf(p, "%2x", &byte);
bogdanm 0:9b334a45a8ff 98 mac[i] = byte;
bogdanm 0:9b334a45a8ff 99 p += 2;
bogdanm 0:9b334a45a8ff 100 }
bogdanm 0:9b334a45a8ff 101 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
bogdanm 0:9b334a45a8ff 102 } else { // else return a default MAC
bogdanm 0:9b334a45a8ff 103 #endif
bogdanm 0:9b334a45a8ff 104 mac[0] = 0x00;
bogdanm 0:9b334a45a8ff 105 mac[1] = 0x02;
bogdanm 0:9b334a45a8ff 106 mac[2] = 0xF7;
bogdanm 0:9b334a45a8ff 107 mac[3] = 0xF0;
bogdanm 0:9b334a45a8ff 108 mac[4] = 0x00;
bogdanm 0:9b334a45a8ff 109 mac[5] = 0x00;
bogdanm 0:9b334a45a8ff 110 #if DEVICE_SEMIHOST
bogdanm 0:9b334a45a8ff 111 }
bogdanm 0:9b334a45a8ff 112 #endif
bogdanm 0:9b334a45a8ff 113 }