Commit ff026122 authored by Roman Okhrimenko's avatar Roman Okhrimenko
Browse files

Cypress: Disable entering deep sleep if no boot/upgrade images found

Entering deep sleep on CM0 without valid application on CM4 caused pyocd error while programming. This fix disables entering deep sleep mode on CM0 if no valid applications found for boot. Waiting for uart complete tx reworked. Code refactoring

Signed-off-by: default avatarRoman Okhrimenko <roman.okhrimenko@cypress.com>
parent af48fcea
Loading
Loading
Loading
Loading
+15 −49
Changes for boot/cypress/MCUBootApp/main.c: 15 added lines, 49 removed lines.
Original line number Diff line number Diff line
@@ -50,43 +50,6 @@
uint32_t smif_id = 1; /* Assume SlaveSelect_0 is used for External Memory */
#endif

extern cy_stc_scb_uart_context_t CYBSP_UART_context;

/* Parameter structures for callback function */
static cy_stc_syspm_callback_params_t deep_sleep_clbk_params = 
{
    CYBSP_UART_HW,
    &CYBSP_UART_context
};

static cy_stc_syspm_callback_params_t deep_sleep_sysclk_pm_clbk_param =
{
    NULL,
    NULL
};

/* Callback structure */
cy_stc_syspm_callback_t uart_deep_sleep = 
{
    &Cy_SCB_UART_DeepSleepCallback, 
    CY_SYSPM_DEEPSLEEP,
    CY_SYSPM_SKIP_BEFORE_TRANSITION ,
    &deep_sleep_clbk_params,
    NULL,
    NULL,
    0
};

cy_stc_syspm_callback_t clk_deep_sleep = 
{
    &Cy_SysClk_DeepSleepCallback, 
    CY_SYSPM_DEEPSLEEP,
    CY_SYSPM_SKIP_BEFORE_TRANSITION ,
    &deep_sleep_sysclk_pm_clbk_param,
    NULL,
    NULL,
    0
};

void hw_deinit(void);

@@ -98,7 +61,9 @@ static void do_boot(struct boot_rsp *rsp)

    BOOT_LOG_INF("Starting User Application on CM4 (wait)...");
    BOOT_LOG_INF("Start Address: 0x%08lx", app_addr);
    Cy_SysLib_Delay(100);
    BOOT_LOG_INF("Deinitializing hardware...");

    cy_retarget_io_wait_tx_complete(CYBSP_UART_HW, 10);

    hw_deinit();

@@ -108,25 +73,20 @@ static void do_boot(struct boot_rsp *rsp)
int main(void)
{
    struct boot_rsp rsp;
    cy_rslt_t result = CY_RSLT_TYPE_ERROR;
    cy_rslt_t rc = CY_RSLT_TYPE_ERROR;
    bool boot_succeeded = false;

    init_cycfg_clocks();
    init_cycfg_peripherals();
    init_cycfg_pins();

    /* register callback funtions that manage peripherals before going to deep sleep */
    if (!Cy_SysPm_RegisterCallback(&uart_deep_sleep) || 
        !Cy_SysPm_RegisterCallback(&clk_deep_sleep))
    {
        CY_ASSERT(0);
    }
    /* enable interrupts */
    __enable_irq();

    /* Initialize retarget-io to use the debug UART port (CYBSP_UART_HW) */
    result = cy_retarget_io_pdl_init(115200u);
    rc = cy_retarget_io_pdl_init(115200u);

    if (result != CY_RSLT_SUCCESS)
    if (rc != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }
@@ -134,7 +94,7 @@ int main(void)
    BOOT_LOG_INF("MCUBoot Bootloader Started");

#ifdef CY_BOOT_USE_EXTERNAL_FLASH
    cy_rslt_t rc = !CY_RSLT_SUCCESS;
    rc = CY_SMIF_CMD_NOT_FOUND;

    #undef MCUBOOT_MAX_IMG_SECTORS
    /* redefine number of sectors as there 2MB will be
@@ -150,13 +110,14 @@ int main(void)
    {
        BOOT_LOG_ERR("External Memory initialization w/ SFDP FAILED: 0x%02x", (int)rc);
    }
    if (0 == rc)
    if (CY_SMIF_SUCCESS == rc)
#endif
    {
        if (boot_go(&rsp) == 0)
        {
            BOOT_LOG_INF("User Application validated successfully");
            do_boot(&rsp);
            boot_succeeded = true;
        }
        else
        {
@@ -166,8 +127,13 @@ int main(void)

    while (1)
    {
        if (boot_succeeded) {
            Cy_SysPm_CpuEnterDeepSleep(CY_SYSPM_WAIT_FOR_INTERRUPT);
        }
        else {
            __WFI();
        }
    }

    return 0;
}
+17 −0
Changes for boot/cypress/platforms/retarget_io_pdl/cy_retarget_io_pdl.c: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -243,6 +243,23 @@ cy_rslt_t cy_retarget_io_pdl_init(uint32_t baudrate)
    return result;
}

/**
 * @brief Wait while UART completes transfer. Try for tries_count times -
 *        once each 10 millisecons.
 */
void cy_retarget_io_wait_tx_complete(CySCB_Type *base, uint32_t tries_count)
{
    while(tries_count > 0)
    {
        if (!Cy_SCB_UART_IsTxComplete(base)) {
            Cy_SysLib_DelayCycles(10 * cy_delayFreqKhz);
            tries_count -= 1;
        } else {
            return;
        }
    }
}

void cy_retarget_io_pdl_deinit()
{
    Cy_SCB_UART_DeInit(CYBSP_UART_HW);
+2 −0
Changes for boot/cypress/platforms/retarget_io_pdl/cy_retarget_io_pdl.h: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ extern "C" {

cy_rslt_t cy_retarget_io_pdl_init(uint32_t baudrate);

void cy_retarget_io_wait_tx_complete(CySCB_Type *base, uint32_t tries_count);

void cy_retarget_io_pdl_deinit(void);

#if defined(__cplusplus)