Peaceable Projects Inc. is a U.S.-based non-profit group that brings the vast resources of the wide world together with the ongoing needs of the people who live, work, and travel on the Camino de Santiago pilgrim trail network in Spain.
Sorry, was typing one-handed so couldn't explain more thoroughly. But if you go to the renfe site, you can search for the train schedule. Select "buscar horarios" (look for schedules), then on the next screen, select "todas las estaciones" (all stations). Select "buscar." Then select "F" & scroll down. Select Fromista, then select Palencia on the next screen. check the times & then you can search for trains to Madrid.