|
|
  |
ATMega162 и FUSE bits |
|
|
|
Oct 26 2010, 09:17
|

Гуру
     
Группа: Свой
Сообщений: 2 076
Регистрация: 10-09-08
Пользователь №: 40 106

|
Господа, помогите советом плиз! Хочется на 162-й меге распознать первое включение (т.е. первое после прожига). Не используя для этого ни FLASH ни EEPROM. Смотрю в сторону фузов BLBxx. Вроде в DS чето пишут по этому поводу, но видать не хватает знаний чтоб разобраться. Растолкуйте мне пожалуйста какие BLB биты и когда можно перепрограммировать? Цитата из DS: Цитата Setting the Boot Loader Lock Bits by SPM To set the Boot Loader Lock bits, write the desired data to R0, write “X0001001” to SPMCR and execute SPM within four clock cycles after writing SPMCR. The only accessible Lock bits are the Boot Lock bits that may prevent the Application and Boot Loader section from any software update by the MCU.
See Table 90 and Table 91 for how the different settings of the Boot Loader bits affect the Flash access. If bits 5..2 in R0 are cleared (zero), the corresponding Boot Lock bit will be programmed if an SPM instruction is executed within four cycles after BLBSET and SPMEN are set in SPMCR. The Z-pointer is don’t care during this operation, but for future compatibility it is recommended to load the Z-pointer with 0x0001 (same as used for reading the Lock bits). For future compatibility it is also recommended to set bits 7, 6, 1, and 0 in R0 to “1” when writing the Lock bits. When programming the Lock bits the entire Flash can be read during the operation.
|
|
|
|
|
Oct 26 2010, 11:27
|

неотягощённый злом
     
Группа: Свой
Сообщений: 2 746
Регистрация: 31-01-08
Из: Санкт-Петербург
Пользователь №: 34 643

|
Цитата(zombi @ Oct 26 2010, 13:17)  Хочется на 162-й меге распознать первое включение (т.е. первое после прожига). Зачем? Цитата To set the Boot Loader Lock bits, write the desired data to R0, write "X0001001" to SPMCR and execute SPM within four clock cycles after writing SPMCR. Для установки BLLBS, 1) поместите в R0 желаемую конфигурацию BLLBS, 2) поместите байт "X0001001" в регистр SPMCR 3) выполните инструкцию SPM не позднее 4 тактов после записи в регистр SPMCR А так их читают (кусочек boot.h из avr-libc): CODE /* Reading lock and fuse bits:
Similarly to writing the lock bits above, set BLBSET and SPMEN (or SELFPRGEN) bits in __SPMREG, and then (within four clock cycles) issue an LPM instruction.
Z address: contents: 0x0000 low fuse bits 0x0001 lock bits 0x0002 extended fuse bits 0x0003 high fuse bits
Sounds confusing, doesn't it?
Unlike the macros in pgmspace.h, no need to care for non-enhanced cores here as these old cores do not provide SPM support anyway. */
/** \ingroup avr_boot \def GET_LOW_FUSE_BITS address to read the low fuse bits, using boot_lock_fuse_bits_get */ #define GET_LOW_FUSE_BITS (0x0000) /** \ingroup avr_boot \def GET_LOCK_BITS address to read the lock bits, using boot_lock_fuse_bits_get */ #define GET_LOCK_BITS (0x0001) /** \ingroup avr_boot \def GET_EXTENDED_FUSE_BITS address to read the extended fuse bits, using boot_lock_fuse_bits_get */ #define GET_EXTENDED_FUSE_BITS (0x0002) /** \ingroup avr_boot \def GET_HIGH_FUSE_BITS address to read the high fuse bits, using boot_lock_fuse_bits_get */ #define GET_HIGH_FUSE_BITS (0x0003)
/** \ingroup avr_boot \def boot_lock_fuse_bits_get(address)
Read the lock or fuse bits at \c address.
Parameter \c address can be any of GET_LOW_FUSE_BITS, GET_LOCK_BITS, GET_EXTENDED_FUSE_BITS, or GET_HIGH_FUSE_BITS.
\note The lock and fuse bits returned are the physical values, i.e. a bit returned as 0 means the corresponding fuse or lock bit is programmed. */ #define boot_lock_fuse_bits_get(address) \ (__extension__({ \ uint8_t __result; \ __asm__ __volatile__ \ ( \ "sts %1, %2\n\t" \ "lpm %0, Z\n\t" \ : "=r" (__result) \ : "i" (_SFR_MEM_ADDR(__SPM_REG)), \ "r" ((uint8_t)(__BOOT_LOCK_BITS_SET)), \ "z" ((uint16_t)(address)) \ ); \ __result; \ }))
--------------------
“Будьте внимательны к своим мыслям - они начало поступков” (Лао-Цзы)
|
|
|
|
|
Oct 26 2010, 14:09
|

Гуру
     
Группа: Свой
Сообщений: 2 076
Регистрация: 10-09-08
Пользователь №: 40 106

|
Цитата(ILYAUL @ Oct 26 2010, 16:44)  А почему Вы не хотите записать флажок в EEPROM при программировании ( прожиге) Первый раз включить и стереть его к ..... . Проще чем заморачиваться с BLLBS. Конечно это самый простой способ. Тем более что флажок запишется автоматически при стирании. Но мне хочется всетаки понять почему LBL биты НЕ пишутся. Вот на асме простейшую прогу написал. Программирую проц с LOCKbit=$FC и после старта читаю тоже $FC. Подскажите что не правильно: Код AVRASM ver. 1.77.3 a.asm Tue Oct 26 16:38:21 2010 .equ SPMCR =$37 .org 0 000000 94f8 RESET: CLI 000001 e0e1 LDI R30,$01 000002 e0f0 LDI R31,$00 000003 ec03 LDI R16,$C3 000004 2e00 MOV R0,R16 000005 e009 LDI R16,$09 000006 bf07 OUT SPMCR,R16 000007 95e8 SPM 000008 cfff ENDP: RJMP ENDP Assembly complete with no errors.
|
|
|
|
|
Oct 27 2010, 05:58
|

неотягощённый злом
     
Группа: Свой
Сообщений: 2 746
Регистрация: 31-01-08
Из: Санкт-Петербург
Пользователь №: 34 643

|
Цитата(zombi @ Oct 26 2010, 20:32)  Т.е. если переход будет по адресу $0000 то получится ли: разместить в бутлоадере программу которая при определенных условиях сама себя сотрет в $FF так чтоб и следа не осталось? Конечно получится при большом желании:-) Обычно, вменяемый загрузчик считает CRC, проверяет различные условия и только потом переходит в режим приём новой прошивки. И даже в этом случае ничего не стирает и выходит по таймауту, если обновление не началось.
--------------------
“Будьте внимательны к своим мыслям - они начало поступков” (Лао-Цзы)
|
|
|
|
|
  |
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0
|
|
|