The first written reference to Trnava dates from 1211. In 1238, Trnava was the first town in (present-day) Slovakia to be granted a town charter (civic privileges) by the king. The former agricultural center gradually became a center of manufacture, trade, and crafts. By the early 13th century, the king of Hungary had invited numerous Germans to settle in Trnava; this settlement increased after the Tatar invasion in 1242. At the turn of the 13th and 14th centuries, a part of Trnava was enclosed by very long city walls. The original Slovak market settlement and the Germans stayed behind this wall.