Even Castle Doctrine or Stand Your Ground cannot help you if you are being attacked or harassed by the police.
I'm anti-gun, but as I understand it, the second amendment only "helps" against state actors if the population as a whole is willing to overthrow the current government. At that point what "is legal" changes, like when George Washington's troops took America from the UK and wrote the constitution.
However, from a legal standpoint (i.e. based on the current government), the police has a "monopoly on lawful use of force".
Sounds like that might be changing for the better, given what transpired in the Breonna Taylor incident. I understand they just dropped the charges against her boyfriend, who shot at the police when they broke in.