Kofi Annan has made his final speech as UN secretary general, calling on the US not to lose sight of its core principles in its fight on terror.