Let's make this clear I already know how to use the timers in the LPC1768. The clock runs at 100MHz. To generate a 5MHz square wave you need to generate a timer interrupt every 100ns or 10 clock cycles
To do that the timer has to be set with a MR0 set to 10, and run off the processor clock (CCLK). This causes a timer interrupt every TEN processor cycles and it takes many more clocks than that to process an interrupt.
Using a timer to generate a periodic ISR is only one of the many uses of a timer.
Another very common use of a timer is to generate a PWM output directly.
And it's easy to program the timer itself in such a way that it overflows every 200ns combined wit resetting the output at overflow, and then setting the output with a capture / compare register halfway the count.
That's why I need a HW generated 5MHz (and 1MHz - though not at the same time).
Yes, exactly. Program the timer once, and it will output 5MHz to a hardware pin for as long as it has power applied or you have had enough of it.
The only limitation is that not all outputs can be used for PWM, which leads to:
PWM doesn't appear to be an option as AFAICT none of these pins appear to be usable as PWM output pins (please put me straight if I got that wrong).
Stop the guesswork and check the datasheet. You'll know soon enough if this can work or not. Usually there is some big matrix in the datasheet which lists all the alternate pin functions for each of the pins.
And if it's possible, it is by far the best method. All the others are kludges. I would even consider cutting a PCB track and routing a wire or two to swap some pins to make this possible, or revise the project and spin a new PCB variant.
This may work:
I'm not sure about abusing I2S to clock out on P0.23 - I've a nasty feeling that it will interfere with way too many other pins I see a lot of google in my future.
With STM32 you can swap pins on an individual bases to a GPIO pin, or to an "alternate function" (which is one of timer, uart, spi, etc pins). and by only setting the clock pin to an "alternate output", it's quite possible it won't interfere with other pins.