Page 1 of 1

Modding Bootloader

Posted: Mon Aug 13, 2018 11:33 pm
by fly135
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));
    

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 2:47 am
by ESP_Sprite
Did you actually configure that GPIO as an output?

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 3:03 am
by WiFive
gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 3:20 am
by ESP_Angus
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);

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 1:36 pm
by fly135
WiFive wrote:gpio_output_set(mybit?bitflag:0, mybit?0:bitflag, bitflag, 0);
Oppps! :oops:

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 1:38 pm
by fly135
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.

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 1:41 pm
by fly135
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.

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 3:48 pm
by fly135
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

Re: Modding Bootloader

Posted: Tue Aug 14, 2018 4:08 pm
by fly135
20180814_120325.jpg
20180814_120325.jpg (126.3 KiB) Viewed 7299 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