From 67b706a3c9da6765a694a753549d78a3be3c9f42 Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Mon, 4 Mar 2019 11:16:14 +0100 Subject: [PATCH 1/9] SAML21J18A: #endif without #if in analogout_api.c This PR: https://github.com/ARMmbed/mbed-os/commit/3bd3aca6db0a5cacd7e46ae7ed47507f83ad1aa3#diff-995cd6fe18f4fabfb549266dde0a3784 broke the SAML21J18A target, as there was no `#if DEVICE_ANALOGOUT` call, and this PR added an `#endif` there that's not matched now. --- .../TARGET_SAM_CortexM0P/TARGET_SAML21J18A/analogout_api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/TARGET_SAML21J18A/analogout_api.c b/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/TARGET_SAML21J18A/analogout_api.c index 773f113cdb..a548f381c9 100644 --- a/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/TARGET_SAML21J18A/analogout_api.c +++ b/targets/TARGET_Atmel/TARGET_SAM_CortexM0P/TARGET_SAML21J18A/analogout_api.c @@ -21,6 +21,8 @@ #include "PeripheralPins.h" #include "dac.h" +#if DEVICE_ANALOGOUT + extern uint8_t g_sys_init; #define MAX_VAL_12BIT 0x0FFF /*12 Bit DAC for SAML21*/ @@ -119,4 +121,5 @@ const PinMap *analogout_pinmap() { return PinMap_DAC; } -#endif + +#endif // DEVICE_ANALOGOUT From 5839a8e7c53037a718369738d7b7f6d339a8c2b3 Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Mon, 4 Mar 2019 17:18:56 +0100 Subject: [PATCH 2/9] NUCLEO_H743ZI: Arduino A5 is mapped on ADC3_IN6 --- .../TARGET_STM32H743xI/TARGET_NUCLEO_H743ZI/PeripheralPins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H743xI/TARGET_NUCLEO_H743ZI/PeripheralPins.c b/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H743xI/TARGET_NUCLEO_H743ZI/PeripheralPins.c index 92742558d9..503d39e94d 100644 --- a/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H743xI/TARGET_NUCLEO_H743ZI/PeripheralPins.c +++ b/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H743xI/TARGET_NUCLEO_H743ZI/PeripheralPins.c @@ -106,8 +106,8 @@ MBED_WEAK const PinMap PinMap_ADC[] = { {PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_INN3 {PF_8_ALT0, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_INP7 {PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_INP2 - {PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_INN2 - {PF_10_ALT0, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_INP6 + {PF_10_ALT0, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_INN2 + {PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_INP6 {PF_11, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_INP2 {PF_12, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_INN2 {PF_12_ALT0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_INP6 From 71a1ed9c8e87982b4da327df8de1d445c4a22776 Mon Sep 17 00:00:00 2001 From: Teemu Kultala Date: Thu, 7 Mar 2019 10:16:09 +0200 Subject: [PATCH 3/9] cellular: BC95 memory leak fix --- .../AT/at_cellularnetwork/at_cellularnetworktest.cpp | 2 ++ features/cellular/framework/AT/AT_CellularNetwork.cpp | 1 + .../targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index f755e557ca..25ed6116b7 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -122,6 +122,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_params) EXPECT_TRUE(reg_params._status == CellularNetwork::RegistrationDenied); EXPECT_TRUE(reg_params._act == CellularNetwork::RAT_EGPRS); EXPECT_TRUE(reg_params._cell_id == -1); + EXPECT_TRUE(reg_params._lac == -1); ATHandler_stub::read_string_index = 4; ATHandler_stub::read_string_table[3] = "00C3"; @@ -129,6 +130,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_params) ATHandler_stub::read_string_table[1] = "00100100"; ATHandler_stub::read_string_table[0] = "01000111"; EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_params(CellularNetwork::C_EREG, reg_params)); + EXPECT_TRUE(reg_params._lac == 0xc3); EXPECT_TRUE(reg_params._cell_id == 305463233); EXPECT_TRUE(reg_params._active_time == 240); EXPECT_TRUE(reg_params._periodic_tau == 70 * 60 * 60); diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 23b88ab992..1fd065cc75 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -177,6 +177,7 @@ void AT_CellularNetwork::read_reg_params_and_compare(RegistrationType type) } if (reg_params._cell_id != -1 && reg_params._cell_id != _reg_params._cell_id) { _reg_params._cell_id = reg_params._cell_id; + _reg_params._lac = reg_params._lac; data.status_data = reg_params._cell_id; _connection_status_cb((nsapi_event_t)CellularCellIDChanged, (intptr_t)&data); } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp index 1cb87db365..63cfd474fb 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp @@ -190,7 +190,7 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc _at.write_int(socket->id); _at.write_int(size); } else { - delete hexstr; + delete [] hexstr; return NSAPI_ERROR_PARAMETER; } @@ -202,7 +202,7 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc sent_len = _at.read_int(); _at.resp_stop(); - delete hexstr; + delete [] hexstr; if (_at.get_last_error() == NSAPI_ERROR_OK) { return sent_len; From d26dc88e9e6c02f0138def63993867c88aaf4edf Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Thu, 7 Mar 2019 16:16:04 +0100 Subject: [PATCH 4/9] TEST_APPS socket_app leaks memory when cannot initialize packetSizes --- TEST_APPS/device/socket_app/cmd_socket.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/TEST_APPS/device/socket_app/cmd_socket.cpp b/TEST_APPS/device/socket_app/cmd_socket.cpp index 7ecf176133..d07c4e8f00 100644 --- a/TEST_APPS/device/socket_app/cmd_socket.cpp +++ b/TEST_APPS/device/socket_app/cmd_socket.cpp @@ -673,6 +673,7 @@ static nsapi_size_or_error_t start_udp_receiver_thread(SInfo *info, int argc, ch int *packetSizes = new (nothrow) int[PACKET_SIZE_ARRAY_LEN]; if (!packetSizes) { cmd_printf("Allocation failed\r\n"); + free(dataIn); return CMDLINE_RETCODE_FAIL; } for (int i = 0; i < PACKET_SIZE_ARRAY_LEN; i++) { From eed2b390d945fca582b19c5a023fc654bfcbfff0 Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Thu, 7 Mar 2019 16:21:52 +0100 Subject: [PATCH 5/9] Dead pointer usage in GenericSecurityManager `pscrk` is set to the address of `csrk`, but `csrk` is out of scope when using the resulting value. There's no guarantee that the memory is still valid. --- features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp index 6422f28336..8fe9624463 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp @@ -883,9 +883,8 @@ ble_error_t GenericSecurityManager::init_si const csrk_t *pcsrk = _db->get_local_csrk(); sign_count_t local_sign_counter = _db->get_local_sign_counter(); + csrk_t csrk; if (!pcsrk) { - csrk_t csrk; - ble_error_t ret = get_random_data(csrk.data(), csrk.size()); if (ret != BLE_ERROR_NONE) { return ret; From 49e970560d391979f0b1d29c2677e829df3592ec Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Thu, 7 Mar 2019 16:41:42 +0100 Subject: [PATCH 6/9] GigaDevice targets can return ninitialized variable in CAN driver --- targets/TARGET_GigaDevice/TARGET_GD32E10X/can_api.c | 2 +- targets/TARGET_GigaDevice/TARGET_GD32F30X/can_api.c | 2 +- targets/TARGET_GigaDevice/TARGET_GD32F4XX/can_api.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_GigaDevice/TARGET_GD32E10X/can_api.c b/targets/TARGET_GigaDevice/TARGET_GD32E10X/can_api.c index df449bbad8..1b7bfe0754 100644 --- a/targets/TARGET_GigaDevice/TARGET_GD32E10X/can_api.c +++ b/targets/TARGET_GigaDevice/TARGET_GD32E10X/can_api.c @@ -305,7 +305,7 @@ void can_free(can_t *obj) */ int can_frequency(can_t *obj, int hz) { - int reval; + int reval = 0; /* The maximum baud rate support to 1M */ if (hz <= 1000000) { diff --git a/targets/TARGET_GigaDevice/TARGET_GD32F30X/can_api.c b/targets/TARGET_GigaDevice/TARGET_GD32F30X/can_api.c index b93a5cf1ce..db92b9db4d 100644 --- a/targets/TARGET_GigaDevice/TARGET_GD32F30X/can_api.c +++ b/targets/TARGET_GigaDevice/TARGET_GD32F30X/can_api.c @@ -305,7 +305,7 @@ void can_free(can_t *obj) */ int can_frequency(can_t *obj, int hz) { - int reval; + int reval = 0; /* The maximum baud rate support to 1M */ if (hz <= 1000000) { diff --git a/targets/TARGET_GigaDevice/TARGET_GD32F4XX/can_api.c b/targets/TARGET_GigaDevice/TARGET_GD32F4XX/can_api.c index 65a5ed54d4..15c67b1726 100644 --- a/targets/TARGET_GigaDevice/TARGET_GD32F4XX/can_api.c +++ b/targets/TARGET_GigaDevice/TARGET_GD32F4XX/can_api.c @@ -306,7 +306,7 @@ void can_free(can_t *obj) */ int can_frequency(can_t *obj, int hz) { - int reval; + int reval = 0; /* The maximum baud rate support to 1M */ if (hz <= 1000000) { From ae45096ce66ecc665af8b191916e7aa855c0a439 Mon Sep 17 00:00:00 2001 From: Sarah Marsh Date: Wed, 6 Mar 2019 14:11:38 -0600 Subject: [PATCH 7/9] Fix undefined tr_debug for QUECTEL_BG96 cellular feature --- .../cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 092652f354..49e04d328c 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -20,6 +20,7 @@ #include "QUECTEL_BG96_CellularStack.h" #include "QUECTEL_BG96_CellularInformation.h" #include "QUECTEL_BG96_CellularContext.h" +#include "CellularLog.h" using namespace mbed; using namespace events; From c5ad72b7815c762336b681b4aaa0e7164e22db71 Mon Sep 17 00:00:00 2001 From: Ganesh Ramachandran Date: Tue, 12 Mar 2019 15:04:57 +0530 Subject: [PATCH 8/9] Error check for reallocation memory fail --- targets/TARGET_TOSHIBA/TARGET_TMPM46B/i2c_api.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/targets/TARGET_TOSHIBA/TARGET_TMPM46B/i2c_api.c b/targets/TARGET_TOSHIBA/TARGET_TMPM46B/i2c_api.c index f75894b102..6ae3ba8919 100644 --- a/targets/TARGET_TOSHIBA/TARGET_TMPM46B/i2c_api.c +++ b/targets/TARGET_TOSHIBA/TARGET_TMPM46B/i2c_api.c @@ -219,6 +219,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) i2c_num = obj->index; gI2C_TxData = (char *)calloc(length, sizeof(int8_t)); + if (gI2C_TxData == NULL) { + error("Insufficient memory"); + return 0; + } for (i = 0; i < length; i++) { gI2C_TxData[i] = data[i]; @@ -258,6 +262,10 @@ int i2c_byte_write(i2c_t *obj, int data) byte_func = 1; if (start_flag == 0 && send_byte == 0) { gI2C_LTxData = (char *)realloc(gI2C_LTxData, counter++); + if (gI2C_LTxData == NULL) { + error("Insufficient memory"); + return 0; + } gI2C_LTxData[counter - 2] = data; } From 2af3a82cd88692f7112d98109b080d4aaa7d3c06 Mon Sep 17 00:00:00 2001 From: Oleg Kapshii Date: Mon, 11 Mar 2019 18:57:03 +0200 Subject: [PATCH 9/9] Removed PSoC6 SystemInit Workaround for ARM compiler --- .../TARGET_MCU_PSOC6_M0/system_psoc6_cm0plus.c | 9 --------- .../TARGET_PSOC6/TARGET_CY8C62XX/device/system_psoc6.h | 6 +----- .../TARGET_CY8CKIT_062_4343W/device/system_psoc6.h | 6 +----- .../TARGET_CY8CKIT_062_BLE/device/system_psoc6.h | 6 +----- .../TARGET_CY8CMOD_062_4343W/device/system_psoc6.h | 6 +----- 5 files changed, 4 insertions(+), 29 deletions(-) diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/TARGET_MCU_PSOC6_M0/system_psoc6_cm0plus.c b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/TARGET_MCU_PSOC6_M0/system_psoc6_cm0plus.c index 0c760e5956..d91a914740 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/TARGET_MCU_PSOC6_M0/system_psoc6_cm0plus.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/TARGET_MCU_PSOC6_M0/system_psoc6_cm0plus.c @@ -193,13 +193,6 @@ void mailbox_init(void); *******************************************************************************/ void SystemInit(void) { - /* Workaround to avoid twice SystemInit() call when ARMC5 compiler is used */ - static uint32_t temp_var = 0; - - if (temp_var == 0) - { - temp_var = 1; - Cy_PDL_Init(CY_DEVICE_CFG); /* Restore FLL registers to the default state as they are not restored by the ROM code */ @@ -299,8 +292,6 @@ void SystemInit(void) #else/* !defined(CY_IPC_DEFAULT_CFG_DISABLE) */ Cy_SemaIpcFlashInit(); #endif /* !defined(CY_IPC_DEFAULT_CFG_DISABLE) */ - - } } diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/device/system_psoc6.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/device/system_psoc6.h index 6dcb0ce124..f4d7bf6724 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/device/system_psoc6.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8C62XX/device/system_psoc6.h @@ -539,11 +539,7 @@ extern "C" { * \addtogroup group_system_config_system_functions * \{ */ -#if defined(__ARMCC_VERSION) - extern void SystemInit(void) __attribute__((constructor)); -#else - extern void SystemInit(void); -#endif /* (__ARMCC_VERSION) */ +extern void SystemInit(void); extern void SystemCoreClockUpdate(void); /** \} group_system_config_system_functions */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_4343W/device/system_psoc6.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_4343W/device/system_psoc6.h index 6dcb0ce124..f4d7bf6724 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_4343W/device/system_psoc6.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_4343W/device/system_psoc6.h @@ -539,11 +539,7 @@ extern "C" { * \addtogroup group_system_config_system_functions * \{ */ -#if defined(__ARMCC_VERSION) - extern void SystemInit(void) __attribute__((constructor)); -#else - extern void SystemInit(void); -#endif /* (__ARMCC_VERSION) */ +extern void SystemInit(void); extern void SystemCoreClockUpdate(void); /** \} group_system_config_system_functions */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_BLE/device/system_psoc6.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_BLE/device/system_psoc6.h index 6dcb0ce124..f4d7bf6724 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_BLE/device/system_psoc6.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_BLE/device/system_psoc6.h @@ -539,11 +539,7 @@ extern "C" { * \addtogroup group_system_config_system_functions * \{ */ -#if defined(__ARMCC_VERSION) - extern void SystemInit(void) __attribute__((constructor)); -#else - extern void SystemInit(void); -#endif /* (__ARMCC_VERSION) */ +extern void SystemInit(void); extern void SystemCoreClockUpdate(void); /** \} group_system_config_system_functions */ diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CMOD_062_4343W/device/system_psoc6.h b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CMOD_062_4343W/device/system_psoc6.h index 6dcb0ce124..f4d7bf6724 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CMOD_062_4343W/device/system_psoc6.h +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CMOD_062_4343W/device/system_psoc6.h @@ -539,11 +539,7 @@ extern "C" { * \addtogroup group_system_config_system_functions * \{ */ -#if defined(__ARMCC_VERSION) - extern void SystemInit(void) __attribute__((constructor)); -#else - extern void SystemInit(void); -#endif /* (__ARMCC_VERSION) */ +extern void SystemInit(void); extern void SystemCoreClockUpdate(void); /** \} group_system_config_system_functions */