You cannot contribute once you are enrolled in any part of Medicare, but you can keep and spend money already in the account.
Part A coverage can be backdated up to 6 months when you sign up after 65, so stop contributions 6 months before you enroll to avoid a tax penalty. Contributions made during the backdated months can count as excess contributions.
After you enroll, your HSA can still pay for qualified medical expenses tax-free, including Medicare premiums, deductibles, copays and coinsurance.