MaJerle / lwcell

Lightweight cellular modem host AT library
MIT License
395 stars 147 forks source link

PWRKEY pin #43

Open blomnik opened 3 years ago

blomnik commented 3 years ago

Hello! I have a custom PCB with PWRKEY pin instead of RST. Is it possible utilize it on init with lwGSM or I have to implement some additional code by myself?

Thank you.

nickfaughey commented 3 years ago

You can implement whatever custom bootup logic you want in your lwgsm_ll_init() function. For example, this is where I wake up my SIM7000 module from sleep mode by pulling its DTR pin low. If you have a board that requires some use of the PWRKEY pin like pulsing it high or low for some time, you could do it here.

blomnik commented 3 years ago

So, my workaround is

/**
 * This function try to init GSM modem and power it on by PWRKEY if init was failed
 */
int gsm_reset(void) {
  if(lwgsm_init(NULL, 1) == lwgsmOK) {
    return 0;
  }

  for (int i = 0; i < 3; ++i) {
    int err;
    LL_GPIO_ResetOutputPin(GSM_PWRKEY_port, GSM_PWRKEY_pin);
    osDelay(1500); // according to 4.2.2.1 of "SIM800 hardware design"
    LL_GPIO_SetOutputPin(GSM_PWRKEY_port, GSM_PWRKEY_pin);
    osDelay(1500);

    err = lwgsm_reset_with_delay(LWGSM_CFG_RESET_DELAY_DEFAULT, NULL, NULL, 1);
    if(err != lwgsmOK) {
      printf("lwGSM error %d", err);
    } else {
      return 0;
    }
  }

  errno = ENODEV;
  return -1;
}