The castle in medieval and modern times
The origin of the medieval castle, in the 10th century, must be contextualised within the border conflicts between Moors and Christians, at a key moment in the establishment of the limits between the Caliphate of Córdoba and the County of Barcelona. Galí de Santmartí, as mayor, was in charge of its construction, and from the top of the hill, he carried out the repopulation of the Penedès.
A strategic site for controlling the territory, the castle was involved in some of the most important historical events in the country, such as the battle between Mir Geribert and Ramon Berenguer I of Barcelona (11th century), the royal disputes between the princes Joan and Martí and Queen Sibil·la de Fortià (14th century), and the Catalan Civil War.In the late 15th century, the use of the castle as a military building shifted towards more residential uses, especially after its acquisition by the Pia Almoina of Barcelona Cathedral. However, its role during the War of the Spanish Succession should be highlighted, since this castle, together with the castle of Cardona, became the last centres of resistance against the troops of Philip V on 18 September 1714, a week after the siege of Barcelona.