Skip to content

Latest commit

 

History

History
154 lines (108 loc) · 7.3 KB

lpc176x.md

File metadata and controls

154 lines (108 loc) · 7.3 KB

Flashing a Board from the SD Card

This method applies to LPC1768 and LPC1769 boards, and other boards which are flashed by copying a file named firmware.bin to the SD card and resetting the board. This includes some STM32 boards which have the required bootloader installed (e.g., SKR Pro v1.1, SKR Mini E3 v2).

Flashing a board from the SD requires that the host can mount the board's on-board SD card to a known mount point in the host filesystem. If your firmware does not expose the SD card to the host, and cannot be configured to do so, this method will not work.

Table of Contents

  1. Marlin Firmware Configuration
    1. PlatformIO Build Environment
    2. Testing Host Storage
  2. SD Card Mounting
    1. Usbmount
      1. Install Usbmount
      2. Configure Usbmount
      3. Configure systemd-udevd
      4. File System Permissions
    2. Sudo Rights
      1. Configure sudo
  3. lpc176x Configuration
  4. Hardware Notes
    1. Creality Ender 3
  5. Troubleshooting
    1. Board Reset Failed
    2. SD Card Mounting

Marlin Firmware Configuration

The following options should be enabled in the Marlin firmware configuration in order for the board's SD card to be accessible by the OctoPrint host:

Configuration.h:

#define SDSUPPORT

Configuration_adv.h:

#define SDCARD_CONNECTION ONBOARD

Optionally, if you do not routinely use the SD card in Marlin, you can prevent Marlin mounting the card at startup, which will make firmware flashing faster as the firmware's lock on the card does not have to be released.

Configuration_adv.h:

#define SD_IGNORE_AT_STARTUP 

PlatformIO Build Environment

Some boards (e.g., SKR Mini E3 V2) need to have a specfic build environment specified in order to include USB storage support in the firmware. If you are compiling with PlatformIO, you can open your platformio.ini file and check the variable default_envs - environments with USB host storage will end in _USB or _USB_maple.

Testing Host Storage

If you plug your board into a PC the computer should see the SD card as a storage device. If this is not the case you need to check and adjust your firmware configuration.

SD Card Mounting

There are several ways to have the SD card mounted by the host. Depending on your level of experience and knowledge with Linux you are free to use whatever method you prefer.

For new users, using usbmount is recommended and is documented below. When properly installed and configured it will automatically mount the board's SD card to /media/usb.

Usbmount

Usbmount needs to be installed and configured to make it work. The instructions below assume that you are running OctoPrint on a Raspberry Pi as the user pi.

Install usbmount

Usbmount can be installed using the package manager. Run this command in an SSH prompt on your OctoPrint host:

sudo apt-get install usbmount

Configure usbmount

Usbmount must be configured so that the mounted device has the correct permissions for the 'pi' user to access the SD card.

  1. Run this command in an SSH prompt on your OctoPrint host:

    sudo nano /etc/usbmount/usbmount.conf

  2. Find the FS_MOUNTOPTIONS line and change it to:

    FS_MOUNTOPTIONS="-fstype=vfat,gid=pi,uid=pi,dmask=0022,fmask=0111"

Configure systemd-udevd

systemd-udevd must be configured so that the mount is accessible.

  1. Run this command in an SSH prompt on your OctoPrint host:

    sudo systemctl edit systemd-udevd

  2. Insert these lines then save and close the file:

    [Service]
    PrivateMounts=no
    MountFlags=shared
    
  3. Run the following commands in an SSH prompt on your OctoPrint host:

    sudo systemctl daemon-reload
    sudo service systemd-udevd --full-restart
    

Once usbmount is installed and configured the on-board SD card should be mounted at /media/usb the next time it is plugged in or restarted.

File System Permissions

Important: Do not modify the permissions on any of the /media/usb* directories!

See here and here for the explanation of why this is important and a very bad idea.

Sudo rights

The plugin needs to be able to unmount the SD card to reduce the risk of file system corruption. The default command the plugin will use is sudo umount /media/usb. You must be able to run this command at the command line without being prompted for a password.

If your system is configured to allow pi to run all sudo commands without a password (the default) then you do not need to do anything further.

Alternatively, you can disable the unmount command entirely by clearing the Unmount command field in the plugin's advanced settings, however this is not recommended.

Configure Sudo

If you need to enter a password when running sudo commands as pi you will need to create a new sudoers entry in order for the plugin to work correctly.

  1. Run this command in an SSH prompt on your OctoPrint host to create a new sudo rule file:

    sudo nano /etc/sudoers.d/020_firmware_updater

  2. Paste this line into the new file:

    pi ALL=NOPASSWD: /bin/umount

  3. Save and close the file

LPC176x Configuration

Firmware Updater

Required Settings

The only required setting is the path to the firmware update folder. If using usbmount it will be /media/usb.

Optional Settings

Option Description
Reset before flashing Adds an extra board reset prior to flashing - can help ensure that the SD card is mounted correctly.
Unmount command The command used to unmount the SD card prior to resetting the board. Clear the command line to disable it

Hardware Notes

Creality Ender 3

Ender 3 V2 printers with 4.2.x boards do not expose the SD card via the USB port. They cannot be updated using this method.

Troubleshooting

Board reset failed

The M997 command is used to reset the board. If flashing an existing Marlin installation, the existing firmware must be newer than March 2nd, 2019 (i.e this commit) as that is when the M997 was added to support resetting the board.

A board running too-old Marlin firmware will report 'Board reset failed' when attempting to flash from the plugin.

SD Card Mounting

The firmware upload will fail if the SD card is not accessible, either because it is not mounted on the host, or because the printer firmware has control over it.

The most common causes are:

  • Firmware not correctly configured to expose SD card to host via USB - reconfigure the firmware
  • Firmware is using the SD card so it is not available to the host - release the firmware's hold on the card with the M22 command
  • usbmount is not configured correctly - follow the instructions to install and configure usbmount