• 浅谈arduino的bootloader


    在arduino的板子上,作为核心的avr单片机往往都会烧录一个bootloader,这个叫做bootloader的东东其实是arduino研发团队针对arduino板子开发的一小段代码,借助于这段代码,我们可以在不用外部烧录工具的情况下来把我们自己的代码下载到AVR单片机中。为了使一些朋友更容易理解,不妨打个比方,bootloader类似于我们电脑中的windows操作系统,而我们的代码则类似于运行于windows上的各种程序。

       一般而言,arduino板的卖家都会把每块板的bootloader都烧好后再出售,这样买家直接收到板后就能够把自己在arduinoIDE中编写的程序借助PC的USB口来下载到arduino单片机内。当然,下载bootloader是需要借助于外部下载器的,可支持的下载器不少,基中比较具有性价比的是usbtinyisp,在淘宝上很多店家都有出售,比如易捷机器人电路的价格就只有38元。对于一般用户,因为在下载自己代码的时候偶尔会出现破坏bootloader的情况,就像PC的windows系统突然之间崩溃了一样。这时候,就会需要用外部下载器来恢复这个bootloader,就相当于PC重装系统。

    在arduinoIDE的菜单中有一项是Burnbootloader,专门是用来烧bootloader用的,在连接好下载器和arduino板的ISP接口后,选择"Burnbootloader",以目前主流的uno板为例,这时程序会按以下步骤自动操作:

        (1)确认采用stk500的通讯协议。bootloader.atmega328P-<BOARD>.programmer(default value: stk500) is the protocal used by thebootloader.  

      (2)允许对相应内存地址空间操作。bootloader.atmega328P-<BOARD>.unlock_bits(default value: 0x3F) is the value to write to theATmega328 lock byte to unlock the bootloadersection.

       (3)写熔丝位的扩展位。bootloader.atmega328P-<BOARD>.extended_fuses(default value: 0x05) is the value to write tothe extended byte of the ATmega168fuses. 

       (4)写熔丝位的高位。bootloader.atmega328P-<BOARD>.high_fuses(default value: 0xde) is the value to write to the high byte of theATmega328 fuses.

      (5)写熔丝位的低位。bootloader.atmega328P-<BOARD>.low_fuses(default value: 0xff) is the value to write to the low byte of theATmega328 fuses.

      (6)给出bootloader文件的路径。bootloader.atmega328P-<BOARD>.path(default value: optiboot) is the path (relative to the Arduinoapplication directory) containing the precompiled bootloader.

       (7)给出bootloader文件名。bootloader.atmega328P-<BOARD>.file(default value: optiboot_atmega328.hex) is the name ofthe file containing the precompiled bootloader code (inbootloader.path).

      (8)锁定,禁止再修改相应内存空间。bootloader.atmega328P-<BOARD>.lock_bits(default value: 0x0F) is the value to write to theATmega328 lock byte to lock the bootloader section (soit doesn't get accidently overwritten when you upload asketch).

       通常,arduino板在下载好了bootloader但还没有upload任何用户代码的时候,会定义一个led(pin13)一闪一闪的,以作指示。

  • 相关阅读:
    attr系列保留方法使用
    利用python的标准库hashlib 的md5()生成唯一的id
    【病因】 神经衰弱的几大病因
    群里看到的一个骗子批八字的例子
    i'll make a man out of you
    It's A Good Day To Die
    两天了。照着SVN的界面画的一个界面。
    起一卦,看看我想要的,依然这么倒霉
    倒霉倒霉真倒霉,这一卦起得和上一卦一样
    只要是倒霉,起卦就能看出来
  • 原文地址:https://www.cnblogs.com/anandexuechengzhangzhilu/p/10719808.html
Copyright © 2020-2023  润新知