Modding Bootloader

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Modding Bootloader

Postby fly135 » Mon Aug 13, 2018 11:33 pm

I'm trying to put a 10msec delay at the very beginning of the 2nd stage bootloader. So that I can tell the delay is actually happening I also toggle GPIO 23 in a loop waiting for the timeout and look at it on a scope. I'm totally guessing what I'm doing and I'm not seeing anything on the scope. Can anyone comment on this....

Code: Select all

void call_start_cpu0()
{
    uint32_t bitflag = 1<<23;
    bool mybit=false;
    uint32_t tm_start = esp_log_early_timestamp();
    uint32_t delay_msec = 10;
    do {
      gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, mybit, 0);
      mybit = !mybit;
    } while (delay_msec > (esp_log_early_timestamp() - tm_start));
    

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Modding Bootloader

Postby ESP_Sprite » Tue Aug 14, 2018 2:47 am

Did you actually configure that GPIO as an output?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Modding Bootloader

Postby WiFive » Tue Aug 14, 2018 3:03 am

gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Modding Bootloader

Postby ESP_Angus » Tue Aug 14, 2018 3:20 am

Hi fly135,

Code: Select all

gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, mybit, 0);
All of these function arguments are bit masks, so to enable GPIO 23 as an output it must be:

Code: Select all

gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
There is also a helper macro in the same ROM header which is more readable, you can call it like this:

Code: Select all

GPIO_OUTPUT_SET(23, mybit);
BTW, ROM code contains a function ets_delay_us(). So if your requirement is only for a 20ms delay (without needing to do anything while waiting) it is possible to call ets_delay_us(20 * 1000);

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Modding Bootloader

Postby fly135 » Tue Aug 14, 2018 1:36 pm

WiFive wrote:gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
Oppps! :oops:

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Modding Bootloader

Postby fly135 » Tue Aug 14, 2018 1:38 pm

ESP_Angus wrote:BTW, ROM code contains a function ets_delay_us(). So if your requirement is only for a 20ms delay (without needing to do anything while waiting) it is possible to call ets_delay_us(20 * 1000);
Thanks! I was doing the output toggle just to see that I was actually delaying.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Modding Bootloader

Postby fly135 » Tue Aug 14, 2018 1:41 pm

ESP_Sprite wrote:Did you actually configure that GPIO as an output?
No I didn't. I'm a little confused about what's API is available during the 2nd stage bootloader. I didn't see anything to set the direction in .../rom/gpio.h. I was hoping it was handled in the gpio_output_set.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Modding Bootloader

Postby fly135 » Tue Aug 14, 2018 3:48 pm

gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
Putting "mybit" in place of bitflag as the 3rd parameter was exactly the problem with not seeing the output pulses. DOH!

Just goes to show how important it is to include code in your questions. :D

I also observed that I had to multiple the delay time by about 3.3 to get 10msec. IOW I put 33 in the delay time and the pulses go for about 10.2 msec before stopping (according to my scope). So verification is also a good thing.

I'll try "ets_delay_us()" next.

John A

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Modding Bootloader

Postby fly135 » Tue Aug 14, 2018 4:08 pm

20180814_120325.jpg
20180814_120325.jpg (126.3 KiB) Viewed 7195 times
I just tried ets_delay_us and got similar results. The delay is about 1/3 of what I expect.

Code: Select all

    gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
    mybit = !mybit;
    ets_delay_us(1000);    
    gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
    mybit = !mybit;
    ets_delay_us(10000);    
    gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
    mybit = !mybit;
    ets_delay_us(1000);    
    gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
Check out the width of one of those 1000 usec pulses (330 usec) in my scope pic. Granted this is a <$300 scope, but hopefully it's not that far off.

John A

Who is online

Users browsing this forum: No registered users and 118 guests