Specific sketch will not upload. The upload reports success but the old code persist

Hi, I have a sketch that will not upload to the nano ESP32, although no compile and download errors are reported.

Other sketches (like blink example or a sketch similar to this specific sketch) do upload and run normally, but when I upload this specific sketch the blink (or previous) sketch remains, without any errors. See output below:

Sketch uses 1713097 bytes (54%) of program storage space. Maximum is 3145728 bytes.
Global variables use 57772 bytes (17%) of dynamic memory, leaving 269908 bytes for local variables. Maximum is 327680 bytes.
"/Users/user123/Library/Arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5/dfu-util" --device 0x2341:0x0070 -D "/Users/user123/Library/Caches/arduino/sketches/740ECF5CAC2F177767DF20F55C9358CF/quantum_dice_teleport_v005_nano.ino.bin" -Q
dfu-util 0.11-arduino4

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
Device ID 2341:0070
Device DFU version 0101
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 0101
Device returned transfer size 4096
Copying data from PC to DFU device

Download	[                         ]   0%            0 bytes
Download	[                         ]   0%         4096 bytes
Download	[=                        ]   4%        69632 bytes
Download	[=                        ]   6%       110592 bytes
Download	[==                       ]   8%       139264 bytes
Download	[===                      ]  12%       208896 bytes
Download	[===                      ]  12%       217088 bytes
Download	[====                     ]  16%       278528 bytes
Download	[====                     ]  19%       335872 bytes
Download	[=====                    ]  20%       344064 bytes
Download	[======                   ]  24%       413696 bytes
Download	[======                   ]  26%       458752 bytes
Download	[=======                  ]  28%       483328 bytes
Download	[========                 ]  32%       552960 bytes
Download	[========                 ]  33%       569344 bytes
Download	[=========                ]  36%       618496 bytes
Download	[=========                ]  39%       684032 bytes
Download	[==========               ]  40%       688128 bytes
Download	[===========              ]  44%       757760 bytes
Download	[===========              ]  46%       794624 bytes
Download	[============             ]  48%       827392 bytes
Download	[=============            ]  52%       897024 bytes
Download	[=============            ]  53%       921600 bytes
Download	[==============           ]  56%       962560 bytes
Download	[==============           ]  59%      1028096 bytes
Download	[===============          ]  60%      1032192 bytes
Download	[================         ]  64%      1101824 bytes
Download	[================         ]  66%      1134592 bytes
Download	[=================        ]  68%      1171456 bytes
Download	[==================       ]  72%      1236992 bytes
Download	[==================       ]  72%      1253376 bytes
Download	[===================      ]  76%      1306624 bytes
Download	[===================      ]  79%      1363968 bytes
Download	[====================     ]  80%      1376256 bytes
Download	[=====================    ]  84%      1445888 bytes
Download	[=====================    ]  85%      1470464 bytes
Download	[======================   ]  88%      1515520 bytes
Download	[=======================  ]  92%      1581056 bytes
Download	[======================== ]  96%      1650688 bytes
Download	[======================== ]  98%      1695744 bytes
Download	[=========================] 100%      1713472 bytes
Download done.
DFU state(7) = dfuMANIFEST, status(0) = No error condition is present
DFU state(2) = dfuIDLE, status(0) = No error condition is present
Done!

I hesitate to reveal this sketch on the internet (it is also quit big), so first I want to know what causes this problem and how can I determine what is wrong with my sketch?

I'm using arduino nano ESP32 with 2.0.18-arduino.5

Thanks for any help

It is going to be difficult to provide help unless you post the sketch that causes the problem. What devices are connected to the board and how is it powered ?

The upload completed normally. Check the Arduino documents for how to make the DFU sketch run. The docs should tell you how to make it run.

I searched on "no error condition." Maybe this helps.

status(0) = No error condition is present

Thanks for your responses. I think it is a problem with this specific sketch, because I can upload and run other sketches normally. Only with this specific sketch the upload reports succes, but the old code persist.

I used a similar sketch (with the same libraries) and had no problem with uploading and running it. Recent uploads of this similar sketch also runs without issue's.

I use Adafruit_GFX, Adafruit_BNO055 , esp_wifi.h, esp_now, Wifi.h libraries. Example sketches with these libraries runs without issue's.

What happens after the upload of a sketch and when is the new sketch "not accepted"?
Meanwhile, I'll do some more testing with the code.

Put a serial.print() message in setup() right after you set the Baud rate and see if that message is displayed.

Thanks for your suggestion. Point is that the old code (from the previous upload) persist. So it runs the code from the previous upload.

You have failed to tell us the difference between the old code and the new code. Adding the message will definitely produce a new code that is not the old code.

Is it possible that the PROGRAM has changed, but the DATA has remained (in FLASH)? Can FLASH be erased? Can all memory be erased?

Due to being unqualified to read the sketch, I could not dig through it.