Zardnaar
Legend
Cannons definitely have their place and are just as medieval as full plate and rapiers, crows' nests, abundant currency, standing armies, and stable nation state monarchies and republics.
I've never seen one true medieval town in all of my time playing the game.
In my own campaign it's canonical that chemistry works nothing like the real world, and that there really are four elements - earth, fire, air, and water. This let's me get around any players metagame chemistry. It's canonical in the history of the world that goblins have invented and tried to deploy guns on multiple occasions, only to have it eventually spectacularly backfire because a single low level magic spell (or simply dropped bag) can trigger a chain reaction in every musketeer's powder case, killing the entire army. By canon, the most powerful explosive known to alchemical science has the brisance of black powder and the stability of raw warm nitroglycerin. Fireworks and explosives are known, but they generally have to be prepared and used the same day. Storing large quantities of explosives just isn't feasible in the homebrew world by design.
(I may have gotten the inspiration here from the Amber series, where the fact that explosives don't work in every universe is a major plot point.)
It's not the firearms that bother me. It's the player that wants to solve all problems by just blowing things up. I have bad enough problems with there is always some PC that wants to burn down the dungeon rather than explore it. The problem gets worse if they can haul gunpowder around. And it's not even really the balance issue to that (hint, it doesn't really work). It's the fact that it's just really unfun.
But cannons themselves are fun, and my only problem with muskets is that they make 1st and 2nd level really hard to survive and they imply the existence of say caplocks, breach loaders, rifled miniballs, elephant guns, punt guns, revolvers, lever action rifles and other merely mechanical things which would be easy to invent in the setting - dwarves would figure these things out in the life time of a single dwarf at most if they had a functional black powder. If muskets are allowed, very little stops you from M-16's and that creates massive anti-heroic balance issues.
Pirate ship cannons are beyond the scope of typical D&D games.
Its the rate of fire as well. Vaguely historical way to slow. To abstract and no point using bows or whatever.
And pirates didnt generally want to full broadside a ship anyway which is a very PC mentality. Espicially if the waters shallow enough for water breathing spells.
Firing 50 cannons plus crews a pain. 1-5 cannons doesn't really capture the feels. Grapeshot in D&D terms is usually to efficient.