Author SHA1 Message Date
Martin Jäger 5196694e42 Inclusive language: Rename master to main branch 2021-04-14 12:32:14 +02:00
Martin Jäger 613e454fed Clean up prj.conf and improve documentation 2021-04-14 12:23:07 +02:00
Martin Jäger 1943533360 Use UEXT serial for ThingSet by default
Rationale: ESP32 modules can be used as gateways without firmware change.
2021-04-14 11:41:52 +02:00
Martin Jäger 8d8a8f06ad Improve Kconfig and docs for battery type setup 2021-04-14 11:41:50 +02:00
Martin Jäger fac325d423 ThingSet: Move info/Timestamp_s to output/Uptime_s
This makes clear that the timestamp is not the actual time, but the
seconds since the device started.

The timestamp is also not stored in NVM anymore, as the DayCount provides
information about the operating time of the device already. This way
it can be found out if there was a reset of the device based on its uptime.
2021-04-14 11:20:20 +02:00
Martin Jäger cc0bdc1004 Print firmware and hardware version during startup 2021-04-14 11:19:31 +02:00
Martin Jäger daff69550f MPPT 1210 HUS: Match LED assignment with manual 2021-04-14 11:19:31 +02:00
Martin Jäger ede29544d2 CI: Add PlatformIO native manually to fix unit tests 2021-04-14 11:19:31 +02:00
Martin Jäger bc61a29bed Increase HS voltage of MPPT 2420 HC to 90V 2021-04-14 11:19:31 +02:00
Martin Jäger b4483129c2 Configure ThingSet pub messages via Kconfig and enable by default 2021-04-08 09:39:38 +02:00
Martin Jäger faf3bde214 Improve MPPT behavior for STM32G4 series
- Increase PWM step size to see differences between each controller run
- Take ADC2 measurements (current sensors) synchronous to voltages
  (previous approach with high-rate current measurement once per PWM
  cycle only makes sense for cycle-by-cylce control, not for slow MPPT)
2021-03-28 17:37:55 +02:00
Martin Jäger 94dc0d9a3f DAQ: Call update after initial calibration
Otherwise the current measurement will show wrong readings in ThingSet
messages read before control thread started.
2021-03-27 18:26:55 +01:00
Martin Jäger b2707067ac NVS data storage: Improve logging 2021-03-17 13:19:19 +01:00
Martin Jäger d2b4eb7f7e DCDC: Make low power shut off less sensitive
The controllers with fast ADC sampling speed were sometimes switched off
immediately after turn-on. Switching off at negative power flow is only an
additional safety measure. Normally the controller should switch off
reliably because of power_good_timestamp already.
2021-03-17 13:00:00 +01:00
Martin Jäger 3f11266838 Disable pull-down on PB4 and PB6 for STM32G4 MCUs
This pull-down caused issues with the latching power-good function in a
board which required PB6 to be configured as an input.
2021-03-16 17:51:24 +01:00
Martin Jäger 3b68bc1bcc Use STM32 LL API to enable clocks (e.g. for CRC)
Reason: We need to wait until the clock enable register is actually set before
we can consider the clock running. This caused an issue with the CRC
peripheral, which sometimes did not work correctly (always returned 0) right
after startup.

This commit switches to LL API, which includes a delay. Updating all occurences
of direct clock enabling via registers and not only the CRC peripheral.
2021-03-16 17:51:15 +01:00
Martin Jäger 5e02ab2292 Data storage: Add NVS backend to use flash instead of EEPROM 2021-03-12 18:40:22 +01:00
Martin Jäger 8c7a18662e Data storage: Use Zephyr logging system 2021-03-12 18:40:22 +01:00
Martin Jäger a06f14b63c Rename eeprom files to more generic data_storage
This is a preparation for futur non-volatile storage in flash memory.
2021-03-12 18:40:22 +01:00
Martin Jäger 483e09d1a2 Use generic Copyright notice in all files 2021-03-12 18:40:22 +01:00
Martin Jäger c87e5f974a Add MPPT 2420 HC v0.2 board 2021-03-12 18:40:21 +01:00
Martin Jäger 2bbba0ba13 Upgrade PlatformIO to ststm32 v12.0.0 (includes Zephyr v2.5) 2021-03-11 16:42:56 +01:00
Martin Jäger cfeec975c1 Include git SHA into firmware version
Removing separate CommitHash data node because it's not needed anymore.
2021-03-11 16:42:43 +01:00
Martin Jäger 98c1daa865 Enable CONFIG_I2C only if needed (e.g. for OLED or EEPROM) 2021-02-28 11:04:42 +01:00
Martin Jäger f8d7b25648 DCDC: Update HV output switch handling 2021-02-24 16:45:01 +01:00
Daniel Fanache 01ca3b4f15 Fix lv_terminal filtered current and add PWM filtered current.
The lv_terminal filtered current was in fact summing voltages.

Added a separate PWM switch low-pass filter current with more
responsive time constant.
2021-02-24 16:45:01 +01:00
Martin Jäger f6aeaa79db Fix hard faults in EEPROM CRC calculation
The hardware CRC calculation fails hard if a non-aligned memory pointer
is passed to it. This was leading to random issues when changing
unrelated parts in the firmware so that the compiler shuffled memory
locations.

Telling GCC that it should word-align the buffer fixes the issue.

Also renaming _lock to eeprom_buf_lock.
2021-02-05 20:58:16 +01:00
Martin Jäger 6aa015a140 Add basic HRTIM implementation for half_bridge 2021-02-05 18:12:31 +01:00
Martin Jäger fc71934010 Add Nucleo G474RE board for testing purposes 2021-02-05 17:51:10 +01:00
Martin Jäger c151213325 Compile EEPROM code only if enabled via Kconfig 2021-02-05 17:41:52 +01:00
Jordan Silverman a9b0a278ad EEPROM buffer mutex
Added a mutex locking system so that the EEPROM buffer cannot be
used by multiple functions at the same time.
2021-02-05 17:18:49 +01:00
Jordan Silverman a5c1d46d63 Consolidate eeprom buffers
We now use 1 statically allocated buffer for both eeprom_store and
eeprom_restore
2021-02-05 17:18:47 +01:00
Martin Jäger 35b390ff24 Battery voltage & current filtering to improve charging algorithm
For PWM charge controllers, the topping stage was sometimes very short
and the battery did not get fully charged.

This commit adds a voltage_filtered and current_filtered member variable
to DcBus and PowerPort classes which can hold measurements more heavily
filtered (initial time constant setting: 10 seconds). This should fix
above issues with the charging algorithm.
2021-02-04 17:28:52 +01:00
Martin Jäger 269ce762a0 Introduce new Zephyr board revisioning feature
This file layout allows to specify the revision using <board-name>@<revision>
during west build calls.
2021-02-04 17:28:52 +01:00
Martin Jäger ed29e54d20 Add reset for J-Link runner of STM32L0/F0 based boards
Otherwise they don't always wake up after flashing.
2021-02-04 17:28:52 +01:00
Martin Jäger bdf405fb7b Load: Clear ERR_LOAD_BUS_SRC_CURRENT if current is available again
Previously, the error was never cleared after it was set, which is obviously
a bad idea.
2021-02-04 17:28:52 +01:00
Martin Jäger 1b1ed838eb Fix log minimal mode Kconfig for Zephyr 2.5 2021-02-04 17:28:52 +01:00
Martin Jäger 2de110b0b7 Half bridge: New dts binding to fix pinmux
The previous approach to define the pinmux in the timer nodes didn't work
because the timers don't have a pinctrl-0 property. This commit adds a new
half-bridge binding similar to upstream Zephyr pwm binding, which is a child
node of the used timer.

It makes sense to define PWM frequency and dead-time also in this node, so
the dcdc devicetree binding is redundant and therefore removed.
2021-02-04 17:28:52 +01:00
Martin Jäger 4eaf89154a Use BOARD_HAS_* macro to identify key hardware features
These macros replace the direct use of DT_ macros in many locations and make
the code more readable.
2021-02-04 17:28:52 +01:00
Martin Jäger 830315cda0 Use new ThingSet macros for CAN and ISO-TP fixed addressing 2021-02-04 17:28:52 +01:00
Martin Jäger 24742fefcb Fix CAN ISO-TP binding and CAN IDs
For the recv_ctx, the rx and tx addresses were swapped. In addition to that,
the binding has to be released before sending.
2021-02-04 17:28:52 +01:00
Martin Jäger fec60aacbb Enable CAN for MCUs with CAN-FD controller 2021-02-04 17:28:52 +01:00
Martin Jäger a352d6b98c Replace software watchdog with Zephyr task_wdt subsystem 2021-02-04 17:28:52 +01:00
Martin Jäger 941545ea7e Move to pinmux based on devicetree 2021-02-04 17:28:51 +01:00
Martin Jäger 0f109297e4 Use generic LL headers 2021-01-14 19:16:06 +01:00
Martin Jäger e63a2db9e5 Update west.yml and platformi.ini to track Zephyr v2.5
The v2.5-branch is based on upstream master until Zephyr v2.5 is released.

hal_stm32 needs to be overwritten with forked version to support new pinctrl
introduced in Zephyr 2.5.

Also fixing some CAN issues because of API changes to make it compile.
2021-01-14 19:11:59 +01:00
Jordan Silverman bcf54f6698 Add latching pgood function to USB power output 2021-01-14 19:07:19 +01:00
Martin Jäger 3653b88d25 Remove ADC/DAC dts nodes now present in upstream Zephyr 2020-12-15 10:47:29 +01:00
Martin Jäger e5b42ace72 Load: Use Zephyr PWM driver for charge pump 2020-12-15 10:47:14 +01:00
Daniel Fanache 9ba540ec8c Configurable log levels for all the modules using Zephyr's logging.
This allows us to enable e.g debug output for the CAN module with
CONFIG_CAN_LOG_LEVEL=4 without enabling the global
CONFIG_LOG_DEFAULT_LEVEL=4 and being swamped with debug output from
all of Zephyr's subsytems.
2020-12-13 11:06:02 +01:00
Martin Jäger 755e555611 Fix DC/DC debug print variables 2020-12-13 11:05:52 +01:00
Martin Jäger a2ab1ebd45 PWM switch: Improve overvoltage protection
In situations with full battery and sufficient solar panel power, the
battery could reach a high voltage directly after start of the PWM switch
and the control algorithm was not fast enough to limit the voltage (it
takes up to 18s to reach 5% duty cycle after starting at 95%).

This commit increases the step size in the direction of reduced power
and introduces an overvoltage flag that results in restart with 5% duty
cycle if the previous stop was caused by an overvoltage event.
2020-12-13 11:05:05 +01:00
Martin Jäger 4f4bdc70ae PWM switch: Clean up comments and add F suffixes 2020-12-13 11:04:56 +01:00
Martin Jäger 76ee3dc28f Doxygen: Disable preprocessing to include all classes 2020-12-11 22:19:23 +01:00
Martin Jäger 583924a9b9 Fix corrupted %f printf because of disabled heap
newlib requires malloc if printf is used with %f. Since PR 28486, the heap
space in RAM is only reserved if explicitly used by the application
(independent of the value of CONFIG_HEAP_MEM_POOL_SIZE) in order to free
some stack memory. As printf calls malloc internally, this commit forces
Zephyr to build with heap support enabled.
2020-11-18 21:05:05 +01:00
Martin Jäger e5e27c10bc Add MPPT 2420 HC link to Readme 2020-11-18 21:05:05 +01:00
Martin Jäger cb4d4ea1d9 LEDs: Use GPIO flags from dts properly
The flags were always assumed to be ACTIVE_HIGH, which is now fixed.
2020-11-18 21:05:04 +01:00
Martin Jäger 47c1614ed0 Add MPPT 2420 HC board 2020-11-10 16:50:52 +01:00
Martin Jäger 5c3e227928 Add west.yml to use native Zephyr build system properly 2020-11-09 20:08:36 +01:00
Martin Jäger 3d9c4589cd Upgrade to Zephyr 2.4
- Make all struct device * constant
- Add additional argument to PWM nodes in devicetree
- Track customized LibreSolar/zephyr branch in platformio
- Update OLED submodule
2020-11-09 20:07:49 +01:00
Martin Jäger 62d28d9e5e Remove unneeded helper.cpp 2020-11-05 20:42:46 +01:00
Martin Jäger b63cdaa06d DC/DC: Use high/low DcBus instead of PowerPort for control
This makes more sense because the DC/DC converter actually connects two
DcBuses and does not need separate PowerPorts. Also makes the code look
more clean as variable access like dcdc.hvs->bus->voltage is avoided.

The DcBus pointers in the Dcdc are now called hvb and lvb for high-
voltage side bus and low-voltage side bus.
2020-11-05 20:42:34 +01:00
Martin Jäger 0756341b29 Rename src/sink_voltage_bound to _intercept
These variables define the voltage at zero current, which is the y axis
intercept of the droop curve (voltage vs. current).
As they do not always specifiy minimum or maximum boundary depending on
the sign of the droop resistance, intercept is a more suitable name.
2020-11-05 20:42:00 +01:00
Martin Jäger 7cd89bc04a PWM switch: Fix start voltage check
Previous statement didn't consider the series multiplier in case of 24V
battery.
2020-11-05 20:38:55 +01:00
Jordan Silverman 1a29aa1a6e Load NVM settings after data_nodes_init 2020-11-05 20:38:36 +01:00
Martin Jäger 1e64c253ac DAQ: Fix LV terminal current for DC/DC + PWM
Current calculation was wrong if both DC/DC and PWM ports are available
on the same device.
2020-11-05 20:38:03 +01:00
Martin Jäger 1e71ed043e DC/DC: Fix ls_voltage_max setting 2020-11-05 20:37:16 +01:00
Martin Jäger 42759947f8 DAQ: Add high-side overvoltage alert limit
Also rename the functions which set the alert limits to set_xx_limit
instead of set_xx_alert.
2020-11-05 20:37:03 +01:00
Martin Jäger c6709f8f00 Rename (Dcdc|PwmSwitch)::emergency_stop to stop
The stop functions can be used in a generic way, not only in an emergency
situation. The name was misleading.
2020-11-05 20:36:51 +01:00
Jordan Silverman 75e2969274 Update thingset lib commit 2020-11-05 20:36:51 +01:00
Martin Jäger 213e2e30b6 Increase control thread priority to -1
Set to lowest cooperative priority so that it cannot be interrupted by main
or other threads (only by ISRs).
2020-11-05 20:34:59 +01:00
Martin Jäger b40a419e3e Optimize timing of 1s loop in main.cpp
Previously, the interval was not exactly 1s, which could have a negative
impact on energy calculations.

This commit also moves the 1s interval tasks from control loop to the main
loop to avoid duplicated loops running at 1s interval.
2020-11-05 20:30:08 +01:00
Martin Jäger 62338711bc Fix ADC2 triggering for STM32G4 MCUs
When switching to edge-aligned PWM, the ADC measurement was accidentally
triggered at the beginning of the switching cycle.
Fixing this using TIM1 OC6, triggering at falling edge.
2020-10-14 10:04:05 +02:00
Martin Jäger db9c9c5b1c Rename DC/DC operation mode and control names
New control states allow to specify the reason for derating more detailed,
also considering the input side.

The operation mode is now also used as a return value for
check_start_conditions function to get rid of magic numbers.
2020-10-14 10:03:34 +02:00
Martin Jäger c38f1c8348 Cleanup of DC/DC control function
The check for high-side MOSFET shorts and startup inhibit are moved to
separate functions to keep the general control function more clean.

Also declared check_start_conditions weak to allow custom overriding.
2020-10-14 09:53:39 +02:00
Martin Jäger a65bcfe3c2 DAQ: Fix VREF calculation for 16-bit left-aligned readings
Calculation was still for previous 12-bit right-aligned ADC readings
and resulted in wrong calculation of MCU internal temperature.
2020-10-14 09:52:20 +02:00
Martin Jäger 06499a2409 PWM solar input: Fix voltage calculation offset in dts
This offset had to be left-shifted by 4 since the DAQ calculations switched
to 16-bit resolution.
2020-10-14 09:51:52 +02:00
Jordan Silverman bb39ff6236 Update data nodes 2020-10-14 09:48:20 +02:00
Jordan Silverman 9d09f1431b Add grid energy counters 2020-10-14 09:45:45 +02:00
Martin Jäger ef9c8571cc ADC filter time constant configurable per channel
Add a filter-const prop to the adc_inputs devicetree binding and use it instead
of the global ADC_FILTER_CONST in daq.cpp.
2020-09-21 13:29:31 +02:00
Martin Jäger 4008a09f3b ADC: Use 16-bit raw values for calculations
Using 16-bit for calculation allows to increase resolution by oversampling.
The ADC was already configured to use left-aligned 12-bit readings, which can
be treated the same as 16-bit native readings.
2020-09-21 13:29:31 +02:00
Martin Jäger 3bb4a86b5c DAQ: Calculate current offset using raw reading
Makes the calculation more efficient compared to floating point math
2020-09-21 13:29:31 +02:00
Martin Jäger 16c629ed86 DC/DC: Use edge-aligned PWM mode with TIM1
This increases the resolution of the PWM duty cycle of the DC/DC converter by a
factor of 2, which helps to set the ratio between input and output voltage for
the MPPT algorithm more precisely.

Some restructuring of the half_bridge functions was necessary.
2020-09-21 12:45:22 +02:00
Martin Jäger 1356de230f Configure half_bridge PWM via board.dts and pinmux.c
Removes some of the hard-coded configuration in half_bridge.cpp and moves it
to board configuration.

The previous manual pinmux for the PWM output pins is now completely replaced
with Zephyr pinmux.
2020-09-21 12:45:22 +02:00
Martin Jäger 716fb367a8 Update development model in Readme 2020-09-16 15:47:30 +02:00
Martin Jäger 073c04967a Restructure ADC filtering and improve explanations 2020-08-31 13:53:35 +02:00
Martin Jäger f55b236a56 Update MCU-specific defines and includes
Distinguish properly between MCU series and actual MCUs. Constants in mcu.h
had to be changed to #defines to be useable from C code (not only C++).
2020-08-25 17:46:48 +02:00
Martin Jäger d274ca6980 Update PlatformIO ststm32 to 8.0.0
Fixes Zephyr compile issues https://github.com/platformio/zephyr/issues/5
2020-08-25 17:46:48 +02:00
Martin Jäger 314075545a Fix whitespace-check in Travis for PRs not to master 2020-08-19 15:55:15 +02:00
Martin Jäger 6be4e20f04 Make load OC and LVD recovery delay configurable 2020-08-19 15:55:15 +02:00
Martin Jäger ab63204adb Make battery configurable via Kconfig (fix #94)
Also adds crazy IS_ENABLED macro to unit tests.
2020-08-19 15:55:15 +02:00
Martin Jäger 5b024dcd60 Increase stack space for ts.process in serial.cpp
Depending on the amount of data nodes, calling ?rec caused a stack overflow.
Larger stack memory solves the issue, for further improvement see also #103.
2020-08-18 19:29:43 +02:00
Martin Jäger b110918797 Select serial port for ThingSet via Kconfig 2020-08-18 19:29:23 +02:00
Martin Jäger 5e5f2c6680 mppt_1210_rc: Use USART1 as debug serial 2020-08-18 12:14:59 +02:00
Martin Jäger c78c5431a4 Enable load short circuit comp for PWM 2420 LUS 2020-08-18 12:14:59 +02:00
azeemshatp 3aada5dbcc Fix trailing whitespace check in Windows and Linux
Previous check in check.bat considered only uncommitted changes.
2020-08-18 12:14:01 +02:00
Martin Jäger d2e833716a Add Grid_A to ThingSet data nodes 2020-08-17 19:59:58 +02:00
Daniel Fanache c8fa15a860 Remove executable bit for board definition files. 2020-08-17 19:59:58 +02:00
Daniel Fanache e427b45352 Use DT macros instead of Kconfig for board pinmux
Stops using CONFIG_device_x style configuration items and checks the
devicetree to determine if the nodes are enabled.

Fixes UEXT serial port not working.
2020-08-17 19:59:58 +02:00
Martin Jäger ee5846323f Fix STM32G4 ADC settings to improve accuracy
- Wait for the reference voltage to stabilize (thanks to yasen)
- Increase internal regulator stabilization period prior to calibration
2020-08-17 19:59:58 +02:00
Martin Jäger 176af4188f Increase serial watchdog timeout
This prevents the watchdog from kicking in while configuration is stored to
slow EEPROM integrated in STM32L072 MCUs.
2020-08-17 19:58:51 +02:00
Martin Jäger 445359c3b5 Make CAN publication frequency more accurate
Using K_TIMEOUT_ABS_MS for k_sleep calculate exact 1s interval.
2020-08-03 14:52:20 +02:00
Martin Jäger 8f96343cf1 Add support for Kconfig in src/custom
Also fixes data_nodes_custom.cpp inclusion based on Kconfig.
2020-07-27 17:53:31 +02:00
Martin Jäger bbd1312fe5 Relocate and clean up application Kconfig structure 2020-07-24 08:49:47 +02:00
Martin Jäger dc85b46477 Remove unused ExtInterface and ExtMgr 2020-07-23 19:27:45 +02:00
Martin Jäger 01650917fd Move ThingSet serial to dedicated thread 2020-07-23 19:18:24 +02:00
Martin Jäger 79ba9006e7 Move OLED display to dedicated thread 2020-07-23 18:31:52 +02:00
Martin Jäger 5e213fdfb1 Generate COMMIT_HASH define via CMake
Previously the commit hash was generated with a python script which was only
called by PlatformIO and caused issues when using Zephyr SDK directly.
2020-07-23 17:34:41 +02:00
Martin Jäger c2ef955a63 Replace custom print_* with Zephyr LOG_* 2020-07-23 17:34:41 +02:00
Martin Jäger 8e06357a7d Make CAN node ID configurable 2020-07-23 17:34:41 +02:00
Martin Jäger 70baedf95d CAN: Separate thread for pub messages 2020-07-23 17:34:41 +02:00
Martin Jäger 3b486f3193 Restructure SW watchdog and fix bug for >3 channels
The feed function considered max. number of channels and not actual number
of registered channels, which resulted in undefined behavior if not all
channels were used.

Also introducing more simple API to hide the software implementation.
2020-07-23 17:34:41 +02:00
Martin Jäger ed374e8e99 Remove CAN msg queue and update ThingSet lib 2020-07-23 17:34:41 +02:00
Martin Jäger dc4576c8b4 Remove all board.h files
Final updates to devicetree files (adding temperature sensor information) make
board.h files obsolete.
2020-07-23 17:34:41 +02:00
Martin Jäger 27cdcb3bf6 LED setup via devicetree
- New charlieplexing-leds binding
- board.dts files updated
- Pin and LED setup removed from pinmux.c and board.h files
2020-07-23 17:34:41 +02:00
Martin Jäger a584904470 Switch to new DT_ macros 2020-07-23 17:34:39 +02:00
Martin Jäger b8fe6d7023 Fix some static code analysis warnings 2020-07-23 12:55:38 +02:00
Martin Jäger 3012501358 Switch to Zephyr 2.3 and update pio check 2020-07-23 12:55:38 +02:00
Martin Jäger 6316dcd57f Add DC/DC HV side output enable switch 2020-07-23 12:55:38 +02:00
Martin Jäger 7dfcac4037 Add ADC reading to/from voltage conversions 2020-07-23 12:55:38 +02:00
Martin Jäger 7af7d1c4ee Add CAN ISO-TP support 2020-07-23 12:55:37 +02:00
Martin Jäger 3fcd27cdba Use separate CMakeLists.txt per directory 2020-07-23 12:41:32 +02:00
Martin Jäger 8a28d8bc22 Remove unused bootloader support 2020-07-23 12:41:32 +02:00
Martin Jäger 705abbed6b Remove broken ESP32 modem driver
This driver was only compatible with mbed and didn't work reliably. Zephyr
has an in-built ESP modem driver already.
2020-07-23 12:41:32 +02:00
Martin Jäger 2a3e50f6ca Add battery temp. sensor to MPPT 2420 RC 2020-07-23 12:41:32 +02:00
Martin Jäger a7f4ccaa91 Add CAN support for MPPT 2420 RC board
The CAN-FD driver is not yet in Zephyr master, so it is required to get
Zephyr PR 22832 to actually use CAN with this MCU.
2020-07-23 12:41:24 +02:00
Martin Jäger d283436747 Move ADC peripheral setup to devicetree
Remove the ADC channel configuration from the board.h files and use new
DT macros to configure the ADC peripheral based on board.dts only.
2020-07-20 09:07:31 +02:00
Martin Jäger 1b6c56d25b Replace adc-gain DT binding with adc-inputs
Preparation for cleanup of ADC driver.
2020-06-26 15:17:53 +02:00
Martin Jäger 3c9a6e49f1 Fix not enabled UART_1 for some boards 2020-06-26 14:36:36 +02:00
Rhushabh 1dc5cdd7ef Software watchdog for multiple threads 2020-06-23 15:59:31 +02:00
Martin Jäger 54bc5eaee8 Add MPPT 2420 RC board 2020-06-17 11:15:50 +02:00
Martin Jäger 3185ff32a1 Add support for Zephyr 2.3.0 (using west)
Enable CONFIG_LEGACY_DEVICETREE_MACROS and fix removed Kconfig values
like UART_1 to support v2.2 and v2.3.
2020-06-17 11:15:38 +02:00
Jordan Silverman a768f059a1 Stop energy counter when disabled 2020-06-16 21:23:07 +02:00
Martin Jäger 9f02287a03 Add custom unit-test option 2020-06-08 14:27:07 +02:00
Martin Jäger fb3251b88a Add HS MOSFET fail-safe protection Kconfig
The function already existed since a while, but was accidentally not activated.
This is fixed by this commit.
2020-06-05 17:24:16 +02:00
Martin Jäger fc0276e72c Allow custom DC/DC control functions
A Kconfig CUSTOM_DCDC_CONTROLLER is introduced to enable implementation of
more sophisticated control functions than the standard perturb and observe.

A function dcdc_low_level_controller() must be implemented and is called
from the DMA interrupt after each new current sensor reading.

The default Dcdc::control() function is defined __weak.
2020-06-05 16:22:41 +02:00
Martin Jäger 2875ea1519 Rename DC/DC control function responsible for MPPT 2020-06-05 16:18:20 +02:00
Martin Jäger 3eb70e9a01 Add test/zephyr.h to mock Zephyr functions/defines 2020-06-04 16:28:19 +02:00
Martin Jäger dfde83d8be Add CCR and ARR based functions to half_bridge 2020-06-04 11:51:42 +02:00
Martin Jäger b288ffdf35 Cleanup of half_bridge driver
Variables are now named same as registers to avoid confusion between duty
cycle as a value between 0 and 1 or as the capture/compare register value.
2020-06-04 11:51:42 +02:00
Martin Jäger a6c0eecf20 Small datatype updates to reduce RAM footprint 2020-06-04 11:51:42 +02:00
Martin Jäger 7769e4063c Allow more generic firmware customization
This commit adds a new Kconfig setting CONFIG_CUSTOMIZATION. If enabled, the
subdirectory src/custom is added to the build. It can contain an own
CMakeLists.txt file to add several different C/C++ files.

Readme has been updated to explain also DTS overlays and custom prj.conf files.
2020-06-04 11:50:09 +02:00
Martin Jäger 0e5e2f89b1 Remove outdated Kconfig options 2020-06-04 11:50:09 +02:00
azeemshatp cfed3ed6e9 Configure custom data nodes 2020-05-26 15:02:26 +02:00
Martin Jäger 81aefff168 Fix load overvoltage control for 24V systems (#96) 2020-05-21 10:09:54 +02:00
Martin Jäger 882f281333 Fix undervoltage error flag reporting
Load shedding should only trigger capacity calculation, but not set the
undervoltage flag. That flag is only set for voltage below absolute min.
2020-05-11 14:09:27 +02:00
Martin Jäger 1bd8734a2e Use K_MSEC macro in k_sleep calls
This is required by Zephyr 2.3, otherwise getting compile error.
2020-05-11 12:26:41 +02:00
Martin Jäger 9a5004e81d Fix DC/DC start check for 24V batteries (#95) 2020-05-11 11:01:47 +02:00
Martin Jäger faf19ee9e0 Fix wrong voltage divider in MPPT 2420 HPX 2020-05-11 10:32:49 +02:00
Martin Jäger e1c7f97f63 Add support for devices without load output 2020-05-11 10:32:24 +02:00
Martin Jäger d292ad425a Add PWM switch off inhibit 2020-05-06 12:53:26 +02:00
Martin Jäger 3d4da66955 Generate DeviceID from hwinfo 2020-05-06 12:53:26 +02:00
Martin Jäger efc0bc8fdc Update to ThingSet library v0.3 2020-05-06 12:53:26 +02:00
Martin Jäger 7da96abbe4 Fix Solar_V enable and use float for gain calc 2020-05-06 12:53:26 +02:00
Martin Jäger f2c063b291 Lock PlatformIO to Zephyr v2.2.0 2020-05-06 12:53:26 +02:00
Martin Jäger 5e94d72117 Use LL for PWM switch driver to support STM32G4
This adds support for PWM solar input of MPPT 2420 HPX. Also adds new
PwmSwitch::test() function.
2020-05-06 12:53:26 +02:00
Martin Jäger 4011370646 MPPT-2420-HPX: Use TIM8 for charge pump
This commit implements the PWM driver manually using STM LL, as the Zephyr
driver doesn't work for "advanced" timers like TIM8.
2020-05-06 12:53:26 +02:00
Martin Jäger e76709f2af Enable load short circuit comparator
The load driver had to be moved to a .c file to allow attaching interrupt
in Zephyr.
2020-05-06 12:53:26 +02:00
Martin Jäger 9f258b6e69 Replace short STM32XXX defines with CONFIG_SOC_... 2020-05-06 12:53:26 +02:00
Martin Jäger c856b28082 Cleanup of comments in bat_charger.h 2020-05-06 12:53:26 +02:00
Martin Jäger 6f490df537 Small fix of data object units 2020-05-06 12:53:26 +02:00
Martin Jäger 9787397708 Rename STM32L073 references to actually used STM32L072 2020-05-06 12:53:26 +02:00
Martin Jäger 8380b928df Fix Solar_V data object for PWM CCs 2020-05-06 12:53:26 +02:00
Martin Jäger a412117b5b New adc-gain devicetree binding 2020-05-06 12:53:26 +02:00
Martin Jäger 4a70293375 Update peripheral pins in board.dts and pinmux.c 2020-05-06 12:53:26 +02:00
Martin Jäger 8dd576e40e Configure PWM switch driver via DTS
Driver now moved to separate .c file to allow ISR handling in Zephyr.
2020-05-06 12:53:26 +02:00
Martin Jäger ce7f63b888 Introduce generic "outputs" DTS binding
Replaces previous "switch" and "pwm-out" bindings and allows to reference
either gpio or pwm handle and specify maximum current.

Also replacing CONFIG_HAS_LOAD and CONFIG_HAS_USB_PWR with DT_ variants.
2020-05-06 12:53:26 +02:00
Martin Jäger 90c1e7fcf5 Replace Zephyr ADC driver with direct LL access
Fixes IRQ conflict with COMP peripheral (#93)
2020-05-06 12:53:26 +02:00
Martin Jäger 2d3594d254 Add watchdog for each thread using Zephyr API 2020-05-06 12:53:26 +02:00
Martin Jäger 1252a1ffa1 Make default battery type configurable via Kconfig 2020-05-06 12:53:26 +02:00
Martin Jäger d2dd50fe99 Add ThingSet passwords to Kconfig 2020-05-06 12:53:26 +02:00
Martin Jäger 5523f93544 Handle PCB versioning with DTS overlays
This commit completely removes versions like _0v4 in board names
and adds DTS overlays to zephyr/ directory. These can be used to
compile for older board versions.

Some additional configuration changes are handled in board.h file
using board version number from DT_CHARGE_CONTROLLER_PCB_VERSION_NUM.
2020-05-06 12:53:26 +02:00
Martin Jäger affaa9d8e8 Move PCB type and version to DTS 2020-05-06 12:53:26 +02:00
Martin Jäger 4e6f6c7365 Move thermal model parameters to DTS 2020-05-06 12:53:26 +02:00
Martin Jäger 38125f3da3 Remove redundant CONFIG_NUM_LED_PINS 2020-05-06 12:53:26 +02:00
Martin Jäger ab504e3dfa DC/DC and PWM switch configuration via DTS
As these settings are clearly hardware-specific, configuration was
moved from Kconfig (hidden symbols) to DTS. New bindings added.
2020-05-06 12:53:26 +02:00
Martin Jäger 64b771cd42 daq: Separate current offset for DC/DC and PWM 2020-05-06 12:53:26 +02:00
Martin Jäger c25640b987 Fix blocking if CAN not connected to bus 2020-05-06 12:53:26 +02:00
Martin Jäger 9efa2f8f77 Use Zephyr EEPROM driver 2020-05-06 12:53:18 +02:00
Martin Jäger 2a71d02aeb Move PCB and user config to board Kconfig
Files in src/pcbs/xyz.h are moved to boards/xyz/board.h. User settings from
src/config.h are also configured via Kconfig, so the file is removed.
2020-04-30 10:53:58 +02:00
Martin Jäger 2d74a3a554 Mbed support removed
Rationale: The support for both Zephyr and Mbed made the code confusing,
especially because of many ifdefs.

Zephyr RTOS is the future!
2020-04-04 08:21:43 +02:00
Martin Jäger 2c2e59c072 Synchronize ADC2 with PWM signal
For boards with STM32G431, the ADC2 is used for fast current measurement,
synchronized with the half bridge switching PWM.
With this change, the ADC2 is triggered in the center of high-side
MOSFET ON signal using a second PWM output of TIM1.
2020-04-02 12:32:43 +02:00
Martin Jäger 91d4ec4424 Fix COMP and ADC interrupt conflict for STM32L0
The STM32L0 uses the same interrupt for ADC and COMP, which creates
interference with the Zephyr ADC driver. Proper fix needed!
2020-03-11 15:11:55 +01:00
Martin Jäger 84f7a4afdd STM32G431: Add VREF+ pin and fix ADC calibration
- Output 2.048V to VREF+ pin is now used as reference for ADC and DAC.
- ADC calbration got stuck before. Explicitly disabling ADC fixed the issue.
2020-03-03 11:15:58 +01:00
Martin Jäger daf43fb967 USB charging output control via LoadOutput class
- Introduce new CONFIG_HAS_USB_PWR_OUTPUT
- Improve charger.discharge_control function
- Add battery empty flag
2020-03-02 11:55:38 +01:00
Martin Jäger 1a9c290485 Charger.num_batteries moved to DcBus.series_multiplier
The reason is that the voltage disconnect thresholds used in the load outputs
need to be multiplied with number of batteries aswell. As the DcBus class
should contain all voltage-relevant information, it is the right place for the
multiplier.
2020-03-01 09:48:35 +01:00
Martin Jäger 651f66616b Add load info variable (combines state and error_flags) 2020-02-29 13:39:34 +01:00
Martin Jäger a20644f145 Update documentation (docs folder)
Outdated information removed and a new firmware structure overview added.
2020-02-28 14:39:02 +01:00
Martin Jäger 0e918e6b2e Add pwm-out DTS binding and fix CONFIG_PWM
The binding .yaml was forgotten in previous charge pump commit. CONFIG_PWM was
moved from prj.conf to board_defconfig as not all boards need the PWM driver.
2020-02-28 13:24:25 +01:00
Martin Jäger 7722f12a0c Add DAC current sensor ref for STM32G4 MCU 2020-02-26 19:36:27 +01:00
Martin Jäger 46630f88cb Enable half bridge for STM32G4 MCU 2020-02-26 19:30:59 +01:00
Martin Jäger 8307314000 Fix MPPT 2420 HPX pinmux and dts for I2C support 2020-02-26 18:22:16 +01:00
Martin Jäger 2154a1cb72 Add charge-pump driver for HS load switch 2020-02-21 18:27:42 +01:00
Martin Jäger fa9d15e796 Separate load and USB out, improve state handling
Identified issues:
- The load output and USB charging port shared the same state machine,
  which did not allow to set different switch-off thresholds.
- Load error codes were global, so it was not possible to have multiple
  load instances.

This commit introduces load-specific error_flags, makes the LoadOutput
class inherit from PowerPort (to improve code readability), separates
the load driver better from higher level implementation and adds a
second LoadOutput object for the USB charging port.
2020-02-21 18:27:36 +01:00
Martin Jäger 3c0bc41164 Add ADC2 channel configuration for STM32G4 board
Some changes regarding DMA setup and data alignment were necessary to
store all values from ADC1 and ADC2 in the same adc_readings array.
2020-02-20 11:07:02 +01:00
Martin Jäger d40dafd8d9 Rename V_SOLAR/BAT pins to more generic V_HIGH/LOW 2020-02-20 11:06:44 +01:00
Martin Jäger 8539fa3557 MPPT 2420 HPX: Add reset after flashing 2020-02-19 14:44:51 +01:00
Martin Jäger 0c20545f88 Differentiate between src and sink droop res again
Necessary for improved load disconnect switch behavior.
2020-02-19 14:34:40 +01:00
Martin Jaeger 6af8e6d93d Improve load voltage limits setup and update 2020-02-19 14:34:40 +01:00
Martin Jaeger cdb9183c11 Fix load overvoltage limit
The setting is now based on LoadOutput menber overvoltage and not
on the bus voltage bounds, which are used for charging setpoint.
2020-02-19 14:34:40 +01:00
Martin Jaeger 68e0336279 Add debounce counter for UV error detection
This prevents switching off the load output due to short undervoltage
events during startup of pumps etc. when the battery is at low SOC.
2020-02-19 14:34:40 +01:00
azeemshatp b717dea6d1 Implement ADC 1 & 2 using low level APIs
ADC2 works for STM32G431RB processor using LL drivers.
Keep the changes in the MPPT 'boards' folder for possible future use with
zephyr drivers.
2020-02-19 14:33:49 +01:00
JordanSilverman 30968e471c Check incoming battery conf 2020-02-17 19:47:51 +01:00
Martin Jaeger 08974169ab Use new Zephyr 2.2 GPIO driver API features
Enable and disable pins are now handled the same using _set function
instead of _write and using ACTIVE_HIGH/LOW setting in dts.
2020-02-13 18:35:42 +01:00
Martin Jaeger c4d4372953 Fix board files for Zephyr 2.2 compatibility
Warning: These changes break compatibility with previous v2.1.
2020-02-13 17:30:19 +01:00
azeemshatp 9b2162b12e Fix ADC-DMA support for STM32G431
Added additional clock setting for DMA and enabled DMAMUX.
2020-02-12 11:12:55 +01:00
Martin Jaeger 14249492a3 Improve full charge detection and topping control
The battery is only full if the topping voltage is still reached AND the
current is below cut-off threshold at the same time. This was not always
detected correctly with previous 2s target voltage monitoring interval.

In addition to that, a new timer was introduced to count seconds at target
voltage and improve full charge detection due to timeout.
2020-02-10 12:47:32 +00:00
Martin Jaeger 5f1d76ef74 Dedicated setup.cpp to clean up main.cpp
Also includes update of timestamp calculation in Zephyr.
2020-02-08 11:08:58 +01:00
Martin Jaeger 7940acccf4 Zephyr: STM bootloader activation added 2020-02-07 17:36:19 +01:00
Martin Jaeger 5dda805dab Zephyr: ThingSet reset function added 2020-02-07 17:24:07 +01:00
Martin Jaeger 43f90eea7c Move voltage control parameters to DcBus class
The sink and source voltage boundaries for droop control and battery
charge voltage management are now part of the DcBus class.
Also added source and sink current margins, which will be used by the
DC/DC for control targets instead of port current limits, which were
difficult to synchronize before.
2020-02-07 12:03:25 +01:00
Martin Jaeger a7d6dbc3b5 Let PWM switch class inherit from PowerPort
First step of unifying different ports connected to one bus. At a later
step, also the load and charger classes should inherit from PowerPort
class to make overall charge controller structure more clean.
2020-02-07 12:00:59 +01:00
Martin Jaeger f0e99cd80f Voltage replaced by DcBus ptr in PowerPort class
Preparation to separate current and voltage measurements and control
parameters into DcBus and PowerPort classes. This will help to
manage current from different sources (grid, solar) going towards
one bus and control the battery voltage. It will also help to align
multiple charge controllers in parallel, communicating via CAN bus.
2020-02-07 11:55:51 +01:00
Martin Jaeger 86bfce8a0c Zephyr: Added solar voltage enable switch 2020-02-05 18:06:17 +01:00
Martin Jaeger 20fbefc19b Zephyr: DAC using LL added for STM32L0 and STM32F0 2020-02-05 18:06:11 +01:00
Martin Jaeger c31f8d5014 Fix PlatformIO debug error in ext.cpp
Without this dummy implementation of std::__throw_bad_alloc() the
linker was throwing errors.
2020-02-05 18:06:06 +01:00
Martin Jaeger 83d7c36778 Zephyr: MPPT 1210 HUS 0v7 board added 2020-02-05 18:05:55 +01:00
Martin Jaeger 3a8103457f Add type-checking to data objects map 2020-01-31 14:50:32 +01:00
Martin Jaeger 1b6a7f82d7 Zephyr: CAN support added
So far, only publishing messages are supported (no RX yet).

Logging is switched on again, but with minimal output only (suitable
for small F0 MCUs). CAN is activated by default for MPPT 2420 LC.
2020-01-30 16:54:58 +01:00
Martin Jaeger e078b87553 Zephyr: MPPT 2420 LC board added 2020-01-29 11:03:09 +01:00
Martin Jaeger 81c0764f2c Fix DMA memory access violation (wrong length setting) 2020-01-28 15:28:46 +01:00
Martin Jaeger 8c3a6b7160 Zephyr: EEPROM for STM32L0 working 2020-01-28 14:23:47 +01:00
Martin Jaeger eed8c9114c Coding style updated/fixed
Indentations of class definitions and preprocessor statements were not
uniform throughout the code. This commit cleans up indentations as well
as the order of include statements.

Style conventions see: https://github.com/LibreSolar/coding-style
2020-01-28 13:20:01 +01:00
Martin Jaeger c04081fc8a Make Serial and OLED configurable via Kconfig 2020-01-28 12:13:54 +01:00
Martin Jaeger 05292c12ba ADC & DMA renamed to DAQ (data acquisition) 2020-01-27 15:13:53 +01:00
Martin Jaeger dc394cc198 DC/DC: HS MOSFET fail-safe protection enabled 2020-01-27 15:12:15 +01:00
Martin Jaeger a457c2cc9b Fix DC/DC startup condition check 2020-01-27 14:41:48 +01:00
Martin Jaeger 24f751b2e5 Initial support of MPPT 2420 HPX board
- Some flags changed to make the firmware compile for new STM32G431 MCU
- Zephyr board definition added
- Serial, OLED display and LED working
- ADC compiling, but not yet working
2020-01-23 14:41:44 +01:00
Martin Jaeger d5ce578aeb Zephyr: DMA setup via LL instead of registers 2020-01-23 09:51:58 +01:00
azeemshatp 64bd1930b0 Support continuous integration test in Windows.
The 'check.bat' file is introduced to support continuous integration test locally in windows environment. The batch file may be run from Windows command prompt.
2020-01-23 08:06:13 +01:00
azeemshatp f830389c33 Implemented Thingset Serial functionality in Zephyr framework.
Implemented using UART driver APIs.
2020-01-23 08:06:13 +01:00
Martin Jaeger 41b4607cc7 Fix additional bug in load unit-test 2020-01-20 15:22:21 +01:00
Martin Jaeger 69747a588d Fix initialization bug in load unit-test 2020-01-20 10:41:48 +01:00
Martin Jaeger 10f7d44bdf Zephyr: Load output added
Overcurrent protection in PWM charge controller not yet working for Zephyr.
2020-01-18 16:30:37 +01:00
Martin Jaeger d5ea6b5653 Zephyr: Custom DTS binding for GPIO switch
Previously, the LED binding was abused. DTS is now much cleaner.
2020-01-18 15:56:57 +01:00
Martin Jaeger 0c01c3d013 Fixed wrong initialization of static Wh counters 2020-01-16 20:21:08 +01:00
Martin Jaeger a76b92c27b time(NULL) replaced with uptime() in helper files
Reason: Zephyr does not support time(NULL). This way it is portable.
2020-01-16 20:04:37 +01:00
Martin Jaeger 632eb5a4f7 Zephyr: ADC HAL replaced with LL 2020-01-16 16:21:21 +01:00
Martin Jaeger 27bb53bbeb Zephyr: ADC based on STM HAL working 2020-01-16 12:24:25 +01:00
Martin Jaeger cb988639ce Zephyr: Added PWM 2420 LUS board 2020-01-09 13:56:02 +01:00
Martin Jaeger 04f0d42970 Zephyr board names unified with mbed code 2020-01-07 09:38:10 +01:00
Martin Jaeger 90f4c9af00 ThingSet and OLED libs added as git submodules 2020-01-07 07:40:46 +01:00
Martin Jaeger e1915ab501 Releases mentioned in README.md 2020-01-06 19:27:13 +01:00
Martin Jaeger 16ca793bb3 Port configuration based on Kconfig implemented 2020-01-06 19:16:44 +01:00
Martin Jaeger 7bd9bdeafd Kconfig: User-configuration added 2020-01-06 19:05:09 +01:00
Martin Jaeger d654324860 Charger-specific features added to Zephyr board spec
Hardware features like PWM switch, DC/DC converter and LED config
are now configured in the board definition. Actual source files still
need to be changed to use defines with CONFIG_ prefix instead of
defines from pcb.h.
2019-12-31 13:19:26 +01:00
Martin Jaeger 7f4aaf97c3 Moved cal register definitions to mcu.h 2019-12-31 13:16:14 +01:00
193 changed files with 10855 additions and 8428 deletions
+1 -4
View File
@@ -3,13 +3,10 @@
.gcc-flags.json
.vscode/browse.vc.db*
.vscode
src/config.cpp
src/config.h
src/version.h
.west
html
memory.map
custom.ini
zephyr/build
tools
*.bak
*_bak
+6
View File
@@ -0,0 +1,6 @@
[submodule "lib/thingset"]
path = lib/thingset
url = https://github.com/LibreSolar/thingset-device-library
[submodule "lib/oled-display"]
path = lib/oled-display
url = https://github.com/LibreSolar/oled-display-library
+7 -6
View File
@@ -10,7 +10,9 @@ env:
- PLATFORMIO_CI_SRC=src
install:
- pip install wheel
- pip install -U platformio
- platformio platform install native
- platformio update
addons:
@@ -20,11 +22,10 @@ addons:
script:
# check for trailing white spaces (comparing with first commit in git log)
- git diff --check `git rev-list HEAD | tail -n 1`..$TRAVIS_BRANCH
- cp src/config.h_template src/config.h
- platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3
- platformio test -e unit-test-native
- platformio check -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3
- git diff --check `git rev-list HEAD | tail -n 1`..
- platformio run -e mppt_2420_lc -e mppt_1210_hus -e mppt_2420_hc -e pwm_2420_lus
- platformio test -e unit_test
- platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high
- doxygen Doxyfile
deploy:
@@ -34,4 +35,4 @@ deploy:
github_token: $GH_REPO_TOKEN
on:
repo: LibreSolar/charge-controller-firmware
branch: master
branch: main
+1 -1
View File
@@ -2094,7 +2094,7 @@ PERLMOD_MAKEVAR_PREFIX =
# C-preprocessor directives found in the sources and include files.
# The default value is: YES.
ENABLE_PREPROCESSING = YES
ENABLE_PREPROCESSING = NO
# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
# in the source code. If set to NO, only conditional compilation will be
+151 -55
View File
@@ -1,63 +1,191 @@
# Libre Solar Charge Controller Firmware
![build badge](https://travis-ci.com/LibreSolar/charge-controller-firmware.svg?branch=master)
![build badge](https://travis-ci.com/LibreSolar/charge-controller-firmware.svg?branch=main)
This repository contains the firmware for the different Libre Solar Charge Controllers. Originally, the firmware was based on [ARM Mbed OS](https://www.mbed.com). The current version also supports using [Zephyr RTOS](https://www.zephyrproject.org/) for some boards.
This repository contains the firmware for the different Libre Solar Charge Controllers based on [Zephyr RTOS](https://www.zephyrproject.org/).
Coding style is described [here](https://libre.solar/docs/coding_style/).
Coding style is described [here](https://github.com/LibreSolar/coding-style).
## Development and release model
The `main` branch contains the latest release of the firmware plus some cherry-picked bug-fixes. So you can always pull this branch to get a stable and working firmware for your charge controller.
New features are developed in the `develop` branch and merged into `main` after passing tests with multiple boards. The `develop` branch is changed frequently and may even be rebased to fix previous commits. Use this branch only if you want to try out most recent features and be aware that something might be broken.
Releases are generated from `main` after significant changes have been made. The year is used as the major version number. The minor version number starts at zero and is increased for each release in that year.
## Supported devices
The software is configurable to support different charge controller PCBs with either STM32F072 (including CAN support) or low-power STM32L072/3 MCUs.
The software is configurable to support different charge controller PCBs with STM32F072, low-power STM32L072 or most recent STM32G431 MCUs:
- [Libre Solar MPPT 12/24V 20A with CAN](https://github.com/LibreSolar/MPPT-2420-LC)
- [Libre Solar MPPT 12V 10A with USB](https://github.com/LibreSolar/MPPT-1210-HUS)
- [Libre Solar PWM 12/24V 20A](https://github.com/LibreSolar/PWM-2420-LUS)
| Board | Default revision | Older revisions |
|-----------------------------------------------------|------------------|-----------------|
| [Libre Solar MPPT 2420 HC](https://github.com/LibreSolar/mppt-2420-hc) | 0.2 | 0.1 |
| [Libre Solar MPPT 2420 LC](https://github.com/LibreSolar/mppt-2420-lc) | 0.10 | |
| [Libre Solar MPPT 1210 HUS](https://github.com/LibreSolar/mppt-1210-hus) | 0.7 | 0.4 |
| [Libre Solar PWM 2420 LUS](https://github.com/LibreSolar/pwm-2420-lus) | 0.3 | 0.2 |
## Building and flashing the firmware
### ARM Mbed OS
This repository contains git submodules, so you need to clone (download) it by calling:
```
git clone --recursive https://github.com/LibreSolar/charge-controller-firmware
```
Unfortunately, the green GitHub "Clone or download" button does not include submodules. If you cloned the repository already and want to pull the submodules, run `git submodule update --init --recursive`.
### PlatformIO
It is suggested to use Visual Studio Code and PlatformIO for firmware development, as it simplifies compiling and uploading the code a lot:
1. Install Visual Studio Code and [PlatformIO](https://platformio.org/platformio-ide) to build the firmware.
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`.
2. Adjust configuration in `zephyr/prj.conf` if necessary.
3. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]` or create a file `custom.ini` with your personal settings.
3. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]` or create a file `custom.ini` with your personal settings. PlatformIO is configured for latest revision of the boards (see table above). For older revisions adjust `platformio.ini` and the `.json` files in `boards` folder manually or use native Zephyr environment.
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.
### Zephyr
### Native Zephyr environment
Support for Zephyr was recently [included in PlatformIO](https://github.com/platformio/platformio-core/issues/1613) and is currently in beta status. In order to try it out, install the developer version of PlatformIO and run update to get also the development version of the `ststm32` package:
You can also use the Zephyr build system directly for advanced configuration with `menuconfig` or if you need more recently added features.
This guide assumes you have already installed the Zephyr SDK and the west tool according to the [Zephyr documentation](https://docs.zephyrproject.org/latest/getting_started/). Also make sure that `west` is at least at version `0.8.0`.
Now after you cloned the repository (see above), go into the root firmware directory and initialize a west workspace:
west init -l zephyr
This command will create a `.west/config` file and set up the repository as specified in `zephyr/west.yml` file. Afterwards the following command pulls the Zephyr source and all necessary modules, which might take a while:
west update
The CMake entry point is in the `zephyr` subfolder, so you need to run `west build` and `west flash` command in that directory.
cd zephyr
Initial board selection (see `boards` subfolder for correct names):
west build -b <board-name>@<revision>
The appended `@<revision>` specifies the board version according to the above table. It can be omitted if only a single board revision is available or if the default (most recent) version should be used. See also [here](https://docs.zephyrproject.org/latest/application/index.html#application-board-version) for more details regarding board revision handling in Zephyr.
Flash with specific debug probe (runner), e.g. J-Link:
west flash -r jlink
User configuration using menuconfig:
west build -t menuconfig
Report of used memory (RAM and flash):
west build -t rom_report
west build -t ram_report
## Firmware customization
This firmware is developed to allow easy customization for individual use-cases. Below options based on the Zephyr devicetree and Kconfig systems try to allow customization without changing any of the files tracked by git, so that a `git pull` does not lead to conflicts with local changes.
### Hardware-specific changes
In Zephyr, all hardware-specific configuration is described in the [devicetree](https://docs.zephyrproject.org/latest/guides/dts/index.html).
The file `boards/arm/board_name/board_name.dts` contains the default devicetree specification (DTS) for a board. It is based on the DTS of the used MCU, which is included from the main Zephyr repository.
In order to overwrite the default devicetree specification, so-called overlays can be used. An overlay file can be specified via the west command line. If it is stored as `board_name.overlay` in the `zephyr` subfolder, it will be recognized automatically when building the firmware for that board (also with PlatformIO).
### Application firmware configuration
For configuration of the application-specific features, Zephyr uses the [Kconfig system](https://docs.zephyrproject.org/latest/guides/kconfig/index.html).
The configuration can be changed using `west build -t menuconfig` command or manually by changing the prj.conf file (see `Kconfig` file for possible options).
Similar to DTS overlays, Kconfig can also be customized per board. Create a folder `zephyr/boards` and a file `board_name.conf` in that folder. The configuration from this file will be merged with the `prj.conf` automatically.
#### Change the battery type
By default, the charge controller is configured for maintainance-free VRLA gel battery (`CONFIG_BAT_TYPE_GEL`). Possible other pre-defined options are `CONFIG_BAT_TYPE_FLOODED`, `CONFIG_BAT_TYPE_AGM`, `CONFIG_BAT_TYPE_LFP`, `CONFIG_BAT_TYPE_NMC` and `CONFIG_BAT_TYPE_NMC_HV`.
The number of cells is automatically selected by Kconfig to get 12V nominal voltage. It can also be manually specified via `CONFIG_BAT_NUM_CELLS`.
To compile the firmware with default settings for 12V LiFePO4 batteries, add the following to `prj.conf` or the board-specific `.conf` file:
```
platformio upgrade --dev
platformio update
CONFIG_BAT_TYPE_LFP=y
CONFIG_BAT_NUM_CELLS=4
```
Now you should be able to compile and flash Zephyr for supported boards (-zephyr suffix in platformio.ini) in the same way as explained above for Mbed.
#### Configure serial for ThingSet protocol
As the build system in PlatformIO is not the same as the native Zephyr build system, there might still be some issues. Generally, also `west build` should work if called from within the zephyr subdirectory.
By default, the charge controller uses the serial interface in the UEXT connector for the [ThingSet protocol](https://libre.solar/thingset/). This allows to use WiFi modules with ESP32 without any firmware change.
### Troubleshooting
Add the following configuration if you prefer to use the serial of the LS.one port or the additional debug RX/TX pins present on most boards:
#### Errors with STM32L072 MCU using OpenOCD
```
CONFIG_UEXT_SERIAL_THINGSET=n
```
To disable regular data publication in one-second interval on ThingSet serial at startup add the following configuration:
```
CONFIG_THINGSET_SERIAL_PUB_DEFAULT=n
```
### Custom functions (separate C/C++ files)
If you want experiment with some completely new functions for the charge controller, new files should be stored in a subfolder `src/custom`.
To add the files to the firmware build, create an own CMakeLists.txt in the folder and enable the Kconfig option `CONFIG_CUSTOMIZATION`.
If you think the customization could be relevant for others, please consider sending a pull request. Integrating features into the upstream charge controller firmware guarantees that the feature stays up-to-date and that it will not accidentally break after changes in the original firmware.
## API documentation
The documentation auto-generated by Doxygen can be found [here](https://libre.solar/charge-controller-firmware/).
## Conformance testing
We are using Travis CI to perform several checks for each commit or pull-request. In order to run
the same tests locally (recommended before pushing to the server) use the script `check.sh` or ` check.bat`:
bash check.sh # Linux
cmd check.bat # Windows
### Unit-tests
Core functions of the firmware are covered by unit-tests (located in test directory). Run the tests with the following command:
platformio test -e unit_test
### Static code analysis
PlatformIO integrates cppcheck and clangtidy. The following command is an example to run the checks for MPPT 1210 HUS charge controller code:
platformio check -e mppt_1210_hus
## Additional firmware documentation (docs folder)
- [Charge controller basic concepts](docs/charger-concepts.md)
- [Firmware module overview](docs/module-overview.md)
## Troubleshooting
### Errors with STM32L072 MCU using OpenOCD
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`.
1. Change OpenOCD settings to `adapter_khz 500` in line 70 in `~/.platformio/packages/tool-openocd/scripts/target/stm32l0.cfg`.
2. Use ST-Link tools. For Windows there is a GUI tool. Under Linux, uncomment the `upload_command` line in `platformio.ini`.
2. Use other tools or debug probes such as [STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html) or [Segger J-Link](https://www.segger.com/products/debug-probes/j-link/).
3. Use other debuggers and tools, e.g. Segger J-Link.
#### Connection failures
### Connection failures
If flashing fails like this in PlatformIO:
@@ -78,35 +206,3 @@ st-flash 1.5.1
```
check the connection between the programmer (for example the ST-Link of the Nucleo board) and the charge controller.
## Bootloader Support (STM32L07x only)
The custom linker script file STM32L073XZ.ld.link_script.ld needs to be updated before generating the application firmware binary. For each application, the flash start address and the maximum code size need to be updated in this file. Currently, the locations 0x08001000 and 0x08018000 are used for applications 1 & 2 respectively.
## API documentation
The documentation auto-generated by Doxygen can be found [here](https://libre.solar/charge-controller-firmware/).
## Conformance testing
We are using Travis CI to perform several checks for each commit or pull-request. In order to run
the same tests locally (recommended before each pull-request) use the script `check.sh`:
bash check.sh
### Unit-tests
In order to run the unit tests, you need a PlatformIO Plus account. Run tests with the following command:
platformio test -e unit-test-native
### Static code analysis
PlatformIO integrates cppcheck and clangtidy. The following command is an example to run the checks for MPPT 1210 HUS charge controller code:
platformio check -e mppt-1210-hus-v0.7
## Additional firmware documentation (docs folder)
- [MPPT charger firmware details](docs/firmware.md)
- [Charger state machine](docs/charger.md)
-92
View File
@@ -1,92 +0,0 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x08018000, LENGTH = 94k
RAM (rwx) : ORIGIN = 0x200000C0, LENGTH = 20K - 0xC0
}
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
KEEP(*(.eh_frame*))
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
__etext = .;
_sidata = .;
.data : AT (__etext)
{
__data_start__ = .;
_sdata = .;
*(vtable)
*(.data*)
. = ALIGN(8);
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(8);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(8);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
KEEP(*(.jcr*))
. = ALIGN(8);
__data_end__ = .;
_edata = .;
} > RAM
.bss :
{
. = ALIGN(8);
__bss_start__ = .;
_sbss = .;
*(.bss*)
*(COMMON)
. = ALIGN(8);
__bss_end__ = .;
_ebss = .;
} > RAM
.heap (COPY):
{
__end__ = .;
end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
_estack = __StackTop;
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
+21
View File
@@ -0,0 +1,21 @@
# Configuration of supported boards
## Zephyr board definition
The definitions found in `boards/arm/my-board/` folders are used directly by Zephyr.
More detiails can be found in Zephyr
[porting guide](https://docs.zephyrproject.org/latest/guides/porting/board_porting.html) and
[Kconfig description](https://docs.zephyrproject.org/latest/guides/kconfig/setting.html#the-initial-configuration).
- `board.cmake`, `CMakeLists.txt`: CMake definitions for board, normally don't need to be touched.
- `Kconfig.board`: Defines the name of the board as used in DTS config.
- `Kconfig.defconfig`: Configuration of invisible Kconfig symbols, i.e. symbols that should not be adjustable by the user via menuconfig.
- `<BOARD>_defconfig`: Default configuration of the board (can be overwritten by prj.conf)
- `<BOARD>.dts`: Main board device tree specification.
- `<BOARD>.yaml`:
- `pinmux.c`: Defines which pins should be used for peripherals like SPI1, SPI2, SPI3 if selected by the user.
## PlatformIO configuration
PlatformIO needs an additional definition file for each board. It is stored as `boards/my-board.json`
@@ -1,7 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
-10
View File
@@ -1,10 +0,0 @@
# Kconfig - Libre Solar MPPT 1210 HUS v0.4
#
# Copyright (c) 2019 Martin Jäger (Libre Solar)
#
# SPDX-License-Identifier: Apache-2.0
#
config BOARD_MPPT1210HUS_0V4
bool "Libre Solar MPPT 1210 HUS v0.4"
depends on SOC_STM32L073XX
@@ -1,37 +0,0 @@
# Kconfig - Libre Solar MPPT 1210 HUS v0.4
#
# Copyright (c) 2019 Martin Jäger (Libre Solar)
#
# SPDX-License-Identifier: Apache-2.0
#
if BOARD_MPPT1210HUS_0V4
config BOARD
default "mppt1210hus_0v4"
if UART_CONSOLE
config UART_2
default y
endif # UART_CONSOLE
if I2C
config I2C_1
default y
endif # I2C
if SPI
config SPI_1
default y
config SPI_STM32_INTERRUPT
default y
endif # SPI
endif # BOARD_MPPT1210HUS_0V4
@@ -1,84 +0,0 @@
/*
* Copyright (c) 2019 Martin Jäger (Libre Solar)
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/l0/stm32l073Xz.dtsi>
/ {
model = "Libre Solar MPPT 1210 HUS v0.4";
compatible = "st,stm32l073rz-nucleo", "st,stm32l073";
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "gpio-leds";
led_pin_gnd: led_gnd {
gpios = <&gpiob 14 GPIO_INT_ACTIVE_LOW>;
label = "LED GND";
};
led_pin_soc12: led_soc12 {
gpios = <&gpiob 13 GPIO_INT_ACTIVE_HIGH>;
label = "LED SOC12";
};
led_pin_soc3: led_soc3 {
gpios = <&gpiob 2 GPIO_INT_ACTIVE_HIGH>;
label = "LED SOC3";
};
led_pin_rxtx: led_rxtx {
gpios = <&gpiob 11 GPIO_INT_ACTIVE_HIGH>;
label = "LED RXTX";
};
led_pin_load: led_load {
gpios = <&gpiob 10 GPIO_INT_ACTIVE_HIGH>;
label = "LED Load";
};
pin_usb_pwr_en: tmp_usb_pwr_en {
gpios = <&gpiob 12 GPIO_INT_ACTIVE_HIGH>;
label = "USB power enable";
};
};
aliases {
led-a = &led_pin_gnd;
led-b = &led_pin_soc12;
led-c = &led_pin_soc3;
led-d = &led_pin_rxtx;
led-e = &led_pin_load;
usb-pwr-en = &pin_usb_pwr_en;
};
};
&usart1 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
&spi1 {
status = "okay";
};
&iwdg {
status = "okay";
};
&adc1 {
status = "okay";
};
-60
View File
@@ -1,60 +0,0 @@
/*
* Copyright (c) 2019 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
// preliminary fix until PR for pinmux_stm32l0.h got accepted and merged to Zephyr master branch,
// see also here: https://github.com/zephyrproject-rtos/zephyr/pull/20997
#ifndef STM32L0_PINMUX_FUNC_PB6_I2C1_SCL
#define STM32L0_PINMUX_FUNC_PB6_I2C1_SCL \
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
#endif
#ifndef STM32L0_PINMUX_FUNC_PB7_I2C1_SDA
#define STM32L0_PINMUX_FUNC_PB7_I2C1_SDA \
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
#endif
/* pin assignments for NUCLEO-L073RZ board */
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_1
{STM32_PIN_PA9, STM32L0_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32L0_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_UART_1 */
#ifdef CONFIG_UART_2
{STM32_PIN_PA2, STM32L0_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32L0_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_2 */
#ifdef CONFIG_I2C_1
{STM32_PIN_PB6, STM32L0_PINMUX_FUNC_PB6_I2C1_SCL},
{STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C_1 */
#ifdef CONFIG_SPI_1
{STM32_PIN_PA5, STM32L0_PINMUX_FUNC_PA5_SPI1_SCK},
{STM32_PIN_PA6, STM32L0_PINMUX_FUNC_PA6_SPI1_MISO},
{STM32_PIN_PA7, STM32L0_PINMUX_FUNC_PA7_SPI1_MOSI},
#endif /* CONFIG_SPI_1 */
#ifdef CONFIG_ADC_1
{STM32_PIN_PA0, STM32L0_PINMUX_FUNC_PA0_ADC_IN0},
#endif /* CONFIG_ADC_1 */
};
static int pinmux_stm32_init(struct device *port)
{
ARG_UNUSED(port);
stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf));
return 0;
}
SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1,
CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);
+6
View File
@@ -0,0 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
config BOARD_MPPT_1210_HUS
bool "Libre Solar MPPT 1210 HUS"
depends on SOC_STM32L072XX
@@ -0,0 +1,19 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
if BOARD_MPPT_1210_HUS
config BOARD
default "mppt_1210_hus"
config LIBRE_SOLAR_TYPE_ID
default 4
if SPI
config SPI_STM32_INTERRUPT
default y
endif # SPI
endif # BOARD_MPPT_1210_HUS_0V7
+1 -1
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=STM32L073RZ" "--speed=4000")
board_runner_args(jlink "--device=STM32L072RZ" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+191
View File
@@ -0,0 +1,191 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/l0/stm32l072Xz.dtsi>
#include <st/l0/stm32l072r(b-z)tx-pinctrl.dtsi>
/ {
model = "Libre Solar MPPT 1210 HUS";
compatible = "st,stm32l072";
pcb {
compatible = "charge-controller";
type = "MPPT 1210 HUS";
hs-voltage-max = <40>;
ls-voltage-max = <16>;
dcdc-current-max = <10>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpiob 13 GPIO_ACTIVE_HIGH>, /* Pin A */
<&gpiob 14 GPIO_ACTIVE_HIGH>, /* Pin B */
<&gpiob 2 GPIO_ACTIVE_HIGH>; /* Pin C */
soc_1 {
states = <1 2 0>; /* LED1 */
};
soc_2 {
states = <0 2 1>; /* LED2 */
};
soc_3 {
states = <1 0 2>; /* LED3 */
};
load {
states = <2 0 1>; /* LED4 */
};
rxtx {
states = <2 1 0>; /* LED5 */
};
};
outputs {
compatible = "outputs";
load {
label = "Load output";
gpios = <&gpioc 13 GPIO_ACTIVE_HIGH>;
current-max = <10>;
kconfig-flag; /* make node visible in Kconfig */
};
usb-pwr {
label = "USB charging port enable";
gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>;
};
boot0 {
label = "BOOT0 pin trigger";
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 0>;
multiplier = <105600>;
divider = <5600>;
};
v-high {
io-channels = <&adc1 1>;
multiplier = <105600>;
divider = <5600>;
enable-gpios = <&gpioc 14 GPIO_ACTIVE_HIGH>;
};
i-load {
io-channels = <&adc1 5>;
// amp gain: 50, resistor: 3 mOhm
multiplier = <1000>;
divider = <150>; // 3*50
};
i-dcdc {
io-channels = <&adc1 6>;
// amp gain: 50, resistor: 3 mOhm
multiplier = <1000>;
divider = <150>; // 3*50
};
temp-bat {
io-channels = <&adc1 7>;
multiplier = <10000>;
divider = <1>;
};
vref-mcu {
io-channels = <&adc1 17>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 18>;
multiplier = <10000>;
divider = <1>;
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
soc {
// not (yet) provided by Zephyr dts, but necessary for dcdc node
timers3: timers@40000400 {
compatible = "st,stm32-timers";
reg = <0x40000400 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000002>;
interrupts = <16 0>;
interrupt-names = "global";
status = "disabled";
label = "TIMERS_3";
};
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
current-speed = <115200>;
status = "okay";
};
&usart2 {
pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
&i2c1 {
pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>;
clock-frequency = <I2C_BITRATE_FAST>;
status = "okay";
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&timers3 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim3_ch3_pb0 &tim3_ch4_pb1>;
frequency = <50000>;
deadtime = <230>;
};
};
&eeprom {
status = "okay";
};
@@ -0,0 +1,18 @@
identifier: mppt_1210_hus
name: MPPT-1210-HUS
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 20
flash: 192
supported:
- arduino_i2c
- gpio
- i2c
- spi
- watchdog
- adc
- eeprom
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
# empty (using defaults from _defconfig file)
@@ -0,0 +1,78 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
pcb {
version-str = "v0.4";
version-num = <4>;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpiob 14 GPIO_ACTIVE_HIGH>, /* GND */
<&gpiob 13 GPIO_ACTIVE_HIGH>, /* SOC_12 */
<&gpiob 2 GPIO_ACTIVE_HIGH>, /* SOC_3 */
<&gpiob 11 GPIO_ACTIVE_HIGH>, /* RXTX */
<&gpiob 10 GPIO_ACTIVE_HIGH>; /* LOAD */
soc_1 {
states = <1 0 0 0 0>;
};
soc_2 {
states = <0 1 0 0 0>;
};
soc_3 {
states = <0 0 1 0 0>;
};
rxtx {
states = <0 0 0 1 0>;
};
load {
states = <0 0 0 0 1>;
};
};
outputs {
compatible = "outputs";
load {
gpios = <&gpioc 13 GPIO_ACTIVE_HIGH>;
label = "Load enable";
};
usb-pwr {
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
label = "USB charging port enable";
};
/delete-node/ v-solar;
/delete-node/ boot0;
};
adc-inputs {
compatible = "adc-inputs";
i-load {
io-channels = <&adc1 6>;
// amp gain: 50, resistor: 4 mOhm
multiplier = <1000>;
divider = <200>; // 4*50
};
i-dcdc {
io-channels = <&adc1 7>;
// amp gain: 50, resistor: 4 mOhm
multiplier = <1000>;
divider = <200>; // 4*50
};
/delete-node/ temp-bat;
};
};
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
# empty (using defaults from _defconfig file)
@@ -0,0 +1,12 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
pcb {
version-str = "v0.7.1";
version-num = <7>; // minor version .1 includes no HW change
};
};
@@ -1,12 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Zephyr Kernel Configuration
CONFIG_ARM=y
CONFIG_SOC_SERIES_STM32L0X=y
# Platform Configuration
CONFIG_SOC_STM32L073XX=y
CONFIG_BOARD_MPPT1210HUS_0V4=y
CONFIG_SOC_STM32L072XX=y
# General Kernel Options
CONFIG_CORTEX_M_SYSTICK=y
@@ -15,7 +10,6 @@ CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=32000000
# Serial Drivers
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
# enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
@@ -29,9 +23,13 @@ CONFIG_GPIO=y
CONFIG_CLOCK_CONTROL=y
# SYSCLK selection
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# PLL configuration
CONFIG_CLOCK_STM32_PLL_SRC_HSI=y
CONFIG_CLOCK_STM32_PLL_MULTIPLIER=4
CONFIG_CLOCK_STM32_PLL_DIVISOR=2
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_EEPROM=y
CONFIG_EEPROM_STM32=y
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_check_revision(
FORMAT MAJOR.MINOR.PATCH
DEFAULT_REVISION 0.7.1
)
@@ -1,5 +1,5 @@
# This is an ST NUCLEO-L073RZ board with single STM32L073RZ chip.
# http://www.st.com/en/evaluation-tools/nucleo-l073rz.html
# STM32L072 MCU
source [find interface/stlink.cfg]
transport select hla_swd
+6
View File
@@ -0,0 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
config BOARD_MPPT_2420_HC
bool "Libre Solar MPPT 2420 HC"
depends on SOC_STM32G431XX
+12
View File
@@ -0,0 +1,12 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
if BOARD_MPPT_2420_HC
config BOARD
default "mppt_2420_hc"
config LIBRE_SOLAR_TYPE_ID
default 8
endif # BOARD_MPPT_2420_HC
+8
View File
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(pyocd "--target=stm32g431rbtx")
board_runner_args(jlink "--device=STM32G431RB" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
+190
View File
@@ -0,0 +1,190 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
#include <st/g4/stm32g431c(6-8-b)tx-pinctrl.dtsi>
/ {
model = "Libre Solar MPPT 2420 HC";
compatible = "st,stm32g431";
pcb {
compatible = "charge-controller";
type = "MPPT 2420 HC";
hs-voltage-max = <90>;
ls-voltage-max = <32>;
dcdc-current-max = <20>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
/* temporary solution only using green color LED */
leds {
compatible = "charlieplexing-leds";
gpios = <&gpioa 6 GPIO_ACTIVE_LOW>, /* chg red */
<&gpioc 14 GPIO_ACTIVE_LOW>, /* chg green */
<&gpiob 9 GPIO_ACTIVE_LOW>, /* dis red */
<&gpioc 15 GPIO_ACTIVE_LOW>; /* dis green */
pwr {
states = <0 1 0 0>;
};
load {
states = <0 0 0 1>;
};
};
outputs {
compatible = "outputs";
load {
label = "Load output";
gpios = <&gpiob 2 GPIO_ACTIVE_LOW>;
current-max = <20>;
kconfig-flag; /* make node visible in Kconfig */
};
charge_pump {
label = "Charge pump for HS MOSFET drivers";
pwms = <&pwm8 2 200000 PWM_POLARITY_NORMAL>; /* 200 us period = 5 kHz */
};
can_en {
label = "CAN disable / standby";
gpios = <&gpiob 11 GPIO_ACTIVE_LOW>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 12>;
multiplier = <105600>;
divider = <5600>;
};
v-high {
io-channels = <&adc1 15>;
multiplier = <102200>;
divider = <2200>;
};
temp-fets {
io-channels = <&adc1 11>;
multiplier = <10000>; // 10k NTC series resistor
divider = <1>;
};
vref-mcu {
io-channels = <&adc1 18>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 16>;
multiplier = <1>;
divider = <1>;
};
i-dcdc {
io-channels = <&adc2 1>;
// amp gain: 25, resistor: 2 mOhm
multiplier = <1000>; // 1000
divider = <50>; // 2*25
};
i-load {
io-channels = <&adc2 2>;
// amp gain: 25, resistor: 2 mOhm
multiplier = <1000>; // 1000
divider = <50>; // 2*25
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
current-speed = <115200>;
status = "okay";
};
&usart2 {
pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
&i2c1 {
pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>;
clock-frequency = <I2C_BITRATE_STANDARD>;
status = "okay";
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>;
status = "okay";
};
&spi2 {
pinctrl-0 = <&spi2_sck_pb13 &spi2_miso_pb14 &spi2_mosi_pb15>;
cs-gpios = <&gpioa 5 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&timers1 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pc13>;
frequency = <70000>;
deadtime = <300>;
};
};
/* TIM8 (CH2) used for charge pump */
&timers8 {
status = "okay";
pwm8: pwm {
status = "okay";
st,prescaler = <149>; /* reduce counter clock frequency to 1 MHz */
pinctrl-0 = <&tim8_ch2_pb8>;
};
};
&can1 {
pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>;
bus-speed = <250000>;
bus-speed-data = <250000>;
sjw = <1>;
sjw-data = <1>;
sample-point = <875>;
sample-point-data = <875>;
status = "okay";
};
+18
View File
@@ -0,0 +1,18 @@
identifier: mppt_2420_hc
name: MPPT-2420-HC
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 32
flash: 128
supported:
- nvs
- pwm
- i2c
- gpio
- usb device
- counter
- spi
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_I2C=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
@@ -0,0 +1,68 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
pcb {
version-str = "v0.1";
version-num = <1>;
};
/* temporary solution w/o using RGB LED */
leds {
compatible = "charlieplexing-leds";
gpios = <&gpiob 14 GPIO_ACTIVE_LOW>, /* red */
<&gpiob 15 GPIO_ACTIVE_LOW>, /* green */
<&gpiob 9 GPIO_ACTIVE_LOW>; /* blue */
pwr {
states = <1 0 0>;
};
load {
states = <0 1 0>;
};
rxtx {
states = <0 0 1>;
};
};
};
&i2c1 {
eeprom@50 {
// Microchip 24AA32A
compatible = "atmel,at24";
reg = <0x50>;
label = "EEPROM_0";
size = <32768>;
pagesize = <32>;
address-width = <16>;
/*
* timeout of 5 ms as suggested in datasheet seems too optimistic
* (several write errors occured during testing)
*/
timeout = <7>;
};
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>;
status = "okay";
};
&timers1 {
halfbridge {
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
};
};
&spi2 {
status = "disabled";
/delete-node/ pinctrl-0;
/delete-node/ cs-gpios;
};
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_LOG_LEVEL_WRN=y
#CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_SFDP_RUNTIME=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NVS=y
CONFIG_NVS_LOG_LEVEL_WRN=y
@@ -0,0 +1,81 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
pcb {
version-str = "v0.2";
version-num = <2>;
};
chosen {
zephyr,code-partition = &slot0_partition;
};
};
&spi2 {
w25q80dv: w25q80dv@0 {
compatible = "jedec,spi-nor";
label = "W25Q80DV";
reg = <0>;
spi-max-frequency = <4000000>;
size = <0x800000>; /* bits */
has-dpd;
t-enter-dpd = <4000>;
t-exit-dpd = <25000>;
jedec-id = [ef 40 14];
};
};
/*
* Below partition layout allows to use MCUboot if CONFIG_BOOTLOADER_MCUBOOT is enabled. Otherwise,
* the code will just use the entire available flash of the MCU.
*/
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* bootloader slot: 32 KiB */
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x8000>;
read-only;
};
/* application image slot: 96 KiB */
slot0_partition: partition@8000 {
label = "image-0";
reg = <0x00008000 0x18000>;
};
};
};
&w25q80dv {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* backup slot: 96 KiB */
slot1_partition: partition@0 {
label = "image-1";
reg = <0x00000000 0x18000>;
};
/* swap slot: 96 KiB */
scratch_partition: partition@18000 {
label = "image-scratch";
reg = <0x00018000 0x00018000>;
};
/* remaining 832 KiB of SPI flash used as storage */
storage_partition: partition@30000 {
label = "storage";
reg = <0x00030000 0x000D0000>;
};
};
};
@@ -0,0 +1,67 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32G4X=y
CONFIG_SOC_STM32G431XX=y
# 170MHz system clock only in 'boost power' mode. RM0440, section
# 5.1.5 states that the R1MODE bit must be cleared before system can
# be 170MHz. This requires an update to the stm32 clock control
# driver, so default to 150MHz until then.
# CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=170000000
# 150MHz system clock in 'normal power' mode
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=150000000
# enable uart driver
CONFIG_SERIAL=y
# enable pinmux
CONFIG_PINMUX=y
# enable GPIO
CONFIG_GPIO=y
# clock configuration
CONFIG_CLOCK_CONTROL=y
# Use PLLCLK for SYSCLK
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# Use HSI (16MHz) to feed into PLL
CONFIG_CLOCK_STM32_PLL_SRC_HSI=y
CONFIG_CLOCK_STM32_PLL_M_DIVISOR=4
CONFIG_CLOCK_STM32_PLL_P_DIVISOR=7
CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=2
CONFIG_CLOCK_STM32_PLL_R_DIVISOR=2
# Produce 150MHz clock at PLLCLK output
CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=75
# Comment out above and uncomment below for 170MHz. Note that you
# must have configured the mcu for boost power mode.
# CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=85
# Produce Max (150MHz or 170MHz) HCLK
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
# Produce Max (150MHz or 170MHz) APB1 clocks and APB2 clocks
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_CLOCK_STM32_APB2_PRESCALER=1
# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Enable MPU
CONFIG_ARM_MPU=y
CONFIG_PWM=y
CONFIG_CAN=y
CONFIG_THINGSET_CAN=y
CONFIG_ISOTP=y
CONFIG_ISOTP_RX_BUF_COUNT=2
CONFIG_ISOTP_RX_BUF_SIZE=100
CONFIG_ISOTP_RX_SF_FF_BUF_COUNT=2
+3
View File
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
board_check_revision(FORMAT MAJOR.MINOR.PATCH)
+6
View File
@@ -0,0 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
config BOARD_MPPT_2420_HPX
bool "Libre Solar MPPT 2420 HPX"
depends on SOC_STM32G431XX
@@ -0,0 +1,19 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
if BOARD_MPPT_2420_HPX
config BOARD
default "mppt_2420_hpx"
config LIBRE_SOLAR_TYPE_ID
default 7
if SPI
config SPI_STM32_INTERRUPT
default y
endif # SPI
endif # BOARD_MPPT_2420_HPX
+7
View File
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(pyocd "--target=stm32g431rbtx")
board_runner_args(jlink "--device=STM32G431RB" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+244
View File
@@ -0,0 +1,244 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
#include <st/g4/stm32g431r(6-8-b)tx-pinctrl.dtsi>
/ {
model = "Libre Solar MPPT 2420 HPX";
compatible = "st,stm32g431";
pcb {
compatible = "charge-controller";
type = "MPPT 2420 HPX";
version-str = "v0.1";
version-num = <1>;
hs-voltage-max = <80>;
ls-voltage-max = <32>;
dcdc-current-max = <20>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpioc 15 GPIO_ACTIVE_HIGH>;
pwr {
states = <1>;
};
};
outputs {
compatible = "outputs";
pwm_switch {
label = "PWM power switch (solar panel)";
pwms = <&pwm3 2 (20*1000*1000) PWM_POLARITY_NORMAL>; /* 20 ms period = 50 Hz */
current-max = <20>;
kconfig-flag; /* make node visible in Kconfig */
};
load {
label = "Load output";
gpios = <&gpiob 15 GPIO_ACTIVE_LOW>;
current-max = <20>;
kconfig-flag; /* make node visible in Kconfig */
};
charge_pump {
label = "Charge pump for HS MOSFET drivers";
pwms = <&pwm8 1 200000 PWM_POLARITY_NORMAL>; /* 200 us period = 5 kHz */
};
hv-out {
label = "HV output sense and enable switch";
gpios = <&gpiob 12 GPIO_ACTIVE_LOW>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 12>;
multiplier = <105600>;
divider = <5600>;
};
v-high {
io-channels = <&adc1 15>;
multiplier = <102200>;
divider = <2200>;
};
hv-ext-sense {
io-channels = <&adc1 11>;
multiplier = <1>;
divider = <1>;
};
v-pwm {
io-channels = <&adc1 4>;
multiplier = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
divider = <984>; // (8.2*12) * 10
offset = <37414>; // 65536 / (1 + 8.2/120 + 8.2/12)
};
temp-fets {
io-channels = <&adc1 6>;
multiplier = <10000>; // 10k NTC series resistor
divider = <1>;
};
vref-mcu {
io-channels = <&adc1 18>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 16>;
multiplier = <1>;
divider = <1>;
};
i-dcdc {
io-channels = <&adc2 1>;
// amp gain: 20, resistor: 2 mOhm
multiplier = <1000>; // 1000
divider = <40>; // 2*20
};
i-load {
io-channels = <&adc2 2>;
// amp gain: 68/2.2, resistor: 2 mOhm
multiplier = <2200>; // 1000*2.2
divider = <136>; // 2*68
};
i-pwm {
io-channels = <&adc2 5>;
// amp gain: 68/2.2, resistor: 2 mOhm
multiplier = <2200>; // 1000*2.2
divider = <136>; // 2*68
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart3;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
current-speed = <115200>;
status = "okay";
};
&usart3 {
pinctrl-0 = <&usart3_tx_pc10 &usart3_rx_pc11>;
current-speed = <115200>;
status = "okay";
};
&i2c1 {
pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>;
status = "okay";
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpiod 2 GPIO_ACTIVE_LOW>;
status = "okay";
};
&rtc {
status = "okay";
};
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* Set 4Kb of storage at the end of the 128Kb of flash */
storage_partition: partition@1f000 {
label = "storage";
reg = <0x0001f000 0x00001000>;
};
};
};
&iwdg {
status = "okay";
};
&timers1 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
/* TIM3 (CH2) used for PWM power switch */
&timers3 {
status = "okay";
pwm3: pwm {
status = "okay";
pinctrl-0 = <&tim3_ch2_pc7>;
};
};
/* TIM8 (CH1) used for charge pump */
&timers8 {
status = "okay";
pwm8: pwm {
status = "okay";
st,prescaler = <149>; /* reduce counter clock frequency to 1 MHz */
pinctrl-0 = <&tim8_ch1_pc6>;
};
};
&i2c3 {
pinctrl-0 = <&i2c3_scl_pc8 &i2c3_sda_pc9>;
status = "okay";
clock-frequency = <I2C_BITRATE_STANDARD>;
eeprom@50 {
// Microchip 24AA32A
compatible = "atmel,at24";
reg = <0x50>;
label = "EEPROM_0";
size = <32768>;
pagesize = <32>;
address-width = <16>;
/*
* timeout of 5 ms as suggested in datasheet seems too optimistic
* (several write errors occured during testing)
*/
timeout = <7>;
};
};
@@ -0,0 +1,18 @@
identifier: mppt_2420_hpx
name: MPPT-2420-HPX
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 32
flash: 128
supported:
- nvs
- pwm
- i2c
- gpio
- usb device
- counter
- spi
@@ -0,0 +1,63 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32G4X=y
CONFIG_SOC_STM32G431XX=y
# 170MHz system clock only in 'boost power' mode. RM0440, section
# 5.1.5 states that the R1MODE bit must be cleared before system can
# be 170MHz. This requires an update to the stm32 clock control
# driver, so default to 150MHz until then.
# CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=170000000
# 150MHz system clock in 'normal power' mode
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=150000000
# enable uart driver
CONFIG_SERIAL=y
# enable pinmux
CONFIG_PINMUX=y
# enable GPIO
CONFIG_GPIO=y
# clock configuration
CONFIG_CLOCK_CONTROL=y
# Use PLLCLK for SYSCLK
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# Use HSI (16MHz) to feed into PLL
CONFIG_CLOCK_STM32_PLL_SRC_HSI=y
CONFIG_CLOCK_STM32_PLL_M_DIVISOR=4
CONFIG_CLOCK_STM32_PLL_P_DIVISOR=7
CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=2
CONFIG_CLOCK_STM32_PLL_R_DIVISOR=2
# Produce 150MHz clock at PLLCLK output
CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=75
# Comment out above and uncomment below for 170MHz. Note that you
# must have configured the mcu for boost power mode.
# CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=85
# Produce Max (150MHz or 170MHz) HCLK
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
# Produce Max (150MHz or 170MHz) APB1 clocks and APB2 clocks
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_CLOCK_STM32_APB2_PRESCALER=1
# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Enable MPU
CONFIG_ARM_MPU=y
CONFIG_PWM=y
CONFIG_I2C=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
+6
View File
@@ -0,0 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
config BOARD_MPPT_2420_LC
bool "Libre Solar MPPT 2420 LC"
depends on SOC_STM32F072XB
+19
View File
@@ -0,0 +1,19 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
if BOARD_MPPT_2420_LC
config BOARD
default "mppt_2420_lc"
config LIBRE_SOLAR_TYPE_ID
default 1
if SPI
config SPI_STM32_INTERRUPT
default y
endif # SPI
endif # BOARD_MPPT_2420_LC_0V10
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=STM32F072CB" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+210
View File
@@ -0,0 +1,210 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/f0/stm32f072Xb.dtsi>
#include <st/f0/stm32f072c(8-b)tx-pinctrl.dtsi>
/ {
model = "Libre Solar MPPT 2420 LC";
compatible = "st,stm32f072";
pcb {
compatible = "charge-controller";
type = "MPPT 2420 LC";
version-str = "v0.10";
version-num = <10>;
hs-voltage-max = <55>;
ls-voltage-max = <32>;
dcdc-current-max = <20>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpiob 14 GPIO_ACTIVE_HIGH>,
<&gpiob 15 GPIO_ACTIVE_HIGH>;
pwr {
states = <1 0>;
};
load {
states = <0 1>;
};
};
outputs {
compatible = "outputs";
load {
label = "Load output";
gpios = <&gpiob 2 GPIO_ACTIVE_LOW>;
current-max = <20>;
kconfig-flag; /* make node visible in Kconfig */
};
uext_en {
label = "UEXT enable";
gpios = <&gpioc 14 GPIO_ACTIVE_LOW>;
};
can_en {
label = "CAN disable / standby";
gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
};
aux_en {
label = "5V output enable";
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
};
vbus_en {
label = "CAN bus power supply enable";
gpios = <&gpioc 15 GPIO_ACTIVE_LOW>;
};
};
adc-inputs {
compatible = "adc-inputs";
temp-bat {
io-channels = <&adc1 0>;
multiplier = <10000>; // 10k NTC series resistor
divider = <1>;
};
temp-fets {
io-channels = <&adc1 1>;
multiplier = <10000>; // 10k NTC series resistor
divider = <1>;
};
vref {
io-channels = <&adc1 5>;
multiplier = <1>;
divider = <1>;
};
v-low {
io-channels = <&adc1 6>;
multiplier = <110000>;
divider = <10000>;
};
v-high {
io-channels = <&adc1 7>;
multiplier = <105600>;
divider = <5600>;
};
i-load {
io-channels = <&adc1 8>;
// amp gain: 150/2.2, resistor: 2 mOhm
multiplier = <2200>; // 1000*2.2
divider = <300>; // 2*150
};
i-dcdc {
io-channels = <&adc1 9>;
// amp gain: 150/2.2, resistor: 2 mOhm
multiplier = <2200>; // 1000*2.2
divider = <300>; // 2*150
};
temp-mcu {
io-channels = <&adc1 16>;
multiplier = <1>;
divider = <1>;
};
vref-mcu {
io-channels = <&adc1 17>;
multiplier = <1>;
divider = <1>;
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
current-speed = <115200>;
status = "okay";
};
&usart2 {
pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>;
clock-frequency = <I2C_BITRATE_FAST>;
};
&i2c2 {
status = "okay";
pinctrl-0 = <&i2c2_scl_pb10 &i2c2_sda_pb11>;
clock-frequency = <I2C_BITRATE_STANDARD>;
eeprom@50 {
// Microchip 24AA32A
compatible = "atmel,at24";
reg = <0x50>;
label = "EEPROM_0";
size = <32768>;
pagesize = <32>; // 24AA01: 8 bytes
address-width = <16>; // 24AA01: 8 bit
/*
* timeout of 5 ms as suggested in datasheet seems too optimistic
* (several write errors occured during testing)
*/
timeout = <7>;
};
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&timers1 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
&can1 {
pinctrl-0 = <&can_rx_pb8 &can_tx_pb9>;
bus-speed = <250000>;
status = "okay";
};
+17
View File
@@ -0,0 +1,17 @@
identifier: mppt_2420_lc
name: MPPT-2420-LC
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 16
flash: 128
supported:
- arduino_i2c
- gpio
- i2c
- spi
- watchdog
- adc
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32F0X=y
CONFIG_SOC_STM32F072XB=y
# General Kernel Options
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=48000000
# Serial Drivers
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Pinmux Driver
CONFIG_PINMUX=y
# GPIO Controller
CONFIG_GPIO=y
# Clock configuration
CONFIG_CLOCK_CONTROL=y
# SYSCLK selection
CONFIG_CLOCK_STM32_HSE_CLOCK=8000000
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# PLL configuration
CONFIG_CLOCK_STM32_PLL_SRC_HSE=y
CONFIG_CLOCK_STM32_PLL_MULTIPLIER=6
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_CAN=y
CONFIG_THINGSET_CAN=y
CONFIG_I2C=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
@@ -0,0 +1,12 @@
source [find board/st_nucleo_f0.cfg]
$_TARGETNAME configure -event gdb-attach {
echo "Debugger attaching: halting execution"
reset halt
gdb_breakpoint_override hard
}
$_TARGETNAME configure -event gdb-detach {
echo "Debugger detaching: resuming execution"
resume
}
+6
View File
@@ -0,0 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
config BOARD_MPPT_2420_RC
bool "Libre Solar MPPT 2420 RC"
depends on SOC_STM32G431XX
+20
View File
@@ -0,0 +1,20 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
if BOARD_MPPT_2420_RC
config BOARD
default "mppt_2420_rc"
config LIBRE_SOLAR_TYPE_ID
default 0
if SPI
config SPI_STM32_INTERRUPT
default y
endif # SPI
endif # BOARD_MPPT_2420_RC
+7
View File
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(pyocd "--target=stm32g431rbtx")
board_runner_args(jlink "--device=STM32G431RB" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+199
View File
@@ -0,0 +1,199 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
#include <st/g4/stm32g431c(6-8-b)tx-pinctrl.dtsi>
/ {
model = "Libre Solar MPPT 2420 RC";
compatible = "st,stm32g431";
pcb {
compatible = "charge-controller";
type = "MPPT 2420 RC";
version-str = "v0.1";
version-num = <1>;
hs-voltage-max = <80>;
ls-voltage-max = <32>;
dcdc-current-max = <20>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpiob 15 GPIO_ACTIVE_HIGH>;
pwr {
states = <1>;
};
};
outputs {
compatible = "outputs";
can_en {
label = "CAN disable / standby";
gpios = <&gpiob 14 GPIO_ACTIVE_LOW>;
};
hv-out {
label = "HV output sense and enable switch";
gpios = <&gpiob 12 GPIO_ACTIVE_LOW>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 12>;
multiplier = <105600>;
divider = <5600>;
};
v-high {
io-channels = <&adc1 15>;
multiplier = <102200>;
divider = <2200>;
};
hv-ext-sense {
io-channels = <&adc1 11>;
multiplier = <1>;
divider = <1>;
};
temp-fets {
io-channels = <&adc1 2>;
multiplier = <10000>; // 10k NTC series resistor
divider = <1>;
};
temp-bat {
io-channels = <&adc1 14>;
multiplier = <10000>; // 10k NTC series resistor
divider = <1>;
};
vref-mcu {
io-channels = <&adc1 18>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 16>;
multiplier = <1>;
divider = <1>;
};
i-dcdc {
io-channels = <&adc2 1>;
// amp gain: 68/2.2, resistor: 2 mOhm
multiplier = <2200>; // 1000*2.2
divider = <136>; // 2*68
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
current-speed = <115200>;
status = "okay";
};
&usart2 {
pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>;
status = "okay";
};
&timers1 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* Set 4Kb of storage at the end of the 128Kb of flash */
storage_partition: partition@1f000 {
label = "storage";
reg = <0x0001f000 0x00001000>;
};
};
};
&iwdg {
status = "okay";
};
&i2c1 {
/* shared between UEXT and EEPROM */
status = "okay";
pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>;
clock-frequency = <I2C_BITRATE_STANDARD>;
eeprom@50 {
// Microchip 24AA32A
compatible = "atmel,at24";
reg = <0x50>;
label = "EEPROM_0";
size = <32768>;
pagesize = <32>;
address-width = <16>;
/*
* timeout of 5 ms as suggested in datasheet seems too optimistic
* (several write errors occured during testing)
*/
timeout = <7>;
};
};
&can1 {
pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>;
bus-speed = <250000>;
bus-speed-data = <250000>;
sjw = <1>;
sjw-data = <1>;
sample-point = <875>;
sample-point-data = <875>;
status = "okay";
};
+18
View File
@@ -0,0 +1,18 @@
identifier: mppt_2420_rc
name: MPPT-2420-RC
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 32
flash: 128
supported:
- nvs
- pwm
- i2c
- gpio
- usb device
- counter
- spi
@@ -0,0 +1,69 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32G4X=y
CONFIG_SOC_STM32G431XX=y
# 170MHz system clock only in 'boost power' mode. RM0440, section
# 5.1.5 states that the R1MODE bit must be cleared before system can
# be 170MHz. This requires an update to the stm32 clock control
# driver, so default to 150MHz until then.
# CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=170000000
# 150MHz system clock in 'normal power' mode
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=150000000
# enable uart driver
CONFIG_SERIAL=y
# enable pinmux
CONFIG_PINMUX=y
# enable GPIO
CONFIG_GPIO=y
# clock configuration
CONFIG_CLOCK_CONTROL=y
# Use PLLCLK for SYSCLK
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# Use HSI (16MHz) to feed into PLL
CONFIG_CLOCK_STM32_PLL_SRC_HSI=y
CONFIG_CLOCK_STM32_PLL_M_DIVISOR=4
CONFIG_CLOCK_STM32_PLL_P_DIVISOR=7
CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=2
CONFIG_CLOCK_STM32_PLL_R_DIVISOR=2
# Produce 150MHz clock at PLLCLK output
CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=75
# Comment out above and uncomment below for 170MHz. Note that you
# must have configured the mcu for boost power mode.
# CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=85
# Produce Max (150MHz or 170MHz) HCLK
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
# Produce Max (150MHz or 170MHz) APB1 clocks and APB2 clocks
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_CLOCK_STM32_APB2_PRESCALER=1
# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Enable MPU
CONFIG_ARM_MPU=y
CONFIG_I2C=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
CONFIG_CAN=y
CONFIG_THINGSET_CAN=y
CONFIG_ISOTP=y
CONFIG_ISOTP_RX_BUF_COUNT=1
CONFIG_ISOTP_RX_BUF_SIZE=100
CONFIG_ISOTP_RX_SF_FF_BUF_COUNT=2
+8
View File
@@ -0,0 +1,8 @@
# STM32G474RE Nucleo board configuration
# Copyright (c) 2019 STMicroelectronics.
# SPDX-License-Identifier: Apache-2.0
config BOARD_NUCLEO_G474RE
bool "Nucleo G474RE Development Board"
depends on SOC_STM32G474XX
@@ -0,0 +1,14 @@
# STM32G474RE Nucleo board configuration
# Copyright (c) 2019 STMicroelectronics.
# SPDX-License-Identifier: Apache-2.0
if BOARD_NUCLEO_G474RE
config BOARD
default "nucleo_g474re"
config LIBRE_SOLAR_TYPE_ID
default 0
endif # BOARD_NUCLEO_G431RB
+10
View File
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
# use target=stm32g474rbtx instead of stm32g474retx
# to allow board re-flashing (see PR #23230)
board_runner_args(pyocd "--target=stm32g474rbtx")
board_runner_args(jlink "--device=STM32G474RE" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
+255
View File
@@ -0,0 +1,255 @@
/*
* Copyright (c) 2019 STMicroelectronics.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This is a dummy charge controller board for testing new features using the STM32G474 MCU
*
* IMPORTANT: You have to remove the VREF jumper on the Nucleo board to make it work. Otherwise
* the MCU will get stuck while trying to generate a reference voltage at VREF+ pin.
*/
/dts-v1/;
#include <st/g4/stm32g474Xe.dtsi>
#include <st/g4/stm32g474r(b-c-e)tx-pinctrl.dtsi>
/ {
model = "STMicroelectronics STM32G474RE-NUCLEO board";
compatible = "st,stm32g474re-nucleo";
pcb {
compatible = "charge-controller";
type = "Nucleo G474 dummy charge controller";
version-str = "v0.1";
version-num = <1>;
hs-voltage-max = <80>;
ls-voltage-max = <32>;
dcdc-current-max = <20>;
};
chosen {
zephyr,console = &lpuart1;
zephyr,shell-uart = &lpuart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpioa 5 GPIO_ACTIVE_HIGH>;
pwr {
states = <1>;
};
};
outputs {
compatible = "outputs";
can_en {
label = "CAN disable / standby";
gpios = <&gpiob 11 GPIO_ACTIVE_LOW>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 12>;
multiplier = <105600>;
divider = <5600>;
};
v-high {
io-channels = <&adc1 15>;
multiplier = <102200>;
divider = <2200>;
};
vref-mcu {
io-channels = <&adc1 18>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 16>;
multiplier = <1>;
divider = <1>;
};
i-dcdc {
io-channels = <&adc2 1>;
// amp gain: 25, resistor: 2 mOhm
multiplier = <1000>; // 1000
divider = <50>; // 2*25
};
};
gpio_keys {
compatible = "gpio-keys";
user_button: button {
label = "User";
gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
};
};
aliases {
sw0 = &user_button;
uart-dbg = &lpuart1;
uart-uext = &usart1;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
soc {
hrtim1: timers@40016800 {
compatible = "st,stm32-timers";
reg = <0x40016800 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_APB2 0x04000000>;
interrupts = <67 0>, <68 0>, <69 0>, <70 0>,
<71 0>, <72 0>, <73 0>, <74 0>;
interrupt-names = "master", "tima", "timb", "timc",
"timd", "time", "flt", "timf";
status = "okay";
label = "HRTIM_1";
};
/* below nodes are required until following PR is merged:
* https://github.com/zephyrproject-rtos/hal_stm32/pull/87
*/
pinctrl: pin-controller@48000000 {
hrtim1_cha1_pa8: hrtim1_cha1_pa8 {
pinmux = <STM32_PINMUX('A', 8, AF13)>;
};
hrtim1_cha2_pa9: hrtim1_cha2_pa9 {
pinmux = <STM32_PINMUX('A', 9, AF13)>;
};
hrtim1_chb1_pa10: hrtim1_chb1_pa10 {
pinmux = <STM32_PINMUX('A', 10, AF13)>;
};
hrtim1_chb2_pa11: hrtim1_chb2_pa11 {
pinmux = <STM32_PINMUX('A', 11, AF13)>;
};
hrtim1_chc1_pb12: hrtim1_chc1_pb12 {
pinmux = <STM32_PINMUX('B', 12, AF13)>;
};
hrtim1_chc2_pb13: hrtim1_chc2_pb13 {
pinmux = <STM32_PINMUX('B', 13, AF13)>;
};
hrtim1_chd1_pb14: hrtim1_chd1_pb14 {
pinmux = <STM32_PINMUX('B', 14, AF13)>;
};
hrtim1_chd2_pb15: hrtim1_chd2_pb15 {
pinmux = <STM32_PINMUX('B', 15, AF13)>;
};
};
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pc4 &usart1_rx_pc5>;
current-speed = <115200>;
status = "okay";
};
&lpuart1 {
pinctrl-0 = <&lpuart1_tx_pa2 &lpuart1_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
&i2c1 {
pinctrl-0 = <&i2c1_scl_pb8 &i2c1_sda_pb9>;
status = "okay";
};
&spi1 {
pinctrl-0 = <&spi1_nss_pa4 &spi1_sck_pb3
&spi1_miso_pa6 &spi1_mosi_pa7>;
status = "okay";
};
&hrtim1 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&hrtim1_cha1_pa8 &hrtim1_cha2_pa9>;
frequency = <70000>;
deadtime = <300>;
};
};
/*
// alternative to HRTIM
&timers1 {
status = "okay";
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
*/
&rtc {
status = "okay";
};
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* Set 2Kb of storage at the end of the 128Kb of flash */
storage_partition: partition@1f800 {
label = "storage";
reg = <0x0001f800 0x00000800>;
};
};
};
&iwdg {
status = "okay";
};
&rng {
status = "okay";
};
&adc1 {
pinctrl-0 = <&adc1_in1_pa0>;
status = "okay";
};
&can1 {
pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>;
bus-speed = <250000>;
bus-speed-data = <250000>;
sjw = <1>;
sjw-data = <1>;
sample-point = <875>;
sample-point-data = <875>;
status = "okay";
};
@@ -0,0 +1,22 @@
identifier: nucleo_g474re
name: ST Nucleo G474RE
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 128
flash: 512
supported:
- nvs
- pwm
- i2c
- gpio
- usb device
- counter
- spi
- watchdog
- adc
- can
- canfd
@@ -0,0 +1,68 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32G4X=y
CONFIG_SOC_STM32G474XX=y
# 170MHz system clock only in 'boost power' mode.
# RM0440, section 5.1.5 states that the R1MODE bit
# must be cleared before system can be 170MHz.
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=170000000
# 150MHz system clock in 'normal power' mode
# CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=150000000
# enable uart driver
CONFIG_SERIAL=y
# enable pinmux
CONFIG_PINMUX=y
# enable GPIO
CONFIG_GPIO=y
# clock configuration
CONFIG_CLOCK_CONTROL=y
# Use PLLCLK for SYSCLK
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# Use HSE (24MHz) to feed into PLL
CONFIG_CLOCK_STM32_PLL_SRC_HSE=y
CONFIG_CLOCK_STM32_HSE_CLOCK=24000000
CONFIG_CLOCK_STM32_PLL_P_DIVISOR=7
CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=2
CONFIG_CLOCK_STM32_PLL_R_DIVISOR=2
# Produce 150MHz clock at PLLCLK output
# CONFIG_CLOCK_STM32_PLL_M_DIVISOR=4
# CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=75
# Produce 170MHz clock at PLLCLK output
CONFIG_CLOCK_STM32_PLL_M_DIVISOR=6
CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=85
# Produce Max (150MHz or 170MHz) HCLK
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
# Produce Max (150MHz or 170MHz) APB1 clocks and APB2 clocks
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_CLOCK_STM32_APB2_PRESCALER=1
# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Enable MPU
CONFIG_ARM_MPU=y
# Enable HW stack protection
CONFIG_HW_STACK_PROTECTION=y
CONFIG_CAN=y
CONFIG_THINGSET_CAN=y
CONFIG_ISOTP=y
CONFIG_ISOTP_RX_BUF_COUNT=2
CONFIG_ISOTP_RX_BUF_SIZE=100
CONFIG_ISOTP_RX_SF_FF_BUF_COUNT=2
@@ -0,0 +1,7 @@
source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32g4x.cfg]
reset_config srst_only
+6
View File
@@ -0,0 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
config BOARD_PWM_2420_LUS
bool "Libre Solar PWM 2420 LUS"
depends on SOC_STM32L072XX
+20
View File
@@ -0,0 +1,20 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
if BOARD_PWM_2420_LUS
config BOARD
default "pwm_2420_lus"
config LIBRE_SOLAR_TYPE_ID
default 5
if SPI
config SPI_STM32_INTERRUPT
default y
endif # SPI
endif # BOARD_PWM_2420_LUS
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=STM32L072RZ" "--speed=4000" "--reset-after-load")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+208
View File
@@ -0,0 +1,208 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/l0/stm32l072Xz.dtsi>
#include <st/l0/stm32l072r(b-z)tx-pinctrl.dtsi>
/ {
model = "Libre Solar PWM 2420 LUS";
compatible = "st,stm32l072";
pcb {
compatible = "charge-controller";
type = "PWM 2420 LUS";
hs-voltage-max = <55>;
ls-voltage-max = <32>;
// The MCU, where internal temperature is measured, is close to the MOSFETs. Tests
// showed that temperature at heat sink is only 10-20°C above measured internal
// temp. As PWM CC doesn't use electrolytic cap for core charging function,
// internal temperature of 70°C can be allowed (instead of default 50°C).
internal-tref-max = <70>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpiob 13 GPIO_ACTIVE_HIGH>, /* Pin A */
<&gpiob 14 GPIO_ACTIVE_HIGH>, /* Pin B */
<&gpiob 15 GPIO_ACTIVE_HIGH>; /* Pin C */
soc_1 {
states = <1 0 2>;
};
soc_2 {
states = <0 1 2>;
};
soc_3 {
states = <1 2 0>;
};
load {
states = <2 1 0>;
};
rxtx {
states = <2 0 1>;
};
};
outputs {
compatible = "outputs";
pwm_switch {
label = "PWM power switch (solar panel)";
pwms = <&pwm3 4 (20*1000*1000) PWM_POLARITY_NORMAL>; /* 20 ms period = 50 Hz */
// Current reduced to 15A. Increase to 20A PCB max values
// only if attached to a big heat sink.
current-max = <15>;
kconfig-flag; /* make node visible in Kconfig */
};
load {
label = "Load output";
gpios = <&gpiob 2 GPIO_ACTIVE_LOW>;
current-max = <15>;
kconfig-flag; /* make node visible in Kconfig */
};
usb-pwr {
label = "USB charging port disable";
gpios = <&gpiob 5 GPIO_ACTIVE_LOW>;
};
boot0 {
label = "BOOT0 pin trigger";
gpios = <&gpiob 12 GPIO_ACTIVE_HIGH>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 0>;
multiplier = <132000>;
divider = <12000>;
};
v-pwm {
io-channels = <&adc1 1>;
multiplier = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
divider = <984>; // (8.2*12) * 10
offset = <37414>; // 65536 / (1 + 8.2/120 + 8.2/12)
};
i-load {
io-channels = <&adc1 5>;
// amp gain: 68/2.2, resistor: 2 mOhm
// fix for hardware bug in overcurrent comparator voltage divider wiring
multiplier = <2931>; // 1000 * (39+12+8.2) / (12+8.2) = 2930.69
divider = <62>; // 2*68/2.2 = 61.8181
};
i-pwm {
io-channels = <&adc1 6>;
// amp gain: 68/2.2, resistor: 2 mOhm
multiplier = <2200>; // 1000*2.2
divider = <136>; // 2*68
};
temp-bat {
io-channels = <&adc1 7>;
multiplier = <8200>; // 8.2k NTC series resistor
divider = <1>;
};
vref-mcu {
io-channels = <&adc1 17>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 18>;
multiplier = <1>;
divider = <1>;
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
// this should normally go to Zephyr repo
soc {
timers3: timers@40000400 {
compatible = "st,stm32-timers";
reg = <0x40000400 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000002>;
status = "okay";
label = "TIMERS_3";
pwm3: pwm {
compatible = "st,stm32-pwm";
status = "okay";
st,prescaler = <10000>;
label = "PWM_3";
#pwm-cells = <3>;
};
};
};
};
&usart1 {
pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>;
current-speed = <115200>;
status = "okay";
};
&usart2 {
pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
&i2c1 {
pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>;
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
&spi1 {
pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>;
cs-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&timers3 {
status = "okay";
pwm3: pwm {
status = "okay";
pinctrl-0 = <&tim3_ch4_pb1>;
};
};
&eeprom {
status = "okay";
};
@@ -1,5 +1,5 @@
identifier: mppt1210hus_0v4
name: MPPT-1210-HUS-0V4
identifier: pwm_2420_lus
name: PWM-2420-LUS
type: mcu
arch: arm
toolchain:
@@ -15,3 +15,4 @@ supported:
- spi
- watchdog
- adc
- eeprom
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
# empty (using defaults from _defconfig file)
@@ -0,0 +1,23 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
pcb {
version-str = "v0.2";
version-num = <2>;
};
adc-inputs {
compatible = "adc-inputs";
i-load {
io-channels = <&adc1 5>;
// amp gain: 68/2.2, resistor: 2 mOhm
multiplier = <1000>;
divider = <62>; // 2*68/2.2 = 61.8181
};
};
};
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
# empty (using defaults from _defconfig file)
@@ -0,0 +1,12 @@
/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
pcb {
version-str = "v0.3";
version-num = <3>;
};
};
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32L0X=y
CONFIG_SOC_STM32L072XX=y
# General Kernel Options
CONFIG_CORTEX_M_SYSTICK=y
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=32000000
# Serial Drivers
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Pinmux Driver
CONFIG_PINMUX=y
# GPIO Controller
CONFIG_GPIO=y
# Clock configuration
CONFIG_CLOCK_CONTROL=y
# SYSCLK selection
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# PLL configuration
CONFIG_CLOCK_STM32_PLL_SRC_HSI=y
CONFIG_CLOCK_STM32_PLL_MULTIPLIER=4
CONFIG_CLOCK_STM32_PLL_DIVISOR=2
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
CONFIG_EEPROM=y
CONFIG_EEPROM_STM32=y
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_check_revision(
FORMAT MAJOR.MINOR.PATCH
DEFAULT_REVISION 0.3
)
@@ -0,0 +1,26 @@
source [find interface/stlink.cfg]
transport select hla_swd
set WORKAREASIZE 0x2000
source [find target/stm32l0.cfg]
# Add the second flash bank.
set _FLASHNAME $_CHIPNAME.flash1
flash bank $_FLASHNAME stm32lx 0 0 0 0 $_TARGETNAME
# There is only system reset line and JTAG/SWD command can be issued when SRST
reset_config srst_only
$_TARGETNAME configure -event gdb-attach {
echo "Debugger attaching: halting execution"
reset halt
gdb_breakpoint_override hard
}
$_TARGETNAME configure -event gdb-detach {
echo "Debugger detaching: resuming execution"
resume
}
@@ -1,19 +1,19 @@
{
"build": {
"cpu": "cortex-m0plus",
"extra_flags": "-DSTM32L073xx",
"extra_flags": "-DSTM32L072xx",
"f_cpu": "32000000L",
"framework_extra_flags": {
"arduino": "-D__CORTEX_SC=0"
},
"mcu": "stm32l073rz",
"mcu": "stm32l072rz",
"variant": "MPPT-1210-HUS"
},
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32L073RZ",
"jlink_device": "STM32L072RZ",
"onboard_tools": [
"stlink"
],
@@ -26,7 +26,7 @@
"stm32cube",
"zephyr"
],
"name": "Libre Solar MPPT 1210 HUS v0.4",
"name": "Libre Solar MPPT 1210 HUS",
"upload": {
"maximum_ram_size": 20480,
"maximum_size": 196608,
+42
View File
@@ -0,0 +1,42 @@
{
"build": {
"cpu": "cortex-m4",
"extra_flags": "-DSTM32G4xx -DSTM32G431xx",
"f_cpu": "150000000L",
"mcu": "stm32g431rb",
"variant": "MPPT-2420-HC"
},
"connectivity": [
"can"
],
"debug": {
"default_tools": [
"jlink"
],
"jlink_device": "STM32G431RB",
"onboard_tools": [
"stlink"
],
"openocd_board": "st_nucleo_g431rb",
"svd_path": "STM32G431xx.svd"
},
"frameworks": [
"arduino",
"stm32cube",
"zephyr"
],
"name": "Libre Solar MPPT 2420 HC",
"upload": {
"maximum_ram_size": 32768,
"maximum_size": 131072,
"protocol": "jlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "https://libre.solar/",
"vendor": "Libre Solar"
}
+42
View File
@@ -0,0 +1,42 @@
{
"build": {
"cpu": "cortex-m4",
"extra_flags": "-DSTM32G4xx -DSTM32G431xx",
"f_cpu": "150000000L",
"mcu": "stm32g431rb",
"variant": "MPPT-2420-HPX"
},
"connectivity": [
"can"
],
"debug": {
"default_tools": [
"jlink"
],
"jlink_device": "STM32G431RB",
"onboard_tools": [
"stlink"
],
"openocd_board": "st_nucleo_g431rb",
"svd_path": "STM32G431xx.svd"
},
"frameworks": [
"arduino",
"stm32cube",
"zephyr"
],
"name": "Libre Solar MPPT 2420 HPX",
"upload": {
"maximum_ram_size": 32768,
"maximum_size": 131072,
"protocol": "jlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "http://libre.solar/",
"vendor": "Libre Solar"
}
+41
View File
@@ -0,0 +1,41 @@
{
"build": {
"cpu": "cortex-m0",
"extra_flags": "-DSTM32F072xB",
"f_cpu": "48000000L",
"mcu": "stm32f072rbt6"
},
"connectivity": [
"can"
],
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32F072RB",
"onboard_tools": [
"stlink"
],
"openocd_board": "st_nucleo_f0",
"svd_path": "STM32F072x.svd"
},
"frameworks": [
"mbed",
"stm32cube",
"zephyr"
],
"name": "Libre Solar MPPT 2420 LC",
"upload": {
"maximum_ram_size": 16384,
"maximum_size": 131072,
"protocol": "stlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "http://libre.solar/",
"vendor": "Libre Solar"
}
+42
View File
@@ -0,0 +1,42 @@
{
"build": {
"cpu": "cortex-m4",
"extra_flags": "-DSTM32G4xx -DSTM32G431xx",
"f_cpu": "150000000L",
"mcu": "stm32g431rb",
"variant": "MPPT-2420-RC"
},
"connectivity": [
"can"
],
"debug": {
"default_tools": [
"jlink"
],
"jlink_device": "STM32G431RB",
"onboard_tools": [
"stlink"
],
"openocd_board": "st_nucleo_g431rb",
"svd_path": "STM32G431xx.svd"
},
"frameworks": [
"arduino",
"stm32cube",
"zephyr"
],
"name": "Libre Solar MPPT 2420 RC",
"upload": {
"maximum_ram_size": 32768,
"maximum_size": 131072,
"protocol": "jlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "http://libre.solar/",
"vendor": "Libre Solar"
}
+42
View File
@@ -0,0 +1,42 @@
{
"build": {
"core": "stm32",
"cpu": "cortex-m4",
"extra_flags": "-DSTM32G4xx -DSTM32G474xx",
"f_cpu": "170000000L",
"mcu": "stm32g474ret6",
"product_line": "STM32G474xx",
"variant": "NUCLEO_G474RE"
},
"connectivity": [
"can"
],
"debug": {
"jlink_device": "STM32G474RE",
"openocd_target": "stm32g4x",
"svd_path": "STM32G474xx.svd"
},
"frameworks": [
"arduino",
"cmsis",
"mbed",
"libopencm3",
"stm32cube",
"zephyr"
],
"name": "Nucleo G474RE",
"upload": {
"maximum_ram_size": 131072,
"maximum_size": 524288,
"protocol": "mbed",
"protocols": [
"jlink",
"stlink",
"cmsis-dap",
"blackmagic",
"mbed"
]
},
"url": "https://www.st.com/en/evaluation-tools/nucleo-g474re.html",
"vendor": "ST"
}
+43
View File
@@ -0,0 +1,43 @@
{
"build": {
"cpu": "cortex-m0plus",
"extra_flags": "-DSTM32L072xx",
"f_cpu": "32000000L",
"framework_extra_flags": {
"arduino": "-D__CORTEX_SC=0"
},
"mcu": "stm32l072rz",
"variant": "PWM-2420-LUS"
},
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32L072RZ",
"onboard_tools": [
"stlink"
],
"openocd_board": "st_nucleo_l073rz",
"svd_path": "STM32L07x.svd"
},
"frameworks": [
"arduino",
"mbed",
"stm32cube",
"zephyr"
],
"name": "Libre Solar PWM 2420 LUS",
"upload": {
"maximum_ram_size": 20480,
"maximum_size": 196608,
"protocol": "stlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "http://libre.solar/",
"vendor": "Libre Solar"
}
+40
View File
@@ -0,0 +1,40 @@
@ECHO OFF
:: This batch file performs the same checks as TravisCI and should be run after each commit and
:: before pushing the commits
echo "---------- Trailing whitespace check -------------"
:: check uncommitted changes
git diff --check HEAD
if errorlevel 1 (
echo Failure Reason is %errorlevel%
exit /b %errorlevel%
)
:: check all commits starting from initial commit
for /F %i in ('"git rev-list --max-parents=0 HEAD"') do git diff --check %i..HEAD
if errorlevel 1 (
echo Failure Reason is %errorlevel%
exit /b %errorlevel%
)
echo "---------- Running compile check -------------"
platformio run -e mppt_2420_lc -e mppt_1210_hus -e mppt_2420_hc -e pwm_2420_lus
if errorlevel 1 (
echo Failure Reason is %errorlevel%
exit /b %errorlevel%
)
echo "---------- Running unit-tests -------------"
platformio test -e unit_test
if errorlevel 1 (
echo Failure Reason is %errorlevel%
exit /b %errorlevel%
)
echo "---------- Running static code checks -------------"
platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high
if errorlevel 1 (
echo Failure Reason is %errorlevel%
exit /b %errorlevel%
)
echo "---------- All tests passed -------------"
+10 -16
View File
@@ -5,39 +5,33 @@
#
echo "---------- Trailing whitespace check -------------"
git diff --check `git rev-list HEAD | tail -n 1`..$TRAVIS_BRANCH
# check uncommitted changes
git diff --check HEAD
if [ $? != 0 ]; then
exit 1;
fi
# check all commits starting from initial commit
git diff --check `git rev-list --max-parents=0 HEAD`..HEAD
if [ $? != 0 ]; then
exit 1;
fi
echo "---------- Preparation of config -------------"
if [ -f "src/config.h" ]; then
echo "Making backup of existing config"
mv src/config.h src/config.h_backup_checksh
fi
cp src/config.h_template src/config.h
echo "---------- Running compile check -------------"
platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3
platformio run -e mppt_2420_lc -e mppt_1210_hus -e mppt_2420_hc -e pwm_2420_lus
if [ $? != 0 ]; then
mv src/config.h_backup_checksh src/config.h
exit 1;
fi
echo "---------- Running unit-tests -------------"
platformio test -e unit-test-native
platformio test -e unit_test
if [ $? != 0 ]; then
mv src/config.h_backup_checksh src/config.h
exit 1;
fi
echo "---------- Running static code checks -------------"
platformio check -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3
platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high
if [ $? != 0 ]; then
mv src/config.h_backup_checksh src/config.h
exit 1;
fi
mv src/config.h_backup_checksh src/config.h
echo "---------- All tests passed -------------"
+19
View File
@@ -0,0 +1,19 @@
# Libre Solar Charge Controller Firmware
## Charge controller basic concepts
[charger-concepts.md](charger-concepts.md)
## Firmware module overview
[module-overview.md](module-overview.md)
## API documentation
The documentation auto-generated by Doxygen can be found [here](https://libre.solar/charge-controller-firmware/).
## Further information
[Zephyr Project documentation](https://docs.zephyrproject.org/latest/)
[Zephyr / West cheatsheet](zephyr-cheatsheet.md)
+43
View File
@@ -0,0 +1,43 @@
# Charge controller concepts
## Bus and port structure
In order to handle multiple different types of charge controllers, the power flow in the charge controller is abstracted using the two base components DC bus and Power Port:
- A **DC bus**, which is a connection of two or more electrical circuits such that the electric potential at each connection point can be considered equal. This can be achieved either by connecting each participant very close to each other or by using large copper cross-section such that voltage drop introduced by current flow is negligible. The voltage control targets of the bus can only be set by one of the connected ports.
- A **Power port**, which connects a DC bus with an internal or external device or sub-circuit. A port usually contains a current measurement. Its voltage is determined by the DC bus it is connected to. A port can also contain a switching element.
The following image gives an overview of the maximum set of features for a charge controller currently considered in the firmware. It contains two DC buses: High-voltage side (typically solar panel or wind turbine) and low-voltage side (typically determined by battery voltage). Most of the power ports are connected at the low voltage side (12V or 24V).
![Charger controller bus and port structure](images/charge-controller-structure.svg)
The image also shows the direction of positive current flow.
## Charger state machine
For general information about battery charging, please check out the [battery chapter at learn.libre.solar](https://learn.libre.solar/system/battery.html#charge-methods).
The charger module in the firmware has the following states:
### 0. Standby
Initial state of the charge controller. If the solar voltage is high enough and the battery is not full, charging in CC mode is started.
### 1. Bulk stage
This first charging stage adds about 70 percent of the stored energy. The battery is charged with a constant current (CC), typically the maximum current the charger can supply. In case of a solar charge controller, this is where the Maximum Power Point Tracking (MPPT) takes place. As a result, the terminal voltage increases until the peak charge voltage limit is reached and topping phase is entered.
### 2. Topping stage
During the topping (sometimes also called boost or absorption) the remaining 30 percent of the energy is continued being charged at a constant voltage (CV) while gradually decreasing the charge current until the battery is fully charged.
### 3. Equalization stage
An additional equalization charging is beneficial for flooded lead-acid batteries only. It can be considered as a periodic controlled overcharge that brings the cells to the same charge level and removes the sulphation by increasing the voltage to a higher value than the peak charge voltage limit. The current during equlization is controlled at a very low value.
### 4. Trickle stage
The trickle or float charging stage is the final phase upon the completion of the absorption or equalization phase which maintains the battery at full charge. During this stage, the charge voltage is reduced and held constant. The current reduces to a very low value.
![Flow-chart of the MPPT charge controller state machine](images/charging-stages.png)
-20
View File
@@ -1,20 +0,0 @@
# Charger state machine
The charge management has the following states:
### Standby
Initial state of the charge controller. If the solar voltage is high enough and the battery is not full, charging in CC mode is started.
### CC / bulk charging
The battery is charged with maximum possible current (MPPT algorithm is active) until the CV voltage limit is reached.
### CV / absorption charging
Lead-acid batteries are charged for some time using a slightly higher charge voltage. After a current cutoff limit or a time limit is reached, the charger goes into trickle or equalization mode for lead-acid batteries or back into Standby for Li-ion batteries.
### Trickle charging
This mode is kept forever for a lead-acid battery and keeps the battery at full state of charge. If too much power is drawn from the battery, the charger switches back into CC / bulk charging mode.
### Equalization charging
This mode is only used for lead-acid batteries after several deep-discharge cycles or a very long period of time with no equalization. Voltage is increased to 15V or above, so care must be taken for the other system components attached to the battery. (currently, no equalization charging is enabled in the software)
![Flow-chart of the MPPT charge controller state machine](MPPT_flow_chart.png)
-29
View File
@@ -1,29 +0,0 @@
# MPPT charger firmware structure
## Important remarks
- Do **not** use mbed Ticker class, as it disturbs the timer settings and might cause the charge controller to crash. In addition to that, it contains a lot of overhead and is not very efficient. Timers are programmed bare metal.
- The PWM signal generation for the DC/DC controller inside the charge controller is done in the file half_bridge_xxx.cpp and dcdc.cpp. Most of the dangerous functions which could turn your MOSFETs into magic smoke are implemented here, so don't touch it unless you know what you're doing.
## Toolchain and flashing instructions
See the Libre Solar website for a detailed instruction how to [develop software](http://libre.solar/docs/toolchain) and [flash new firmware](http://libre.solar/docs/flashing).
## Timer configuration
- mbed us_ticker (cannot be changed)
- TIM2 for STM32F0
- TIM21 for STM32L0
- PWM generation for DC/DC half bridge (50-70 kHz)
- TIM1 for STM32F0 (advanced timer)
- TIM3 for STM32L0 (standard timer)
- ADC and DMA (1 kHz)
- TIM15 for STM32F0
- TIM6 for STM32L0
- DC/DC control function (10 Hz)
- TIM16 for STM32F0
- TIM7 for STM32L0
- LED light control
- TIM17 for STM32F0
- TIM22 for STM32L0
+582
View File
@@ -0,0 +1,582 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="600"
height="170"
viewBox="0 0 158.75 44.97918"
version="1.1"
id="svg5625"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
sodipodi:docname="charge-controller-structure.svg"
inkscape:export-filename="/home/martin/test.png"
inkscape:export-xdpi="200.1694"
inkscape:export-ydpi="200.1694"
style="enable-background:new">
<defs
id="defs5619">
<marker
inkscape:stockid="DotS"
orient="auto"
refY="0"
refX="0"
id="DotS"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path16850"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.2,0,0,0.2,1.48,0.2)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="DotM"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path16847"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-9"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-1"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-7"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-0"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-3"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-6"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-7-6"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-0-2"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-7-6-1"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-0-2-8"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-7-9"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-0-20"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-7-9-9"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-0-20-2"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="marker7066-2-7-9-9-3"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path7064-7-0-20-2-6"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.00000003pt;stroke-opacity:1"
transform="matrix(0.4,0,0,0.4,2.96,0.4)"
inkscape:connector-curvature="0" />
</marker>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="2.0000001"
inkscape:cx="290.19529"
inkscape:cy="110.23898"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="true"
showguides="false"
inkscape:snap-grids="true"
inkscape:snap-to-guides="true"
inkscape:window-width="1916"
inkscape:window-height="1156"
inkscape:window-x="1920"
inkscape:window-y="20"
inkscape:window-maximized="0"
units="px"
scale-x="2">
<inkscape:grid
type="xygrid"
id="grid6225"
spacingx="2.6458333"
spacingy="2.6458333"
dotted="false" />
</sodipodi:namedview>
<metadata
id="metadata5622">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
<dc:creator>
<cc:Agent>
<dc:title>Martin Jäger</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Ebene 2"
style="display:inline"
transform="translate(0,-261.70842)" />
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-261.70842)">
<rect
style="display:inline;fill:none;fill-opacity:1;stroke:#6b6b6b;stroke-width:0.26458335;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;enable-background:new"
id="rect6825"
width="113.77083"
height="26.458336"
x="29.104166"
y="269.6459"
ry="0.076052353" />
<rect
style="display:inline;fill:none;fill-opacity:1;stroke:#005e85;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;enable-background:new"
id="rect6825-9-8-36-1"
width="50.270832"
height="5.2916832"
x="87.3125"
y="280.22925"
ry="0.01521052" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2);enable-background:new"
d="M 68.79166,282.87508 H 58.208333"
id="path6950-0"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<rect
style="display:inline;fill:none;fill-opacity:1;stroke:#005e85;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;enable-background:new"
id="rect6825-9-8-36-1-2"
width="26.458338"
height="5.2916832"
x="34.395832"
y="280.22925"
ry="0.01521052" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-9);enable-background:new"
d="m 79.375001,282.87509 h 10.58333"
id="path6950-0-2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-7-6);enable-background:new"
d="m 39.687503,298.75008 -10e-7,-15.875"
id="path6950-0-9-6"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-7);enable-background:new"
d="m 52.916666,290.8126 -10e-7,-7.9375"
id="path6950-0-9"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 52.916669,290.8126 1.5875,2.11666"
id="path2655"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
d="m 52.916669,293.45843 v 5.29166"
id="path2657"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-7-6-1);enable-background:new"
d="m 95.249999,298.75008 v -15.875"
id="path6950-0-9-6-7"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-7-9);enable-background:new"
d="m 105.83333,290.8126 v -7.9375"
id="path6950-0-9-3"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 105.83333,290.8126 1.5875,2.11666"
id="path2655-7"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
d="m 105.83333,293.45843 v 5.29166"
id="path2657-5"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-7-9-9);enable-background:new"
d="m 119.0625,290.8126 v -7.9375"
id="path6950-0-9-3-8"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 119.0625,290.8126 1.5875,2.11666"
id="path2655-7-9"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
d="m 119.0625,293.45843 v 5.29166"
id="path2657-5-7"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7066-2-7-9-9-3);enable-background:new"
d="m 132.29166,290.8126 v -7.9375"
id="path6950-0-9-3-8-2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 132.29166,290.8126 1.5875,2.11666"
id="path2655-7-9-9"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
d="m 132.29166,293.45843 v 5.29166"
id="path2657-5-7-3"
inkscape:connector-curvature="0" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#005e85;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none"
x="41.576717"
y="278.35446"
id="text3483"><tspan
sodipodi:role="line"
id="tspan3481"
x="41.576717"
y="278.35446"
style="fill:#005e85;fill-opacity:1;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none">hv_bus</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#005e85;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none"
x="108.93037"
y="278.27698"
id="text3487"><tspan
sodipodi:role="line"
id="tspan3485"
x="108.93037"
y="278.27698"
style="fill:#005e85;fill-opacity:1;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none">lv_bus</tspan></text>
<g
id="g3517"
transform="matrix(1.3333333,0,0,1.3333336,12.347285,-124.27817)"
style="stroke-width:0.74999994">
<rect
ry="0.022815673"
y="301.39612"
x="42.333282"
height="7.9374866"
width="7.9375014"
id="rect6825-9-8-1"
style="display:inline;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.19843747;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;enable-background:new" />
<path
inkscape:connector-curvature="0"
id="path7008"
d="m 42.33328,309.33361 7.9375,-7.9375 v 0 0 0"
style="display:inline;fill:none;stroke:#000000;stroke-width:0.19843747px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;enable-background:new" />
<path
style="fill:none;stroke:#000000;stroke-width:0.29765621;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 43.920782,303.77737 h 1.984375"
id="path7786"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.29765621;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 43.920782,302.58674 h 1.984375"
id="path7788"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.29765621;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;enable-background:new"
d="m 46.698908,308.14294 h 1.984375"
id="path7786-1"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.29765621;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;enable-background:new"
d="m 46.698908,306.95231 h 1.984375"
id="path7788-9"
inkscape:connector-curvature="0" />
</g>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="93.662498"
y="304.04181"
id="text8274"><tspan
sodipodi:role="line"
id="tspan8272"
x="93.662498"
y="304.04181"
style="stroke-width:0.26458332">lv</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="101.59998"
y="304.04181"
id="text8278"><tspan
sodipodi:role="line"
id="tspan8276"
x="101.59998"
y="304.04181"
style="stroke-width:0.26458332">load</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="114.30003"
y="304.04181"
id="text8282"><tspan
sodipodi:role="line"
id="tspan8280"
x="114.30003"
y="304.04181"
style="stroke-width:0.26458332">pwm</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="129.1167"
y="304.04181"
id="text8286"><tspan
sodipodi:role="line"
id="tspan8284"
x="129.1167"
y="304.04181"
style="stroke-width:0.26458332">usb</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="47.095833"
y="304.04181"
id="text8290"><tspan
sodipodi:role="line"
id="tspan8288"
x="47.095833"
y="304.04181"
style="stroke-width:0.26458332">dump</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="38.099998"
y="304.04181"
id="text8294"><tspan
sodipodi:role="line"
id="tspan8292"
x="38.099998"
y="304.04181"
style="stroke-width:0.26458332">hv</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="69.453125"
y="275.73135"
id="text8298"><tspan
sodipodi:role="line"
id="tspan8296"
x="69.453125"
y="275.73135"
style="stroke-width:0.26458332">dcdc</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="8.9222355"
y="303.98309"
id="text8548"><tspan
sodipodi:role="line"
x="8.9222355"
y="303.98309"
style="stroke-width:0.26458332"
id="tspan8550">Power Ports:</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.88055563px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332;enable-background:new"
x="29.10416"
y="268.05841"
id="text1902"><tspan
sodipodi:role="line"
id="tspan1900"
x="29.10416"
y="268.05841"
style="stroke-width:0.26458332">Charge Controller</tspan></text>
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 63.499999,282.87509 1.058323,0.66147 2.4e-5,-1.32291 z"
id="path1050-1"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 84.666666,282.87509 -1.058323,-0.66147 -2.4e-5,1.32291 z"
id="path1050-1-3"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 39.687499,288.16675 0.66147,-1.05832 -1.32291,-2e-5 z"
id="path1050-1-6"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 52.916669,288.16675 0.66147,-1.05832 -1.32291,-2e-5 z"
id="path1050-1-6-1"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 95.249999,288.16675 0.661475,-1.05832 -1.322915,-2e-5 z"
id="path1050-1-6-1-0"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 105.83333,288.16675 0.66147,-1.05832 -1.32291,-2e-5 z"
id="path1050-1-6-1-0-6"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 119.0625,288.16675 0.66147,-1.05832 -1.32291,-2e-5 z"
id="path1050-1-6-1-0-6-3"
inkscape:connector-curvature="0" />
<path
style="display:inline;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;enable-background:new"
d="m 132.29167,288.16675 0.66147,-1.05832 -1.32291,-2e-5 z"
id="path1050-1-6-1-0-6-2"
inkscape:connector-curvature="0" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 26 KiB

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

+81
View File
@@ -0,0 +1,81 @@
# Firmware modules
## Data Acquisition
Files: daq*.h/cpp
Handles current and voltage measurement through the ADC with direct memory access (DMA). As a reference for current measurement, a digital-analog-converter (DAC) is used and also configured in this module.
The measurements are filtered and afterwards stored in the different sub-component objects.
## DC/DC converter
Files: dcdc.h/cpp
High-level functions to control the DC/DC converter. This module does not directly access any hardware. The PWM signal for the half bridge is generated in a separate module (see below).
## Data Objects for ThingSet protocol
Files: data_objects.h/cpp
The charge controller uses the [ThingSet protocol](https://thingset.github.io/) for communication with external devices. Internal data that should be exposed via the protocol is defined in the Data Objects module.
## Device status
Files: device_status.h/cpp
Stores global error flags and system-level measurements that are not specific to one sub-component.
## EEPROM
Files: eeprom.h/cpp
Stores data in ThingSet protocol format in the internal or external EEPROM (depending on the board).
## Half bridge
Files: half_bridge.h/cpp
Generates the synchronous PWM signal for the half bridge in the DC/DC converter. Depending on the MCU, either the advanced timer TIM1 or the basic timer TIM3 is used.
## LEDs
Files: leds.h/cpp
Provides higher-level access to different LEDs (e.g. blinking and flickering). Internally, charlieplexing is used to optimize power consumption and needed pin numbers.
## Load Output
Files: load*.h/cpp
Load output and USB charging output functions. Hardware-access is defined in load_drv.cpp file.
## Power Port and DC bus
Files: power_port.h/cpp
Contains DcBus and PowerPort classes. See [charger concepts](charger-concepts.md) for further details.
## PWM Switch
Files: pwm_switch.h/cpp
Only used for PWM solar charge controllers. This module is currently not yet separated into hardware-level and high-level functions.
## Timer configuration in mbed firmware
- mbed us_ticker (cannot be changed)
- TIM2 for STM32F0
- TIM21 for STM32L0
- PWM generation for DC/DC half bridge (50-70 kHz)
- TIM1 for STM32F0 (advanced timer)
- TIM3 for STM32L0 (standard timer)
- ADC and DMA (1 kHz)
- TIM15 for STM32F0
- TIM6 for STM32L0
- DC/DC control function (10 Hz)
- TIM16 for STM32F0
- TIM7 for STM32L0
- LED light control
- TIM17 for STM32F0
- TIM22 for STM32L0
+20
View File
@@ -0,0 +1,20 @@
# Zephyr cheat sheet
## West commands
Initial board selection
west build -b <board-name>
Flash with specific debug probe (runner), e.g. J-Link
west flash -r jlink
Report of used memory (RAM and flash)
west build -t rom_report
west build -t ram_report
User configuration using menuconfig
west build -t menuconfig
-19
View File
@@ -1,19 +0,0 @@
# Custom script to generate src/version.h file containing the git commit hash
#
# See also http://docs.platformio.org/en/latest/projectconf.html#extra-script
#
import subprocess
try:
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
except:
commit_hash = ""
f = open("src/version.h","w+")
f.write("/* Auto-generated file with git commit hash to be included by C code\n")
f.write(" * Do not change this file manually!\n")
f.write(" */\n")
f.write("\n")
f.write('#define COMMIT_HASH "' + commit_hash.decode('utf-8') + '"\n')
f.close
-442
View File
@@ -1,442 +0,0 @@
/***********************************
This is a our graphics core library, for all our displays.
We'll be adapting all the
existing libaries to use this core to make updating, support
and upgrading easier!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
****************************************/
/*
* Modified by Neal Horman 7/14/2012 for use in mbed
*
* Further modified by Martin Jäger (11/2019) to make it independent of mbed and useable in Zephyr
*/
#include "Adafruit_GFX.h"
#include "glcdfont.h"
#include <math.h>
#if defined(GFX_WANT_ABSTRACTS)
void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
{
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
drawPixel(x0, y0+r, color);
drawPixel(x0, y0-r, color);
drawPixel(x0+r, y0, color);
drawPixel(x0-r, y0, color);
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
drawPixel(x0 + x, y0 + y, color);
drawPixel(x0 - x, y0 + y, color);
drawPixel(x0 + x, y0 - y, color);
drawPixel(x0 - x, y0 - y, color);
drawPixel(x0 + y, y0 + x, color);
drawPixel(x0 - y, y0 + x, color);
drawPixel(x0 + y, y0 - x, color);
drawPixel(x0 - y, y0 - x, color);
}
}
void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color)
{
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
drawPixel(x0 + x, y0 + y, color);
drawPixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
drawPixel(x0 + x, y0 - y, color);
drawPixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
drawPixel(x0 - y, y0 + x, color);
drawPixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
drawPixel(x0 - y, y0 - x, color);
drawPixel(x0 - x, y0 - y, color);
}
}
}
void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
{
drawFastVLine(x0, y0-r, 2*r+1, color);
fillCircleHelper(x0, y0, r, 3, 0, color);
}
// used to do circles and roundrects!
void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color)
{
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x1) {
drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
}
if (cornername & 0x2) {
drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
}
}
}
#endif
#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
// bresenham's algorithm - thx wikpedia
void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
{
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1)
ystep = 1;
else
ystep = -1;
for (; x0<=x1; x0++)
{
if (steep)
drawPixel(y0, x0, color);
else
drawPixel(x0, y0, color);
err -= dy;
if (err < 0)
{
y0 += ystep;
err += dx;
}
}
}
void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
{
// stupidest version - update in subclasses if desired!
drawLine(x, y, x, y+h-1, color);
}
void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
// stupidest version - update in subclasses if desired!
for (int16_t i=x; i<x+w; i++) {
drawFastVLine(i, y, h, color);
}
}
#endif
#if defined(GFX_WANT_ABSTRACTS)
void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
drawFastHLine(x, y, w, color);
drawFastHLine(x, y+h-1, w, color);
drawFastVLine(x, y, h, color);
drawFastVLine(x+w-1, y, h, color);
}
void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
{
// stupidest version - update in subclasses if desired!
drawLine(x, y, x+w-1, y, color);
}
void Adafruit_GFX::fillScreen(uint16_t color)
{
fillRect(0, 0, _width, _height, color);
}
void Adafruit_GFX::drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
{
// smarter version
drawFastHLine(x+r , y , w-2*r, color); // Top
drawFastHLine(x+r , y+h-1, w-2*r, color); // Bottom
drawFastVLine( x , y+r , h-2*r, color); // Left
drawFastVLine( x+w-1, y+r , h-2*r, color); // Right
// draw four corners
drawCircleHelper(x+r , y+r , r, 1, color);
drawCircleHelper(x+w-r-1, y+r , r, 2, color);
drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
drawCircleHelper(x+r , y+h-r-1, r, 8, color);
}
void Adafruit_GFX::fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
{
// smarter version
fillRect(x+r, y, w-2*r, h, color);
// draw four corners
fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
fillCircleHelper(x+r , y+r, r, 2, h-2*r-1, color);
}
void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
{
drawLine(x0, y0, x1, y1, color);
drawLine(x1, y1, x2, y2, color);
drawLine(x2, y2, x0, y0, color);
}
void Adafruit_GFX::fillTriangle ( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
{
int16_t a, b, y, last;
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
swap(y0, y1); swap(x0, x1);
}
if (y1 > y2) {
swap(y2, y1); swap(x2, x1);
}
if (y0 > y1) {
swap(y0, y1); swap(x0, x1);
}
if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a)
a = x1;
else if (x1 > b)
b = x1;
if (x2 < a)
a = x2;
else if (x2 > b) b = x2;
drawFastHLine(a, y0, b-a+1, color);
return;
}
int16_t
dx01 = x1 - x0,
dy01 = y1 - y0,
dx02 = x2 - x0,
dy02 = y2 - y0,
dx12 = x2 - x1,
dy12 = y2 - y1,
sa = 0,
sb = 0;
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if(y1 == y2)
last = y1; // Include y1 scanline
else
last = y1-1; // Skip it
for(y=y0; y<=last; y++)
{
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if(a > b)
swap(a,b);
drawFastHLine(a, y, b-a+1, color);
}
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for(; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if(a > b)
swap(a,b);
drawFastHLine(a, y, b-a+1, color);
}
}
void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
{
for (int16_t j=0; j<h; j++) {
for (int16_t i=0; i<w; i++ ) {
if (bitmap[i + (j/8)*w] & _BV(j%8))
drawPixel(x+i, y+j, color);
}
}
}
#endif
void Adafruit_GFX::writeChar(uint8_t c)
{
if (c == '\n') {
cursor_y += textsize*8;
cursor_x = 0;
}
else if (c == '\r') {
cursor_x = 0;
}
else {
drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
cursor_x += textsize*6;
if (wrap && (cursor_x > (_width - textsize*6)))
{
cursor_y += textsize*8;
cursor_x = 0;
}
}
}
void Adafruit_GFX::writeString(const char *buf, size_t len)
{
for (unsigned int i = 0; i < len; i++) {
writeChar(buf[i]);
}
}
void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
{
if ((x >= _width) || // Clip right
(y >= _height) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
{
return;
}
for (int8_t i = 0; i < 6; i++) {
uint8_t line = 0;
if (i == 5) {
line = 0x0;
}
else {
line = font[(c*5)+i];
}
for (int8_t j = 0; j<8; j++) {
if (line & 0x1) {
#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
if (size == 1) // default size
drawPixel(x+i, y+j, color);
else // big size
fillRect(x+(i*size), y+(j*size), size, size, color);
#else
drawPixel(x+i, y+j, color);
#endif
}
else if (bg != color) {
#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
if (size == 1) // default size
drawPixel(x+i, y+j, bg);
else // big size
fillRect(x+i*size, y+j*size, size, size, bg);
#else
drawPixel(x+i, y+j, bg);
#endif
}
line >>= 1;
}
}
}
void Adafruit_GFX::setRotation(uint8_t x)
{
x %= 4; // cant be higher than 3
rotation = x;
switch (x)
{
case 0:
case 2:
_width = _rawWidth;
_height = _rawHeight;
break;
case 1:
case 3:
_width = _rawHeight;
_height = _rawWidth;
break;
}
}
-201
View File
@@ -1,201 +0,0 @@
/***********************************
This is a our graphics core library, for all our displays.
We'll be adapting all the
existing libaries to use this core to make updating, support
and upgrading easier!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
****************************************/
/*
* Modified by Neal Horman 7/14/2012 for use in mbed
*
* Further modified by Martin Jäger (11/2019) to make it independent of mbed and useable in Zephyr
*/
#ifndef ADAFRUIT_GFX_H_
#define ADAFRUIT_GFX_H_
#include <stdint.h>
#include <string.h>
// Uncomment this to enable all functionality
#define GFX_WANT_ABSTRACTS
static inline void swap(int16_t &a, int16_t &b)
{
int16_t t = a;
a = b;
b = t;
}
#ifndef _BV
#define _BV(bit) (1<<(bit))
#endif
#define BLACK 0
#define WHITE 1
/**
* This is a Text and Graphics element drawing class.
* These functions draw to the display buffer.
*
* Display drivers should be derived from here.
* The Display drivers push the display buffer to the
* hardware based on application control.
*
*/
class Adafruit_GFX
{
public:
Adafruit_GFX(int16_t w, int16_t h) :
_rawWidth(w),
_rawHeight(h),
_width(w),
_height(h),
cursor_x(0),
cursor_y(0),
textcolor(WHITE),
textbgcolor(BLACK),
textsize(1),
rotation(0),
wrap(true)
{};
/// Paint one BLACK or WHITE pixel in the display buffer
// this must be defined by the subclass
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
// this is optional
virtual void invert(bool i) {};
#ifdef GFX_WANT_ABSTRACTS
// these are 'generic' drawing functions, so we can share them!
/** Draw a Horizontal Line
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
/** Draw a rectangle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
/** Fill the entire display
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
virtual void fillScreen(uint16_t color);
/** Draw a circle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
/** Draw and fill a circle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
/** Draw a triangle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
/** Draw and fill a triangle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
/** Draw a rounded rectangle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
/** Draw and fill a rounded rectangle
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
/** Draw a bitmap
* @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
*/
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
#endif
#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
/** Draw a line
* @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
*/
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
/** Draw a vertical line
* @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
*/
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
/** Draw and fill a rectangle
* @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
*/
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
#endif
/// Draw a text character at a specified pixel location
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
/// Draw a text character at the text cursor location
void writeChar(uint8_t);
/// Draw a string at the text cursor location
void writeString(const char *buf, size_t len);
/// Get the width of the display in pixels
inline int16_t width(void) { return _width; };
/// Get the height of the display in pixels
inline int16_t height(void) { return _height; };
/// Set the text cursor location, based on the size of the text
inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
/** Set the size of the text to be drawn
* @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS
*/
inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
#endif
/// Set the text foreground and background colors to be the same
inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
/// Set the text foreground and background colors independantly
inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
/// Set text wraping mode true or false
inline void setTextWrap(bool w) { wrap = w; };
/// Set the display rotation, 1, 2, 3, or 4
void setRotation(uint8_t r);
/// Get the current rotation
inline uint8_t getRotation(void) { rotation %= 4; return rotation; };
protected:
int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes
int16_t _width, _height; // dependent on rotation
int16_t cursor_x, cursor_y;
uint16_t textcolor, textbgcolor;
uint8_t textsize;
uint8_t rotation;
bool wrap; // If set, 'wrap' text at right edge of display
};
#endif
-24
View File
@@ -1,24 +0,0 @@
Software License Agreement (BSD License)
Copyright (c) 2012 Adafruit Industries. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-213
View File
@@ -1,213 +0,0 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 Adafruit Industries. All rights reserved.
*
* This class is partly based on the library developed by Adafruit and modified by Neal Horman
* 7/14/2012 for use in mbed.
*
* Significant modifications were done by Martin Jäger (11/2019) to use it also in Zephyr
*/
#include "OledSSD1306.h"
#include "logo.h"
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#if defined(__MBED__)
OledSSD1306::OledSSD1306(I2C &i2c, uint8_t i2cAddress) :
Adafruit_GFX(SSD1306_WIDTH, SSD1306_HEIGHT),
_i2c(i2c),
_i2cAddress(i2cAddress)
{
;
}
#elif defined(__ZEPHYR__)
OledSSD1306::OledSSD1306(const char *i2c_name, uint8_t i2cAddress) :
Adafruit_GFX(SSD1306_WIDTH, SSD1306_HEIGHT),
_i2cAddress(i2cAddress)
{
_i2c = device_get_binding(i2c_name);
if (!_i2c) {
printk("I2C: Device driver not found.\n");
}
}
#endif
void OledSSD1306::init(uint8_t brightness)
{
command(SSD1306_DISPLAYOFF);
command(SSD1306_SETDISPLAYCLOCKDIV);
command(0x80); // the suggested ratio 0x80
command(SSD1306_SETMULTIPLEX);
command(_rawHeight-1);
command(SSD1306_SETDISPLAYOFFSET);
command(0x0); // no offset
command(SSD1306_SETSTARTLINE | 0x0); // line #0
command(SSD1306_CHARGEPUMP);
command((SSD1306_SWITCHCAPVCC == SSD1306_EXTERNALVCC) ? 0x10 : 0x14);
command(SSD1306_MEMORYMODE);
command(0x00); // 0x0 act like ks0108
command(SSD1306_SEGREMAP | 0x1);
command(SSD1306_COMSCANDEC);
command(SSD1306_SETCOMPINS);
command(_rawHeight == 32 ? 0x02 : 0x12); // TODO - calculate based on _rawHieght ?
command(SSD1306_SETCONTRAST);
command(_rawHeight == 32 ? 0x8F : ((SSD1306_SWITCHCAPVCC == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF) );
command(SSD1306_SETPRECHARGE);
command((SSD1306_SWITCHCAPVCC == SSD1306_EXTERNALVCC) ? 0x22 : 0xF1);
command(SSD1306_SETVCOMDETECT);
command(0x40);
command(SSD1306_DISPLAYALLON_RESUME);
command(SSD1306_NORMALDISPLAY);
command(SSD1306_DISPLAYON);
// make sure that display has not shifted even without power on reset
command(0x22);
command(0x00);
command(0x07);
command(SSD1306_SETCONTRAST);
command(brightness);
splash();
display();
}
void OledSSD1306::drawPixel(int16_t x, int16_t y, uint16_t color)
{
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return;
switch (getRotation())
{
case 1:
swap(x, y);
x = _rawWidth - x - 1;
break;
case 2:
x = _rawWidth - x - 1;
y = _rawHeight - y - 1;
break;
case 3:
swap(x, y);
y = _rawHeight - y - 1;
break;
}
// x is which column
if (color == WHITE) {
buffer[x + (y/8)*_rawWidth] |= _BV((y % 8));
}
else {
buffer[x + (y/8)*_rawWidth] &= ~_BV((y % 8));
}
}
void OledSSD1306::invert(bool i)
{
command(i ? SSD1306_INVERTDISPLAY : SSD1306_NORMALDISPLAY);
}
// Send the display buffer out to the display
void OledSSD1306::display(void)
{
command(SSD1306_SETLOWCOLUMN | 0x0); // low col = 0
command(SSD1306_SETHIGHCOLUMN | 0x0); // hi col = 0
command(SSD1306_SETSTARTLINE | 0x0); // line #0
sendBuffer();
}
void OledSSD1306::clear(void)
{
std::fill(buffer.begin(), buffer.end(), 0);
}
void OledSSD1306::splash(void)
{
std::copy(&logo[0], &logo[0] + sizeof(logo), buffer.begin());
}
void OledSSD1306::command(uint8_t c)
{
uint8_t buf[2];
buf[0] = 0; // Command Mode
buf[1] = c;
#if defined(__MBED__)
_i2c.write(_i2cAddress, (char *)buf, sizeof(buf));
#elif defined(__ZEPHYR__)
i2c_write(_i2c, buf, sizeof(buf), _i2cAddress);
#endif
}
void OledSSD1306::data(uint8_t c)
{
uint8_t buf[2];
buf[0] = 0x40; // Data Mode
buf[1] = c;
#if defined(__MBED__)
_i2c.write(_i2cAddress, (char *)buf, sizeof(buf));
#elif defined(__ZEPHYR__)
i2c_write(_i2c, buf, sizeof(buf), _i2cAddress);
#endif
};
void OledSSD1306::sendBuffer()
{
uint8_t buf[17];
buf[0] = 0x40; // Data Mode
// send display buffer in 16 byte chunks
for (uint16_t i = 0; i < buffer.size(); i += 16)
{
for(uint8_t x = 1; x < sizeof(buf); x++) {
uint16_t pos = i + x - 1;
if (buffer.size() > pos) {
buf[x] = buffer[pos];
}
}
#if defined(__MBED__)
_i2c.write(_i2cAddress, (char *)buf, sizeof(buf));
#elif defined(__ZEPHYR__)
i2c_write(_i2c, buf, sizeof(buf), _i2cAddress);
#endif
}
};
-84
View File
@@ -1,84 +0,0 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 Adafruit Industries. All rights reserved.
*
* This class is partly based on the library developed by Adafruit and modified by Neal Horman
* 7/14/2012 for use in mbed.
*
* Significant modifications were done by Martin Jäger (11/2019) to use it also in Zephyr
*/
#ifndef OLEDSSD1306_H_
#define OLEDSSD1306_H_
#if defined(__MBED__)
#include "mbed.h"
#elif defined(__ZEPHYR__)
#include <zephyr.h>
#include <drivers/i2c.h>
#endif
#include "Adafruit_GFX.h"
#include <array>
#include <algorithm>
#define SSD1306_I2C_ADDRESS 0x3c // needs to be left-shifted by 1 for mbed (=0x78)
#define SSD1306_WIDTH 128
#define SSD1306_HEIGHT 64
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
/** SSD1306 OLED display driver based on Adafruit GFX library
*/
class OledSSD1306 : public Adafruit_GFX
{
public:
/** Create a SSD1306 I2C transport display driver instance
*
* @param i2c A reference to an initialized I2C object
* @param i2cAddress The i2c address of the display
* @param brightness Sets contrast between 0x01-0xFF or 1-255
*/
#if defined(__MBED__)
OledSSD1306(I2C &i2c, uint8_t i2cAddress = (SSD1306_I2C_ADDRESS << 1));
#elif defined(__ZEPHYR__)
OledSSD1306(const char *i2c_name, uint8_t i2cAddress = SSD1306_I2C_ADDRESS);
#endif
void init(uint8_t brightness = 0x01);
void drawPixel(int16_t x, int16_t y, uint16_t color);
void clear(void);
void invert(bool i);
/// Cause the display to be updated with the buffer content.
void display();
/// Fill the buffer with the logo splash screen.
void splash();
void command(uint8_t c);
void data(uint8_t c);
protected:
void sendBuffer();
std::array<uint8_t, SSD1306_HEIGHT * SSD1306_WIDTH / 8> buffer;
#if defined(__MBED__)
I2C &_i2c;
#elif defined(__ZEPHYR__)
struct device *_i2c;
#endif
uint8_t _i2cAddress;
};
#endif // OLEDSSD1306_H_
-272
View File
@@ -1,272 +0,0 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 Adafruit Industries. All rights reserved.
*/
// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
// See gfxfont.h for newer custom bitmap font info.
#ifndef FONT5X7_H
#define FONT5X7_H
// Standard ASCII 5x7 font
static const unsigned char font[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
};
#endif // FONT5X7_H
-74
View File
@@ -1,74 +0,0 @@
/*
* Copyright (c) 2018 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
static const uint8_t logo[64 * 128 / 8] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0xE7, 0xC7,
0xC3, 0x87, 0x07, 0x07, 0x0F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1E, 0x1F, 0x1F, 0x3F,
0x3E, 0x7E, 0x7E, 0xFC, 0xFC, 0xF8, 0xF0, 0xC0, 0x01, 0x03, 0x87, 0x87, 0x87, 0x87, 0x87, 0x00,
0x30, 0x30, 0x30, 0x20, 0x20, 0x60, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE,
0xFE, 0xFC, 0xF8, 0xF0, 0xE3, 0xC7, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x03, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, 0xC0,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x80, 0xC0,
0x60, 0x20, 0x20, 0x20, 0x20, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x60, 0x20,
0x20, 0x60, 0x40, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x60, 0x40, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x77,
0xC0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x30, 0xD0, 0x08, 0x04, 0x03, 0x00,
0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0F,
0x08, 0x18, 0x18, 0x10, 0x10, 0x30, 0xE0, 0x80, 0x00, 0x00, 0x10, 0xFF, 0x81, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC7, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x8F, 0x81, 0x80, 0x87, 0x9C, 0xF0, 0x80, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x30, 0xF0, 0x88, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0C, 0x06,
0x03, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0E, 0x08, 0x00,
0x00, 0x00, 0x00, 0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x02, 0x06,
0x04, 0x04, 0x0C, 0x04, 0x04, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x04, 0x0C,
0x0C, 0x04, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x00, 0x08, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x0C, 0x00,
0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x0C, 0x00, 0x00, 0x00, 0x00
};
-215
View File
@@ -1,215 +0,0 @@
/*
* Copyright (c) 2018 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "ESP32.h"
#include "mbed.h"
ESP32::ESP32(UARTSerial &s) :
_serial(s),
_at(&_serial, "\r\n", 200, 4000)
{
}
ESP32::~ESP32()
{ }
// Soft reset of ESP32
int ESP32::reset(void)
{
_at.set_timeout(3000);
_at.send("AT+RST");
char buf[100];
_at.read(buf, sizeof(buf));
printf(buf);
return _at.recv("ready");
}
void ESP32::print_firmware()
{
_at.set_timeout(1000);
char buf[100];
_at.send("AT+GMR");
_at.read(buf, sizeof(buf));
printf(buf);
}
int ESP32::set_wifi_mode(ESP32_wifi_mode_t mode)
{
_at.set_timeout(1000);
_at.flush();
_at.send("AT+CWMODE=%d", mode);
return _at.recv("OK");
}
void ESP32::list_APs(char *buf, int size)
{
_at.set_timeout(5000); // use long timeout
_at.send("AT+CWLAP");
_at.read(buf, size);
}
int ESP32::join_AP(const char *ssid, const char *pwd)
{
_at.set_timeout(2000);
_at.send("AT+CWJAP=\"%s\",\"%s\"", ssid, pwd);
char buf[100];
_at.read(buf, sizeof(buf));
printf(buf);
return _at.recv("OK");
}
int ESP32::quit_AP(void)
{
_at.send("AT+CWQAP");
return _at.recv("OK");
}
int ESP32::get_IP(char *ip, int size)
{
int ip_arr[4] = {0};
_at.set_timeout(500);
_at.flush();
_at.send("AT+CIFSR");
// valid answer:
// +CIFSR:STAIP,"192.168.178.50"
// +CIFSR:STAMAC,"30:ae:a4:c3:70:88"
//
// OK
// hack to obtain IP address, as _at.recv seems to contain a bug (it returns 192.168.0.4 instead of 192.168.0.43)
char buf[100];
char *ip_start = buf;
_at.read(buf, sizeof(buf));
//printf(buf);
for (unsigned int i = 0; i < sizeof(buf); i++) {
if (strncmp(&buf[i], "busy now", 8) == 0) {
printf("IP busy now!!\n");
snprintf(ip, size, "ERROR");
_at.flush();
return 0;
}
else if (buf[i] < '0' || buf[i] > '9') { // find first numeric character
ip_start++;
}
else
break;
}
int res = sscanf(ip_start, "%d.%d.%d.%d", &ip_arr[0], &ip_arr[1], &ip_arr[2], &ip_arr[3]);
// TODO: figure out bug in _at.recv and correct it
//int res = _at.recv("%d.%d.%d.%d\r", &ip_arr[0], &ip_arr[1], &ip_arr[2], &ip_arr[3]);
if (res > 0)
snprintf(ip, size, "%d.%d.%d.%d", ip_arr[0], ip_arr[1], ip_arr[2], ip_arr[3]);
else
snprintf(ip, size, "ERROR");
return res;
}
int ESP32::ping(const char *ip)
{
_at.set_timeout(2000);
_at.send("AT+PING=\"%s\"", ip);
return _at.recv("OK");
}
int ESP32::set_single()
{
_at.send("AT+CIPMUX=0");
return _at.recv("OK");
}
int ESP32::set_multiple()
{
_at.send("AT+CIPMUX=1");
return _at.recv("OK");
}
int ESP32::get_conn_status()
{
int status = -1;
_at.set_timeout(2000);
_at.flush();
_at.send("AT+CIPSTATUS");
//char buf[100];
//_at.read(buf, sizeof(buf));
//printf(buf);
_at.recv("STATUS:%d", &status);
return status;
}
int ESP32::set_ip_mode(ESP32_ip_mode_t mode)
{
_at.set_timeout(500);
_at.send("AT+CIPMODE=%d", mode);
return _at.recv("OK");
}
int ESP32::start_TCP_conn(const char *ip, const char *port, bool ssl)
{
_at.set_timeout(2000);
if (ssl) {
printf("Setting SSL conf... ");
_at.send("AT+CIPSSLCCONF=0");
int res = _at.recv("OK");
printf((res > 0) ? "OK\n" : "ERROR\n");
_at.send("AT+CIPSTART=\"SSL\",\"%s\",%s", ip, port);
}
else {
_at.send("AT+CIPSTART=\"TCP\",\"%s\",%s", ip, port);
}
return _at.recv("OK");
}
int ESP32::close_TCP_conn()
{
_at.set_timeout(500);
_at.send("AT+CIPCLOSE");
return _at.recv("OK");
}
int ESP32::send_URL(char *url, char *host)
{
char request[500];
snprintf(request, sizeof(request), "GET %s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", url, host);
_at.send("AT+CIPSEND=%d", strlen(request));
_at.recv("> ");
_at.send(request);
return _at.recv("SEND OK");
}
int ESP32::send_TCP_data(uint8_t *data, int length)
{
_at.send("AT+CIPSEND=%d", length);
_at.recv("> ");
for (int i = 0; i < length; i++) {
_at.putc(data[i]);
}
return _at.recv("SEND OK");
}
int ESP32::start_TCP_server(int port)
{
_at.set_timeout(500);
_at.send("AT+CIPSERVER=1,%d", port);
return _at.recv("OK");
}
int ESP32::close_TCP_server()
{
_at.set_timeout(500);
_at.send("AT+CIPSERVER=0");
return _at.recv("OK");
}
-67
View File
@@ -1,67 +0,0 @@
/*
* Copyright (c) 2018 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __ESP32_H__
#define __ESP32_H__
#include "mbed.h"
enum ESP32_status_t {
ESP32_STATUS_AP_CONNECTED = 2,
ESP32_STATUS_TCP_ACTIVE,
ESP32_STATUS_TCP_DIS,
ESP32_STATUS_AP_DISCONNECTED
};
enum ESP32_wifi_mode_t {
ESP32_WIFI_MODE_NULL = 0,
ESP32_WIFI_MODE_STATION,
ESP32_WIFI_MODE_SOFTAP,
ESP32_WIFI_MODE_BOTH
};
enum ESP32_ip_mode_t {
ESP32_IP_MODE_NORMAL = 0,
ESP32_IP_MODE_PASSTHROUGH
};
class ESP32
{
public:
ESP32(UARTSerial &s);
~ESP32();
int reset();
void print_firmware();
int set_wifi_mode(ESP32_wifi_mode_t mode);
int get_conn_status();
void list_APs(char *buf, int size);
int join_AP(const char *id, const char *pwd);
int quit_AP();
int get_IP(char* ip, int size);
int ping(const char* ip);
int set_single();
int set_multiple();
int set_ip_mode(ESP32_ip_mode_t mode);
int start_TCP_conn(const char *ip, const char *port, bool ssl=false);
int close_TCP_conn();
int send_URL(char *url, char *host);
int send_TCP_data(uint8_t *data, int length);
int start_TCP_server(int port);
int close_TCP_server();
private:
UARTSerial &_serial;
ATCmdParser _at;
};
#endif /* __ESP32_H__ */

Some files were not shown because too many files have changed in this diff Show More