I can't comment here yet, so I'll have to make this an answer despite its being broad, but I hope useful. If you're looking for the end of the sword "being used as a primary weapon by infantrymen or cavalrymen in Western warfare" then I think you have answered your own question: "the High Middle Ages (12th century)." Stretch that to 1300 or so.
One might wonder whether the sword was ever "primary." Until gunpowder, the best way to kill people (or shock veteran units into breaking) outside of really close combat (such as took place on castle walls) was always with pointy sticks---whether feathered or carried by men on foot or on horseback. The Romans used short swords and shields in close coordination with spears. The Normans used spears and long, blunt swords against infantry in mail armor; no horseman or footman used either one exclusively of the other. Until longer lances were developed, light cavalry used straight or curved swords against other lightly armored cavalry. Heavy cavalry used heavy lances on horseback and swords/axes on foot, and these forces were often decisive.
But when the Swiss pikemen emerged, heavy cavalry declined; when gunpowder weapons arrived, close combat on castle walls and anywhere else declined in military importance too. The sword as a primary military weapon was moribund at this point, though far from dead. Swords were still used as backup or personal defense, though other armor-penetrating weapons seem to have taken up some slack as armor continued to improve.
I think the question---as well as available information---is too imprecise to give a battle or a precise date. But 1300 is the usual date given for both the gunpowder revolution and the rise of the Swiss pikes. Heavy cavalry armor continued to improve, but heavy cavalry itself declined in importance from 1300 to 1500, when it was abandoned. From 1300 onward, swords slowly declined into essentially civilian weapons or military sidearms---or fetishized symbols of former power.
Dronz: Again, this is in answer form because I still can't comment. The zweihander certainly dates from post-1300 and may have been the last type of sword used as a primary weapon in a military formation (i.e., unit tactics) in Europe, aside from the occasional cavalry charge. But even this is dubious. Wikipedia has this to say about the zweihander:
The Zweihänder was allegedly used by the Doppelsöldner to break
through formations of pikemen, especially Swiss pikemen, by either
being swung to break the ends of the pikes themselves or to knock them
aside and attack the pikemen directly. The veracity of this tradition
is disputed, but at least as a legend, it appears to date to at least
the 17th century.
...
These swords represent the final stage in the trend of increasing size
that started in the 14th century. In its developed form, the
Zweihänder has acquired the characteristics of a polearm rather than a
sword. Consequently, it is not carried in a sheath but across the
shoulder like a halberd.
By the second half of the 16th century, these swords had largely
ceased to have a practical application, but they continued to see
ceremonial or representative use well into the 17th century.