DIY tutorial: Mazda PCM/ECU replacement and reprogramming using vxdiag vcx nano Ford/Mazda scanner.
Model example: 2005 series 1 automatic rx8
Tools you will need:
current car pcm
Ford VCM obd scanner (vxdiag vcx nano ford/mazda is the one i use)
Mazda iDS (install guide and download link here)
incode by outcode app (Play Store Link FREE)
a used or new replacement pcm
2 key fobs
Procedure:
plug in the vxdiag vcx nano mazda scan tool to the obdII port under the steering wheel
Open iDS and select start new session>all other

it will read your pcm and recognise your vehicle

if you have dsc select yes

advanced keyless entry > select correct option for you

Check vehicle information and then continue

enter odometer reading if you want to (not required)

select module programming

select programable module installation > pcm

set ignition to on
set ignition back to off when prompted

Install a new module in vehicle. when this prompt comes up unplug your pcm and plug in the replacement

Take off the cover and undo all the bolts holding the pcm down. disconnect the air tubes at the front of the pcm

unplug these 4 connectors on the back of the pcm

set ignition to on
set ignition back to off when prompted
VXDIAG Mazda IDS will rewrite the data on the new pcm from your old one

set ignition back to on
set ignition to off again
Programming complete. if you cannot crank your car now you will have to run the pats function.
Go to body>security>PATS

follow on screen instructions then set ignition to on

select ignition key code erase and reprogram

download incode by outcode on google play store

check that vin is correct before continuing
this page has the OUTCODE you need. put that code into the incode by outcode app then press next when the app gives you an incode

put that outcode into the incode by outcode app and get your incode

type in incode provided by app

if it worked you get this screen

You will need 2 keys to start vehicle. After this page its pretty simple. Just follow on screen instructions until complete then you will have a working rx8 with a new pcm installed.

The tutorial might work on older Mazda, for newer models, you may need Mazda MDARS. The vxdiag vcx nano mazda can also be used as a J2534 passthru device with MDARS.
How to Reprogram New Mazda PCM with MDARS?