1 Reply Latest reply on Sep 12, 2017 7:04 AM by thomas.maintz_2685056

    Struggling creating a factory reset app

    thomas.maintz_2685056

      Hi there,

      I would like to get a firmware reset app running. This should be accessible by holding a specific button for more than X ms at the system startup.

      If I try to build the program by the makefile call "apps.FirmwareReset-BCM943907_QUADRO-ThreadX download download_apps run" (like suggested within snip.ota_fr) I can not access the factory reset program. What can I do to make that working?

       

      I made some changes within platform.c and platform.h

      // ... platform.h
      /* Bootloader OTA and OTA2 factory reset during settings */
      #define PLATFORM_FACTORY_RESET_BUTTON_INDEX     ( PLATFORM_BUTTON_1 )
      #define PLATFORM_FACTORY_RESET_TIMEOUT          ( 10000 )
      

       

      // ... platform.c
      const gpio_button_t platform_gpio_buttons[] =
      {
          [PLATFORM_BUTTON_1] =
          {
              .polarity   = WICED_ACTIVE_LOW,
              .gpio       = PIN_PWM_0,
              .trigger    = IRQ_TRIGGER_FALLING_EDGE,
          },
      
          [PLATFORM_BUTTON_2] =
          {
              .polarity   = WICED_ACTIVE_LOW,
              .gpio       = PIN_PWM_1,
              .trigger    = IRQ_TRIGGER_FALLING_EDGE,
          }
      };
      
      uint32_t  platform_get_button_press_time ( int button_index, uint32_t max_time )
      {
          int             button_gpio;
          uint32_t        button_press_timer = 0;
      
          /* Initialize input */
          button_gpio     = platform_gpio_buttons[button_index].gpio;
          platform_gpio_init( &platform_gpio_pins[ button_gpio ], INPUT_PULL_UP );
      
          while ( (PLATFORM_BUTTON_PRESSED_STATE == platform_gpio_input_get(&platform_gpio_pins[ button_gpio ])) )
          {
              /* wait a bit */
              host_rtos_delay_milliseconds( PLATFORM_BUTTON_PRESS_CHECK_PERIOD );
      
              /* keep track of time */
              button_press_timer += PLATFORM_BUTTON_PRESS_CHECK_PERIOD;
              if ((max_time > 0) && (button_press_timer >= max_time))
              {
                  break;
              }
          }
      
          return button_press_timer;
      }
      
      uint32_t  platform_get_factory_reset_button_time ( uint32_t max_time )
      {
          return platform_get_button_press_time ( PLATFORM_FACTORY_RESET_BUTTON_INDEX, max_time );
      }
      

      The main application looks like this:

      void application_start( )
      {
          wiced_config_soft_ap_t* soft_ap;
          wiced_result_t          result;
      
          wiced_init( );
      
          char ssid_name[63];
          char ssid_pass[63];
          
      
          /* Get the SoftAP name and output to console */
          result = wiced_dct_read_lock( (void**) &soft_ap, WICED_FALSE, DCT_WIFI_CONFIG_SECTION,  OFFSETOF(platform_dct_wifi_config_t, soft_ap_settings), sizeof(wiced_config_soft_ap_t) );
          if ( result == WICED_SUCCESS )
          {
              if(strcmp(ssid_name, (char*)soft_ap->SSID.value[0]) != 0)
              {
                  WPRINT_APP_INFO( ( "\r\nUpdating the SSID Name\n\r") );
                  memcpy(soft_ap->SSID.value, ssid_name,9);
                  soft_ap->SSID.length = 9;
                  soft_ap->security = WICED_SECURITY_OPEN;
              }
      
              wiced_dct_write(soft_ap, DCT_WIFI_CONFIG_SECTION, OFFSETOF(platform_dct_wifi_config_t, soft_ap_settings), sizeof(wiced_config_soft_ap_t));
      
              wiced_dct_read_unlock( soft_ap, WICED_FALSE );
          }
      
          result = wiced_dct_read_lock( (void**) &soft_ap, WICED_FALSE, DCT_WIFI_CONFIG_SECTION,  OFFSETOF(platform_dct_wifi_config_t, soft_ap_settings), sizeof(wiced_config_soft_ap_t) );
          if ( result == WICED_SUCCESS )
          {
              WPRINT_APP_INFO( ( "\r\n\r\nSoftAP start, AP name: %s\r\n", soft_ap->SSID.value));
              WPRINT_APP_INFO( ( "\tPassword: %s\r\n\r\n", soft_ap->security_key));
          }
      
          wiced_rtos_delay_milliseconds(200);
      
          /* Bringup the network interface */
          wiced_network_up( WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &device_init_ip_settings );
          wiced_ota_server_start( WICED_AP_INTERFACE );
      
      
          while ( 1 )
          {
              wiced_rtos_delay_milliseconds( 100 );
          }
      }