Can't get SWD working on PSoC4 BLE module - Page 1
Forum section: electronics / general

author: Renate
author_rank: Super Contributor
timestamp: September 26, 2021, 02:27:20 am
content: I've been trying to get up to speed on a Cypress CYBLE-012011-00 Bluetooth module. It has some factory software loaded on it already and it can pair with hosts. I'm using an Atmel ICE which is CMSIS-DAP 1.0 compatible. I can't get any response from the module using PSoC Creator 4.4 or OpenOCD or even writing my own code for the CMSIS-DAP commands (DAP_SWJSEQUENCE, DAP_TRANSFER). I can see both clock and data on all of these doing a JTAG to SWD (7x 0xff, 0x9e, 0xe7, 7x 0xff, 0x00) and then attempting to read the IDR. The module never asserts data, no ACK. I've tried very slow speeds too. I've even watched the USB data going to the Atmel ICE and it's all about the same for all three ways.I get from reading the comments in OpenOCD psoc4.cfg that this is a difficult device. What am I missing?Please don't tell me that I have to blow $100 for a genuine ProgKit4 to make this work. We're talking about a protocol that you can bit-bang at low speed.

author: Renate
author_rank: Super Contributor
timestamp: September 26, 2021, 12:13:41 pm
content: Quote from: evb149 on September 26, 2021, 03:24:15 amThe module is running on two fresh AAA batteries, verified as 3.2V. The Atmel ICE reports that voltage and has level shifters that track Vtarget. SWDIO & SWCLK are swinging to the rails. I can wiggle SWDIO, SWCLK & Reset manually (DAP_SWJPINS) or automatically (DAP_SWJSEQUENCE). The module apparently is flashed with something with a debug UART and I can see it reset. (I also tested the Atmel ICE on my usual AVR devices.)Code:@E,003B,BOOT,E=0101011A,S=03030035,P=0103,H=01,C=01,A=00A05017136C@E,000E,ASC,S=01,R=03The SWD can appear at only one set of pins. I've checked it many times. (Cypress is great for mixing top view and bottom view indiscriminately on their spec sheets.)The PSoC Creator tries to find a target at a leisurely rate when you open one of the dialogs for that (e.g. Select Debug Target). When you hit the "Port Acquire" it does the same thing, but it hammers it for 15 seconds. I've tried resetting randomly during the middle of this but haven't got it to do anything. I can see the resets on the debug UART.OK! Now we're getting somewhere!Code:Cmd=05, Xfers=1, Code=01, ID=0bb11477So at least I know that the pinout is right. I noticed that OpenOCD closes and reopens the connection (DAP_CONNECT) on failing to get an ack. PSoC Creator doesn't. So I made my own loop to hammer the SWD then randomly reset and eventually it came out with ID above.The only thing I can think of is that SWD is disabled (being used for somthing else) in whatever the factory flashed and the only way to get a toehold on SWD is if you get in after the reset and before the SWD pins have been reconfigured??? But that would really be criminal of Cypress if they did that.

author: Renate
author_rank: Super Contributor
timestamp: September 26, 2021, 01:39:52 pm
content: So I think I've got this pretty well characterized, now I just have to make it work.I loop, doing DAP_CONNECT, DAP_SWJSEQUENCE, DAP_TRANSFER, DAP_DISCONNECT.If the transfer succeeds, I just keep on doing the transfer.While it's doing this I do a reset using the DGI interface (which I can simultaneously use as the CMSIS-DAP).About 1 out of every 3-4 resets it hits a golden spot and the transfer works.When it works, it will work for a number of times. The higher the clock rate, the more times it will work. The less chars I print on the PC, the more times it will work.It's clear that SWD works for a specific amount of time after reset. I calculate this window to be around 10 mS. You can see that at the 9th ID query the module doesn't assert data.Does anyone know the specific CMSIS-DAP command to halt the processor? I think that if I can do that then I can use PSoC Creator to flash something (anything!) that doesn't reassign the SWD pins.

author: Renate
author_rank: Super Contributor
timestamp: September 29, 2021, 11:45:03 am
content: Gosh! What a lot of links. I have hit a bunch of those.(DFU only works on PSoC with more than 128 kB.)I've learned a bunch and there is more than enough blame to go around.Atmel ICE programmerThe clock rate adjustment using DAP_SWJCLOCK is very screwy. Setting it to under 7500000 gives you a very slow clock, setting it to over 7500000 gives you a faster, but still slow clock.The clock for DAP_JWJSEQUENCE is unaffected by DAP_SWJCLOCKIf there is no ACK to a DAP command the Atmel ICE does not recover. The SWDIO will be stuck in input mode. Subsequent commands will wiggle the clock but not assert data. You must DAP_DISCONNECT/DAP_CONNECT to recover.There is no direct way to reset the target using the CMSIS-DAP interface. DAP_RESETTARGET does not work. Interestingly, the DGI (Data Gateway, a separate USB interface) allows you to reset from there, but only if the CMSIS-DAP interface is not currently DAP_CONNECTed. In my exploration of all these problems I use the AVR specific command "enter programming mode" which asserts reset, wiggles looking unsuccessfully for an AVR, gives up and unasserts reset. This is currently the most time-accurate way I've found to hard reset before my SWD commands.Cypress/InfineonEven if I'm not 100% sure that EZ-Serial is the problem, why the heck did my brand new chip get stuck with this junk? You'd think that they'd deliver the chip with the most accessible bootloader(s).Why is there even a requirement that a SWD "port acquire" occur within 1-2 milliseconds (depending on chip) of hard reset? Why isn't this just open all the time, possible with some option to limit it to that post-reset period.The "port acquire" in PSoC Creator is lame. The Debug dialog does a scan already, the "Port Acquire" just ramps up the rate. (It's running on the UI thread so you can't even slide the dialog around when it's running.)It never even tries to do a DAP_RESETTARGET.It never even tries to do a DAP_DISCONNECT/DAP_CONNECT.

author: Renate
author_rank: Super Contributor
timestamp: October 01, 2021, 12:07:51 am
content: Ha! So I flashed it. (Finally.)More things that I've learned:Although Cypress speaks of "Acquire Port" as line reset and ID query, there is also the important step of putting the device into "Test Mode" (which stops the user code from starting).The check for "Test Mode" occurs within the insanely tight reset timing, < 2mS.Even if you don't manage to snatch that golden ring in time, you still have free reign on the SWD until the user program eventually shuts it down at ~ 9mS.You can do the complete line reset, ID query, unlock, 48 MHz config, erase all (at least starting) in under 9mS.Once you've killed EZ-Serial you can flash it with anything that leaves the SWD open all the time.Edit:I found that the best way to do a target reset is with an explicit wiggling of the reset pin with DAP_SWJPINS.Cypress PSoC Creator still flounders trying to connect.OpenOCD can't seem to program directly, the config file might need to be massaged some.gdb to OpenOCD can program correctly.