There is a difference between full protection and most likely protection.
If you want full protection, I say, go with what Krunal suggests: Full isolation.
If you want likely protection, you need to think of the motor driver as using just an old-fashion-y transistor. It could possibly be fused or drain too much current in several paths and in that case limiting the amount of energy that can cost you is usually sufficient. As unlikely as this is, with high current spikes and other distortions when it comes to motors, it may not be unwise for various other reasons to consider.
In fact, these spikes, when looped "correctly" (from a design point of view that should say badly) through your ground system might be so annoying, that full isolation may be the easiest option anyway.
What you can do to limit the energy is several things:
- Connect a diode in series
- Connect a resistor in series
- Connect a diode in parallel
- A combination of the above
All four have different reasons. Sometimes your signal will take too much current to use a resistor, sometimes your signal will suffer from 0.7V from the simplest, smallest signal diodes in series. Sometimes, as sketched by Krunal, just a parallel diode (TVS or otherwise) may not help and just burn up first.
In your particular case, if I had reason to worry for fusing to either ground or 12V, but no extra reasons to want full isolation, I'd probably go for something like this:
simulate this circuit – Schematic created using CircuitLab
If your MCU has a 3.3V supply, it's probably good to get a 3.6V TVS, as usually a 10% margin on the input is tollerable to the MCU, while if the MCU outputs a high, at 3.3V, it will not notice the TVS diode, since it only "breaks down" at 3.6V
If the input of the motor driver takes about 0.5mA, the resistor of 1kOhm will only "lose" 0.5V, which should be acceptable and I suspect the motor driver has a lower input current, though I'm too lazy to lookup the PDF of the number you gave myself to check whether this is true in all cases.
When the driver suddenly becomes a hard 12V output, even if the TVS avalanches to short, the resistor and TVS will never see more than 12mA (12V over a 1k resistor). If your motor driver needs more current on the input, your resistor may have to go down a little in value, but then you should start looking at power dissipation in your resistor and TVS for the higher currents when the chip shorts to 12V.
Of course, put the protection as close to the intelligent chip (MCU) as you can, to protect against as many problems as possible.
I rehash that this does not at all protect against everything, but it protects against the most likely problems with 12V motors.
One may be tempted to use the old diode to VCC trick as an alternative to the TVS, like this:
simulate this circuit
In theory this works just as well, since your 3.3V is strongly regulated, and the BAT54 schkottky diodes at 10mA haven't got a very high forward voltage drop, so the input will likely not see much more than the 3.6V peak we had just before.
BUT: You must always look at what happens in all cases.
Let's say your MCU only uses 5mA on average, now what happens when the motor driver shorts to 12V on only one pin (let alone all of them):
the 1kOhm resistor has 12V on one side, and the MCU drains on average 5mA, and the regulator is only designed to give current, not take it (in most cases). So the resistor has on average no more than 5mA running through it, because any more current can't go anywhere.
So the voltage drop, according to Ohm's law across the 1kOhm resistor can not be more than:
V = I * R = 0.005A * 1000 Ohm = 5V, which leaves 7V at the anode of the diode, which makes for 6.5V-ish on the MCU. I think it's very likely it will not enjoy that very much. Nor will the voltage regulator, even if it manages to compensate it down to nearly 3.3V.
And that's using the average MCU current. Not even the lowest possible. And you should always use the lowest possible in this "worst case" estimation, because at the lowest current you have the highest peak voltage.
So if you do go by that trick, as many sites still may suggest, you first need to very carefully consider the resistor value and the lowest current use of your digital system and often these days you will soon figure out that the resistor needs to be too large, or that the other risks are just getting too high. Thing is, this trick comes from the days boards had so many chips warming up that 1A or more on the 5V VCC rail weren't uncommon in professional logic systems.