Using Atmega328p IC from arduino hex

Can I use the atmega328p-TQFP MCU on my design directly while the code is done on arduino? I want to use the MCU directly on my circuit board. In this case can I load the hex file which I got from my arduino code to burn my MCU of my circuit board? Or I need to burn the bootloader first then the hex file?

If you use SPI programming, you do not need to burn the bootloader. For SPI programming you can use for example an Uno with the ArduinoISP sketch loaded. Or you can use a dedicated SPI programmer like USBasp.

If you wish to use serial programming, you must first use ISP programming techniques to burn the bootloader. Then after that you can use a USB serial adaptor to upload sketches.

When you do Tools > Burn Bootloader in the Arduino IDE it does two processes:

  • Set the microcontroller's configuration fuses according to the hardware definition of the selected board.
  • Flash the bootloader to the microcontroller.

Unless the fuses are already set correctly on your ATmega328P, the first process is absolutely necessary. Typically if you buy bare chips they will come with the factory default settings, which include a 1 MHz clock (likely not what you want). You can also buy chips with a bootloader installed and these will probably have a non-factory fuse settings, likely set as on the Uno, but who knows for sure. It's safest and easiest to just set the fuses so you can be sure it's configured as you're expecting.

As PaulRB has explained, the second step of Burn Bootloader is only necessary for uploading programs to your ATmega328P via serial, as is typically done with an Arduino board.

So if you're just going to be uploading your program via an ISP programmer the second step is pointless but in the Arduino world it's easiest to just do Burn Bootloader even when you only want to set the fuses. The second step only takes seconds, less time than would be required to manually run the avrdude command to set the fuses only. Of course if you want custom fuse settings it may be easier to just run the command you want. There is a hardware package that provides a wide range of configuration options for the ATmega328P:

You can select Tools > Bootloader > No if you don't want to use a bootloader. It will still run the bootloader flashing step during Burn Bootloader but it only flashes an empty dummy file so that will take very little time.