Welcome in the forum, dzone!
Two things I can see.
1st: You call frequently DMA_Config() which allocates resources (DMA channels, TDs) but you never free those. When you declare the Channel and the TD as global, you might re-use them instead of freeing and re-allocate.
2nd: You did not get the error yet, but when you increase the optimization level your program will stall. Declare all global vars changed in an interrupt handler as "volatile" or they might get optimized-out of your while(!flag)Wait();
Many thanks Bob!
I can find the solution is using CyDmaTdFree everytime as you say.
And I had forgotten using volatile. You are great teacher!