From 5e48d5e7c5042da88f7d50956142a6446234a11f Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Wed, 10 Jul 2019 21:15:22 +0200 Subject: [PATCH] Update to PlatformIO 4.0 --- .gitignore | 3 +- README.md | 39 ++++++++++------------ platformio.ini | 90 ++++++++++++++------------------------------------ 3 files changed, 43 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index 9f7d1fe..fc7366a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ -.pioenvs +.pio .clang_complete .gcc-flags.json -.piolibdeps .vscode/browse.vc.db* .vscode .vscode/c_cpp_properties.json diff --git a/README.md b/README.md index 9550762..ccbf0ac 100644 --- a/README.md +++ b/README.md @@ -12,41 +12,39 @@ The software is configurable to support different charge controller PCBs with ei - [Libre Solar MPPT 12V 10A with USB (v0.2 and v0.4)](https://github.com/LibreSolar/MPPT-1210-HUS) - [Libre Solar PWM 12/24V 20A](https://github.com/LibreSolar/PWM-2420-LUS) -## Initial software setup (IMPORTANT!) +## Building and flashing the firmware -1. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]` -2. Copy `src/config.h_template` to `src/config.h`, and adjust basic settings +This firmware is developed using the [ARM mbed OS](https://developer.mbed.org/) embedded framework which has easy-to-understand C++ syntax (similar to Arduino) and thus enhances community based software development. - (`config.h` is ignored by git, so your changes are kept after software updates using `git pull`) +If used together with Visual Studio Code and PlatformIO, starting firmware development is only a matter of a few clicks: - cp src/config.h_template src/config.h - $EDITOR src/config.h +1. Install Visual Studio Code and [PlatformIO](https://platformio.org/platformio-ide) to build the firmware. -## Toolchain and flashing instructions +2. Copy `src/config.h_template` to `src/config.h`, and adjust basic settings. `config.h` is ignored by git, so your changes are kept after software updates using `git pull`. -See the Libre Solar website for project-agnostic instructions on how to -[develop software](http://libre.solar/docs/toolchain) and -[flash new firmware](http://libre.solar/docs/flashing). +3. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]` + +4. Connect the board via a programmer. See the Libre Solar website for [further project-agnostic instructions](http://libre.solar/docs/flashing). + +5. Press the upload button at the bottom left corner in VS Code. ### Troubleshooting -#### If flashing the STM32L072 MCU using OpenOCD fails +#### Errors with STM32L072 MCU using OpenOCD -... as seems to happen with the standard settings from PlatformIO, then ... - -*NOTE* This MCU is used in the MPPT 1210 HUS and the PWM charge controller, for example. +The standard OpenOCD settings sometimes fail to flash firmware to this MCU, which is used in the MPPT 1210 HUS and the PWM charge controller. Try one of these workarounds: 1. Change OpenOCD settings to `set WORKAREASIZE 0x1000` in the file `~/.platformio/packages/tool-openocd/scripts/board/st_nucleo_l073rz.cfg`. -2. Use ST-Link tools. For Windows there is a GUI tool. Under Linux, use the following command: - st-flash write .pioenvs/mppt-2420-lc-v0.10/firmware.bin 0x08000000 +2. Use ST-Link tools. For Windows there is a GUI tool. Under Linux, uncomment the `upload_command` line in `platformio.ini`. + 3. Use other debuggers and tools, e.g. Segger J-Link. -#### If flashing fails like this ... +#### Connection failures -In PlatformIO: +If flashing fails like this in PlatformIO: ``` Error: init mode failed (unable to connect to the target) @@ -58,14 +56,13 @@ shutdown command invoked or with ST-Link: ```bash -$ st-flash write .pioenvs/mppt-1210-hus-v0.4/firmware.bin 0x08000000 +$ st-flash write .pio/build/mppt-1210-hus-v0.4/firmware.bin 0x08000000 st-flash 1.5.1 2019-06-21T18:13:03 INFO common.c: Loading device parameters.... 2019-06-21T18:13:03 WARN common.c: unknown chip id! 0x5fa0004 ``` -check the connection between the board used for flashing -(for example the Nucleo), and the MPPT. +check the connection between the programmer (for example the ST-Link of the Nucleo board) and the charge controller. ## API documentation diff --git a/platformio.ini b/platformio.ini index 949a1ba..cd02fd4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,25 +8,31 @@ [platformio] # Select the charge controller hardware by uncommenting one of the following lines +default_envs = +# mppt-2420-lc-v0.10 +# mppt-1210-hus-v0.2 +# mppt-1210-hus-v0.4 +# mppt-1210-hus-v0.6 +# pwm-2420-lus-v0.1 +# pwm-2420-lus-v0.2 +# unit-test-native -#env_default = mppt-2420-lc-v0.10 -#env_default = mppt-1210-hus-v0.2 -#env_default = mppt-1210-hus-v0.4 -#env_default = mppt-1210-hus-v0.6 -#env_default = pwm-2420-lus-v0.1 -#env_default = pwm-2420-lus-v0.2 -#env_default = unit-test-native - -[common] +[env] # select specific stm32 version, as automatic updates of mbed could break compatibility platform = ststm32@~5.3.0 #platform = https://github.com/platformio/platform-ststm32.git +framework = mbed + #upload_protocol = mbed upload_protocol = stlink #upload_protocol = jlink +# Custom upload tools (overwrites upload_protocol) +#upload_command = $PROJECTPACKAGES_DIR/tool-stlink/st-flash write $SOURCE 0x8000000 +#upload_command = dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D $SOURCE + # Custom Serial Monitor baud rate monitor_speed = 115200 @@ -52,95 +58,47 @@ lib_ignore = USB, mbed-USBDevice, mbed-mbedtls # https://github.com/LibreSolar/MPPT-2420-LC/tree/5bc39183c8 [env:mppt-2420-lc-v0.10] -platform = ${common.platform} -framework = mbed board = nucleo_f072rb -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} +build_flags = ${env.build_flags} -D MPPT_2420_LC_0V10 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} -build_unflags= ${common.build_unflags} -extra_scripts = ${common.extra_scripts} - # https://github.com/LibreSolar/MPPT-1210-HUS/tree/586626f3d8 [env:mppt-1210-hus-v0.2] -platform = ${common.platform} -framework = mbed board = nucleo_f072rb -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} +build_flags = ${env.build_flags} -D MPPT_1210_HUS_0V2 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} -build_unflags= ${common.build_unflags} -extra_scripts = ${common.extra_scripts} # https://github.com/LibreSolar/MPPT-1210-HUS/tree/63e5842671 [env:mppt-1210-hus-v0.4] -platform = ${common.platform} -framework = mbed board = nucleo_l073rz -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} +build_flags = ${env.build_flags} -D MPPT_1210_HUS_0V4 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} -build_unflags= ${common.build_unflags} -extra_scripts = ${common.extra_scripts} [env:mppt-1210-hus-v0.6] -platform = ${common.platform} -framework = mbed board = nucleo_l073rz -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} +build_flags = ${env.build_flags} -D MPPT_1210_HUS_0V6 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} -build_unflags= ${common.build_unflags} -extra_scripts = ${common.extra_scripts} # initial test version (obsolete) [env:pwm-2420-lus-v0.1] -platform = ${common.platform} -framework = mbed board = nucleo_l073rz -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} +build_flags = ${env.build_flags} -D PWM_2420_LUS_0V1 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} -build_unflags= ${common.build_unflags} -extra_scripts = ${common.extra_scripts} # https://github.com/LibreSolar/PWM-2420-LUS [env:pwm-2420-lus-v0.2] -platform = ${common.platform} -framework = mbed board = nucleo_l073rz -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} +build_flags = ${env.build_flags} -D PWM_2420_LUS_0V2 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} -build_unflags= ${common.build_unflags} -extra_scripts = ${common.extra_scripts} [env:unit-test-native] platform = native +framework = build_flags = -std=gnu++11 -D LITTLE_ENDIAN -D UNIT_TEST # include src directory (otherwise unit-tests will only include lib directory) test_build_project_src = true -lib_ignore = USB, mbed-USBDevice, mbed-mbedtls, USBSerial, ESP32, Adafruit_GFX -build_unflags= ${common.build_unflags} +lib_ignore = USB, mbed-USBDevice, mbed-mbedtls, USBSerial, ESP32, Adafruit_GFX, SX1276GenericLib +extra_scripts =