Jetson Nano通过i2c更新NUCLEO FW

  • 开发环境

    • nano dev kit with l4t32.3.1.
    • stm32 NUCLEO-L433RC-P
  • 连线

    Nano Nucleo
    J41 Pin 27 (SDA) CN7 Pin9 PB7(SDA)
    J41 Pin 28 (SCL) CN7 Pin1 PB6(SCL)
    J41 Pin 1 (3.3V) CN5 Pin 7(BOOT0)
    J41 Pin 6 (GND) GND
    J41 Pin 17 (3.3V) CN8 Pin 4(3.3v)
    J41 Pin 12 (GPIO) CB8 Pin3 (NRST)
  • 下载编译stm32flash工具

    $ git clone https://git.code.sf.net/p/stm32flash/code stm32flash-code
    $ cd stm32flash-code
    $ make
    

    注意: 这里在什么平台上运行, 就在什么平台上编译, 如果是交叉编译, 要设置交叉编译环境.

  • stm32flash工具测试过程

    1. Nano上电

      这里Nucleo由nano给它供电, 就不需要再用usb供电.

    2. 让NUCLEO-L433RC-P进入system memory boot mode

      $ su //这里用 sudo+oommand 不可以
      # echo 79 > /sys/class/gpio/export
      # echo out > /sys/class/gpio/gpio79/direction
      # echo 0 > /sys/class/gpio/gpio79/value
      # echo 1 > /sys/class/gpio/gpio79/value
      

      以上的BOOTM已经接了3.3v, 这里只需要将NRST由低拉高即可进入system memory boot mode

    3. i2c slave检测

      # i2cdetect -y -r 0
       0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
      00:          -- -- -- -- -- -- -- -- -- -- -- -- --
      10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
      50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
      70: -- -- -- -- -- -- -- --
      
    4. stm32flash命令检测Nucleo信息

      # ./stm32flash -a 0x48 /dev/i2c-0  //要root权限
      stm32flash 0.5
      
      http://stm32flash.sourceforge.net/
      
      Warning: Not a tty: /dev/i2c-0
      Error probing interface "serial_posix"
      Interface i2c: addr 0x48
      Version      : 0x12
      Device ID    : 0x0435 (STM32L43xxx/44xxx)
      - RAM        : Up to 48KiB  (12544b reserved by bootloader)
      - Flash      : Up to 256KiB (size first sector: 1x2048)
      - Option RAM : 16b
      - System RAM : 28KiB
      
    5. 尝试读取和写入Nucleo

      • 读取失败
      root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r ./test_led.bin
      stm32flash 0.5
      
      http://stm32flash.sourceforge.net/
      
      Warning: Not a tty: /dev/i2c-0
      Error probing interface "serial_posix"
      Interface i2c: addr 0x48
      Version      : 0x12
      Device ID    : 0x0435 (STM32L43xxx/44xxx)
      - RAM        : Up to 48KiB  (12544b reserved by bootloader)
      - Flash      : Up to 256KiB (size first sector: 1x2048)
      - Option RAM : 16b
      - System RAM : 28KiB
      Memory read
      Failed to send command
      Failed to read memory at address 0x08000000, target write-protected?
      
      • 往NUCLEO-L433RC-P里写进新FW失败
      # ./stm32flash -a 0x48 /dev/i2c-0 -w ./test_led.bin
      stm32flash 0.5
      
      http://stm32flash.sourceforge.net/
      
      Using Parser : Intel HEX
      Warning: Not a tty: /dev/i2c-0
      Error probing interface "serial_posix"
      Interface i2c: addr 0x48
      Version      : 0x12
      Device ID    : 0x0435 (STM32L43xxx/44xxx)
      - RAM        : Up to 48KiB  (12544b reserved by bootloader)
      - Flash      : Up to 256KiB (size first sector: 1x2048)
      - Option RAM : 16b
      - System RAM : 28KiB
      Write to memory
      Erasing memory
      Got byte 0x7f instead of ACK
      Mass erase failed. Try specifying the number of pages to be erased.
      Failed to erase memory
      
    6. 改写保护模式
      参考文章erase stm32L152

      Some products don’t support Mass erase operation. To perform a mass erase operation using bootloader, two options are available:
      – Erase all sectors one by one using the Erase command
      – Set protection level to Level 1. Then, set it to Level 0 (using the Read protect command and then the Read Unprotect command). This operation results in a mass erase of the internal Flash memory.

      # ./stm32flash -j -a 0x48 /dev/i2c-0
      stm32flash 0.5
      
      http://stm32flash.sourceforge.net/
      
      Warning: Not a tty: /dev/i2c-0
      Error probing interface "serial_posix"
      Interface i2c: addr 0x48
      Version      : 0x12
      Device ID    : 0x0435 (STM32L43xxx/44xxx)
      - RAM        : Up to 48KiB  (12544b reserved by bootloader)
      - Flash      : Up to 256KiB (size first sector: 1x2048)
      - Option RAM : 16b
      - System RAM : 28KiB
      Read-Protecting flash
      Failed to read ACK byte
      Failed to read-protect flash
      # ./stm32flash -k -a 0x48 /dev/i2c-0   //好像没做~
      
    7. 读取并保存成功

      root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r test_read.bin
      stm32flash 0.5
      
      http://stm32flash.sourceforge.net/
      
      Warning: Not a tty: /dev/i2c-0
      Error probing interface "serial_posix"
      Interface i2c: addr 0x48
      Version      : 0x12
      Device ID    : 0x0435 (STM32L43xxx/44xxx)
      - RAM        : Up to 48KiB  (12544b reserved by bootloader)
      - Flash      : Up to 256KiB (size first sector: 1x2048)
      - Option RAM : 16b
      - System RAM : 28KiB
      Memory read
      Read address 0x08040000 (100.00%) Done.
      
    8. 向Nucleo写入新的FW成功

      # ./stm32flash -a 0x48 /dev/i2c-0 -w test_led.bin
      stm32flash 0.5
      
      http://stm32flash.sourceforge.net/
      
      Using Parser : Raw BINARY
      Warning: Not a tty: /dev/i2c-0
      Error probing interface "serial_posix"
      Interface i2c: addr 0x48
      Version      : 0x12
      Device ID    : 0x0435 (STM32L43xxx/44xxx)
      - RAM        : Up to 48KiB  (12544b reserved by bootloader)
      - Flash      : Up to 256KiB (size first sector: 1x2048)
      - Option RAM : 16b
      - System RAM : 28KiB
      Write to memory
      Erasing memory
      Wrote address 0x08000100 (100.00%) Done.
      
  • 再次尝试

root@localhost:/home/sercomm# ./stm32flash -j -a 0x48 /dev/i2c-0
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Read-Protecting flash
Got NACK from device on command 0x83
Failed to read-protect flash

root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r test_read.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Memory read
Got NACK from device on command 0x11
Failed to read memory at address 0x08000000, target write-protected?

root@localhost:/home/sercomm# ./stm32flash -k -a 0x48 /dev/i2c-0
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Read-UnProtecting flash
Done.

root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r test_read.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Failed to send command

root@localhost:/home/sercomm# echo 0 > /sys/class/gpio/gpio79/value
root@localhost:/home/sercomm# echo 1 > /sys/class/gpio/gpio79/value
root@localhost:/home/sercomm# i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
  • 这次的不同

    root@localhost:/home/sercomm# ./stm32flash -k -a 0x48 /dev/i2c-0
    stm32flash 0.5
    
    http://stm32flash.sourceforge.net/
    
    Warning: Not a tty: /dev/i2c-0
    Error probing interface "serial_posix"
    Interface i2c: addr 0x48
    Version      : 0x12
    Device ID    : 0x0435 (STM32L43xxx/44xxx)
    - RAM        : Up to 48KiB  (12544b reserved by bootloader)
    - Flash      : Up to 256KiB (size first sector: 1x2048)
    - Option RAM : 16b
    - System RAM : 28KiB
    Read-UnProtecting flash
    Done.
    

    但怎么写GPIO, 就是侦测不到Nucleo了

    • Nano reboot后拔掉电源重启后一切正常了, 可读可写了.
    Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.9.140-tegra aarch64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
    This system has been minimized by removing packages and content that are
    not required on a system that users do not log into.
    
    To restore this content, you can run the 'unminimize' command.
    
    206 packages can be updated.
    100 updates are security updates.
    
    Last login: Mon Dec 23 16:22:34 2019
    sercomm:~$ cls
    sercomm:~$ reset
    Erase is control-H (^H).
    sercomm:~$ su
    Password:
    root@localhost:/home/sercomm# i2cdetect -y -r 0
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    root@localhost:/home/sercomm#  echo 79 > /sys/class/gpio/export
    root@localhost:/home/sercomm# echo out > /sys/class/gpio/gpio79/direction
    root@localhost:/home/sercomm# echo 0 > /sys/class/gpio/gpio79/value
    root@localhost:/home/sercomm# echo 1 > /sys/class/gpio/gpio79/value
    root@localhost:/home/sercomm# i2cdetect -y -r 0
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0
    stm32flash 0.5
    
    http://stm32flash.sourceforge.net/
    
    Warning: Not a tty: /dev/i2c-0
    Error probing interface "serial_posix"
    Interface i2c: addr 0x48
    Version      : 0x12
    Device ID    : 0x0435 (STM32L43xxx/44xxx)
    - RAM        : Up to 48KiB  (12544b reserved by bootloader)
    - Flash      : Up to 256KiB (size first sector: 1x2048)
    - Option RAM : 16b
    - System RAM : 28KiB
    
    root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r ./test_led_new.bin
    stm32flash 0.5
    
    http://stm32flash.sourceforge.net/
    
    Warning: Not a tty: /dev/i2c-0
    Error probing interface "serial_posix"
    Interface i2c: addr 0x48
    Version      : 0x12
    Device ID    : 0x0435 (STM32L43xxx/44xxx)
    - RAM        : Up to 48KiB  (12544b reserved by bootloader)
    - Flash      : Up to 256KiB (size first sector: 1x2048)
    - Option RAM : 16b
    - System RAM : 28KiB
    Memory read
    Read address 0x08040000 (100.00%) Done.
    
    root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -w ./test_led.bin
    stm32flash 0.5
    
    http://stm32flash.sourceforge.net/
    
    Using Parser : Intel HEX
    Warning: Not a tty: /dev/i2c-0
    Error probing interface "serial_posix"
    Interface i2c: addr 0x48
    Version      : 0x12
    Device ID    : 0x0435 (STM32L43xxx/44xxx)
    - RAM        : Up to 48KiB  (12544b reserved by bootloader)
    - Flash      : Up to 256KiB (size first sector: 1x2048)
    - Option RAM : 16b
    - System RAM : 28KiB
    Write to memory
    Erasing memory
    Done.
    
  • 没有断电直接重启

直接可以发现i2c, 烧写正常

Last login: Mon Dec 23 16:35:06 2019
sercomm:~$ su
Password:
root@localhost:/home/sercomm# i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB

root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r ./test_led_new.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Memory read
Read address 0x08040000 (100.00%) Done.

root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -w ./test_led.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Using Parser : Intel HEX
Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Write to memory
Erasing memory
Done.
  • 关机后重启

    会断电, 读取和烧写都没问题

root@localhost:/home/sercomm# shutdown -h now
100 updates are security updates.

Last login: Mon Dec 23 16:39:23 2019
sercomm:~$ su
Password:
root@localhost:/home/sercomm# i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@localhost:/home/sercomm# echo 79 > /sys/class/gpio/export
root@localhost:/home/sercomm# echo out > /sys/class/gpio/gpio79/direction
root@localhost:/home/sercomm# echo 0 > /sys/class/gpio/gpio79/value
root@localhost:/home/sercomm#  echo 1 > /sys/class/gpio/gpio79/value
root@localhost:/home/sercomm# i2cdetect -y -r 0   //是不是输入太快
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@localhost:/home/sercomm# i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB

root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -r ./test_led_new.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Memory read
Read address 0x08040000 (100.00%) Done.

root@localhost:/home/sercomm# ./stm32flash -a 0x48 /dev/i2c-0 -w ./test_led_new.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Using Parser : Raw BINARY
Warning: Not a tty: /dev/i2c-0
Error probing interface "serial_posix"
Interface i2c: addr 0x48
Version      : 0x12
Device ID    : 0x0435 (STM32L43xxx/44xxx)
- RAM        : Up to 48KiB  (12544b reserved by bootloader)
- Flash      : Up to 256KiB (size first sector: 1x2048)
- Option RAM : 16b
- System RAM : 28KiB
Write to memory
Erasing memory
Wrote address 0x08040000 (100.00%) Done.

root@localhost:/home/sercomm#


发布了1 篇原创文章 · 获赞 0 · 访问量 59
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览