然而,板的行为改变,取决于它是如何重置的。 If it was reset from JLink (by reboot_device.sh or by "monitor reset" from gdb), XTAL16M is running all the time (we checked with an oscilloscope), the LEDs stay on and UART output works.
But if it's reset either from firmware, or using the reset button, or by taking the battery out and putting it back in, XTAL16M stops and the LEDs go off during sleep; the LEDs still work when the board is awake. And if I try to use the UART after waking up, the CPU hangs and XTAL16M keeps running.
I'll appreciate if you can tell us how to use UARTs with extended sleep. The situation is a bit hard to debug, as I haven't found a way to attach the debugger without resetting the SoC.
Below are our periph_init() and write() functions.
Many thanks for your attention,
Vadim, MatchX.
static void periph_init(void)
{
/*
* Set-up Peripheral GPIOs
*/
hw_uart_reinit(HW_UART2, &uart_cfg);
hw_gpio_set_pin_function(HW_GPIO_PORT_4, HW_GPIO_PIN_5, HW_GPIO_MODE_OUTPUT,
HW_GPIO_FUNC_UART2_TX);
hw_gpio_set_pin_function(HW_GPIO_PORT_4, HW_GPIO_PIN_4, HW_GPIO_MODE_OUTPUT,
HW_GPIO_FUNC_UART2_RX);
/*
* Power up peripherals
*/
/*
* GPIO initializations
*/
/* Configure GPIO for LED output. */
timer2_config t2cfg = {
.pwm3_start = 0,
.pwm3_end = 0xffff,
.pwm4_start = 0,
.pwm4_end = 0xffff,
};
hw_timer2_init(&t2cfg);
hw_timer2_enable();
hw_led_set_led2_src(HW_LED_SRC2_PWM3);
hw_led_set_led3_src(HW_LED_SRC3_PWM4);
hw_led_enable_led2( ulLEDState & 1UL );
/* Configure GPIO for button. */
hw_gpio_set_pin_function(HW_GPIO_PORT_3, HW_GPIO_PIN_3, HW_GPIO_MODE_INPUT, HW_GPIO_FUNC_GPIO);
//printf("init\r\n");
}
int _write(int fd, char *ptr, int len)
{
hw_uart_write_buffer(HW_UART2, ptr, len);
return len;
}