tests-mbed_hal-flash: optimieze time_cpu_cycles() function
tests-mbed_hal-flash: optimieze time_cpu_cycles() function

This function should perform instruction cycles count in critical section.
Additionally remove redundant code.

mbedmicro/mbed,mbedmicro/mbed,mbedmicro/mbed,betzw/mbed-os,betzw/mbed-os,betzw/mbed-os,kjbracey-arm/mbed,c1728p9/mbed-os,betzw/mbed-os,andcor02/mbed-os,andcor02/mbed-os,kjbracey-arm/mbed,kjbracey-arm/mbed,andcor02/mbed-os,andcor02/mbed-os,betzw/mbed-os,betzw/mbed-os,c1728p9/mbed-os,c1728p9/mbed-os,c1728p9/mbed-os,kjbracey-arm/mbed,andcor02/mbed-os,c1728p9/mbed-os,c1728p9/mbed-os,andcor02/mbed-os,mbedmicro/mbed,mbedmicro/mbed