hal_tick.h changed for the L432KC target in TARGET/../device/ in order to reassign the system ticker from TIM2 to TIM7, since TIM2 was needed as a 32bit encoder counter.
Dependents: Nucleo_L432KC_Quadrature_Decoder_with_ADC_and_DAC
Fork of mbed-dev by
platform/mbed_semihost_api.c@161:bd0311f1ad86, 2017-05-27 (annotated)
- Committer:
- tonnyleonard
- Date:
- Sat May 27 01:26:18 2017 +0000
- Revision:
- 161:bd0311f1ad86
- Parent:
- 149:156823d33999
Testing ADC with shunt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /* mbed Microcontroller Library |
<> | 149:156823d33999 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 149:156823d33999 | 3 | * |
<> | 149:156823d33999 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 149:156823d33999 | 5 | * you may not use this file except in compliance with the License. |
<> | 149:156823d33999 | 6 | * You may obtain a copy of the License at |
<> | 149:156823d33999 | 7 | * |
<> | 149:156823d33999 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 149:156823d33999 | 9 | * |
<> | 149:156823d33999 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 149:156823d33999 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 149:156823d33999 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 149:156823d33999 | 13 | * See the License for the specific language governing permissions and |
<> | 149:156823d33999 | 14 | * limitations under the License. |
<> | 149:156823d33999 | 15 | */ |
<> | 149:156823d33999 | 16 | #include "cmsis.h" |
<> | 149:156823d33999 | 17 | #include "platform/semihost_api.h" |
<> | 149:156823d33999 | 18 | |
<> | 149:156823d33999 | 19 | #include <stdint.h> |
<> | 149:156823d33999 | 20 | #include <string.h> |
<> | 149:156823d33999 | 21 | |
<> | 149:156823d33999 | 22 | #if DEVICE_SEMIHOST |
<> | 149:156823d33999 | 23 | |
<> | 149:156823d33999 | 24 | // ARM Semihosting Commands |
<> | 149:156823d33999 | 25 | #define SYS_OPEN (0x1) |
<> | 149:156823d33999 | 26 | #define SYS_CLOSE (0x2) |
<> | 149:156823d33999 | 27 | #define SYS_WRITE (0x5) |
<> | 149:156823d33999 | 28 | #define SYS_READ (0x6) |
<> | 149:156823d33999 | 29 | #define SYS_ISTTY (0x9) |
<> | 149:156823d33999 | 30 | #define SYS_SEEK (0xa) |
<> | 149:156823d33999 | 31 | #define SYS_ENSURE (0xb) |
<> | 149:156823d33999 | 32 | #define SYS_FLEN (0xc) |
<> | 149:156823d33999 | 33 | #define SYS_REMOVE (0xe) |
<> | 149:156823d33999 | 34 | #define SYS_RENAME (0xf) |
<> | 149:156823d33999 | 35 | #define SYS_EXIT (0x18) |
<> | 149:156823d33999 | 36 | |
<> | 149:156823d33999 | 37 | // mbed Semihosting Commands |
<> | 149:156823d33999 | 38 | #define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff |
<> | 149:156823d33999 | 39 | #define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0) |
<> | 149:156823d33999 | 40 | #define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1) |
<> | 149:156823d33999 | 41 | #define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2) |
<> | 149:156823d33999 | 42 | #define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3) |
<> | 149:156823d33999 | 43 | #define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4) |
<> | 149:156823d33999 | 44 | #define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5) |
<> | 149:156823d33999 | 45 | |
<> | 149:156823d33999 | 46 | #if DEVICE_LOCALFILESYSTEM |
<> | 149:156823d33999 | 47 | FILEHANDLE semihost_open(const char* name, int openmode) { |
<> | 149:156823d33999 | 48 | uint32_t args[3]; |
<> | 149:156823d33999 | 49 | args[0] = (uint32_t)name; |
<> | 149:156823d33999 | 50 | args[1] = (uint32_t)openmode; |
<> | 149:156823d33999 | 51 | args[2] = (uint32_t)strlen(name); |
<> | 149:156823d33999 | 52 | return __semihost(SYS_OPEN, args); |
<> | 149:156823d33999 | 53 | } |
<> | 149:156823d33999 | 54 | |
<> | 149:156823d33999 | 55 | int semihost_close(FILEHANDLE fh) { |
<> | 149:156823d33999 | 56 | return __semihost(SYS_CLOSE, &fh); |
<> | 149:156823d33999 | 57 | } |
<> | 149:156823d33999 | 58 | |
<> | 149:156823d33999 | 59 | int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) { |
<> | 149:156823d33999 | 60 | if (length == 0) return 0; |
<> | 149:156823d33999 | 61 | |
<> | 149:156823d33999 | 62 | uint32_t args[3]; |
<> | 149:156823d33999 | 63 | args[0] = (uint32_t)fh; |
<> | 149:156823d33999 | 64 | args[1] = (uint32_t)buffer; |
<> | 149:156823d33999 | 65 | args[2] = (uint32_t)length; |
<> | 149:156823d33999 | 66 | return __semihost(SYS_WRITE, args); |
<> | 149:156823d33999 | 67 | } |
<> | 149:156823d33999 | 68 | |
<> | 149:156823d33999 | 69 | int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode) { |
<> | 149:156823d33999 | 70 | uint32_t args[3]; |
<> | 149:156823d33999 | 71 | args[0] = (uint32_t)fh; |
<> | 149:156823d33999 | 72 | args[1] = (uint32_t)buffer; |
<> | 149:156823d33999 | 73 | args[2] = (uint32_t)length; |
<> | 149:156823d33999 | 74 | return __semihost(SYS_READ, args); |
<> | 149:156823d33999 | 75 | } |
<> | 149:156823d33999 | 76 | |
<> | 149:156823d33999 | 77 | int semihost_istty(FILEHANDLE fh) { |
<> | 149:156823d33999 | 78 | return __semihost(SYS_ISTTY, &fh); |
<> | 149:156823d33999 | 79 | } |
<> | 149:156823d33999 | 80 | |
<> | 149:156823d33999 | 81 | int semihost_seek(FILEHANDLE fh, long position) { |
<> | 149:156823d33999 | 82 | uint32_t args[2]; |
<> | 149:156823d33999 | 83 | args[0] = (uint32_t)fh; |
<> | 149:156823d33999 | 84 | args[1] = (uint32_t)position; |
<> | 149:156823d33999 | 85 | return __semihost(SYS_SEEK, args); |
<> | 149:156823d33999 | 86 | } |
<> | 149:156823d33999 | 87 | |
<> | 149:156823d33999 | 88 | int semihost_ensure(FILEHANDLE fh) { |
<> | 149:156823d33999 | 89 | return __semihost(SYS_ENSURE, &fh); |
<> | 149:156823d33999 | 90 | } |
<> | 149:156823d33999 | 91 | |
<> | 149:156823d33999 | 92 | long semihost_flen(FILEHANDLE fh) { |
<> | 149:156823d33999 | 93 | return __semihost(SYS_FLEN, &fh); |
<> | 149:156823d33999 | 94 | } |
<> | 149:156823d33999 | 95 | |
<> | 149:156823d33999 | 96 | int semihost_remove(const char *name) { |
<> | 149:156823d33999 | 97 | uint32_t args[2]; |
<> | 149:156823d33999 | 98 | args[0] = (uint32_t)name; |
<> | 149:156823d33999 | 99 | args[1] = (uint32_t)strlen(name); |
<> | 149:156823d33999 | 100 | return __semihost(SYS_REMOVE, args); |
<> | 149:156823d33999 | 101 | } |
<> | 149:156823d33999 | 102 | |
<> | 149:156823d33999 | 103 | int semihost_rename(const char *old_name, const char *new_name) { |
<> | 149:156823d33999 | 104 | uint32_t args[4]; |
<> | 149:156823d33999 | 105 | args[0] = (uint32_t)old_name; |
<> | 149:156823d33999 | 106 | args[1] = (uint32_t)strlen(old_name); |
<> | 149:156823d33999 | 107 | args[0] = (uint32_t)new_name; |
<> | 149:156823d33999 | 108 | args[1] = (uint32_t)strlen(new_name); |
<> | 149:156823d33999 | 109 | return __semihost(SYS_RENAME, args); |
<> | 149:156823d33999 | 110 | } |
<> | 149:156823d33999 | 111 | #endif |
<> | 149:156823d33999 | 112 | |
<> | 149:156823d33999 | 113 | int semihost_exit(void) { |
<> | 149:156823d33999 | 114 | uint32_t args[4]; |
<> | 149:156823d33999 | 115 | return __semihost(SYS_EXIT, args); |
<> | 149:156823d33999 | 116 | } |
<> | 149:156823d33999 | 117 | |
<> | 149:156823d33999 | 118 | int semihost_uid(char *uid) { |
<> | 149:156823d33999 | 119 | uint32_t args[2]; |
<> | 149:156823d33999 | 120 | args[0] = (uint32_t)uid; |
<> | 149:156823d33999 | 121 | args[1] = DEVICE_ID_LENGTH + 1; |
<> | 149:156823d33999 | 122 | return __semihost(USR_UID, &args); |
<> | 149:156823d33999 | 123 | } |
<> | 149:156823d33999 | 124 | |
<> | 149:156823d33999 | 125 | int semihost_reset(void) { |
<> | 149:156823d33999 | 126 | // Does not normally return, however if used with older firmware versions |
<> | 149:156823d33999 | 127 | // that do not support this call it will return -1. |
<> | 149:156823d33999 | 128 | return __semihost(USR_RESET, NULL); |
<> | 149:156823d33999 | 129 | } |
<> | 149:156823d33999 | 130 | |
<> | 149:156823d33999 | 131 | int semihost_vbus(void) { |
<> | 149:156823d33999 | 132 | return __semihost(USR_VBUS, NULL); |
<> | 149:156823d33999 | 133 | } |
<> | 149:156823d33999 | 134 | |
<> | 149:156823d33999 | 135 | int semihost_powerdown(void) { |
<> | 149:156823d33999 | 136 | return __semihost(USR_POWERDOWN, NULL); |
<> | 149:156823d33999 | 137 | } |
<> | 149:156823d33999 | 138 | |
<> | 149:156823d33999 | 139 | #if DEVICE_DEBUG_AWARENESS |
<> | 149:156823d33999 | 140 | |
<> | 149:156823d33999 | 141 | int semihost_connected(void) { |
<> | 149:156823d33999 | 142 | return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0; |
<> | 149:156823d33999 | 143 | } |
<> | 149:156823d33999 | 144 | |
<> | 149:156823d33999 | 145 | #else |
<> | 149:156823d33999 | 146 | // These processors cannot know if the interface is connect, assume so: |
<> | 149:156823d33999 | 147 | static int is_debugger_attached = 1; |
<> | 149:156823d33999 | 148 | |
<> | 149:156823d33999 | 149 | int semihost_connected(void) { |
<> | 149:156823d33999 | 150 | return is_debugger_attached; |
<> | 149:156823d33999 | 151 | } |
<> | 149:156823d33999 | 152 | #endif |
<> | 149:156823d33999 | 153 | |
<> | 149:156823d33999 | 154 | int semihost_disabledebug(void) { |
<> | 149:156823d33999 | 155 | #if !(DEVICE_DEBUG_AWARENESS) |
<> | 149:156823d33999 | 156 | is_debugger_attached = 0; |
<> | 149:156823d33999 | 157 | #endif |
<> | 149:156823d33999 | 158 | return __semihost(USR_DISABLEDEBUG, NULL); |
<> | 149:156823d33999 | 159 | } |
<> | 149:156823d33999 | 160 | |
<> | 149:156823d33999 | 161 | #endif |
<> | 149:156823d33999 | 162 |