QTPY-S3 RESET always starts bootload

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
alainsam
 
Posts: 206
Joined: Tue Oct 04, 2016 7:58 pm

QTPY-S3 RESET always starts bootload

Post by alainsam »

I am trying to run a sketch on qtpy-s3 The sketch compiles and downloads correctly but when I want to start it on the board by pushing the Reset button (not double push) I get the UF2 bootloader instead of running the program. What is wrong?
TinyUF2 Bootloader 0.10.2 - tinyusb (0.12.0-203-ga4cfd1c69)
Model: Adafruit QT Py ESP32-S3
Board-ID: ESP32S3-QTPy-A
Date: Jun 24 2022

User avatar
adafruit_support_carter
 
Posts: 29522
Joined: Tue Nov 29, 2016 2:45 pm

Re: QTPY-S3 RESET always starts bootload

Post by adafruit_support_carter »

Are you seeing the same behavior if you upload the basic Blink example sketch?

User avatar
alainsam
 
Posts: 206
Joined: Tue Oct 04, 2016 7:58 pm

Re: QTPY-S3 RESET always starts bootload

Post by alainsam »

No, the Neopixel is blinking correctly with the blink program.
Here is the code that produces the problem:

Code: Select all

#include <Arduino.h>

#include <Adafruit_NeoPixel.h>

// How many internal neopixels do we have? some boards have more than one!
#define NUMPIXELS        1

Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
int dutyPercent =50;//Percent off<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

// Use 12-bit precision for LEDC timer
#define LEDC_TIMER_12_BIT 12

// Use 4 Hz as the LEDC base frequency
int freq= 4;//Hz <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#define LEDC_BASE_FREQ freq

// Define the LED pin (replace with LED_BUILTIN constant for built-in LED)
#define LED_PIN 2 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

void setup() {

//NeoPix setup
	#if defined(NEOPIXEL_POWER)
	pinMode(NEOPIXEL_POWER, OUTPUT);
	digitalWrite(NEOPIXEL_POWER, HIGH);
	#endif
	pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
	pixels.setBrightness(200); // not so bright  // Setup timer with given frequency and resolution, and attach it to the LED pin
    
//setup PWM  
    ledcAttachPin(LED_PIN, LEDC_TIMER_12_BIT);

    // Set the LED duty cycle to 50% (4095 corresponds to 100%)
    ledcWrite(LED_PIN, 4095/(100/dutyPercent));
}
void loop() {
       pixels.fill(0x000000);//light off
      pixels.show();
	  Serial.println("BLK");
	  delay(1000*(1/(freq*(dutyPercent/100))));//
   
    pixels.fill(0xFF0000); // Light on
    pixels.show();
	 delay(1000*(1/(freq-1/freq*(dutyPercent/100))));//
	Serial.println("RED");
	
  }
  

User avatar
alainsam
 
Posts: 206
Joined: Tue Oct 04, 2016 7:58 pm

Re: QTPY-S3 RESET always starts bootload

Post by alainsam »

Oops! My mistake in the delays, they should have used division instead of multiplication. No wonder my bank account is in trouble...

User avatar
adafruit_support_carter
 
Posts: 29522
Joined: Tue Nov 29, 2016 2:45 pm

Re: QTPY-S3 RESET always starts bootload

Post by adafruit_support_carter »

Is that also fixing the resetting into bootloader behavior?

User avatar
alainsam
 
Posts: 206
Joined: Tue Oct 04, 2016 7:58 pm

Re: QTPY-S3 RESET always starts bootload

Post by alainsam »

unfortunately no...

User avatar
adafruit_support_carter
 
Posts: 29522
Joined: Tue Nov 29, 2016 2:45 pm

Re: QTPY-S3 RESET always starts bootload

Post by adafruit_support_carter »

Try adding a call to Serial.begin in setup(). There are Serial.prints in loop(), but no call to Serial.begin().

That's just a guess. Not sure what would be causing that behavior.

User avatar
alainsam
 
Posts: 206
Joined: Tue Oct 04, 2016 7:58 pm

Re: QTPY-S3 RESET always starts bootload

Post by alainsam »

It still does the same with or without the Serial.begin.

User avatar
adafruit_support_carter
 
Posts: 29522
Joined: Tue Nov 29, 2016 2:45 pm

Re: QTPY-S3 RESET always starts bootload

Post by adafruit_support_carter »

Not sure then.

Start with the Blink example that is known to be working and slowly modify it towards your sketch that is not working. Find out at what point (what code added) causes the behavior to show up.

User avatar
alainsam
 
Posts: 206
Joined: Tue Oct 04, 2016 7:58 pm

Re: QTPY-S3 RESET always starts bootload

Post by alainsam »

The error came from:
ledcWrite(LED_PIN, 4095/(100/dutyPercent));
When dutyPercent=0 (No blink) and somehow the boatload appears...

User avatar
adafruit_support_carter
 
Posts: 29522
Joined: Tue Nov 29, 2016 2:45 pm

Re: QTPY-S3 RESET always starts bootload

Post by adafruit_support_carter »

The division by zero is causing a fault that triggers the reset. Not sure why it resets into bootloader mode though. But easy enough to add code protect against a divide by zero.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”