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

nRF51822 controller connection through UART/SWD.

I need to program the nrf51 controller directly from PC. How to connect nRF51822 controller from PC through UART/SWD pins to program.

Parents
  • I need to do something similar to the above. I have a finished pulse oximeter using the nRF51822 on a YJ-14001-nrf51822 daughter board. The device is to test a new BLE protocol specification and I have been provided with the original software in a Keil project. I need to replace the existing BLE protocol with the new protocol specification.

    According to the company, I can flash the software using SWD. They have given me the input soldering points on the daughter board to make the SWD connection on the Pulse OX. Now what I need to do is interface that to the PC. I have no idea how to do this.

    From this discussion it appears that I cannot repurpose a USB cable and flash the device from the Keil IDE even though it supports SWD via USB when using a DK..

    How do I do this directly to the nrf51822 SWD contact points? Do I need additional hardware to go from USB to SWD?

    Thanks. If this is not answered in a few days (old post) I will make an additional post.

  • Hi,

     

    Not sure I understand correctly, but the DK has a debugger IC on it (the one with the sticker) that translates the information received from Keil over the USB cable into SWD. Hypothetically you could direct SWD over a USB cable from the debugger to your target nRF51, the nRF51 just needs an electrical connection to the SWD, SWDIO, VDD and GND pins on the debugger.

    You can use P20 or P19 on the DK to program or debug an external target (instead of the nRF51 on the DK itself), see section 6.10 in the DK User Guide.

     

    Best regards,
    Andreas

  • Hi,

     

    The header 'layout' follows the Arduino shield standards, allowing 3rd party PCBs to be popped on top and connect to the nRF52 and/or IF MCU through the GPIO headers. A target nRF51 on such a shield would be able to be debugged through the P20 header, but it can of course be used with fully external targets as well.

     

    The error you get could be due to the wiring (e.g. swapped SWDIO and SWDCLK) or due to missing power supply of the target. Could you try nrfjprog instead? Install if you do not have it (write 'nrjprog -v' in a CMD window) and run

    nrfjprog -f NRF51 --readregs

    Do you get any error? Hopefully that should be more indicative.

     

    Best regards,
    Andreas

  • The error was solved by googling which led me to a post in this forum. Found that I needed to set the debug mode to 'SW' instead of Jlink or whatever it was. Doing that solved the 'cortex' error.

    I still have a slew of other issues as there is a separate sensor MCU running independently of the BLE. I have managed to mess it up enough that the BLE is no longer advertising. Probably did something in the starting the debugger that the BLE stack got corrupted.

  • Hi,

     

    Sounds like you might have reprogrammed the device, possibly erased the flash where the Application and Softdevice was stored. You should look into the settings in Keil, if it does a full erase, or partial and if so which sectors. In this case you need to reprogram the Softdevice also.

     

    Best regards,
    Andreas

  • Andreas,

    After some searching I found that Keil is set to erase sectors. But I do not know what 'sectors'. All I have is an address range.

    I cannot copy-paste so its hard to get this hand-typed copy right. nRF51xxx with Range is 0000...0H  to 001FF...FFH. When I click on 'add' I see there are three options including SoftDevice. When I add that it has the same range as the already included nRF51xxx option. Would suggest that SoftDevice was erased as well. But I am not sure if that is not relative to something else.

    If SoftDevice is gone can I use Keil to re-install is or DO I need to use the nRF tool?

    Well, using the nrfTool is says that I don't need to load SoftDevice. So nrf51822 is probably damaged. But since I have no idea what I am doing and working with a chip in a production device without the tools one really needs for this job, I have no idea.

  • Erasing sectors means that it will erase only those flash sectors (4kB flash pages) that overlap with the firmware you are trying to program. Typically this will keep other parts of the flash intact (e.g. bonding information and softdevice will not be replaced or erased if you program the application).

    In Keil you typically have a drop down box where you can either program the precompiled BLE stack (e.g. flash_s132_nRF52_x.x.x._softdevice) or the application (e.g. nrf528322_xxaa), this is chosen like this:

    If the softdevice stack is chosen you should flash the softdevice, do not press compile! If you press compile the softdevice hex file found in \components\softdevice will be erased, and you can no longer flash it. In that case you need to unzip those folders from the nRF5 SDK zip file again.

    If the application is chosen, then you can compile and program the application. 

    Typically you program the softdevice stack first, and then you only need to work with the application firmware.

    To erase entire flash (softdevice and application) you can click:

Reply
  • Erasing sectors means that it will erase only those flash sectors (4kB flash pages) that overlap with the firmware you are trying to program. Typically this will keep other parts of the flash intact (e.g. bonding information and softdevice will not be replaced or erased if you program the application).

    In Keil you typically have a drop down box where you can either program the precompiled BLE stack (e.g. flash_s132_nRF52_x.x.x._softdevice) or the application (e.g. nrf528322_xxaa), this is chosen like this:

    If the softdevice stack is chosen you should flash the softdevice, do not press compile! If you press compile the softdevice hex file found in \components\softdevice will be erased, and you can no longer flash it. In that case you need to unzip those folders from the nRF5 SDK zip file again.

    If the application is chosen, then you can compile and program the application. 

    Typically you program the softdevice stack first, and then you only need to work with the application firmware.

    To erase entire flash (softdevice and application) you can click:

Children
  • Thanks for the help. But the problem turned out to be the difficulty of working with a production device that I only have half the information for. In order to flash the device, I have to turn it on which runs the current program immediately. When I flash, the flashing happens somewhere in the middle of that program running. Who knows where? This caused the saved data (in particular bonding info) to get corrupted. Restarts basically did not get pass reloading bonding. I removed all the code related to bonding (so I connect unencrypted) and it worked. So I did not erase the Softdevice and I did not fry my chip with my clunky soldering of the SWD interface.

    I have learned to give a lot more respect to those hardware engineers that can solder micro wires to micro pins.

Related