Detection of charged pions and protons in the segmented electromagnetic calorimeter TAPS