Skip to content

Commit 88438df

Browse files
authored
Merge pull request #12394 from miteshdedhia7/pr/bug-fix-misc
Fix SDIO communication issue on Cypress 1M boards and other minor fixes
2 parents 7fd5119 + df5ac64 commit 88438df

File tree

18 files changed

+101
-79
lines changed

18 files changed

+101
-79
lines changed

features/netsocket/emac-drivers/TARGET_Cypress/COMPONENT_WHD/interface/WhdSTAInterface.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ nsapi_error_t WhdSTAInterface::connect()
250250

251251
// initialize wiced, this is noop if already init
252252
if (!_whd_emac.powered_up) {
253-
_whd_emac.power_up();
253+
if(!_whd_emac.power_up()) {
254+
return NSAPI_ERROR_DEVICE_ERROR;
255+
}
254256
}
255257

256258
res = whd_management_set_event_handler(_whd_emac.ifp, sta_link_change_events,
@@ -322,7 +324,9 @@ nsapi_error_t WhdSTAInterface::connect()
322324
void WhdSTAInterface::wifi_on()
323325
{
324326
if (!_whd_emac.powered_up) {
325-
_whd_emac.power_up();
327+
if(!_whd_emac.power_up()) {
328+
CY_ASSERT(false);
329+
}
326330
}
327331
}
328332

@@ -384,11 +388,14 @@ int8_t WhdSTAInterface::get_rssi()
384388

385389
// initialize wiced, this is noop if already init
386390
if (!_whd_emac.powered_up) {
387-
_whd_emac.power_up();
391+
if(!_whd_emac.power_up()) {
392+
CY_ASSERT(false);
393+
}
388394
}
389395

390396
res = (whd_result_t)whd_wifi_get_rssi(_whd_emac.ifp, &rssi);
391397
if (res != 0) {
398+
CY_ASSERT(false);
392399
return 0;
393400
}
394401

@@ -463,7 +470,9 @@ int WhdSTAInterface::internal_scan(WiFiAccessPoint *aps, unsigned count, scan_re
463470

464471
// initialize wiced, this is noop if already init
465472
if (!_whd_emac.powered_up) {
466-
_whd_emac.power_up();
473+
if(!_whd_emac.power_up()) {
474+
return NSAPI_ERROR_DEVICE_ERROR;
475+
}
467476
}
468477

469478
interal_scan_data.sema = new Semaphore();
@@ -476,7 +485,6 @@ int WhdSTAInterface::internal_scan(WiFiAccessPoint *aps, unsigned count, scan_re
476485
whd_result_t whd_res;
477486
int res;
478487

479-
480488
whd_res = (whd_result_t)whd_wifi_scan(_whd_emac.ifp, WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY,
481489
NULL, NULL, NULL, NULL, whd_scan_handler, &internal_scan_result, &interal_scan_data);
482490
if (whd_res != WHD_SUCCESS) {

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_WIFI_BT/SDIO_HOST/SDIO_HOST.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -111,7 +111,7 @@ cy_en_syspm_status_t SDIO_DeepSleepCallback(cy_stc_syspm_callback_params_t *para
111111
CY_UNUSED_PARAMETER(params);
112112
cy_en_syspm_status_t status = CY_SYSPM_FAIL;
113113

114-
switch (mode)
114+
switch (mode)
115115
{
116116
case CY_SYSPM_CHECK_READY:
117117
case CY_SYSPM_CHECK_FAIL:
@@ -656,7 +656,7 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
656656
cy_rslt_t result;
657657

658658
/* Initialize the semaphore. This is not done in init because init is called
659-
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
659+
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
660660
* interrupt thread.
661661
*/
662662
if(!sema_initialized)
@@ -770,16 +770,16 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
770770

771771
#ifdef CY_RTOS_AWARE
772772
/* Wait for the transfer to finish.
773-
* Acquire semaphore and wait until it will be released
773+
* Acquire semaphore and wait until it will be released
774774
* in SDIO_IRQ:
775-
* 1. sdio_transfer_finished_semaphore count is equal to
776-
* zero. cy_rtos_get_semaphore waits until semaphore
777-
* count is increased by cy_rtos_set_semaphore() in
775+
* 1. sdio_transfer_finished_semaphore count is equal to
776+
* zero. cy_rtos_get_semaphore waits until semaphore
777+
* count is increased by cy_rtos_set_semaphore() in
778778
* SDIO_IRQ.
779-
* 2. The cy_rtos_set_semaphore() increases
779+
* 2. The cy_rtos_set_semaphore() increases
780780
* sdio_transfer_finished_semaphore count.
781-
* 3. The cy_rtos_get_semaphore() function decreases
782-
* sdio_transfer_finished_semaphore back to zero
781+
* 3. The cy_rtos_get_semaphore() function decreases
782+
* sdio_transfer_finished_semaphore back to zero
783783
* and exit. Or timeout occurs
784784
*/
785785
result = cy_rtos_get_semaphore( &sdio_transfer_finished_semaphore, 10, false );
@@ -1080,7 +1080,12 @@ void SDIO_DisableSdClk(void)
10801080
void SDIO_SetSdClkFrequency(uint32_t u32SdClkFreqHz)
10811081
{
10821082
uint16_t u16Div;
1083-
u16Div = Cy_SysClk_ClkPeriGetFrequency() / u32SdClkFreqHz;
1083+
/*
1084+
* The UDB SDIO implemenation has a extra divider internally that divides the input clock to the UDB
1085+
* by 2. The desired clock frequency is hence intentionally multiplied by 2 in order to get the required
1086+
* SDIO operating frequency.
1087+
*/
1088+
u16Div = Cy_SysClk_ClkPeriGetFrequency() / (2 * u32SdClkFreqHz);
10841089
Cy_SysClk_PeriphSetDivider(SDIO_HOST_Internal_Clock_DIV_TYPE, SDIO_HOST_Internal_Clock_DIV_NUM, (u16Div-1));
10851090
}
10861091

@@ -1247,10 +1252,10 @@ void SDIO_IRQ(void)
12471252
{
12481253
pfnCardInt_count++;
12491254
}
1250-
1255+
12511256
/* Execute card interrupt callback if neccesary */
12521257
if (0 != pfnCardInt_count)
1253-
{
1258+
{
12541259
if (NULL != gstcInternalData.pstcCallBacks.pfnCardIntCb)
12551260
{
12561261
gstcInternalData.pstcCallBacks.pfnCardIntCb();
@@ -1277,7 +1282,7 @@ void SDIO_IRQ(void)
12771282
/* CRC was bad, set the flag */
12781283
gstcInternalData.stcEvents.u8CRCError++;
12791284
}
1280-
1285+
12811286
/* Set the done flag */
12821287

12831288
#ifdef CY_RTOS_AWARE

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_WIFI_BT/SDIO_HOST/SDIO_HOST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
********************************************************************************
99
* \copyright
10-
* Copyright 2016-2019 Cypress Semiconductor Corporation
10+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1111
* SPDX-License-Identifier: Apache-2.0
1212
*
1313
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_WIFI_BT/SDIO_HOST/SDIO_HOST_cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CY8CKIT_062_WIFI_BT/SDIO_HOST/SDIO_HOST_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/SDIO_HOST/SDIO_HOST.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -111,7 +111,7 @@ cy_en_syspm_status_t SDIO_DeepSleepCallback(cy_stc_syspm_callback_params_t *para
111111
CY_UNUSED_PARAMETER(params);
112112
cy_en_syspm_status_t status = CY_SYSPM_FAIL;
113113

114-
switch (mode)
114+
switch (mode)
115115
{
116116
case CY_SYSPM_CHECK_READY:
117117
case CY_SYSPM_CHECK_FAIL:
@@ -656,7 +656,7 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
656656
cy_rslt_t result;
657657

658658
/* Initialize the semaphore. This is not done in init because init is called
659-
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
659+
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
660660
* interrupt thread.
661661
*/
662662
if(!sema_initialized)
@@ -770,16 +770,16 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
770770

771771
#ifdef CY_RTOS_AWARE
772772
/* Wait for the transfer to finish.
773-
* Acquire semaphore and wait until it will be released
773+
* Acquire semaphore and wait until it will be released
774774
* in SDIO_IRQ:
775-
* 1. sdio_transfer_finished_semaphore count is equal to
776-
* zero. cy_rtos_get_semaphore waits until semaphore
777-
* count is increased by cy_rtos_set_semaphore() in
775+
* 1. sdio_transfer_finished_semaphore count is equal to
776+
* zero. cy_rtos_get_semaphore waits until semaphore
777+
* count is increased by cy_rtos_set_semaphore() in
778778
* SDIO_IRQ.
779-
* 2. The cy_rtos_set_semaphore() increases
779+
* 2. The cy_rtos_set_semaphore() increases
780780
* sdio_transfer_finished_semaphore count.
781-
* 3. The cy_rtos_get_semaphore() function decreases
782-
* sdio_transfer_finished_semaphore back to zero
781+
* 3. The cy_rtos_get_semaphore() function decreases
782+
* sdio_transfer_finished_semaphore back to zero
783783
* and exit. Or timeout occurs
784784
*/
785785
result = cy_rtos_get_semaphore( &sdio_transfer_finished_semaphore, 10, false );
@@ -1080,7 +1080,12 @@ void SDIO_DisableSdClk(void)
10801080
void SDIO_SetSdClkFrequency(uint32_t u32SdClkFreqHz)
10811081
{
10821082
uint16_t u16Div;
1083-
u16Div = Cy_SysClk_ClkPeriGetFrequency() / u32SdClkFreqHz;
1083+
/*
1084+
* The UDB SDIO implemenation has a extra divider internally that divides the input clock to the UDB
1085+
* by 2. The desired clock frequency is hence intentionally multiplied by 2 in order to get the required
1086+
* SDIO operating frequency.
1087+
*/
1088+
u16Div = Cy_SysClk_ClkPeriGetFrequency() / (2 * u32SdClkFreqHz);
10841089
Cy_SysClk_PeriphSetDivider(SDIO_HOST_Internal_Clock_DIV_TYPE, SDIO_HOST_Internal_Clock_DIV_NUM, (u16Div-1));
10851090
}
10861091

@@ -1247,10 +1252,10 @@ void SDIO_IRQ(void)
12471252
{
12481253
pfnCardInt_count++;
12491254
}
1250-
1255+
12511256
/* Execute card interrupt callback if neccesary */
12521257
if (0 != pfnCardInt_count)
1253-
{
1258+
{
12541259
if (NULL != gstcInternalData.pstcCallBacks.pfnCardIntCb)
12551260
{
12561261
gstcInternalData.pstcCallBacks.pfnCardIntCb();
@@ -1277,7 +1282,7 @@ void SDIO_IRQ(void)
12771282
/* CRC was bad, set the flag */
12781283
gstcInternalData.stcEvents.u8CRCError++;
12791284
}
1280-
1285+
12811286
/* Set the done flag */
12821287

12831288
#ifdef CY_RTOS_AWARE

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/SDIO_HOST/SDIO_HOST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
********************************************************************************
99
* \copyright
10-
* Copyright 2016-2019 Cypress Semiconductor Corporation
10+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1111
* SPDX-License-Identifier: Apache-2.0
1212
*
1313
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/SDIO_HOST/SDIO_HOST_cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW943012P6EVB_01/SDIO_HOST/SDIO_HOST_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW9P62S1_43012EVB_01/SDIO_HOST/SDIO_HOST.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -111,7 +111,7 @@ cy_en_syspm_status_t SDIO_DeepSleepCallback(cy_stc_syspm_callback_params_t *para
111111
CY_UNUSED_PARAMETER(params);
112112
cy_en_syspm_status_t status = CY_SYSPM_FAIL;
113113

114-
switch (mode)
114+
switch (mode)
115115
{
116116
case CY_SYSPM_CHECK_READY:
117117
case CY_SYSPM_CHECK_FAIL:
@@ -656,7 +656,7 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
656656
cy_rslt_t result;
657657

658658
/* Initialize the semaphore. This is not done in init because init is called
659-
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
659+
* in interrupt thread. cy_rtos_init_semaphore call is prohibited in
660660
* interrupt thread.
661661
*/
662662
if(!sema_initialized)
@@ -770,16 +770,16 @@ en_sdio_result_t SDIO_SendCommandAndWait(stc_sdio_cmd_t *pstcCmd)
770770

771771
#ifdef CY_RTOS_AWARE
772772
/* Wait for the transfer to finish.
773-
* Acquire semaphore and wait until it will be released
773+
* Acquire semaphore and wait until it will be released
774774
* in SDIO_IRQ:
775-
* 1. sdio_transfer_finished_semaphore count is equal to
776-
* zero. cy_rtos_get_semaphore waits until semaphore
777-
* count is increased by cy_rtos_set_semaphore() in
775+
* 1. sdio_transfer_finished_semaphore count is equal to
776+
* zero. cy_rtos_get_semaphore waits until semaphore
777+
* count is increased by cy_rtos_set_semaphore() in
778778
* SDIO_IRQ.
779-
* 2. The cy_rtos_set_semaphore() increases
779+
* 2. The cy_rtos_set_semaphore() increases
780780
* sdio_transfer_finished_semaphore count.
781-
* 3. The cy_rtos_get_semaphore() function decreases
782-
* sdio_transfer_finished_semaphore back to zero
781+
* 3. The cy_rtos_get_semaphore() function decreases
782+
* sdio_transfer_finished_semaphore back to zero
783783
* and exit. Or timeout occurs
784784
*/
785785
result = cy_rtos_get_semaphore( &sdio_transfer_finished_semaphore, 10, false );
@@ -1080,7 +1080,12 @@ void SDIO_DisableSdClk(void)
10801080
void SDIO_SetSdClkFrequency(uint32_t u32SdClkFreqHz)
10811081
{
10821082
uint16_t u16Div;
1083-
u16Div = Cy_SysClk_ClkPeriGetFrequency() / u32SdClkFreqHz;
1083+
/*
1084+
* The UDB SDIO implemenation has a extra divider internally that divides the input clock to the UDB
1085+
* by 2. The desired clock frequency is hence intentionally multiplied by 2 in order to get the required
1086+
* SDIO operating frequency.
1087+
*/
1088+
u16Div = Cy_SysClk_ClkPeriGetFrequency() / (2 * u32SdClkFreqHz);
10841089
Cy_SysClk_PeriphSetDivider(SDIO_HOST_Internal_Clock_DIV_TYPE, SDIO_HOST_Internal_Clock_DIV_NUM, (u16Div-1));
10851090
}
10861091

@@ -1247,10 +1252,10 @@ void SDIO_IRQ(void)
12471252
{
12481253
pfnCardInt_count++;
12491254
}
1250-
1255+
12511256
/* Execute card interrupt callback if neccesary */
12521257
if (0 != pfnCardInt_count)
1253-
{
1258+
{
12541259
if (NULL != gstcInternalData.pstcCallBacks.pfnCardIntCb)
12551260
{
12561261
gstcInternalData.pstcCallBacks.pfnCardIntCb();
@@ -1277,7 +1282,7 @@ void SDIO_IRQ(void)
12771282
/* CRC was bad, set the flag */
12781283
gstcInternalData.stcEvents.u8CRCError++;
12791284
}
1280-
1285+
12811286
/* Set the done flag */
12821287

12831288
#ifdef CY_RTOS_AWARE

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW9P62S1_43012EVB_01/SDIO_HOST/SDIO_HOST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
********************************************************************************
99
* \copyright
10-
* Copyright 2016-2019 Cypress Semiconductor Corporation
10+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1111
* SPDX-License-Identifier: Apache-2.0
1212
*
1313
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW9P62S1_43012EVB_01/SDIO_HOST/SDIO_HOST_cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYW9P62S1_43012EVB_01/SDIO_HOST/SDIO_HOST_cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
********************************************************************************
88
* \copyright
9-
* Copyright 2016-2019 Cypress Semiconductor Corporation
9+
* Copyright 2016-2020 Cypress Semiconductor Corporation
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)