GPIO wake-up and sleep

Dear Dialog Support,

I am testing the example ble_app_peripheral in SDK_6.0.18.1182.1. I want to realize the following function:

Once DA14531 is powered on, it enters into the extended sleep mode. When the button is pressed down once, DA14531 wakes up and the functions of the original example ble_app_peripheral can normally perform. And when the button is pressed down once again, DA14531 enters into the extended sleep mode again, and so on.

Could you please show me how to achieve this. Thanks a lot!

  • Hi Nick,

    Thank you for the reply.
    By default, I used the DA14531MOD which has the P25Q11U part number.
    On user_periph_setup.h file please add the following:

    /****************************************************************************************/
    /* SPI configuration                                                                    */
    /****************************************************************************************/
    // Define SPI Pads
    #if defined (__DA14531__)
        #define SPI_EN_PORT             GPIO_PORT_0
        #define SPI_EN_PIN              GPIO_PIN_1
    
        #define SPI_CLK_PORT            GPIO_PORT_0
        #define SPI_CLK_PIN             GPIO_PIN_4
    
        #define SPI_DO_PORT             GPIO_PORT_0
        #define SPI_DO_PIN              GPIO_PIN_0
    
        #define SPI_DI_PORT             GPIO_PORT_0
        #define SPI_DI_PIN              GPIO_PIN_3
    
    #elif !defined (__DA14586__)
        #define SPI_EN_PORT             GPIO_PORT_0
        #define SPI_EN_PIN              GPIO_PIN_3
    
        #define SPI_CLK_PORT            GPIO_PORT_0
        #define SPI_CLK_PIN             GPIO_PIN_0
    
        #define SPI_DO_PORT             GPIO_PORT_0
        #define SPI_DO_PIN              GPIO_PIN_6
    
        #define SPI_DI_PORT             GPIO_PORT_0
        #define SPI_DI_PIN              GPIO_PIN_5
    #endif
    
    /***************************************************************************************/
    /* Production debug output configuration                                               */
    /***************************************************************************************/
    #if PRODUCTION_DEBUG_OUTPUT
    #if defined (__DA14531__)
        #define PRODUCTION_DEBUG_PORT   GPIO_PORT_0
        #define PRODUCTION_DEBUG_PIN    GPIO_PIN_11
    #else
        #define PRODUCTION_DEBUG_PORT   GPIO_PORT_2
        #define PRODUCTION_DEBUG_PIN    GPIO_PIN_5
    #endif
    #endif
    
    // Define SPI Configuration
        #define SPI_MS_MODE             SPI_MS_MODE_MASTER
        #define SPI_CP_MODE             SPI_CP_MODE_0
        #define SPI_WSZ                 SPI_MODE_8BIT
        #define SPI_CS                  SPI_CS_0
    
    #if defined(__DA14531__)
        #define SPI_SPEED_MODE          SPI_SPEED_MODE_4MHz
        #define SPI_EDGE_CAPTURE        SPI_MASTER_EDGE_CAPTURE
    #else // (DA14585, DA14586)
        #define SPI_SPEED_MODE          SPI_SPEED_MODE_4MHz
    #endif
    #if !defined (__DA14586__)
    #define SPI_FLASH_DEV_SIZE          (512 * 1024)	//for P25Q40 4Mb
    #endif
    

    Please modify the SPI pins based on your board.
    And on user_periph_setup.c file:
    /**
     ****************************************************************************************
     *
     * @file user_periph_setup.c
     *
     * @brief Peripherals setup and initialization.
     *
     * Copyright (C) 2015-2019 Dialog Semiconductor.
     * This computer program includes Confidential, Proprietary Information
     * of Dialog Semiconductor. All Rights Reserved.
     *
     ****************************************************************************************
     */
    
    /*
     * INCLUDE FILES
     ****************************************************************************************
     */
    
    #include "user_periph_setup.h"
    #include "datasheet.h"
    #include "system_library.h"
    #include "rwip_config.h"
    #include "gpio.h"
    #include "uart.h"
    #include "syscntl.h"
    #include "fpga_helper.h"
    
    /*
     * GLOBAL VARIABLE DEFINITIONS
     ****************************************************************************************
     */
    
    /**
     ****************************************************************************************
     * @brief Each application reserves its own GPIOs here.
     ****************************************************************************************
     */
    
    #if DEVELOPMENT_DEBUG
    
    void GPIO_reservations(void)
    {
    /*
        i.e. to reserve P0_1 as Generic Purpose I/O:
        RESERVE_GPIO(DESCRIPTIVE_NAME, GPIO_PORT_0, GPIO_PIN_1, PID_GPIO);
    */
    	    // Push Button
        RESERVE_GPIO(PUSH_BUTTON, GPIO_BUTTON_PORT, GPIO_BUTTON_PIN, PID_GPIO);
    
    #if defined (CFG_PRINTF_UART2)
        RESERVE_GPIO(UART2_TX, UART2_TX_PORT, UART2_TX_PIN, PID_UART2_TX);
    #endif
    
        RESERVE_GPIO(LED, GPIO_LED_PORT, GPIO_LED_PIN, PID_GPIO);
    
    #if defined (CFG_SPI_FLASH_ENABLE)	
    	RESERVE_GPIO(SPI_FLASH_CS, SPI_EN_PORT, SPI_EN_PIN, PID_SPI_EN);
    	RESERVE_GPIO(SPI_FLASH_CLK, SPI_CLK_PORT, SPI_CLK_PIN, PID_SPI_CLK);
    	RESERVE_GPIO(SPI_FLASH_DO, SPI_DO_PORT, SPI_DO_PIN, PID_SPI_DO);
    	RESERVE_GPIO(SPI_FLASH_DI, SPI_DI_PORT, SPI_DI_PIN, PID_SPI_DI);
    #endif
    }
    
    #endif
    
    void set_pad_functions(void)
    {
    /*
        i.e. to set P0_1 as Generic purpose Output:
        GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_1, OUTPUT, PID_GPIO, false);
    */
    
        // Push Button
        GPIO_ConfigurePin(GPIO_BUTTON_PORT, GPIO_BUTTON_PIN, INPUT_PULLUP, PID_GPIO, false);
    	
    #if defined (CFG_SPI_FLASH_ENABLE)
        // Configure SPI pins
        GPIO_ConfigurePin(SPI_EN_PORT, SPI_EN_PIN, OUTPUT, PID_SPI_EN, true);
        GPIO_ConfigurePin(SPI_CLK_PORT, SPI_CLK_PIN, OUTPUT, PID_SPI_CLK, false);
        GPIO_ConfigurePin(SPI_DO_PORT, SPI_DO_PIN, OUTPUT, PID_SPI_DO, false);
        GPIO_ConfigurePin(SPI_DI_PORT, SPI_DI_PIN, INPUT, PID_SPI_DI, false);
        
       
    #endif
    
    #if defined (CFG_PRINTF_UART2)
        // Configure UART2 TX Pad
        GPIO_ConfigurePin(UART2_TX_PORT, UART2_TX_PIN, OUTPUT, PID_UART2_TX, false);
    #endif
    
        GPIO_ConfigurePin(GPIO_LED_PORT, GPIO_LED_PIN, OUTPUT, PID_GPIO, false);
    }
    
    
    
    #if defined (CFG_PRINTF_UART2)
    // Configuration struct for UART2
    static const uart_cfg_t uart_cfg = {
        .baud_rate = UART2_BAUDRATE,
        .data_bits = UART2_DATABITS,
        .parity = UART2_PARITY,
        .stop_bits = UART2_STOPBITS,
        .auto_flow_control = UART2_AFCE,
        .use_fifo = UART2_FIFO,
        .tx_fifo_tr_lvl = UART2_TX_FIFO_LEVEL,
        .rx_fifo_tr_lvl = UART2_RX_FIFO_LEVEL,
        .intr_priority = 2,
    };
    #endif
    
    // Configuration struct for SPI
    const spi_cfg_t spi_cfg = {
        .spi_ms = SPI_MS_MODE,
        .spi_cp = SPI_CP_MODE,
        .spi_speed = SPI_SPEED_MODE,
        .spi_wsz = SPI_WSZ,
        .spi_cs = SPI_CS,
        .cs_pad.port = SPI_EN_PORT,
        .cs_pad.pin = SPI_EN_PIN,
    #if defined (__DA14531__)
        .spi_capture = SPI_EDGE_CAPTURE,
    #endif
    #if defined (CFG_SPI_DMA_SUPPORT)
        .spi_dma_channel = SPI_DMA_CHANNEL_01,
        .spi_dma_priority = DMA_PRIO_0,
    #endif
    };
    
    // Configuration struct for SPI FLASH
    const spi_flash_cfg_t spi_flash_cfg = {
        .chip_size = SPI_FLASH_DEV_SIZE,
    		.jedec_id = P25Q40U_JEDEC_ID,
    		.dev_index = P25Q40U_DEV_INDEX
    };
    void periph_init(void)
    {
    #if defined (__DA14531__)
        // Select FPGA GPIO_MAP 1
        // set debugger SWD to SW_CLK = P0[2], SW_DIO=P0[5]
        FPGA_HELPER(FPGA_GPIO_MAP_1, SWD_DATA_AT_P0_5);
    
        // In Boost mode enable the DCDC converter to supply VBAT_HIGH for the used GPIOs
        // Assumption: The connected external peripheral is powered by 3V
        syscntl_dcdc_turn_on_in_boost(SYSCNTL_DCDC_LEVEL_3V0);
    #else
        // Power up peripherals' power domain
        SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 0);
        while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP));
        SetBits16(CLK_16M_REG, XTAL16_BIAS_SH_ENABLE, 1);
    #endif
    
        // ROM patch
        patch_func();
    
        // Initialize peripherals
    #if defined (CFG_PRINTF_UART2)
        // Initialize UART2
        uart_initialize(UART2, &uart_cfg);
    #endif
    
    #if defined (CFG_SPI_FLASH_ENABLE)
        // Configure SPI Flash environment
         spi_flash_configure_env(&spi_flash_cfg);
    
        // Initialize SPI
        spi_initialize(&spi_cfg);
    #endif
    
        // Set pad functionality
        set_pad_functions();
    
        // Enable the pads
        GPIO_set_pad_latch_en(true);
    }
    

    Make sure you also define the CFG_SPI_FLASH_ENABLE macro on the da1458x_config_basic.h file and you call the spi_flash_power_down() API on the user_app_init to get the SPI Flash to power down when the application starts. 
    Note: You will need to include the spi_flash.h file in order to do that.

    Then please compile and load the new FW into your board and test again.

    Best Regards,
    OV_Renesas