3
\$\begingroup\$

I'm interested in creating simple interface to SWD to be able to write flash memory of ARM chips. I.e. to create a make-shift programming device - more for sake of exercise.

I started reading the documentation and searching for examples (for I think people already tried this). Currently I have a few questions, for which I would be thankful for guidance:

  • I'm going to configure SWDCLK as normal output, and SWDIO as an open-drain (acting as input when it is in high-Z, see below) - I suspect that it is also open-drain on the side of the target device, so with the help of pull-up I will never have a short-circuit by mistake - is this correct?
  • is there minimum allowed clock period? or anything will do, even just a few Hertz? Or perhaps this is dependent on target device?
  • is it correct that in waiting mode both lines are driven HIGH on the host side, and when the communication begins, the first edge on SWDCLK is falling?
  • HOST should change SWDIO on falling edge of SWCLK - and sample data from target (when needed) on falling edge of SWCLK either - right?

I think currently that's enough (though I would be also thankful for short sample of commands sequence to read / write the flash - but I believe I'll find it out anyway soon) - thank you in advance!

Currently I'm trying to use Arduino to create a basic prototype, though I can switch to plain Atmega or LPC111x with FTDI cable at any time... Though I believe this is not important.

P.S. to explain better about SWDIO - with AVR's for example I put the pin to LOW state and then if it is switched to output, it produces 0. However if it is switched to input, it is in high-Z state and really works as input. I.e. I manipulate not PORTx bit, but DDRx instead (while PORTx is permanent 0 and PINx is used for reading).

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

I'm going to configure SWDCLK as normal output, and SWDIO as an open-drain

SWDCLK is OK, but SWDIO is bidirectional and not open drain. That means you must be able to switch from output to input mode and vice versa.

is there minimum allowed clock period?

Usually not, but some devices have minimum clock rates for special functions like unlocking.

I would be also thankful for short sample of commands sequence to read / write the flash

That is specific for each device. OpenOCD supports many different types (both microcontrollers and programmers) and has source code available.

I have already ported Versaloon to the LPC1343 MCU on the CCC R0ket, this might be a simpler starting point.

\$\endgroup\$
3
  • \$\begingroup\$ "but SWDIO is bidirectional and not open drain" - oh, I poorly explained my idea, I'll update the description. Thank you for all your hints! \$\endgroup\$
    – Alumashka
    Commented Dec 28, 2015 at 16:14
  • \$\begingroup\$ If power consumption and speed aren't important, it's possible to use a resistor rather than a 3-state driver to interface an output to an I/O pin. When the I/O pin is driving a signal, it wins. When it's floating, the resistor-tied output wins. It's generally not hard to find a resistor which is high enough to avoid damaging the output but low enough to overpower any parasitic leakage. Parasitic capacitance may limit the usable speed, but for a manual interface that shouldn't be a problem. \$\endgroup\$
    – supercat
    Commented May 25, 2016 at 18:37
  • \$\begingroup\$ BTW, I've never switch-programmed a processor serially, but I have used a group of 8 data switches, 8 LEDS, some mode switches, and a button, to to feed a 16-byte short program into an RCA-1801 processor. \$\endgroup\$
    – supercat
    Commented May 25, 2016 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.