Don't install any third party drivers from HP as they may not be compatible with an M1 Mac and Big Sur. Just let macOS locate the drivers for your printer. If you have tried to install the HP drivers manually, then run the HP uninstaller app to completely remove the HP drivers.
If you have an older printer where macOS cannot download drivers automatically (this should be rare), then manually search for a Gutenprint or CUPS driver from the list of available drivers using the "Add Printer" feature of macOS.
If you don't see any Gutenprint or CUPS drivers, then you can try using the CUPS web administrative interface to manually configure your printer (this is a bit more difficult). Open a web browser and type the following URL:
localhost:631
When you select "Adding Printers and Classes" link under "CUPS for Administrators" link. On the next page click "Add Printer" under the "Printers" section where you will be prompted to enter your macOS admin username and password.
https://www.macworld.com/article/2449561/three-printer-management-tricks.html
If HP does have drivers available for your printer and an M1 Mac, then you can try to install them, but I highly recommend letting macOS locate the drivers instead of manually installing the HP drivers. The HP website only mentions Big Sur and not an M1 Mac so who knows if the driver will work on an M1 Mac.
https://support.hp.com/us-en/drivers/selfservice/hp-deskjet-ink-advantage-2640-all-in-one-printer-series/5357278/model/5357279
Perhaps you have some third party software installed that is interfering. Anti-virus apps, cleaning apps, and third party security apps can interfere with macOS and are completely unnecessary. These types of apps usually cause more problems than they solve plus they impact system performance. Uninstall these apps by following the developer's instructions.