Bit-bang XIAO-ESP32C6 GPIO registers; processor rebooting

Thank you, PJ! I’ve made some changes to my code such that it is now compiling and running without crashing the processor. However, I’m not seeing the GPIO pin change state as hoped. Please let me know if you see any obvious problems with my new code as follows:

// Code to test GPIO pin control via register bit-banging.
// I connect an LED to pin D3 on the XIAO-ESP323C6 module.
// Pin D3 maps to GPIO21 (IO# 21) on the ESP32C6 module

#include <stdint.h>

#define GPIO_OUT_REG 0x60091004
#define GPIO_OUT_W1TS_REG 0x60091008
#define GPIO_OUT_W1TC_REG 0x6009100C
#define GPIO_ENABLE_W1TS_REG 0x60091024
#define GPIO_ENABLE_W1TC_REG 0x60091028
#define GPIO_IN_REG 0x6009103C
#define GPIO_PIN_ESP32 21

volatile uint32_t* gpio_enable_w1ts_reg = (volatile uint32_t*) GPIO_ENABLE_W1TS_REG;
volatile uint32_t* gpio_enable_w1tc_reg = (volatile uint32_t*) GPIO_ENABLE_W1TC_REG;
volatile uint32_t* gpio_out_w1ts_reg = (volatile uint32_t*) GPIO_OUT_W1TS_REG;
volatile uint32_t* gpio_out_w1tc_reg = (volatile uint32_t*) GPIO_OUT_W1TC_REG;
volatile uint32_t* gpio_out_reg = (volatile uint32_t*) GPIO_OUT_REG;

void setup() {
*gpio_enable_w1ts_reg = (1 << GPIO_PIN_ESP32);
*gpio_enable_w1tc_reg = (1 << GPIO_PIN_ESP32);
Serial.begin(115200);
}

void loop() {
*gpio_out_w1ts_reg = (1 << GPIO_PIN_ESP32); // Set the bit
printf(“Post bit set : GPIO_OUT_REG = %ld\n”,*gpio_out_reg);
delay(2000);
*gpio_out_w1tc_reg = (1 << GPIO_PIN_ESP32); // Clear the bit
printf(“Post bit clear: GPIO_OUT_REG = %ld\n”,*gpio_out_reg);
}

***Here are a few lines resulting from the printf statements I added:

11:26:27.504 → Post bit set : GPIO_OUT_REG = 2097152

11:26:29.531 → Post bit clear: GPIO_OUT_REG = 0

11:26:29.531 → Post bit set : GPIO_OUT_REG = 2097152

11:26:31.524 → Post bit clear: GPIO_OUT_REG = 0

Thanks again!

1 Like