No way can you do this at all. What do you not understand about that?
How do you know there's no way to do that? I was hoping for someone knowledgeable to explain
the details.
Unless you write your own boot loader. What is so hard about understanding that?
Nothing. I even mentioned that as a possibility in my original post: "Is it a limitation of the bootloader that allows flashing over USB?" And after a quick disassembly of the bootloader, it does seem that that's the case. I didn't spend much time looking into it, but as far as I can tell, flash_nrf_erase
writes to the ERASEPAGE register in a loop, starting at some point until the end of the flash (presumably starting after the pages where the bootloader is stored).
4e86: f8c1 5508 str.w r5, [r1, #1288] ; 0x508
4e8a: f7ff ffb1 bl 4df0 <nvmc_wait_ready>
4e8e: 1a36 subs r6, r6, r0
4e90: 4405 add r5, r0
4e92: d1f8 bne.n 4e86 <flash_nrf_erase+0x4e>
r0: page size, r5: address of page to be erased, r6: number of bytes to erase
But I then specifically asked about using a standalone programmer, which you completely ignored.
So what has that got to do with a Nano 33 BLE processor?
Sounds like you're not actually familiar with the Nano 33 BLE, in which case, I'm not sure why you're trying to answer my question. The nRF52840 is the processor that the Nano 33 BLE uses. https://docs.arduino.cc/hardware/nano-33-ble/ "The Arduino Nano 33 BLE shares its pinout with the classic Arduino Nano but builds on the nRF52840 microcontroller with 1MB CPU Flash Memory."
Anyway to know what page it is possible to erase you need to know where things are stored and why you want to erase the sections you do.
I know all of that. The bootloader is stored in the first page, page 0. My sketch ends at FLASHIAP_APP_ROM_END_ADDR, which is #defined in FlashIAP.h as
#define FLASHIAP_APP_ROM_END_ADDR std::max(std::max((uint32_t) __section_end(".rodata"), (uint32_t) __section_end(".text")), \
(uint32_t) __section_end(".init_array"))
But that's actually only tangentially relevant to what I'm asking about. I don't really need to know that; the Arduino IDE/bossac is what needs to know it, and it does. Whenever it uploads a sketch, it says stuff like "Write 237624 bytes to flash (59 pages)". It obviously knows where to start writing, and how much to write. It just needs to be able to erase only the pages it writes, rather than everything after the bootloader.
lets see is someone else comes along and disagrees with me.
I'm already disagreeing with you, at least about your answer to my question as a whole. I do agree that due to limitations of the bootloader that the Nano BLE comes with, it's not possible to upload a sketch over the USB port without erasing the entire flash. However, it would be possible with a different bootloader that supported doing that. And after looking into it more, I'm pretty sure that it is also possible if I used an external programmer attached to the SWD pins.
So as far as I can tell, the answer to my question is: No, it's not currently possible to do that through the USB port, but it is possible with an external programmer via SWD.