This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 flash programming over SWD

Hi, I would like to program nRF51822 flash over SWD interface. I have another micro LPC1100 series that has the flash image for RF51822 and connected to nRF51822 over SWDIO and SWCLK pins. What are the steps to achieve so? Could anyone please share the details or existing implementation? or better approach which doesn't require any tools like Segger or J-Link.

Parents
  • That's not very easy. You'd need a complete, well at least a partial, implementation of the SWD protocol on the LPC1100, enough to bit bang the SWD interface on the nrf51 into responding, halting and uploading data.

    Then you'd need to write more code on the LPC1100 to drive the SWD code and do the upload, which means understanding the SWD protocol.

    CMSIS-DAP has a free source implementation of a bit banger for SWD, it's designed for use with USB but the underlying code could be used.

    This is a very hard way to do it. You'd be better off putting a bootloader on the nrf51 and using one of the serial bootloader implementations to talk to it. That means however programming the chip once with some kind of commercial programmer (or buying modules which have bootloaders on them).

Reply
  • That's not very easy. You'd need a complete, well at least a partial, implementation of the SWD protocol on the LPC1100, enough to bit bang the SWD interface on the nrf51 into responding, halting and uploading data.

    Then you'd need to write more code on the LPC1100 to drive the SWD code and do the upload, which means understanding the SWD protocol.

    CMSIS-DAP has a free source implementation of a bit banger for SWD, it's designed for use with USB but the underlying code could be used.

    This is a very hard way to do it. You'd be better off putting a bootloader on the nrf51 and using one of the serial bootloader implementations to talk to it. That means however programming the chip once with some kind of commercial programmer (or buying modules which have bootloaders on them).

Children
  • Hi RK,

    Thanks, unfortunately, we don't plan to use any commercial programmer or have pre-flashed boot loader on the nRF51822.

    If I interpret it correctly the sequence would be

    1. initialize SWD connection between LPC100 and nrf51822 by bit banging the SWDIO/SWCLK signals (50 clock cycles, reading IDCODE register and getting ack)

    2. send commands from LPC1100 to nRF51822 to halt //Do I need to do it under MEM-AP or any other register of nRFP8122 or DP?

    3. Write routine on LPC1100 to erase flash of nRF51822 and send those to nRF51822 //Do I need to connect to MEM-AP and send those command to memory, how does the nRF51822 knows that it needs to erase the flash?

    4. Write a routine on LPC1100 to upload the data to nRF51822// Do I need to connect to MEM-AP?

    5. Write a routine on LPC1100 to reset the nRF51822 to reset after the upload? //how do I do it under SWD control?

    This are the top level sequence (what I think) which will turn into sub section of each. If you can provide any pointers that would be appreciated.

  • Yep that's pretty much it. I would then really suggest you start with the CMSIS-DAP code, it's two parts, a bit-banger on one side to talk SWD and a thin veneer intended to attach to a USB interface to get the commands. You just need to separate out the interface piece and drive it directly. That's not the most-efficient way to do it, but it's code which works, the interface is pretty clean, you just call the functions and you have a comms channel.

    I wouldn't bother too much about MEM-AP or anything else, just get the startup sequence sent and use the rest of CMSIS-DAP as written. Effectively you're calling a sequence of the CMSIS-DAP functions, and there are only a couple of 10s of them, that's the fastest to market I can think of.

  • Hi RK, Thank you very much for quick reply. I just downloaded the CMSIS-DAP Beta 0.01 from the link text this is the source you are talking about? If you intend to refer different code base please let me know.

Related