As I mentioned above, your example has been built on the GHS compiler, and I am working on the GCC compiler, so I followed the steps stated in the reference manual.
1. initialising flash (clearing error bits)
2. initialising UTEST mode by writing a password to UT0
3. Setting the appropriate SELn bits (SEL2 = 0x1)
4. Setting the AIS bit for sequential sequence
5. No breakpoints
6. seeding UMn registers with offline-generated MISR
7. Setting the AIE bit to start the check
I tried to follow your example, but all your functions are written in hexadecimal, so I couldn't figure out what they really do.
You can kindly check out my attached project.