Skip to content

Commit aa90406

Browse files
committed
Merge branch 'master' of https://github.com/mbedmicro/mbed
2 parents 4a18b90 + 5804ee6 commit aa90406

File tree

276 files changed

+227179
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+227179
-148
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ NXP:
3838
* [LPC1549](https://mbed.org/platforms/LPCXpresso1549/) (Cortex-M3)
3939

4040
Freescale:
41-
* FRDM-K20D50M
41+
* FRDM-K20D50M (Cortex-M4)
4242
* [FRDM-KL05Z](https://mbed.org/platforms/FRDM-KL05Z/) (Cortex-M0+)
4343
* [FRDM-KL25Z](http://mbed.org/platforms/KL25Z/) (Cortex-M0+)
4444
* [FRDM-KL46Z](https://mbed.org/platforms/FRDM-KL46Z/) (Cortex-M0+)
45+
* FRDM-K64F (Cortex-M4)
4546

4647
STMicroelectronics:
4748
* [Nucleo-F103RB](https://mbed.org/platforms/ST-Nucleo-F103RB/) (Cortex-M3)
4849
* [Nucleo-L152RE](https://mbed.org/platforms/ST-Nucleo-L152RE/) (Cortex-M3)
4950
* [Nucleo-F030R8](https://mbed.org/platforms/ST-Nucleo-F030R8/) (Cortex-M0)
5051
* [Nucleo-F401RE](https://mbed.org/platforms/ST-Nucleo-F401RE/) (Cortex-M4)
51-
* STM32F407 (Cortex-M4)
52+
* STM32F407 (Cortex-M4F)
53+
* STM32F0-Discovery (Cortex-M0)
54+
* STM32VL-Discovery (Cortex-M3)
55+
* STM32F4-Discovery (Cortex-M4F)
56+
5257

5358
Nordic:
5459
* [nRF51822-mKIT](https://mbed.org/platforms/Nordic-nRF51822/) (Cortex-M0)

libraries/USBDevice/USBDevice/USBEndpoints.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef enum {
4141
#include "USBEndpoints_LPC17_LPC23.h"
4242
#elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347)
4343
#include "USBEndpoints_LPC11U.h"
44-
#elif defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M)
44+
#elif defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
4545
#include "USBEndpoints_KL25Z.h"
4646
#elif defined (TARGET_STM32F4XX)
4747
#include "USBEndpoints_STM32F4.h"

libraries/USBDevice/USBDevice/USBHAL_KL25Z.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717
*/
1818

19-
#if defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M)
19+
#if defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
2020

2121
#include "USBHAL.h"
2222

@@ -86,6 +86,9 @@ USBHAL::USBHAL(void) {
8686
// Disable IRQ
8787
NVIC_DisableIRQ(USB0_IRQn);
8888

89+
#if defined(TARGET_K64F)
90+
MPU->CESR=0;
91+
#endif
8992
// fill in callback array
9093
epCallback[0] = &USBHAL::EP1_OUT_callback;
9194
epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -136,9 +139,9 @@ USBHAL::USBHAL(void) {
136139
while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
137140

138141
// Set BDT Base Register
139-
USB0->BDTPAGE1=(uint8_t)((uint32_t)bdt>>8);
140-
USB0->BDTPAGE2=(uint8_t)((uint32_t)bdt>>16);
141-
USB0->BDTPAGE3=(uint8_t)((uint32_t)bdt>>24);
142+
USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt>>8);
143+
USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt>>16);
144+
USB0->BDTPAGE3 = (uint8_t)((uint32_t)bdt>>24);
142145

143146
// Clear interrupt flag
144147
USB0->ISTAT = 0xff;

libraries/ble/ble-api/hw/Gap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ class Gap
3636
GapEvents *m_pEventHandler;
3737

3838
public:
39+
typedef enum addr_type_e{
40+
ADDR_TYPE_PUBLIC = 0,
41+
ADDR_TYPE_RANDOM_STATIC,
42+
ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
43+
ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
44+
} addr_type_t;
45+
3946
/* These functions must be defined in the sub-class */
47+
virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]) = 0;
4048
virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0;
4149
virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0;
4250
virtual ble_error_t stopAdvertising(void) = 0;

libraries/ble/nRF51822/btle/btle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ static void btle_handler(ble_evt_t * p_ble_evt)
9494
switch (p_ble_evt->header.evt_id)
9595
{
9696
case BLE_GAP_EVT_CONNECTED:
97-
nRF51GattServer::getInstance().m_connectionHandle = p_ble_evt->evt.gap_evt.conn_handle;
97+
nRF51Gap::getInstance().setConnectionHandle( p_ble_evt->evt.gap_evt.conn_handle );
9898
nRF51Gap::getInstance().handleEvent(GapEvents::GAP_EVENT_CONNECTED);
9999
break;
100100

101101
case BLE_GAP_EVT_DISCONNECTED:
102102
// Since we are not in a connection and have not started advertising, store bonds
103-
nRF51GattServer::getInstance().m_connectionHandle = BLE_CONN_HANDLE_INVALID;
103+
nRF51Gap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID);
104104
ASSERT_STATUS_RET_VOID ( ble_bondmngr_bonded_centrals_store() );
105105
nRF51Gap::getInstance().handleEvent(GapEvents::GAP_EVENT_DISCONNECTED);
106106
break;
@@ -117,7 +117,7 @@ static void btle_handler(ble_evt_t * p_ble_evt)
117117
sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE ;
118118
sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE ;
119119

120-
ASSERT_STATUS_RET_VOID ( sd_ble_gap_sec_params_reply(nRF51GattServer::getInstance().m_connectionHandle, BLE_GAP_SEC_STATUS_SUCCESS, &sec_params) );
120+
ASSERT_STATUS_RET_VOID ( sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(), BLE_GAP_SEC_STATUS_SUCCESS, &sec_params) );
121121
}
122122
break;
123123

libraries/ble/nRF51822/nRF51Gap.cpp

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "common/common.h"
2121
#include "ble_advdata.h"
22+
#include "ble_hci.h"
2223

2324
/**************************************************************************/
2425
/*!
@@ -197,12 +198,12 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params)
197198
/**************************************************************************/
198199
ble_error_t nRF51Gap::stopAdvertising(void)
199200
{
200-
/* Stop Advertising */
201-
ASSERT( ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
201+
/* Stop Advertising */
202+
ASSERT( ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
202203

203204
state.advertising = 0;
204205

205-
return BLE_ERROR_NONE;
206+
return BLE_ERROR_NONE;
206207
}
207208

208209
/**************************************************************************/
@@ -223,11 +224,61 @@ ble_error_t nRF51Gap::stopAdvertising(void)
223224
/**************************************************************************/
224225
ble_error_t nRF51Gap::disconnect(void)
225226
{
226-
/* Disconnect if we are connected to a central device */
227-
// ASSERT( ERROR_NONE == sd_ble_gap_disconnect(), BLE_ERROR_PARAM_OUT_OF_RANGE);
228-
229227
state.advertising = 0;
230-
state.connected = 0;
228+
state.connected = 0;
231229

232-
return BLE_ERROR_NONE;
230+
/* Disconnect if we are connected to a central device */
231+
ASSERT_INT(ERROR_NONE, sd_ble_gap_disconnect(m_connectionHandle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION),
232+
BLE_ERROR_PARAM_OUT_OF_RANGE);
233+
234+
return BLE_ERROR_NONE;
235+
}
236+
237+
/**************************************************************************/
238+
/*!
239+
@brief Sets the 16-bit connection handle
240+
*/
241+
/**************************************************************************/
242+
void nRF51Gap::setConnectionHandle(uint16_t con_handle)
243+
{
244+
m_connectionHandle = con_handle;
245+
}
246+
247+
/**************************************************************************/
248+
/*!
249+
@brief Gets the 16-bit connection handle
250+
*/
251+
/**************************************************************************/
252+
uint16_t nRF51Gap::getConnectionHandle(void)
253+
{
254+
return m_connectionHandle;
255+
}
256+
257+
/**************************************************************************/
258+
/*!
259+
@brief Sets the BLE device address
260+
261+
@returns ble_error_t
262+
263+
@section EXAMPLE
264+
265+
@code
266+
267+
uint8_t device_address[6] = { 0xca, 0xfe, 0xf0, 0xf0, 0xf0, 0xf0 };
268+
nrf.getGap().setAddress(Gap::ADDR_TYPE_RANDOM_STATIC, device_address);
269+
270+
@endcode
271+
*/
272+
/**************************************************************************/
273+
ble_error_t nRF51Gap::setAddress(addr_type_t type, uint8_t address[6])
274+
{
275+
if ( type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) return BLE_ERROR_PARAM_OUT_OF_RANGE;
276+
277+
ble_gap_addr_t dev_addr;
278+
dev_addr.addr_type = type;
279+
memcpy(dev_addr.addr, address, 6);
280+
281+
ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(&dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
282+
283+
return BLE_ERROR_NONE;
233284
}

libraries/ble/nRF51822/nRF51Gap.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "mbed.h"
2121
#include "blecommon.h"
22+
#include "ble.h"
2223
#include "GapAdvertisingParams.h"
2324
#include "GapAdvertisingData.h"
2425
#include "hw/Gap.h"
@@ -39,13 +40,18 @@ class nRF51Gap : public Gap
3940
}
4041

4142
/* Functions that must be implemented from Gap */
43+
virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]);
4244
virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &);
4345
virtual ble_error_t startAdvertising(GapAdvertisingParams &);
4446
virtual ble_error_t stopAdvertising(void);
4547
virtual ble_error_t disconnect(void);
4648

49+
void setConnectionHandle(uint16_t con_handle);
50+
uint16_t getConnectionHandle(void);
51+
4752
private:
48-
nRF51Gap() { };
53+
uint16_t m_connectionHandle;
54+
nRF51Gap() { m_connectionHandle = BLE_CONN_HANDLE_INVALID; };
4955
nRF51Gap(nRF51Gap const&);
5056
void operator=(nRF51Gap const&);
5157
};

libraries/ble/nRF51822/nRF51GattServer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "common/common.h"
2121
#include "btle/custom/custom_helper.h"
2222

23+
#include "nRF51Gap.h"
24+
2325
/**************************************************************************/
2426
/*!
2527
@brief Adds a new service to the GATT table on the peripheral
@@ -138,13 +140,16 @@ ble_error_t nRF51GattServer::readValue(uint16_t charHandle, uint8_t buffer[], ui
138140
/**************************************************************************/
139141
ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len, bool localOnly)
140142
{
143+
uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle();
144+
141145
if (localOnly)
142146
{
143147
/* Only update locally regardless of notify/indicate */
144148
ASSERT_INT( ERROR_NONE, sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), BLE_ERROR_PARAM_OUT_OF_RANGE );
145149
}
150+
146151
if ((p_characteristics[charHandle]->properties & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) &&
147-
(m_connectionHandle != BLE_CONN_HANDLE_INVALID) )
152+
(gapConnectionHandle != BLE_CONN_HANDLE_INVALID) )
148153
{
149154
/* HVX update for the characteristic value */
150155
ble_gatts_hvx_params_t hvx_params;
@@ -155,7 +160,7 @@ ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[],
155160
hvx_params.p_data = buffer;
156161
hvx_params.p_len = &len;
157162

158-
error_t error = (error_t) sd_ble_gatts_hvx(m_connectionHandle, &hvx_params);
163+
error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params);
159164

160165
/* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and ERROR_NO_TX_BUFFERS the ATT table has been updated. */
161166
if ( (error != ERROR_NONE ) && (error != ERROR_INVALID_STATE) &&

libraries/ble/nRF51822/nRF51GattServer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ class nRF51GattServer : public GattServer
4949
void eventCallback(void);
5050
void hwCallback(ble_evt_t * p_ble_evt);
5151

52-
uint16_t m_connectionHandle; // TODO move to private
53-
5452
private:
5553
GattCharacteristic* p_characteristics[BLE_TOTAL_CHARACTERISTICS];
5654
ble_gatts_char_handles_t nrfCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS];
5755

58-
nRF51GattServer() { serviceCount = 0; characteristicCount = 0; m_connectionHandle = BLE_CONN_HANDLE_INVALID; };
56+
nRF51GattServer() { serviceCount = 0; characteristicCount = 0; };
5957

6058
nRF51GattServer(nRF51GattServer const&);
6159
void operator=(nRF51GattServer const&);

0 commit comments

Comments
 (0)