pyOCD icon indicating copy to clipboard operation
pyOCD copied to clipboard

pyOCD fails to program/erase LPC43xx

Open elfmimi opened this issue 2 years ago • 0 comments

Using Keil.LPC4300_DFP.2.10.0.pack from Keil or Keil.LPC4300_DFP.2.8.0.pack from Arm both ends in failure. Errors may differ depending on what chip is being targeted. But its cause is the same. By looking into the source code of .FLM inside the pack, it is apparent that it's partly their fault. Quoting the minimun,

#define BANK_A    0x1A000000
...
flash_bank = (adr == BANK_A) ? 0 : 1;

this is how it decides if destination bank is A or B. Expected input for adr is only either 0x1A000000 or 0x1B000000. In fact dedicated LPC18xx43xx_512_BA.FLM is assigned to Bank-A and LPC18xx43xx_512_BB.FLM for Bank-B, so there's no need to check adr. LPC...BA.FLM could just assume flash_bank = 0, and for LPC...BB.FLM, flash_back = 1 .

Each bank of LPC4300 series are divided into two sections. 0x1A000000 to 0x1A00FFFF : sector size = 8 KB 0x1A010000 to 0x1A07FFFF : sector size = 64 KB 0x1B000000 to 0x1B00FFFF : sector size = 8 KB 0x1B010000 to 0x1B07FFFF : sector size = 64 KB pyOCD splits MemoryRegion into FlashRegion-s by sector size and assign each region's start-address to property .start. The problem is that pyOCD is passing this value 0x1A010000 to Init() function instead of original start-address 0x1A000000.

That will result in erasing 0x1B010000 when commanded to erase 0x1A010000. or failing if there are no Bank-B for the target variant.

elfmimi avatar Apr 08 '22 14:04 elfmimi