mkleemann / cmake-avr

cmake toolchain for AVR
Other
173 stars 61 forks source link

Support for efuses #12

Open tehplague opened 6 years ago

tehplague commented 6 years ago

Could you add support for setting efuses (e.g. for the ATmega168)?

mkleemann commented 6 years ago

I'll look into it, but don't expect fast results. For a quickhack add the efuses into the call, i.e. for avrdude (I didn't check if it works!):

   # get fuses
   add_custom_target(
      get_fuses
      ${AVR_UPLOADTOOL} -p ${AVR_MCU} -c ${AVR_PROGRAMMER} -P ${AVR_UPLOADTOOL_PORT} -n
         -U lfuse:r:-:b
         -U hfuse:r:-:b
         -U efuse:r:-:b
      COMMENT "Get fuses from ${AVR_MCU}"
   )

   # set fuses
   add_custom_target(
      set_fuses
      ${AVR_UPLOADTOOL} -p ${AVR_MCU} -c ${AVR_PROGRAMMER} -P ${AVR_UPLOADTOOL_PORT}
         -U lfuse:w:${AVR_L_FUSE}:m
         -U hfuse:w:${AVR_H_FUSE}:m
         -U efuse:w:${AVR_E_FUSE}:m
         COMMENT "Setup: High Fuse: ${AVR_H_FUSE} Low Fuse: ${AVR_L_FUSE} Extended Fuse: ${AVR_E_FUSE}"
   )

For a real solution I would check the MCU type if it supports efuses at all. I also saw some forks cleaning up the stuff a little. Maybe some of them already provide the solution. Have to get into it again some time.

rvalle commented 5 years ago

I also need efuses... will try with the hack.

Here in our build scripts I have a note, efuses in atmega328p (at least) include 5 bits that are not used/reserved, some programmers require them to be passed as 1's i.e. atmelice_isp and other requires then as 0's like: avrispmkii

for example to setup BOD 1.8V I need to use 0x06 or 0xF6 depending on the programmer.