193 Commits
Author SHA1 Message Date
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
179 changed files with 10110 additions and 8182 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
+4 -5
View File
@@ -20,11 +20,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:
+94 -29
View File
@@ -2,27 +2,44 @@
![build badge](https://travis-ci.com/LibreSolar/charge-controller-firmware.svg?branch=master)
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 `master` 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 master 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 master 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)
- [Libre Solar MPPT 2420 HC](https://github.com/LibreSolar/mppt-2420-hc)
- [Libre Solar MPPT 2420 LC](https://github.com/LibreSolar/mppt-2420-lc)
- [Libre Solar MPPT 1210 HUS](https://github.com/LibreSolar/mppt-1210-hus)
- [Libre Solar PWM 2420 LUS](https://github.com/LibreSolar/pwm-2420-lus)
## 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.
@@ -30,18 +47,40 @@ It is suggested to use Visual Studio Code and PlatformIO for firmware developmen
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.
```
platformio upgrade --dev
platformio update
```
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 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.
Now after you cloned the repository (see above), go into the root firmware directory and initialize a west workspace:
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.
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>
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
### Troubleshooting
@@ -51,11 +90,9 @@ The standard OpenOCD settings sometimes fail to flash firmware to this MCU, whic
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`.
3. Use other debuggers and tools, e.g. Segger J-Link.
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/).
#### Connection failures
@@ -79,9 +116,35 @@ 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)
## Firmware customization
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.
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 configuration, 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).
In order to support older board versions (e.g. with changed pins), some overlays with appended version numbers are already existing as a template. Remove the version number (e.g. `_0v4`) to "activate" them.
### 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.
Similar to DTS overlays, the Kconfig can also be customized for each board. Copy the default `prj.conf` to a file `prj_board_name.conf` to use this file instead of `prj.conf`. Please not that, in contrast to overlays, the board-specific Kconfig files are not **added** to the default `prj.conf`, but they **replace** the default configuration instead.
### 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
@@ -90,23 +153,25 @@ The documentation auto-generated by Doxygen can be found [here](https://libre.so
## 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`:
the same tests locally (recommended before pushing to the server) use the script `check.sh` or ` check.bat`:
bash check.sh
bash check.sh # Linux
cmd check.bat # Windows
### Unit-tests
In order to run the unit tests, you need a PlatformIO Plus account. Run tests with the following command:
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-native
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-v0.7
platformio check -e mppt_1210_hus
## Additional firmware documentation (docs folder)
- [MPPT charger firmware details](docs/firmware.md)
- [Charger state machine](docs/charger.md)
- [Charge controller basic concepts](docs/charger-concepts.md)
- [Firmware module overview](docs/module-overview.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`
-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);
@@ -5,3 +5,5 @@ zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
config BOARD_MPPT_1210_HUS
bool "Libre Solar MPPT 1210 HUS"
depends on SOC_STM32L072XX
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
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")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+184
View File
@@ -0,0 +1,184 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/l0/stm32l072Xz.dtsi>
/ {
model = "Libre Solar MPPT 1210 HUS";
compatible = "st,stm32l072";
pcb {
compatible = "charge-controller";
type = "MPPT 1210 HUS";
version-str = "v0.7.1";
version-num = <7>; // minor version .1 includes no HW change
hs-voltage-max = <40>;
ls-voltage-max = <16>;
};
dcdc {
compatible = "dcdc";
timer = <&timers3>;
pwm-frequency = <50000>;
pwm-deadtime = <230>;
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 2 GPIO_ACTIVE_HIGH>, /* Pin C */
<&gpiob 14 GPIO_ACTIVE_HIGH>; /* Pin B */
soc_1 {
states = <1 0 2>;
};
soc_2 {
states = <0 1 2>;
};
soc_3 {
states = <1 2 0>;
};
rxtx {
states = <2 1 0>;
};
load {
states = <2 0 1>;
};
};
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 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
clock-frequency = <I2C_BITRATE_FAST>;
status = "okay";
};
&spi1 {
cs-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&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
@@ -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
+59
View File
@@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2019 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
#define STM32L0_PINMUX_FUNC_PB0_TIM3_CH3 \
(STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
#define STM32L0_PINMUX_FUNC_PB1_TIM3_CH4 \
(STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
static const struct pin_config pinconf[] = {
/* TIM3_CH3 and TIM3_CH4 */
{STM32_PIN_PB0, STM32L0_PINMUX_FUNC_PB0_TIM3_CH3},
{STM32_PIN_PB1, STM32L0_PINMUX_FUNC_PB1_TIM3_CH4},
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL
{STM32_PIN_PA9, STM32L0_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32L0_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) && CONFIG_SERIAL
{STM32_PIN_PA2, STM32L0_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32L0_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_SERIAL, usart2 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PB6, STM32L0_PINMUX_FUNC_PB6_I2C1_SCL},
{STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C, i2c1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI
{STM32_PIN_PB3, STM32L0_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PB4, STM32L0_PINMUX_FUNC_PB4_SPI1_MISO},
{STM32_PIN_PB5, STM32L0_PINMUX_FUNC_PB5_SPI1_MOSI},
#endif /* CONFIG_SPI, spi1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(adc1), okay) && CONFIG_ADC
{STM32_PIN_PA0, STM32L0_PINMUX_FUNC_PA0_ADC_IN0},
#endif /* CONFIG_ADC, adc1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(dac1), okay) && CONFIG_DAC
{STM32_PIN_PA4, STM32L0_PINMUX_FUNC_PA4_DAC_OUT1},
#endif /* CONFIG_DAC, dac1 */
};
static int pinmux_stm32_init(const 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);
@@ -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
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
config BOARD_MPPT_2420_HC
bool "Libre Solar MPPT 2420 HC"
depends on SOC_STM32G431XX
+12
View File
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
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)
+229
View File
@@ -0,0 +1,229 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/g4/stm32g431Xb.dtsi>
/ {
model = "Libre Solar MPPT 2420 HC";
compatible = "st,stm32g431";
pcb {
compatible = "charge-controller";
type = "MPPT 2420 HC";
version-str = "v0.1";
version-num = <1>;
hs-voltage-max = <80>;
ls-voltage-max = <32>;
};
dcdc {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
current-max = <20>;
};
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
/* 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>;
};
};
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
};
};
soc {
dac1: dac@50000800 {
compatible = "st,stm32-dac";
reg = <0x50000800 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00010000>;
status = "disabled";
label = "DAC_1";
#io-channel-cells = <1>;
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
};
&spi1 {
cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>;
status = "okay";
};
&usb {
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>;
};
};
&iwdg {
status = "okay";
};
/* TIM8 (CH2) used for charge pump, but is currently not working with original Zephyr driver */
&timers8 {
status = "okay";
pwm8: pwm {
status = "okay";
};
};
&i2c1 {
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>;
};
};
/*
// This requires https://github.com/zephyrproject-rtos/zephyr/pull/22832
&can1 {
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,72 @@
# 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
# don't enable CAN by default until PR #22832 is merged to upstream Zephyr
#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
+62
View File
@@ -0,0 +1,62 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
/* this should normally go to drivers/pinmux/stm32/pinmux_stm32g4x.h */
#define STM32G4X_PINMUX_FUNC_PB8_PWM8_CH2 \
(STM32_PINMUX_ALT_FUNC_10 | STM32_PUSHPULL_NOPULL)
#define STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1 \
(STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL)
#define STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N \
(STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL)
static const struct pin_config pinconf[] = {
/* USART1 */
{STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32G4X_PINMUX_FUNC_PA10_USART1_RX},
/* TIM1_CH1 and TIM1_CH1N */
{STM32_PIN_PA8, STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1},
{STM32_PIN_PB13, STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N},
/* PWM for charge pump */
{STM32_PIN_PB8, STM32G4X_PINMUX_FUNC_PB8_PWM8_CH2},
#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) && CONFIG_SERIAL
{STM32_PIN_PA2, STM32G4X_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32G4X_PINMUX_FUNC_PA3_USART2_RX},
#endif
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PA15, STM32G4X_PINMUX_FUNC_PA15_I2C1_SCL},
{STM32_PIN_PB7, STM32G4X_PINMUX_FUNC_PB7_I2C1_SDA},
#endif
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI
{STM32_PIN_PB3, STM32G4X_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PB4, STM32G4X_PINMUX_FUNC_PB4_SPI1_MISO},
{STM32_PIN_PB5, STM32G4X_PINMUX_FUNC_PB5_SPI1_MOSI},
#endif
#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) && CONFIG_CAN
{STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_FDCAN1_RX},
{STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_FDCAN1_TX},
#endif
};
static int pinmux_stm32_init(const 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);
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
config BOARD_MPPT_2420_HPX
bool "Libre Solar MPPT 2420 HPX"
depends on SOC_STM32G431XX
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
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)
+267
View File
@@ -0,0 +1,267 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/g4/stm32g431Xb.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 {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
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-ext-sense {
label = "HV external sense and 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
};
};
soc {
// ADC nodes not yet provided by Zephyr, but needed for adc-gain compatibles
adc1: adc@50000000 {
compatible = "st,stm32-adc";
reg = <0x50000000 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00002000>;
interrupts = <18 0>;
status = "disabled";
label = "ADC_1";
#io-channel-cells = <1>;
};
adc2: adc@50000100 {
compatible = "st,stm32-adc";
reg = <0x50000100 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00002000>;
interrupts = <18 0>;
status = "disabled";
label = "ADC_2";
#io-channel-cells = <1>;
};
dac1: dac@50000800 {
compatible = "st,stm32-dac";
reg = <0x50000800 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00010000>;
status = "disabled";
label = "DAC_1";
#io-channel-cells = <1>;
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart3;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
current-speed = <115200>;
status = "okay";
};
&usart3 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
};
&spi1 {
cs-gpios = <&gpiod 2 GPIO_ACTIVE_LOW>;
status = "okay";
};
&usb {
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";
};
/* TIM3 (CH2) used for PWM power switch */
&timers3 {
status = "okay";
pwm3: pwm {
status = "okay";
};
};
/* TIM8 (CH1) used for charge pump, but is currently not working with original Zephyr driver */
&timers8 {
status = "okay";
pwm8: pwm {
status = "okay";
};
};
&i2c3 {
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
+67
View File
@@ -0,0 +1,67 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
/* this should normally go to drivers/pinmux/stm32/pinmux_stm32g4x.h */
#define STM32G4X_PINMUX_FUNC_PC6_PWM8_CH1 \
(STM32_PINMUX_ALT_FUNC_4 | STM32_PUSHPULL_NOPULL)
#define STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1 \
(STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL)
#define STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N \
(STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL)
static const struct pin_config pinconf[] = {
/* TIM1_CH1 and TIM1_CH1N */
{STM32_PIN_PA8, STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1},
{STM32_PIN_PB13, STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N},
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL
{STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32G4X_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */
{STM32_PIN_PC6, STM32G4X_PINMUX_FUNC_PC6_PWM8_CH1},
{STM32_PIN_PC7, STM32G4X_PINMUX_FUNC_PC7_PWM3_CH2},
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart3), okay) && CONFIG_SERIAL
{STM32_PIN_PC10, STM32G4X_PINMUX_FUNC_PC10_USART3_TX},
{STM32_PIN_PC11, STM32G4X_PINMUX_FUNC_PC11_USART3_RX},
#endif /* CONFIG_SERIAL, usart3 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PA15, STM32G4X_PINMUX_FUNC_PA15_I2C1_SCL},
{STM32_PIN_PB7, STM32G4X_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C, i2c1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c3), okay) && CONFIG_I2C
{STM32_PIN_PC8, STM32G4X_PINMUX_FUNC_PC8_I2C3_SCL},
{STM32_PIN_PC9, STM32G4X_PINMUX_FUNC_PC9_I2C3_SDA},
#endif /* CONFIG_I2C, i2c3 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI
{STM32_PIN_PB3, STM32G4X_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PB4, STM32G4X_PINMUX_FUNC_PB4_SPI1_MISO},
{STM32_PIN_PB5, STM32G4X_PINMUX_FUNC_PB5_SPI1_MOSI},
#endif /* CONFIG_SPI, spi1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb), okay) && CONFIG_USB_DC_STM32
{STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_USB_DM},
{STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_USB_DP},
#endif /* CONFIG_USB_DC_STM32 */
};
static int pinmux_stm32_init(const 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);
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
config BOARD_MPPT_2420_LC
bool "Libre Solar MPPT 2420 LC"
depends on SOC_STM32F072XB
+19
View File
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
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")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+199
View File
@@ -0,0 +1,199 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/f0/stm32f072Xb.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 {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
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 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
&i2c2 {
status = "okay";
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 {
cs-gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&can1 {
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,39 @@
# 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_I2C=y
CONFIG_CAN=y
CONFIG_THINGSET_CAN=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
+71
View File
@@ -0,0 +1,71 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#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, as Zephyr doesn't yet include all possible pinmuxes
#ifndef STM32F0_PINMUX_FUNC_PB6_I2C1_SCL
#define STM32F0_PINMUX_FUNC_PB6_I2C1_SCL \
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
#endif
#ifndef STM32F0_PINMUX_FUNC_PB7_I2C1_SDA
#define STM32F0_PINMUX_FUNC_PB7_I2C1_SDA \
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
#endif
#define STM32F0_PINMUX_FUNC_PA8_TIM1_CH1 \
(STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
#define STM32F0_PINMUX_FUNC_PB13_TIM1_CH1N \
(STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
static const struct pin_config pinconf[] = {
/* TIM1_CH1 and TIM1_CH1N */
{STM32_PIN_PA8, STM32F0_PINMUX_FUNC_PA8_TIM1_CH1},
{STM32_PIN_PB13, STM32F0_PINMUX_FUNC_PB13_TIM1_CH1N},
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL
{STM32_PIN_PA9, STM32F0_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32F0_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) && CONFIG_SERIAL
{STM32_PIN_PA2, STM32F0_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F0_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_SERIAL, usart2 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PB6, STM32F0_PINMUX_FUNC_PB6_I2C1_SCL},
{STM32_PIN_PB7, STM32F0_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C, i2c1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PB10, STM32F0_PINMUX_FUNC_PB10_I2C2_SCL},
{STM32_PIN_PB11, STM32F0_PINMUX_FUNC_PB11_I2C2_SDA},
#endif /* CONFIG_I2C, i2c1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI
{STM32_PIN_PB3, STM32F0_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PB4, STM32F0_PINMUX_FUNC_PB4_SPI1_MISO},
{STM32_PIN_PB5, STM32F0_PINMUX_FUNC_PB5_SPI1_MOSI},
#endif /* CONFIG_SPI, spi1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) && CONFIG_CAN
{STM32_PIN_PB8, STM32F0_PINMUX_FUNC_PB8_CAN_RX},
{STM32_PIN_PB9, STM32F0_PINMUX_FUNC_PB9_CAN_TX},
#endif /* CONFIG_CAN, can1 */
};
static int pinmux_stm32_init(const 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);
@@ -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
}
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
config BOARD_MPPT_2420_RC
bool "Libre Solar MPPT 2420 RC"
depends on SOC_STM32G431XX
+20
View File
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
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)
+228
View File
@@ -0,0 +1,228 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/g4/stm32g431Xb.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 {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
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-ext-sense {
label = "HV external sense and 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
};
};
soc {
// ADC nodes not yet provided by Zephyr, but needed for adc-gain compatibles
adc1: adc@50000000 {
compatible = "st,stm32-adc";
reg = <0x50000000 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00002000>;
interrupts = <18 0>;
status = "disabled";
label = "ADC_1";
#io-channel-cells = <1>;
};
adc2: adc@50000100 {
compatible = "st,stm32-adc";
reg = <0x50000100 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00002000>;
interrupts = <18 0>;
status = "disabled";
label = "ADC_2";
#io-channel-cells = <1>;
};
dac1: dac@50000800 {
compatible = "st,stm32-dac";
reg = <0x50000800 0x400>;
clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00010000>;
status = "disabled";
label = "DAC_1";
#io-channel-cells = <1>;
};
};
aliases {
uart-dbg = &usart1;
uart-uext = &usart2;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
};
&usart1 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&spi1 {
cs-gpios = <&gpiob 6 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";
};
&i2c1 {
/* shared between UEXT and EEPROM */
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>;
};
};
/*
// This requires https://github.com/zephyrproject-rtos/zephyr/pull/22832
&can1 {
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,71 @@
# 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_I2C_1=y
CONFIG_EEPROM=y
CONFIG_EEPROM_AT24=y
# don't enable CAN by default until PR #22832 is merged to upstream Zephyr
#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
+62
View File
@@ -0,0 +1,62 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
#define STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1 \
(STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL)
#define STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N \
(STM32_PINMUX_ALT_FUNC_6 | STM32_PUSHPULL_NOPULL)
static const struct pin_config pinconf[] = {
/* USART1 */
{STM32_PIN_PA9, STM32G4X_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32G4X_PINMUX_FUNC_PA10_USART1_RX},
/* USART2 */
{STM32_PIN_PA2, STM32G4X_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32G4X_PINMUX_FUNC_PA3_USART2_RX},
/* TIM1_CH1 and TIM1_CH1N */
{STM32_PIN_PA8, STM32G4X_PINMUX_FUNC_PA8_TIM1_CH1},
{STM32_PIN_PB13, STM32G4X_PINMUX_FUNC_PB13_TIM1_CH1N},
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PA15, STM32G4X_PINMUX_FUNC_PA15_I2C1_SCL},
{STM32_PIN_PB7, STM32G4X_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C, i2c1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI
{STM32_PIN_PB3, STM32G4X_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PB4, STM32G4X_PINMUX_FUNC_PB4_SPI1_MISO},
{STM32_PIN_PB5, STM32G4X_PINMUX_FUNC_PB5_SPI1_MOSI},
#endif /* CONFIG_SPI, spi1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usb), okay) && CONFIG_USB_DC_STM32
{STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_USB_DM},
{STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_USB_DP},
#endif /* CONFIG_USB_DC_STM32 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay) && CONFIG_CAN
{STM32_PIN_PA11, STM32G4X_PINMUX_FUNC_PA11_FDCAN1_RX},
{STM32_PIN_PA12, STM32G4X_PINMUX_FUNC_PA12_FDCAN1_TX},
#endif
#if defined(CONFIG_USB_DC_STM32) && DT_NODE_HAS_STATUS(DT_NODELABEL(can1), okay)
#error "PINMUX does not allow concurrent USB and CAN."
#endif
};
static int pinmux_stm32_init(const 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);
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
config BOARD_PWM_2420_LUS
bool "Libre Solar PWM 2420 LUS"
depends on SOC_STM32L072XX
+20
View File
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
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")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020 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>
/* this should normally go to drivers/pinmux/stm32/pinmux_stm32l0.h */
#define STM32L0_PINMUX_FUNC_PB1_PWM3_CH4 \
(STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
static const struct pin_config pinconf[] = {
#if DT_NODE_HAS_STATUS(DT_NODELABEL(pwm3), okay)
{STM32_PIN_PB1, STM32L0_PINMUX_FUNC_PB1_PWM3_CH4},
#endif /* CONFIG_PWM, pwm3 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart1), okay) && CONFIG_SERIAL
{STM32_PIN_PA9, STM32L0_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32L0_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_SERIAL || UART_CONSOLE, usart1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usart2), okay) && CONFIG_SERIAL
{STM32_PIN_PA2, STM32L0_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32L0_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_SERIAL, usart2 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(i2c1), okay) && CONFIG_I2C
{STM32_PIN_PB6, STM32L0_PINMUX_FUNC_PB6_I2C1_SCL},
{STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C, i2c1 */
#if DT_NODE_HAS_STATUS(DT_NODELABEL(spi1), okay) && CONFIG_SPI
{STM32_PIN_PB3, STM32L0_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PA11, STM32L0_PINMUX_FUNC_PA11_SPI1_MISO},
{STM32_PIN_PA12, STM32L0_PINMUX_FUNC_PA12_SPI1_MOSI},
#endif /* CONFIG_SPI, spi1 */
};
static int pinmux_stm32_init(const 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);
+197
View File
@@ -0,0 +1,197 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2019 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/l0/stm32l072Xz.dtsi>
/ {
model = "Libre Solar PWM 2420 LUS";
compatible = "st,stm32l072";
pcb {
compatible = "charge-controller";
type = "PWM 2420 LUS";
version-str = "v0.3";
version-num = <3>;
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 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
&spi1 {
cs-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
status = "okay";
};
&iwdg {
status = "okay";
};
&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,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
@@ -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"
}
+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__ */
+1
Submodule lib/oled-display added at 4eec1ea4d8
Submodule
+1
Submodule lib/thingset added at 4b9434d562
-18
View File
@@ -1,18 +0,0 @@
# Custom settings, as referred to as "extra_script" in platformio.ini
#
# See http://docs.platformio.org/en/latest/projectconf.html#extra-script
# and https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#extra-linker-flags-without-wl-prefix
#
# We are setting the required linker flags for use of newlib-nano
Import("env")
env.Append(
LINKFLAGS=[
"-Wl,-u,_printf_float",
"--specs=nano.specs",
"--specs=nosys.specs"
])
env.Append( CXXFLAGS=[ "-Wno-register" ] )
-22
View File
@@ -1,22 +0,0 @@
{
"config": {
"enable-led-control-example": true,
"LED": "NC",
"BUTTON": "NC",
"BUTTON_MODE": "PullUp"
},
"target_overrides": {
"NUCLEO_L073RZ": {
"target.lse_available" : 0,
"target.clock_source" : "USE_PLL_HSI",
"target.stdio_uart_tx" : "PA_9",
"target.stdio_uart_rx" : "PA_10"
},
"NUCLEO_F072RB": {
"target.lse_available" : 0,
"target.clock_source" : "USE_PLL_HSE_XTAL|USE_PLL_HSI",
"target.stdio_uart_tx" : "PA_9",
"target.stdio_uart_rx" : "PA_10"
}
}
}
+8
View File
@@ -0,0 +1,8 @@
# Custom settings, as referred to as "extra_script" in platformio.ini
#
# See http://docs.platformio.org/en/latest/projectconf.html#extra-script
Import("env")
env.Append( CXXFLAGS=[ "-Wno-register -fno-rtti" ] )
+34 -83
View File
@@ -9,16 +9,11 @@
# Select the charge controller hardware by uncommenting one of the following lines
default_envs =
# mppt-2420-lc-v0.10
# mppt-1210-hus-v0.2
# mppt-1210-hus-v0.4
# mppt-1210-hus-v0.6
# mppt-1210-hus-v0.7
# mppt-1210-hus-v0.4-zephyr
# pwm-2420-lus-v0.2
# pwm-2420-lus-v0.3
# pwm-2420-lus-v0.3-bl
# unit-test-native
# mppt_2420_lc
# mppt_2420_rc
# mppt_2420_hpx
# mppt_1210_hus
# pwm_2420_lus
# Or create your own custom.ini file to overwrite settings in this file, e.g. for board selection.
# For further information see here:
@@ -28,19 +23,19 @@ extra_configs =
[env]
# select specific stm32 version, as automatic updates of mbed could break compatibility
platform = ststm32@~5.3.0
#platform = https://github.com/platformio/platform-ststm32.git
platform = ststm32@~8.1.0
framework = mbed
framework = zephyr
# Use customized Zephyr branch from Libre Solar repository
platform_packages = framework-zephyr@https://github.com/LibreSolar/zephyr#v2.4-branch
#upload_protocol = mbed
upload_protocol = stlink
#upload_protocol = jlink
# Custom upload tools (overwrites upload_protocol)
#upload_command = st-flash write $SOURCE 0x8000000
#upload_command = dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D $SOURCE
#debug_tool = jlink
# Custom Serial Monitor baud rate
monitor_speed = 115200
@@ -50,97 +45,53 @@ build_flags =
-std=gnu++17
-fsingle-precision-constant
-Wl,-Map,memory.map
-D TURN_OFF_MBED_DEPRECATED_WARNING
-D DEBUG_PRINT_FLAGS=0x7
-D MBED_BUILD_PROFILE_RELEASE
# -D MBED_BUILD_PROFILE_DEBUG
build_unflags = -std=gnu++98 -std=gnu++14
extra_scripts =
pre:linker_flags_newlib-nano.py
generate_version_file.py
lib_deps =
https://github.com/ThingSet/thingset-cpp
# Below flags are only valid for C++ and create warnings for C files, so we add them as
# CXXFLAGS in extra_script.
build_unflags = -Wno-register -fno-rtti
extra_scripts = platformio-extra.py
check_tool = cppcheck, clangtidy
check_flags =
cppcheck: --enable=warning,style,performance,portability,information,missingInclude -j 7
cppcheck: --enable=warning,style,performance,portability,information,missingInclude -j 7 --inline-suppr
# --addon=addons/misra.py --addon=addons/cert.py
clangtidy: --checks=-*,cert-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,-readability-magic-numbers,-cert-err58-cpp
#### BOARD DEFINITIONS ########################################################
# https://github.com/LibreSolar/MPPT-2420-LC/tree/5bc39183c8
[env:mppt-2420-lc-v0.10]
board = nucleo_f072rb
build_flags = ${env.build_flags}
-D MPPT_2420_LC_0V10
[env:mppt_2420_lc]
board = mppt_2420_lc
# https://github.com/LibreSolar/MPPT-1210-HUS/tree/586626f3d8
[env:mppt-1210-hus-v0.2]
board = nucleo_f072rb
build_flags = ${env.build_flags}
-D MPPT_1210_HUS_0V2
# https://github.com/LibreSolar/mppt-2420-rc
[env:mppt_2420_rc]
board = mppt_2420_rc
# https://github.com/LibreSolar/MPPT-1210-HUS/tree/63e5842671
[env:mppt-1210-hus-v0.4]
board = nucleo_l073rz
build_flags = ${env.build_flags}
-D MPPT_1210_HUS_0V4
# https://github.com/LibreSolar/mppt-1210-hus/releases/tag/v0.6
[env:mppt-1210-hus-v0.6]
board = nucleo_l073rz
build_flags = ${env.build_flags}
-D MPPT_1210_HUS_0V7
# https://github.com/LibreSolar/mppt-2420-hc
[env:mppt_2420_hc]
board = mppt_2420_hc
# https://github.com/LibreSolar/MPPT-1210-HUS
[env:mppt-1210-hus-v0.7]
board = nucleo_l073rz
build_flags = ${env.build_flags}
-D MPPT_1210_HUS_0V7
[env:mppt_1210_hus]
board = mppt_1210_hus
[env:mppt-1210-hus-v0.4-zephyr]
board = mppt1210hus_0v4
framework = zephyr
build_flags =
-std=gnu++17
-fsingle-precision-constant
-Wl,-Map,memory.map
platform = https://github.com/platformio/platform-ststm32.git
lib_ignore = ESP32
extra_scripts = generate_version_file.py
# https://github.com/LibreSolar/mppt-2420-hpx
[env:mppt_2420_hpx]
board = mppt_2420_hpx
# https://github.com/LibreSolar/PWM-2420-LUS
[env:pwm-2420-lus-v0.2]
board = nucleo_l073rz
build_flags = ${env.build_flags}
-D PWM_2420_LUS_0V2
[env:pwm_2420_lus]
board = pwm_2420_lus
[env:pwm-2420-lus-v0.3]
board = nucleo_l073rz
build_flags = ${env.build_flags}
-D PWM_2420_LUS_0V3
[env:pwm-2420-lus-v0.3-bl]
board = nucleo_l073rz
build_flags = ${env.build_flags}
-D PWM_2420_LUS_0V3
-D BOOTLOADER_ENABLED
-Wl,-T'"$PROJECT_DIR\STM32L073XZ.ld.link_script.ld"',-v
[env:unit-test-native]
[env:unit_test]
platform = native
framework =
build_flags =
-std=gnu++17
-Wall
-D LITTLE_ENDIAN
-D UNIT_TEST
-D __STDC_FORMAT_MACROS
-D DEBUG_PRINT_FLAGS=0xF
-D COMMIT_HASH=\"test\"
-I test
# include src directory (otherwise unit-tests will only include lib directory)
test_build_project_src = true
lib_ignore = ESP32, Adafruit_GFX
extra_scripts =
+35
View File
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_include_directories(.)
target_sources(app PRIVATE
bat_charger.cpp
data_nodes.cpp
daq.cpp
daq_driver.c
device_status.cpp
dcdc.cpp
eeprom.cpp
half_bridge.cpp
hardware.cpp
leds.cpp
load.cpp
load_driver.c
main.cpp
power_port.cpp
pwm_switch_driver.c
pwm_switch.cpp
setup.cpp
)
add_subdirectory(ext)
if(${CONFIG_CUSTOM_DATA_NODES_FILE})
target_sources(app PRIVATE data_nodes_custom.cpp)
endif()
# Using this option enables user-specific customization of the firmware. The
# custom subfolder should have its own CMakeLists.txt file.
if(${CONFIG_CUSTOMIZATION})
add_subdirectory(custom build/custom)
endif()
-546
View File
@@ -1,546 +0,0 @@
/*
* Copyright (c) 2016 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "adc_dma.h"
#include <math.h> // log for thermistor calculation
#include <assert.h>
#ifdef __MBED__
#include "mbed.h"
#endif
#include "mcu.h"
#include "main.h"
#include "debug.h"
#include "pcb.h" // contains defines for pins
// factory calibration values for internal voltage reference and temperature sensor
// (see MCU datasheet, not RM)
#if defined(STM32F0)
const uint16_t VREFINT_CAL = *((uint16_t *)0x1FFFF7BA); // VREFINT @3.3V/30°C
#define VREFINT_VALUE 3300 // mV
const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FFFF7B8);
const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FFFF7C2);
#define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point
#define TSENSE_CAL2_VALUE 110.0 // temperature of second calibration point
#elif defined(STM32L0)
const uint16_t VREFINT_CAL = *((uint16_t *)0x1FF80078); // VREFINT @3.0V/25°C
#define VREFINT_VALUE 3000 // mV
const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FF8007A);
const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FF8007E);
#define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point
#define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point
#elif defined(UNIT_TEST)
#define VREFINT_CAL (4096 * 1.224 / 3.0) // VREFINT @3.0V/25°C
#define VREFINT_VALUE 3000 // mV
#define TSENSE_CAL1 (4096.0 * (670 - 161) / 3300) // datasheet: slope 1.61 mV/°C
#define TSENSE_CAL2 (4096.0 * 670 / 3300) // datasheet: 670 mV
#define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point
#define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point
#endif
#if defined(__MBED__) && defined(PIN_REF_I_DCDC)
AnalogOut ref_i_dcdc(PIN_REF_I_DCDC);
#endif
static float solar_current_offset;
static float load_current_offset;
// for ADC and DMA
static volatile uint16_t adc_readings[NUM_ADC_CH] = {};
static volatile uint32_t adc_filtered[NUM_ADC_CH] = {};
static volatile AdcAlert adc_alerts_upper[NUM_ADC_CH] = {};
static volatile AdcAlert adc_alerts_lower[NUM_ADC_CH] = {};
extern DeviceStatus dev_stat;
/**
* Average value for ADC channel
* @param channel valid ADC channel pos ADC_POS_..., see adc_h.c
*/
static inline uint32_t adc_value(uint32_t channel)
{
assert(channel < NUM_ADC_CH);
return adc_filtered[channel] >> (4 + ADC_FILTER_CONST);
}
/**
* Measured voltage for ADC channel after average
* @param channel valid ADC channel pos ADC_POS_..., see adc_h.c
* @param vcc reference voltage in millivolts
*
* @return voltage in millivolts
*/
static inline float adc_voltage(uint32_t channel, int32_t vcc)
{
return (adc_value(channel) * vcc) / 4096;
}
/**
* Measured current/voltage for ADC channel after average and scaling
* @param channel valid ADC channel pos ADC_POS_..., see adc_h.c
* @param vcc reference voltage in millivolts
*
* @return scaled final value
*/
static inline float adc_scaled(uint32_t channel, int32_t vcc, const float gain)
{
return adc_voltage(channel,vcc) * (gain/1000.0);
}
static inline float ntc_temp(uint32_t channel, int32_t vcc)
{
/** \todo Improved (faster) temperature calculation:
https://www.embeddedrelated.com/showarticle/91.php
*/
float v_temp = adc_voltage(channel, vcc); // voltage read by ADC (mV)
float rts = NTC_SERIES_RESISTOR * v_temp / (vcc - v_temp); // resistance of NTC (Ohm)
return 1.0/(1.0/(273.15+25) + 1.0/NTC_BETA_VALUE*log(rts/10000.0)) - 273.15; // °C
}
void calibrate_current_sensors()
{
int vcc = VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU);
#if FEATURE_PWM_SWITCH
solar_current_offset = -adc_scaled(ADC_POS_I_SOLAR, vcc, ADC_GAIN_I_SOLAR);
#endif
#if FEATURE_DCDC_CONVERTER
solar_current_offset = -adc_scaled(ADC_POS_I_DCDC, vcc, ADC_GAIN_I_DCDC);
#endif
load_current_offset = -adc_scaled(ADC_POS_I_LOAD, vcc, ADC_GAIN_I_LOAD);
}
void adc_update_value(unsigned int pos)
{
// low pass filter with filter constant c = 1/(2^ADC_FILTER_CONST)
// y(n) = c * x(n) + (c - 1) * y(n-1)
// see also here: http://techteach.no/simview/lowpass_filter/doc/filter_algorithm.pdf
#if FEATURE_PWM_SWITCH == 1
if (pos == ADC_POS_V_SOLAR || pos == ADC_POS_I_SOLAR) {
// only read input voltage and current when switch is on or permanently off
if (pwm_switch.signal_high() || pwm_switch.active() == false) {
adc_filtered[pos] += (uint32_t)adc_readings[pos] - (adc_filtered[pos] >> ADC_FILTER_CONST);
}
}
else
#endif
{
// adc_readings: 12-bit ADC values left-aligned in uint16_t
adc_filtered[pos] += (uint32_t)adc_readings[pos] - (adc_filtered[pos] >> ADC_FILTER_CONST);
}
// check upper alerts
adc_alerts_upper[pos].debounce_ms++;
if (adc_alerts_upper[pos].callback != NULL &&
adc_readings[pos] >= adc_alerts_upper[pos].limit)
{
if (adc_alerts_upper[pos].debounce_ms > 1) {
// create function pointer and call function
adc_alerts_upper[pos].callback();
}
}
else if (adc_alerts_upper[pos].debounce_ms > 0) {
// reset debounce ms counter only if already close to triggering to allow setting negative
// values to specify a one-time inhibit delay
adc_alerts_upper[pos].debounce_ms = 0;
}
// same for lower alerts
adc_alerts_lower[pos].debounce_ms++;
if (adc_alerts_lower[pos].callback != NULL &&
adc_readings[pos] <= adc_alerts_lower[pos].limit)
{
if (adc_alerts_lower[pos].debounce_ms > 1) {
adc_alerts_lower[pos].callback();
}
}
else if (adc_alerts_lower[pos].debounce_ms > 0) {
adc_alerts_lower[pos].debounce_ms = 0;
}
}
//----------------------------------------------------------------------------
void update_measurements()
{
// reference voltage of 2.5 V at PIN_V_REF
//int vcc = 2500 * 4096 / (adc_filtered[ADC_POS_V_REF] >> (4 + ADC_FILTER_CONST));
// internal STM reference voltage
int vcc = VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU);
// rely on LDO accuracy
//int vcc = 3300;
// calculate lower voltage first, as it is needed for PWM terminal voltage calculation
lv_terminal.voltage = adc_scaled(ADC_POS_V_BAT, vcc, ADC_GAIN_V_BAT);
load_terminal.voltage = lv_terminal.voltage;
#if FEATURE_DCDC_CONVERTER
hv_terminal.voltage = adc_scaled(ADC_POS_V_SOLAR, vcc, ADC_GAIN_V_SOLAR);
dcdc_lv_port.voltage = lv_terminal.voltage;
#endif
#if FEATURE_PWM_SWITCH
pwm_terminal.voltage = lv_terminal.voltage - vcc * (ADC_OFFSET_V_SOLAR / 1000.0) -
adc_scaled(ADC_POS_V_SOLAR, vcc, ADC_GAIN_V_SOLAR);
pwm_port_int.voltage = lv_terminal.voltage;
#endif
load_terminal.current =
adc_scaled(ADC_POS_I_LOAD, vcc, ADC_GAIN_I_LOAD) + load_current_offset;
#if FEATURE_PWM_SWITCH
// current multiplied with PWM duty cycle for PWM charger to get avg current for correct power calculation
pwm_port_int.current = pwm_switch.get_duty_cycle() * (
adc_scaled(ADC_POS_I_SOLAR, vcc, ADC_GAIN_I_SOLAR) + solar_current_offset);
pwm_terminal.current = -pwm_port_int.current;
lv_terminal.current = pwm_port_int.current - load_terminal.current;
pwm_port_int.power = pwm_port_int.voltage * pwm_port_int.current;
pwm_terminal.power = pwm_terminal.voltage * pwm_terminal.current;
#endif
#if FEATURE_DCDC_CONVERTER
dcdc_lv_port.current =
adc_scaled(ADC_POS_I_DCDC, vcc, ADC_GAIN_I_DCDC) + solar_current_offset;
lv_terminal.current = dcdc_lv_port.current - load_terminal.current;
hv_terminal.current = -dcdc_lv_port.current * lv_terminal.voltage / hv_terminal.voltage;
dcdc_lv_port.power = dcdc_lv_port.voltage * dcdc_lv_port.current;
hv_terminal.power = hv_terminal.voltage * hv_terminal.current;
#endif
lv_terminal.power = lv_terminal.voltage * lv_terminal.current;
load_terminal.power = load_terminal.voltage * load_terminal.current;
#ifdef PIN_ADC_TEMP_BAT
// battery temperature calculation
float bat_temp = ntc_temp(ADC_POS_TEMP_BAT, vcc);
if (bat_temp > -50) {
// external sensor connected: take measured value
charger.bat_temperature = bat_temp;
charger.ext_temp_sensor = true;
}
else {
// no external sensor: assume typical room temperature
charger.bat_temperature = 25;
charger.ext_temp_sensor = false;
}
#endif
#ifdef PIN_ADC_TEMP_FETS
// MOSFET temperature calculation
dcdc.temp_mosfets = ntc_temp(ADC_POS_TEMP_FETS, vcc);
#endif
// internal MCU temperature
uint16_t adcval = adc_value(ADC_POS_TEMP_MCU) * vcc / VREFINT_VALUE;
dev_stat.internal_temp = (TSENSE_CAL2_VALUE - TSENSE_CAL1_VALUE) /
(TSENSE_CAL2 - TSENSE_CAL1) * (adcval - TSENSE_CAL1) + TSENSE_CAL1_VALUE;
if (dev_stat.internal_temp > 80) {
dev_stat.set_error(ERR_INT_OVERTEMP);
}
else if (dev_stat.internal_temp < 70 && (dev_stat.has_error(ERR_INT_OVERTEMP))) {
// remove error flag with hysteresis of 10°C
dev_stat.clear_error(ERR_INT_OVERTEMP);
}
// else: keep previous setting
}
void high_voltage_alert()
{
// disable any sort of input
#if FEATURE_DCDC_CONVERTER
dcdc.emergency_stop();
#endif
#if FEATURE_PWM_SWITCH
pwm_switch.emergency_stop();
#endif
// do not use enter_state function, as we don't want to wait entire recharge delay
charger.state = CHG_STATE_IDLE;
dev_stat.set_error(ERR_BAT_OVERVOLTAGE);
print_error("High voltage alert, ADC reading: %d limit: %d\n",
adc_readings[ADC_POS_V_BAT], adc_alerts_upper[ADC_POS_V_BAT].limit);
}
void low_voltage_alert()
{
// the battery undervoltage must have been caused by a load current peak
load.stop(ERR_LOAD_VOLTAGE_DIP);
print_error("Low voltage alert, ADC reading: %d limit: %d\n",
adc_readings[ADC_POS_V_BAT], adc_alerts_lower[ADC_POS_V_BAT].limit);
}
void adc_upper_alert_inhibit(int adc_pos, int timeout_ms)
{
// set negative value so that we get a final debouncing of this timeout + the original
// delay in the alert function (currently only waiting for 2 samples = 2 ms)
adc_alerts_upper[adc_pos].debounce_ms = -timeout_ms;
}
uint16_t adc_get_alert_limit(float scale, float limit)
{
const float adclimit = (UINT16_MAX >> 4); // 12 bits ADC resolution
const float limit_scaled = limit * scale;
// even if we have a higher voltage limit, we must limit it
// to the max value the ADC will be able to deliver
return (limit_scaled > adclimit ? 0x0FFF : (uint16_t)(limit_scaled)) << 4;
// shift 4 bits left to generate left aligned 16bit value
}
void adc_set_lv_alerts(float upper, float lower)
{
int vcc = VREFINT_VALUE * VREFINT_CAL / adc_value(ADC_POS_VREF_MCU);
float scale = ((4096* 1000) / (ADC_GAIN_V_BAT)) / vcc;
// LV side (battery) overvoltage alert
adc_alerts_upper[ADC_POS_V_BAT].limit = adc_get_alert_limit(scale, upper);
adc_alerts_upper[ADC_POS_V_BAT].callback = high_voltage_alert;
// LV side (battery) undervoltage alert
adc_alerts_lower[ADC_POS_V_BAT].limit = adc_get_alert_limit(scale, lower);
adc_alerts_lower[ADC_POS_V_BAT].callback = low_voltage_alert;
}
#if defined(__MBED__) && !defined(UNIT_TEST)
void dma_setup()
{
//__HAL_RCC_DMA1_CLK_ENABLE();
/* Enable the peripheral clock on DMA */
RCC->AHBENR |= RCC_AHBENR_DMA1EN;
/* Enable DMA transfer on ADC and circular mode */
ADC1->CFGR1 |= ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG;
/* Configure the peripheral data register address */
DMA1_Channel1->CPAR = (uint32_t)(&(ADC1->DR));
/* Configure the memory address */
DMA1_Channel1->CMAR = (uint32_t)(&(adc_readings[0]));
/* Configure the number of DMA tranfer to be performed on DMA channel 1 */
DMA1_Channel1->CNDTR = NUM_ADC_CH;
/* Configure increment, size, interrupts and circular mode */
DMA1_Channel1->CCR =
DMA_CCR_MINC | /* memory increment mode enabled */
DMA_CCR_MSIZE_0 | /* memory size 16-bit */
DMA_CCR_PSIZE_0 | /* peripheral size 16-bit */
DMA_CCR_TEIE | /* transfer error interrupt enable */
DMA_CCR_TCIE | /* transfer complete interrupt enable */
DMA_CCR_CIRC; /* circular mode enable */
/* DIR = 0: read from peripheral */
/* Enable DMA Channel 1 */
DMA1_Channel1->CCR |= DMA_CCR_EN;
/* Configure NVIC for DMA (priority 2: second-lowest value for STM32L0/F0) */
NVIC_SetPriority(DMA1_Channel1_IRQn, 2);
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
// Trigger ADC conversions
ADC1->CR |= ADC_CR_ADSTART;
}
extern "C" void DMA1_Channel1_IRQHandler(void)
{
if ((DMA1->ISR & DMA_ISR_TCIF1) != 0) // Test if transfer completed on DMA channel 1
{
for (unsigned int i = 0; i < NUM_ADC_CH; i++) {
adc_update_value(i);
}
}
DMA1->IFCR |= 0x0FFFFFFF; // clear all interrupt registers
}
void adc_setup()
{
#ifdef PIN_REF_I_DCDC
ref_i_dcdc = 0.1; // reference voltage for zero current (0.1 for buck, 0.9 for boost, 0.5 for bi-directional)
#endif
#ifdef PIN_V_SOLAR_EN
DigitalOut solar_en(PIN_V_SOLAR_EN);
solar_en = 1;
#endif
ADC_HandleTypeDef hadc = {0};
ADC_ChannelConfTypeDef sConfig = {0};
__HAL_RCC_ADC1_CLK_ENABLE();
// Configure ADC object structures
hadc.Instance = ADC1;
hadc.State = HAL_ADC_STATE_RESET;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_LEFT; // for exponential moving average filter
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = ENABLE; //DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
if (HAL_ADC_Init(&hadc) != HAL_OK) {
error("Cannot initialize ADC");
}
#if defined(STM32L0)
HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED);
#else
HAL_ADCEx_Calibration_Start(&hadc);
#endif
// Configure ADC channel
sConfig.Channel = ADC_CHANNEL_0; // can be any channel for initialization
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
// Clear all channels as it is not done in HAL_ADC_ConfigChannel()
hadc.Instance->CHSELR = 0;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) {
error("Cannot initialize ADC");
}
HAL_ADC_Start(&hadc); // Start conversion
// Read out value one time to finish ADC configuration
if (HAL_ADC_PollForConversion(&hadc, 10) == HAL_OK) {
HAL_ADC_GetValue(&hadc);
}
// ADC sampling time register
// 000: 1.5 ADC clock cycles
// 001: 7.5 ADC clock cycles
// 010: 13.5 ADC clock cycles
// 011: 28.5 ADC clock cycles
// 100: 41.5 ADC clock cycles
// 101: 55.5 ADC clock cycles
// 110: 71.5 ADC clock cycles
// 111: 239.5 ADC clock cycles
//ADC1->SMPR = ADC_SMPR_SMP_1; // for normal ADC OK
ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2; // necessary for internal reference and temperature
// Select ADC channels based on setup in config.h
ADC1->CHSELR = ADC_CHSEL;
// Enable internal voltage reference and temperature sensor
// ToDo check sample rate
ADC->CCR |= ADC_CCR_TSEN | ADC_CCR_VREFEN;
}
#endif // UNIT_TEST
#if defined(STM32F0)
void adc_timer_start(int freq_Hz) // max. 10 kHz
{
// Enable TIM15 clock
RCC->APB2ENR |= RCC_APB2ENR_TIM15EN;
// Set timer clock to 10 kHz
TIM15->PSC = SystemCoreClock / 10000 - 1;
// Interrupt on timer update
TIM15->DIER |= TIM_DIER_UIE;
// Auto Reload Register sets interrupt frequency
TIM15->ARR = 10000 / freq_Hz - 1;
// 2 = second-lowest priority of STM32L0/F0
NVIC_SetPriority(TIM15_IRQn, 2);
NVIC_EnableIRQ(TIM15_IRQn);
// Control Register 1
// TIM_CR1_CEN = 1: Counter enable
TIM15->CR1 |= TIM_CR1_CEN;
}
extern "C" void TIM15_IRQHandler(void)
{
TIM15->SR &= ~(1 << 0);
ADC1->CR |= ADC_CR_ADSTART;
}
#elif defined(STM32L0)
void adc_timer_start(int freq_Hz) // max. 10 kHz
{
// Enable TIM6 clock
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
// Set timer clock to 10 kHz
TIM6->PSC = SystemCoreClock / 10000 - 1;
// Interrupt on timer update
TIM6->DIER |= TIM_DIER_UIE;
// Auto Reload Register sets interrupt frequency
TIM6->ARR = 10000 / freq_Hz - 1;
// 2 = second-lowest priority of STM32L0/F0
NVIC_SetPriority(TIM6_IRQn, 2);
NVIC_EnableIRQ(TIM6_IRQn);
// Control Register 1
// TIM_CR1_CEN = 1: Counter enable
TIM6->CR1 |= TIM_CR1_CEN;
}
extern "C" void TIM6_IRQHandler(void)
{
TIM6->SR &= ~(1 << 0);
ADC1->CR |= ADC_CR_ADSTART;
}
#else
#include "../test/adc_dma_stub.h"
void prepare_adc_readings(AdcValues values)
{
adc_readings[ADC_POS_VREF_MCU] = (uint16_t)(1.224 / 3.3 * 4096) << 4;
adc_readings[ADC_POS_V_SOLAR] = (uint16_t)((values.solar_voltage / (ADC_GAIN_V_SOLAR)) / 3.3 * 4096) << 4;
adc_readings[ADC_POS_V_BAT] = (uint16_t)((values.battery_voltage / (ADC_GAIN_V_BAT)) / 3.3 * 4096) << 4;
adc_readings[ADC_POS_I_DCDC] = (uint16_t)((values.dcdc_current / (ADC_GAIN_I_DCDC)) / 3.3 * 4096) << 4;
adc_readings[ADC_POS_I_LOAD] = (uint16_t)((values.load_current / (ADC_GAIN_I_LOAD)) / 3.3 * 4096) << 4;
}
void prepare_adc_filtered()
{
// initialize also filtered values
for (int i = 0; i < NUM_ADC_CH; i++) {
adc_filtered[i] = adc_readings[i] << ADC_FILTER_CONST;
}
}
void clear_adc_filtered()
{
// initialize also filtered values
for (int i = 0; i < NUM_ADC_CH; i++) {
adc_filtered[i] = 0;
}
}
uint32_t get_adc_filtered(uint32_t channel)
{
return adc_value(channel);
}
#endif
-69
View File
@@ -1,69 +0,0 @@
/*
* Copyright (c) 2016 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ADC_DMA_H
#define ADC_DMA_H
/** @file
*
* @brief Reads ADC via DMA and stores data into necessary structs
*/
#include "dcdc.h"
#include "load.h"
#include "bat_charger.h"
#define ADC_FILTER_CONST 5 // filter multiplier = 1/(2^ADC_FILTER_CONST)
/** Struct to definie upper and lower limit alerts for any ADC channel
*/
typedef struct {
void (*callback)() = NULL; ///< Function to be called when limits are exceeded
uint16_t limit = 0; ///< ADC reading for lower limit
int debounce_ms = 0; ///< Milliseconds delay for triggering alert
} AdcAlert;
/** Sets offset to actual measured value, i.e. sets zero current point.
*
* All input/output switches and consumers should be switched off before calling this function
*/
void calibrate_current_sensors();
/** Updates structures with data read from ADC
*/
void update_measurements();
/** Initializes registers and starts ADC timer
*/
void adc_timer_start(int freq_Hz);
/** Sets necessary ADC registers
*/
void adc_setup(void);
/** Sets necessary DMA registers
*/
void dma_setup(void);
/** Read, filter and check raw ADC readings stored by DMA controller
*/
void adc_update_value(unsigned int pos);
/** Set lv side (battery) voltage limits where an alert should be triggered
*
* @param upper Upper voltage limit
* @param lower Lower voltage limit
*/
void adc_set_lv_alerts(float upper, float lower);
/** Add an inhibit delay to the alerts to disable it temporarily
*
* @param adc_pos The position of the ADC measurement channel
* @param timeout_ms Timeout in milliseconds
*/
void adc_upper_alert_inhibit(int adc_pos, int timeout_ms);
#endif /* ADC_DMA */
+280 -151
View File
@@ -5,30 +5,44 @@
*/
#include "bat_charger.h"
#include "config.h"
#include "pcb.h"
#include "device_status.h"
extern DeviceStatus dev_stat;
#include <zephyr.h>
#ifndef UNIT_TEST
#include <logging/log.h>
LOG_MODULE_REGISTER(bat_charger, CONFIG_LOG_DEFAULT_LEVEL);
#endif
#include <math.h> // for fabs function
#include <stdio.h>
#include <time.h>
void battery_conf_init(BatConf *bat, BatType type, int num_cells, float nominal_capacity)
#include "helper.h"
#include "device_status.h"
extern DeviceStatus dev_stat;
extern LoadOutput load;
// DISCHARGE_CURRENT_MAX used to estimate current-compensation of load disconnect voltage
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load))
#define DISCHARGE_CURRENT_MAX DT_PROP(DT_CHILD(DT_PATH(outputs), load), current_max)
#else
#define DISCHARGE_CURRENT_MAX DT_PROP(DT_PATH(dcdc), current_max)
#endif
void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capacity)
{
bat->nominal_capacity = nominal_capacity;
// 1C should be safe for all batteries
bat->charge_current_max = bat->nominal_capacity;
bat->charge_current_max = bat->nominal_capacity;
bat->discharge_current_max = bat->nominal_capacity;
bat->time_limit_recharge = 60; // sec
bat->topping_duration = 120*60; // sec
bat->topping_duration = 120*60; // sec
bat->charge_temp_max = 50;
bat->charge_temp_min = -10;
bat->discharge_temp_max = 50;
bat->charge_temp_max = 50;
bat->charge_temp_min = -10;
bat->discharge_temp_max = 50;
bat->discharge_temp_min = -10;
switch (type)
@@ -36,95 +50,153 @@ void battery_conf_init(BatConf *bat, BatType type, int num_cells, float nominal_
case BAT_TYPE_FLOODED:
case BAT_TYPE_AGM:
case BAT_TYPE_GEL:
bat->voltage_absolute_max = num_cells * 2.45;
bat->topping_voltage = num_cells * 2.4;
bat->voltage_recharge = num_cells * 2.3;
bat->voltage_absolute_max = static_cast<float>(num_cells) * 2.45F;
bat->topping_voltage = static_cast<float>(num_cells) * 2.4F;
bat->voltage_recharge = static_cast<float>(num_cells) * 2.3F;
// Cell-level thresholds based on EN 62509:2011 (both thresholds current-compensated)
bat->voltage_load_disconnect = num_cells * 1.95;
bat->voltage_load_reconnect = num_cells * 2.10;
bat->voltage_load_disconnect = static_cast<float>(num_cells) * 1.95F;
bat->voltage_load_reconnect = static_cast<float>(num_cells) * 2.10F;
// assumption: Battery selection matching charge controller
bat->internal_resistance = num_cells * (1.95 - 1.80) / LOAD_CURRENT_MAX;
bat->internal_resistance = static_cast<float>(num_cells) * (1.95F - 1.80F) /
DISCHARGE_CURRENT_MAX;
bat->voltage_absolute_min = num_cells * 1.6;
bat->voltage_absolute_min = static_cast<float>(num_cells) * 1.6F;
// Voltages during idle (no charging/discharging current)
bat->ocv_full = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.10 : 2.15);
bat->ocv_empty = num_cells * 1.90;
bat->ocv_full = static_cast<float>(num_cells) *
((type == BAT_TYPE_FLOODED) ? 2.10F : 2.15F);
bat->ocv_empty = static_cast<float>(num_cells) * 1.90F;
// https://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
bat->topping_current_cutoff = bat->nominal_capacity * 0.04; // 3-5 % of C/1
bat->topping_current_cutoff = bat->nominal_capacity * 0.04F; // 3-5 % of C/1
bat->trickle_enabled = true;
bat->trickle_recharge_time = 30*60;
bat->trickle_enabled = true;
bat->trickle_recharge_time = 30*60;
// Values as suggested in EN 62509:2011
bat->trickle_voltage = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.35 : 2.3);
bat->trickle_voltage = static_cast<float>(num_cells) *
((type == BAT_TYPE_FLOODED) ? 2.35F : 2.3F);
// Enable for flooded batteries only, according to
// https://discoverbattery.com/battery-101/equalizing-flooded-batteries-only
bat->equalization_enabled = false;
bat->equalization_enabled = false;
// Values as suggested in EN 62509:2011
bat->equalization_voltage = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.50 : 2.45);
bat->equalization_duration = 60*60;
bat->equalization_current_limit = (1.0 / 7.0) * bat->nominal_capacity;
bat->equalization_voltage = static_cast<float>(num_cells) *
((type == BAT_TYPE_FLOODED) ? 2.50F : 2.45F);
bat->equalization_duration = 60*60;
bat->equalization_current_limit = (1.0F / 7.0F) * bat->nominal_capacity;
bat->equalization_trigger_days = 60;
bat->equalization_trigger_deep_cycles = 10;
bat->temperature_compensation = -0.003; // -3 mV/°C/cell
bat->temperature_compensation = -0.003F; // -3 mV/°C/cell
break;
case BAT_TYPE_LFP:
bat->voltage_absolute_max = num_cells * 3.60;
bat->topping_voltage = num_cells * 3.55; // CV voltage
bat->voltage_recharge = num_cells * 3.35;
bat->voltage_absolute_max = static_cast<float>(num_cells) * 3.60F;
bat->topping_voltage = static_cast<float>(num_cells) * 3.55F; // CV voltage
bat->voltage_recharge = static_cast<float>(num_cells) * 3.35F;
bat->voltage_load_disconnect = num_cells * 3.0;
bat->voltage_load_reconnect = num_cells * 3.15;
bat->voltage_load_disconnect = static_cast<float>(num_cells) * 3.00F;
bat->voltage_load_reconnect = static_cast<float>(num_cells) * 3.15F;
// 5% voltage drop at max current
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 / LOAD_CURRENT_MAX;
bat->voltage_absolute_min = num_cells * 2.0;
bat->internal_resistance = bat->voltage_load_disconnect * 0.05F /
DISCHARGE_CURRENT_MAX;
bat->voltage_absolute_min = static_cast<float>(num_cells) * 2.0F;
bat->ocv_full = num_cells * 3.4; // will give really nonlinear SOC calculation
bat->ocv_empty = num_cells * 3.0; // because of flat OCV of LFP cells...
// will give really nonlinear SOC calculation because of flat OCV of LFP cells...
bat->ocv_full = static_cast<float>(num_cells) * 3.4F;
bat->ocv_empty = static_cast<float>(num_cells) * 3.0F;
// C/10 cut-off at end of CV phase by default
bat->topping_current_cutoff = bat->nominal_capacity / 10;
bat->trickle_enabled = false;
bat->equalization_enabled = false;
bat->temperature_compensation = 0.0;
bat->temperature_compensation = 0;
bat->charge_temp_min = 0;
break;
case BAT_TYPE_NMC:
case BAT_TYPE_NMC_HV:
bat->topping_voltage = num_cells * ((type == BAT_TYPE_NMC_HV) ? 4.35 : 4.20);
bat->voltage_absolute_max = bat->topping_voltage + num_cells * 0.05;
bat->voltage_recharge = num_cells * 3.9;
bat->topping_voltage = static_cast<float>(num_cells) *
((type == BAT_TYPE_NMC_HV) ? 4.35F : 4.20F);
bat->voltage_absolute_max = bat->topping_voltage +
static_cast<float>(num_cells) * 0.05F;
bat->voltage_recharge = static_cast<float>(num_cells) * 3.9F;
bat->voltage_load_disconnect = num_cells * 3.3;
bat->voltage_load_reconnect = num_cells * 3.6;
bat->voltage_load_disconnect = static_cast<float>(num_cells) * 3.3F;
bat->voltage_load_reconnect = static_cast<float>(num_cells) * 3.6F;
// 5% voltage drop at max current
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 / LOAD_CURRENT_MAX;
bat->internal_resistance = bat->voltage_load_disconnect * 0.05F /
DISCHARGE_CURRENT_MAX;
bat->voltage_absolute_min = num_cells * 2.5;
bat->voltage_absolute_min = static_cast<float>(num_cells) * 2.5F;
bat->ocv_full = num_cells * 4.0;
bat->ocv_empty = num_cells * 3.0;
bat->ocv_full = static_cast<float>(num_cells) * 4.0F;
bat->ocv_empty = static_cast<float>(num_cells) * 3.0F;
// C/10 cut-off at end of CV phase by default
bat->topping_current_cutoff = bat->nominal_capacity / 10;
bat->topping_current_cutoff = bat->nominal_capacity / 10;
bat->trickle_enabled = false;
bat->equalization_enabled = false;
bat->temperature_compensation = 0.0;
bat->temperature_compensation = 0;
bat->charge_temp_min = 0;
break;
case BAT_TYPE_NONE:
case BAT_TYPE_CUSTOM:
bat->voltage_absolute_max = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_ABS_MAX_VOLTAGE_MV);
bat->topping_voltage = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_TOPPING_VOLTAGE_MV);
bat->voltage_recharge = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_RECHARGE_VOLTAGE_MV);
bat->voltage_load_disconnect = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_DISCONNECT_VOLTAGE_MV);
bat->voltage_load_reconnect = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_RECONNECT_VOLTAGE_MV);
bat->internal_resistance = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_INTERNAL_RESISTANCE_MOHM);
bat->voltage_absolute_min = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_ABS_MIN_VOLTAGE_MV);
// Voltages during idle (no charging/discharging current)
bat->ocv_full = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_OCV_FULL_MV);
bat->ocv_empty = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_OCV_EMPTY_MV);
// https://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
bat->topping_current_cutoff = bat->nominal_capacity * 0.04F; // 3-5 % of C/1
bat->trickle_enabled = IS_ENABLED(CONFIG_CELL_TRICKLE);
bat->trickle_recharge_time = CONFIG_CELL_TRICKLE_RECHARGE_TIME;
bat->trickle_voltage = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_TRICKLE_VOLTAGE_MV);
bat->equalization_enabled = IS_ENABLED(CONFIG_CELL_EQUALIZATION);
bat->equalization_voltage = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_EQUALIZATION_VOLTAGE_MV);
bat->equalization_duration = CONFIG_CELL_EQUALIZATION_DURATION;
bat->equalization_current_limit = (1.0F / 7.0F) * bat->nominal_capacity;
bat->equalization_trigger_days = CONFIG_CELL_EQUALIZATION_TRIGGER_DAYS;
bat->equalization_trigger_deep_cycles = CONFIG_CELL_EQUALIZATION_TRIGGER_DEEP_CYCLES;
bat->temperature_compensation = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_TEMP_COMPENSATION_MV_K);
bat->charge_temp_max = CONFIG_BAT_CHARGE_TEMP_MAX;
bat->charge_temp_min = CONFIG_BAT_CHARGE_TEMP_MIN;
bat->discharge_temp_max = CONFIG_BAT_DISCHARGE_TEMP_MAX;
bat->discharge_temp_min = CONFIG_BAT_DISCHARGE_TEMP_MIN;
break;
}
}
@@ -137,36 +209,35 @@ bool battery_conf_check(BatConf *bat_conf)
// - cutoff current not extremely low/high
// - capacity plausible
/*
printf("battery_conf_check: %d %d %d %d %d %d %d\n",
LOG_DBG("battery_conf_check: %d %d %d %d %d %d %d",
bat_conf->voltage_load_reconnect > (bat_conf->voltage_load_disconnect + 0.6),
bat_conf->voltage_recharge < (bat_conf->voltage_max - 0.4),
bat_conf->voltage_recharge < (bat_conf->topping_voltage - 0.4),
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1),
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4),
bat_conf->current_cutoff_CV < (bat_conf->nominal_capacity / 10.0), // C/10 or lower allowed
bat_conf->current_cutoff_CV > 0.01,
bat_conf->topping_current_cutoff < (bat_conf->nominal_capacity / 10.0),
bat_conf->topping_current_cutoff > 0.01,
(bat_conf->trickle_enabled == false ||
(bat_conf->trickle_voltage < bat_conf->voltage_max &&
(bat_conf->trickle_voltage < bat_conf->topping_voltage &&
bat_conf->trickle_voltage > bat_conf->voltage_load_disconnect))
);
*/
return
(bat_conf->voltage_load_reconnect > (bat_conf->voltage_load_disconnect + 0.4) &&
return (
bat_conf->voltage_load_reconnect > (bat_conf->voltage_load_disconnect + 0.4) &&
bat_conf->voltage_recharge < (bat_conf->topping_voltage - 0.4) &&
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1) &&
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4) &&
// max. 10% drop
bat_conf->internal_resistance < bat_conf->voltage_load_disconnect * 0.1 / LOAD_CURRENT_MAX &&
bat_conf->internal_resistance < bat_conf->voltage_load_disconnect * 0.1 /
DISCHARGE_CURRENT_MAX &&
// max. 3% loss
bat_conf->wire_resistance < bat_conf->topping_voltage * 0.03 / LOAD_CURRENT_MAX &&
bat_conf->wire_resistance < bat_conf->topping_voltage * 0.03 / DISCHARGE_CURRENT_MAX &&
// C/10 or lower current cutoff allowed
bat_conf->topping_current_cutoff < (bat_conf->nominal_capacity / 10.0) &&
bat_conf->topping_current_cutoff > 0.01 &&
(bat_conf->trickle_enabled == false ||
(bat_conf->trickle_voltage < bat_conf->topping_voltage &&
bat_conf->trickle_voltage > bat_conf->voltage_load_disconnect))
);
);
}
void battery_conf_overwrite(BatConf *source, BatConf *destination, Charger *charger)
@@ -208,11 +279,37 @@ void battery_conf_overwrite(BatConf *source, BatConf *destination, Charger *char
// - restart DC/DC
}
void Charger::detect_num_batteries(BatConf *bat)
bool battery_conf_changed(BatConf *a, BatConf *b)
{
if (port->voltage > bat->voltage_absolute_min * 2 &&
port->voltage < bat->voltage_absolute_max * 2) {
num_batteries = 2;
return (
a->topping_voltage != b->topping_voltage ||
a->voltage_recharge != b->voltage_recharge ||
a->voltage_load_reconnect != b->voltage_load_reconnect ||
a->voltage_load_disconnect != b->voltage_load_disconnect ||
a->voltage_absolute_max != b->voltage_absolute_max ||
a->voltage_absolute_min != b->voltage_absolute_min ||
a->charge_current_max != b->charge_current_max ||
a->topping_current_cutoff != b->topping_current_cutoff ||
a->topping_duration != b->topping_duration ||
a->trickle_enabled != b->trickle_enabled ||
a->trickle_voltage != b->trickle_voltage ||
a->trickle_recharge_time != b->trickle_recharge_time ||
a->charge_temp_max != b->charge_temp_max ||
a->charge_temp_min != b->charge_temp_min ||
a->discharge_temp_max != b->discharge_temp_max ||
a->discharge_temp_min != b->discharge_temp_min ||
a->temperature_compensation != b->temperature_compensation ||
a->internal_resistance != b->internal_resistance ||
a->wire_resistance != b->wire_resistance
);
}
void Charger::detect_num_batteries(BatConf *bat) const
{
if (port->bus->voltage > bat->voltage_absolute_min * 2 &&
port->bus->voltage < bat->voltage_absolute_max * 2)
{
port->bus->series_multiplier = 2;
printf("Detected two batteries (total %.2f V max)\n", bat->topping_voltage * 2);
}
else {
@@ -225,7 +322,7 @@ void Charger::update_soc(BatConf *bat_conf)
static int soc_filtered = 0; // SOC / 100 for better filtering
if (fabs(port->current) < 0.2) {
int soc_new = (int)((port->voltage - bat_conf->ocv_empty) /
int soc_new = (int)((port->bus->voltage - bat_conf->ocv_empty) /
(bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0);
if (soc_new > 500 && soc_filtered == 0) {
@@ -246,46 +343,61 @@ void Charger::update_soc(BatConf *bat_conf)
soc = soc_filtered / 100;
}
discharged_Ah += -port->current / 3600.0; // charged current is positive: change sign
discharged_Ah += -port->current / 3600.0F; // charged current is positive: change sign
}
void Charger::enter_state(int next_state)
{
//printf("Enter State: %d\n", next_state);
time_state_changed = time(NULL);
LOG_DBG("Enter State: %d", next_state);
time_state_changed = uptime();
state = next_state;
}
void Charger::discharge_control(BatConf *bat_conf)
{
// load output state is defined by battery negative current limit
if (port->neg_current_limit < 0) {
// discharging currently allowed. see if that's still valid:
if (port->voltage < num_batteries *
(bat_conf->voltage_load_disconnect - port->current * port->neg_droop_res))
{
// low state of charge
port->neg_current_limit = 0;
num_deep_discharges++;
dev_stat.set_error(ERR_BAT_UNDERVOLTAGE);
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load)) || \
DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), usb_pwr))
if (usable_capacity < 0.1) {
if (!empty) {
// as we don't have a proper SOC estimation, we determine an empty battery by the main
// load output being switched off
if (flags_check(&load.error_flags, ERR_LOAD_SHEDDING)) {
empty = true;
num_deep_discharges++;
if (usable_capacity == 0.0F) {
// reset to measured value if discharged the first time
if (first_full_charge_reached) {
usable_capacity = discharged_Ah;
}
usable_capacity = discharged_Ah;
}
else {
// slowly adapt new measurements with low-pass filter
usable_capacity =
0.8 * usable_capacity +
0.2 * discharged_Ah;
0.8F * usable_capacity +
0.2F * discharged_Ah;
}
// simple SOH estimation
soh = usable_capacity / bat_conf->nominal_capacity;
}
else if (bat_temperature > bat_conf->discharge_temp_max) {
}
else {
if (!flags_check(&load.error_flags, ERR_LOAD_SHEDDING)) {
empty = false;
}
}
// negative current limit = allowed battery discharge current
if (port->neg_current_limit < 0) {
// This limit should normally never be reached, as the load output settings should be
// higher. The flag can be used to trigger actions of last resort, e.g. deep-sleep
// of the charge controller itself.
if (port->bus->voltage < port->bus->src_control_voltage(bat_conf->voltage_absolute_min)) {
port->neg_current_limit = 0;
dev_stat.set_error(ERR_BAT_UNDERVOLTAGE);
}
if (bat_temperature > bat_conf->discharge_temp_max) {
port->neg_current_limit = 0;
dev_stat.set_error(ERR_BAT_DIS_OVERTEMP);
}
@@ -296,21 +408,29 @@ void Charger::discharge_control(BatConf *bat_conf)
}
else {
// discharging currently not allowed. should we allow it?
if (port->voltage >= num_batteries *
(bat_conf->voltage_load_reconnect - port->current * port->neg_droop_res)
&& bat_temperature < bat_conf->discharge_temp_max - 1
&& bat_temperature > bat_conf->discharge_temp_min + 1)
if (port->bus->voltage >=
port->bus->src_control_voltage(bat_conf->voltage_absolute_min + 0.1F))
{
dev_stat.clear_error(ERR_BAT_UNDERVOLTAGE);
}
if (bat_temperature < bat_conf->discharge_temp_max - 1 &&
bat_temperature > bat_conf->discharge_temp_min + 1)
{
dev_stat.clear_error(ERR_BAT_DIS_OVERTEMP | ERR_BAT_DIS_UNDERTEMP);
}
if (!dev_stat.has_error(
ERR_BAT_UNDERVOLTAGE | ERR_BAT_DIS_OVERTEMP | ERR_BAT_DIS_UNDERTEMP))
{
// discharge current is stored as absolute value in bat_conf, but defined
// as negative current for power port
port->neg_current_limit = -bat_conf->discharge_current_max;
// delete all discharge error flags
dev_stat.clear_error(ERR_BAT_DIS_OVERTEMP);
dev_stat.clear_error(ERR_BAT_DIS_UNDERTEMP);
dev_stat.clear_error(ERR_BAT_UNDERVOLTAGE);
}
}
#endif
}
void Charger::charge_control(BatConf *bat_conf)
@@ -328,7 +448,7 @@ void Charger::charge_control(BatConf *bat_conf)
}
if (dev_stat.has_error(ERR_BAT_OVERVOLTAGE) &&
port->voltage < (bat_conf->voltage_absolute_max - 0.5) * num_batteries)
port->bus->voltage < (bat_conf->voltage_absolute_max - 0.5F) * port->bus->series_multiplier)
{
dev_stat.clear_error(ERR_BAT_OVERVOLTAGE);
}
@@ -336,13 +456,14 @@ void Charger::charge_control(BatConf *bat_conf)
// state machine
switch (state) {
case CHG_STATE_IDLE: {
if (port->voltage < bat_conf->voltage_recharge * num_batteries
&& (time(NULL) - time_state_changed) > bat_conf->time_limit_recharge
if (port->bus->voltage < port->bus->sink_control_voltage(bat_conf->voltage_recharge)
&& port->bus->voltage > port->bus->sink_control_voltage(bat_conf->voltage_absolute_min) // ToDo set error flag otherwise
&& (uptime() - time_state_changed) > bat_conf->time_limit_recharge
&& bat_temperature < bat_conf->charge_temp_max - 1
&& bat_temperature > bat_conf->charge_temp_min + 1)
{
port->sink_voltage_max = num_batteries * (bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
port->pos_current_limit = bat_conf->charge_current_max;
full = false;
dev_stat.clear_error(ERR_BAT_CHG_OVERTEMP);
@@ -354,51 +475,53 @@ void Charger::charge_control(BatConf *bat_conf)
}
case CHG_STATE_BULK: {
// continuously adjust voltage setting for temperature compensation
port->sink_voltage_max = num_batteries * (bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
if (port->voltage > num_batteries *
(port->sink_voltage_max - port->current * port->pos_droop_res))
{
if (port->bus->voltage > port->bus->sink_control_voltage()) {
target_voltage_timer = 0;
enter_state(CHG_STATE_TOPPING);
}
break;
}
case CHG_STATE_TOPPING: {
// continuously adjust voltage setting for temperature compensation
port->sink_voltage_max = num_batteries * (bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
if (port->voltage >= num_batteries *
(port->sink_voltage_max - port->current * port->pos_droop_res))
{
time_voltage_limit_reached = time(NULL);
if (port->bus->voltage >= port->bus->sink_control_voltage() - 0.05F) {
// battery is full if topping target voltage is still reached (i.e. sufficient
// solar power available) and time limit or cut-off current reached
if (port->current < bat_conf->topping_current_cutoff ||
target_voltage_timer > bat_conf->topping_duration)
{
full = true;
}
target_voltage_timer++;
}
else if (uptime() - time_state_changed > 8 * 60 * 60) {
// in topping phase already for 8 hours (i.e. not enough solar power available)
// --> go back to bulk charging for the next day
enter_state(CHG_STATE_BULK);
}
// cut-off limit reached because battery full (i.e. CV limit still
// reached by available solar power within last 2s) or CV period long enough?
if ((port->current < bat_conf->topping_current_cutoff &&
(time(NULL) - time_voltage_limit_reached) < 2)
|| (time(NULL) - time_state_changed) > bat_conf->topping_duration)
{
full = true;
if (full) {
num_full_charges++;
discharged_Ah = 0; // reset coulomb counter
first_full_charge_reached = true;
if (bat_conf->equalization_enabled && (
(time(NULL) - time_last_equalization) / (24*60*60)
(uptime() - time_last_equalization) / (24*60*60)
>= bat_conf->equalization_trigger_days ||
num_deep_discharges - deep_dis_last_equalization
>= bat_conf->equalization_trigger_deep_cycles))
{
port->sink_voltage_max = bat_conf->equalization_voltage;
port->bus->sink_voltage_intercept = bat_conf->equalization_voltage;
port->pos_current_limit = bat_conf->equalization_current_limit;
enter_state(CHG_STATE_EQUALIZATION);
}
else if (bat_conf->trickle_enabled) {
port->sink_voltage_max = num_batteries * (bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
enter_state(CHG_STATE_TRICKLE);
}
else {
@@ -410,42 +533,41 @@ void Charger::charge_control(BatConf *bat_conf)
}
case CHG_STATE_TRICKLE: {
// continuously adjust voltage setting for temperature compensation
port->sink_voltage_max = num_batteries * (bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
if (port->voltage >= num_batteries *
(port->sink_voltage_max - port->current * port->pos_droop_res))
{
time_voltage_limit_reached = time(NULL);
if (port->bus->voltage >= port->bus->sink_control_voltage()) {
time_target_voltage_reached = uptime();
}
if (time(NULL) - time_voltage_limit_reached > bat_conf->trickle_recharge_time)
if (uptime() - time_target_voltage_reached > bat_conf->trickle_recharge_time)
{
// the battery was discharged: trickle voltage could not be reached anymore
port->pos_current_limit = bat_conf->charge_current_max;
full = false;
// assumption: trickle does not harm the battery --> never go back to idle
// (for Li-ion battery: disable trickle!)
enter_state(CHG_STATE_BULK);
}
// assumption: trickle does not harm the battery --> never go back to idle
// (for Li-ion battery: disable trickle!)
break;
}
case CHG_STATE_EQUALIZATION: {
// continuously adjust voltage setting for temperature compensation
port->sink_voltage_max = num_batteries * (bat_conf->equalization_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->equalization_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
// current or time limit for equalization reached
if (time(NULL) - time_state_changed > bat_conf->equalization_duration)
if (uptime() - time_state_changed > bat_conf->equalization_duration)
{
// reset triggers
time_last_equalization = time(NULL);
time_last_equalization = uptime();
deep_dis_last_equalization = num_deep_discharges;
discharged_Ah = 0; // reset coulomb counter again
if (bat_conf->trickle_enabled) {
port->sink_voltage_max = num_batteries * (bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25));
port->bus->sink_voltage_intercept = bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
enter_state(CHG_STATE_TRICKLE);
}
else {
@@ -458,21 +580,28 @@ void Charger::charge_control(BatConf *bat_conf)
}
}
void battery_init_dc_bus(PowerPort *port, BatConf *bat, unsigned int num_batteries)
void Charger::init_terminal(BatConf *bat) const
{
unsigned int n = (num_batteries == 2 ? 2 : 1); // only 1 or 2 allowed
port->bus->sink_voltage_intercept = bat->topping_voltage;
port->bus->src_voltage_intercept = bat->voltage_load_disconnect;
port->src_voltage_start = bat->voltage_load_reconnect * n;
port->src_voltage_stop = bat->voltage_load_disconnect * n;
port->neg_current_limit = -bat->discharge_current_max;
// negative sign for compensation of actual resistance
port->neg_droop_res = -(bat->internal_resistance + -bat->wire_resistance) * n;
port->sink_voltage_max = bat->topping_voltage * n;
port->sink_voltage_min = bat->voltage_absolute_min * n;
port->pos_current_limit = bat->charge_current_max;
// negative sign for compensation of actual resistance
port->pos_droop_res = -bat->wire_resistance * n;
/*
* Negative sign for compensation of actual resistance
*
* droop_res is multiplied with number of series connected batteries to calculate control
* voltage, so we need to divide by number of batteries here for correction
*/
port->bus->sink_droop_res = -bat->wire_resistance /
static_cast<float>(port->bus->series_multiplier);
/*
* In discharging direction also include battery internal resistance for current-compensation
* of voltage setpoints
*/
port->bus->src_droop_res = -bat->wire_resistance /
static_cast<float>(port->bus->series_multiplier)
- bat->internal_resistance;
}
+216 -90
View File
@@ -15,13 +15,18 @@
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <time.h>
#include "power_port.h"
/** Battery cell types
/**
* Battery cell types
*/
enum BatType {
BAT_TYPE_NONE = 0, ///< Safe standard settings
/*
* IMPORTANT: make sure to adjust also boards/Kconfig if enum is changed here!
*/
BAT_TYPE_CUSTOM = 0, ///< Custom battery type
BAT_TYPE_FLOODED, ///< Old flooded (wet) lead-acid batteries
BAT_TYPE_GEL, ///< VRLA gel batteries (maintainance-free)
BAT_TYPE_AGM, ///< AGM batteries (maintainance-free)
@@ -30,131 +35,153 @@ enum BatType {
BAT_TYPE_NMC_HV ///< NMC/Graphite High Voltage Li-ion batteries (3.7V nominal, 4.35 max)
};
/** Battery configuration data
/**
* Battery configuration data
*
* Data will be initialized in battery_init depending on configured cell type in config.h.
*/
typedef struct
{
/** Nominal battery capacity or sum of parallel cells capacity (Ah)
/**
* Nominal battery capacity or sum of parallel cells capacity (Ah)
*
* The nominal capacity is used for SOC calculation and definition of current limits.
*/
float nominal_capacity;
/** Recharge voltage (V)
/**
* Recharge voltage (V)
*
* Start charging again if voltage of fully charged battery drops below this threshold.
*
* Remark: Setting the value too close to the max voltage will cause more charging stress on lithium based batteries.
* Remark: Setting the value too close to the max voltage will cause more charging stress on
* lithium based batteries.
*/
float voltage_recharge;
/** Recharge time limit (sec)
/**
* Recharge time limit (sec)
*
* Start charging of previously fully charged battery earliest after this period of time.
*/
int time_limit_recharge;
int32_t time_limit_recharge;
/** Absolute maximum voltage (V)
/**
* Absolute maximum voltage (V)
*
* Above this voltage the battery or loads might get damaged.
*/
float voltage_absolute_max;
/** Absolute minimum voltage (V)
/**
* Absolute minimum voltage (V)
*
* Below this voltage the battery is considered damaged.
*/
float voltage_absolute_min;
/** Maximum charge current in *CC/bulk* phase (A)
/**
* Maximum charge current in *CC/bulk* phase (A)
*
* Limits the current if the PCB allows more than the battery. (positive value)
*/
float charge_current_max;
/** Maximum discharge current via load port (A)
/**
* Maximum discharge current via load port (A)
*
* Limits the current if the PCB allows more than the battery. (positive value)
*/
float discharge_current_max;
/** Maximum voltage in CV/absorption phase (V)
/**
* Maximum voltage in CV/absorption phase (V)
*
* Charger target voltage, switching from CC to CV at this voltage threshold.
*/
float topping_voltage;
/** CV phase cut-off current limit (A)
/**
* CV phase cut-off current limit (A)
*
* Constant voltage charging phase stopped if current is below this value.
*/
float topping_current_cutoff;
/** CV phase cut-off time limit (s)
/**
* CV phase cut-off time limit (s)
*
* After this time, CV charging is stopped independent of current.
*/
int topping_duration;
int32_t topping_duration;
/** Enable float/trickle charging
/**
* Enable float/trickle charging
*
* Caution: Do not enable trickle charging for lithium-ion batteries
*/
bool trickle_enabled;
/** Trickle voltage (V)
/**
* Trickle voltage (V)
*
* Charger target voltage for trickle charging of lead-acid batteries
*/
float trickle_voltage;
/** Trickle recharge time (s)
/**
* Trickle recharge time (s)
*
* If the trickle voltage is not reached anymore (e.g. because of lack of solar
* input power) for this period of time, the charger state machine goes back
* into CC/bulk charging mode.
*/
int trickle_recharge_time;
int32_t trickle_recharge_time;
/** Enable equalization charging
/**
* Enable equalization charging
*
* Caution: Do not enable trickle charging for lithium-ion batteries
*/
bool equalization_enabled;
/** Equalization voltage (V)
/**
* Equalization voltage (V)
*
* Charger target voltage for equalization charging of lead-acid batteries
*/
float equalization_voltage;
/** Equalization cut-off time limit (s)
/**
* Equalization cut-off time limit (s)
*
* After this time, equalization charging is stopped.
*/
int equalization_duration;
int32_t equalization_duration;
/** Equalization phase maximum current (A)
/**
* Equalization phase maximum current (A)
*
* The current of the charger is controlled to stay below this limit during equalization.
*/
float equalization_current_limit;
/** Equalization trigger time interval (days)
/**
* Equalization trigger time interval (days)
*
* After passing specified amount of days, an equalization charge is triggered.
*/
int equalization_trigger_days;
int32_t equalization_trigger_days;
/** Equalization trigger deep-discharge cycles
/**
* Equalization trigger deep-discharge cycles
*
* After specified number of deep discharges, an equalization charge is triggered.
*/
int equalization_trigger_deep_cycles;
int32_t equalization_trigger_deep_cycles;
/** Load disconnect open circuit voltage (V)
/**
* Load disconnect open circuit voltage (V)
*
* Load output is disabled if battery voltage is below this threshold.
*
@@ -165,7 +192,8 @@ typedef struct
*/
float voltage_load_disconnect;
/** Load reconnect open circuit voltage (V)
/**
* Load reconnect open circuit voltage (V)
*
* Re-enable the load only after charged beyond this value.
*
@@ -176,43 +204,62 @@ typedef struct
*/
float voltage_load_reconnect;
/** Battery internal resistance (Ohm)
/**
* Battery internal resistance (Ohm)
*
* Resistance value for current-compensation of load switch voltage thresholds.
*
* The value must have a positive sign. Only resistance values leading to less than 10% voltage drop at max. current are allowed.
* The value must have a positive sign. Only resistance values leading to less than 10% voltage
* drop at max. current are allowed.
*/
float internal_resistance;
/** Resistance of wire between charge controller and battery (Ohm)
/**
* Resistance of wire between charge controller and battery (Ohm)
*
* Resistance value for current-compensation of charging voltages.
*
* The value must have a positive sign. Only resistance values leading to less than 3% voltage loss at max. current are allowed.
* The value must have a positive sign. Only resistance values leading to less than 3% voltage
* loss at max. current are allowed.
*/
float wire_resistance;
// used to calculate state of charge information
/**
* Open circuit voltage of full battery (V)
*
* Used for simple state of charge (SOC) algorithm.
*/
float ocv_full;
/**
* Open circuit voltage of empty battery (V)
*
* Used for simple state of charge (SOC) algorithm.
*/
float ocv_empty;
/** Maximum allowed charging temperature of the battery (°C)
/**
* Maximum allowed charging temperature of the battery (°C)
*/
float charge_temp_max;
/** Minimum allowed charging temperature of the battery (°C)
/**
* Minimum allowed charging temperature of the battery (°C)
*/
float charge_temp_min;
/** Maximum allowed discharging temperature of the battery (°C)
/**
* Maximum allowed discharging temperature of the battery (°C)
*/
float discharge_temp_max;
/** Minimum allowed discharging temperature of the battery (°C)
/**
* Minimum allowed discharging temperature of the battery (°C)
*/
float discharge_temp_min;
/** Voltage compensation based on battery temperature (mV/K/cell)
/**
* Voltage compensation based on battery temperature (mV/K/cell)
*
* Suggested value: -3 mV/K/cell
*/
@@ -220,7 +267,8 @@ typedef struct
} BatConf;
/** Charger configuration and battery state
/**
* Charger configuration and battery state
*/
class Charger
{
@@ -230,60 +278,123 @@ public:
PowerPort *port;
unsigned int state; ///< Current charger state (see enum ChargerState)
int num_batteries = 1; ///< Used for automatic 12V/24V battery detection at
///< start-up (can be 1 or 2 only)
float bat_temperature = 25; ///< Battery temperature in °C from ext. temperature sensor
///< (if existing)
bool ext_temp_sensor; ///< True if external temperature sensor was detected
float usable_capacity; ///< Estimated usable capacity (Ah) based on coulomb counting
float discharged_Ah; ///< Coulomb counter for SOH calculation
uint16_t num_full_charges; ///< Number of full charge cycles
uint16_t num_deep_discharges; ///< Number of deep-discharge cycles
uint16_t soc = 100; ///< State of Charge (%)
uint16_t soh = 100; ///< State of Health (%)
int time_state_changed; ///< Timestamp of last state change
int time_voltage_limit_reached; ///< Last time the CV limit was reached
int time_last_equalization; ///< Timestamp after finish of last equalization charge
int deep_dis_last_equalization; ///< Deep discharge counter value after last equalization
bool full; ///< Flag to indicate if battery was fully charged
bool first_full_charge_reached = false;
//< Set to true if battery was fully charged at least once
///< (necessary for proper capacity estimation)
/** Detect if two batteries are connected in series (12V/24V auto-detection)
/**
* Current charger state (see enum ChargerState)
*/
void detect_num_batteries(BatConf *bat);
uint32_t state;
/** Discharging control update (for load output), should be called once per second
/**
* Battery temperature (°C) from ext. temperature sensor (if existing)
*/
float bat_temperature = 25;
/**
* Flag to indicate if external temperature sensor was detected
*/
bool ext_temp_sensor;
/**
* Estimated usable capacity (Ah) based on coulomb counting
*/
float usable_capacity;
/**
* Coulomb counter for SOH calculation
*/
float discharged_Ah;
/**
* Number of full charge cycles
*/
uint16_t num_full_charges;
/**
* Number of deep-discharge cycles
*/
uint16_t num_deep_discharges;
/**
* State of Charge (%)
*/
uint16_t soc = 100;
/**
* State of Health (%)
*/
uint16_t soh = 100;
/**
* Timestamp of last state change
*/
time_t time_state_changed;
/**
* Last time the CV limit was reached
*/
time_t time_target_voltage_reached;
/**
* Counts the number of seconds during which the target voltage of current charging phase was
* reached.
*/
int target_voltage_timer;
/**
* Timestamp after finish of last equalization charge
*/
time_t time_last_equalization;
/**
* Deep discharge counter value after last equalization
*/
int deep_dis_last_equalization;
/**
* Flag to indicate if battery was fully charged
*/
bool full;
/**
* Flag to indicate if battery was completely discharged
*/
bool empty;
/**
* Detect if two batteries are connected in series (12V/24V auto-detection)
*/
void detect_num_batteries(BatConf *bat) const;
/**
* Discharging control update (for load output), should be called once per second
*/
void discharge_control(BatConf *bat_conf);
/** Charger state machine update, should be called once per second
/**
* Charger state machine update, should be called once per second
*/
void charge_control(BatConf *bat_conf);
/** SOC estimation
/**
* SOC estimation
*
* Must be called exactly once per second, otherwise SOC calculation gets wrong.
*/
void update_soc(BatConf *bat_conf);
/**
* Initialize terminal and dc bus for battery connection
*
* @param bat Configuration to be used for terminal setpoints
*/
void init_terminal(BatConf *bat) const;
private:
void enter_state(int next_state);
};
/** Possible charger states
/**
* Possible charger states
*
* Further information:
* - https://en.wikipedia.org/wiki/IUoU_battery_charging
@@ -291,21 +402,24 @@ private:
*/
enum ChargerState {
/** Idle
/**
* Idle
*
* Initial state of the charge controller. If the solar voltage is high enough
* and the battery is not full, bulk charging mode is started.
*/
CHG_STATE_IDLE,
/** Bulk / CC / MPPT charging
/**
* Bulk / CC / MPPT charging
*
* The battery is charged with maximum possible current (MPPT algorithm is
* active) until the CV voltage limit is reached.
*/
CHG_STATE_BULK,
/** Topping / CV / absorption charging
/**
* Topping / 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
@@ -314,7 +428,8 @@ enum ChargerState {
*/
CHG_STATE_TOPPING,
/** Trickle charging
/**
* 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
@@ -322,7 +437,8 @@ enum ChargerState {
*/
CHG_STATE_TRICKLE,
/** Equalization charging
/**
* 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
@@ -333,28 +449,38 @@ enum ChargerState {
CHG_STATE_EQUALIZATION
};
/** Basic initialization of battery configuration
/**
* Basic initialization of battery configuration
*
* Configures battery based on settings defined in config.h and initializes
* bat_user with same values
*
* @param bat Battery configuration that should be initialized
* @param type Battery type, one of enum BatType (declared as int instead of enum BatType because
* configuration via Kconfig symbol cannot handle enums)
* @param num_cells Number of cells (e.g. 6 for 12V lead-acid battery)
* @param nominal_capacity Nominal capacity (Ah)
*/
void battery_conf_init(BatConf *bat, BatType type, int num_cells, float nominal_capacity);
void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capacity);
/** Checks battery user settings for plausibility
/**
* Checks battery user settings for plausibility
*/
bool battery_conf_check(BatConf *bat);
/** Overwrites battery settings (config should be checked first)
/**
* Overwrites battery settings (config should be checked first)
*
* Settings specified in bat_user will be copied to actual battery_t,
* if suggested updates are valid (includes plausibility check!)
*/
void battery_conf_overwrite(BatConf *source, BatConf *destination, Charger *charger = NULL);
/** Initialize dc bus for battery connection
/**
* Checks if incoming configuration is different to current configuration
*
* @param num_batteries definies the number of series connected batteries, e.g. 2 for 24V system
* Returns true if changed
*/
void battery_init_dc_bus(PowerPort *port, BatConf *bat, unsigned int num_batteries);
bool battery_conf_changed(BatConf *a, BatConf *b);
#endif /* BAT_CHARGER_H */
-138
View File
@@ -1,138 +0,0 @@
/*
* Copyright (c) 2019 Scene Connect Ltd.
*
* This code is based on the bootloader developed by Okra Solar.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef BOOTLOADER_ENABLED
#include "bl_support.h"
#include "stm32l0xx.h"
#include "debug.h"
/**
* Unlock the FLASH control register access and the program memory access.
*/
void flash_unlock(void)
{
if (HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PRGLOCK)) {
/* Unlocking FLASH_PECR register access*/
if (HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PELOCK)) {
WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY1);
WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY2);
}
/* Unlocking the program memory access */
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY1);
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY2);
}
else {
// Error handler
}
}
/**
* Program a word at a specified address in the flash memory.
* (1) Perform the data write (32-bit word) at the desired address
* (2) Wait until the BSY bit is reset in the FLASH_SR register
* (3) Check the EOP flag in the FLASH_SR register
* (4) clear it by software by writing it at 1
*/
void flash_program(uint32_t address, uint32_t data)
{
/* Program word (32-bit) at a specified address.*/
*(__IO uint32_t *)address = data;
while ((FLASH->SR & FLASH_SR_BSY) != 0) { /* (2) */
/* For robust implementation, add here time-out management */
}
if ((FLASH->SR & FLASH_SR_EOP) != 0) { /* (3) */
FLASH->SR = FLASH_SR_EOP; /* (4) */
}
else {
/* Manage the error cases */
}
}
/**
* Function to write the bootloader status to the flash address 'BOOTLOADER_STATUS_STRUCT_ADDR'.
* @param status: The struct containing the bootloader status information.
*/
void write_status_reg(BootloaderStatus& status)
{
// Make sure the status reg is halfword aligned
// Check if this is really required.
static_assert(sizeof(status) % 2 == 0);
// Unlock the FLASH_PECR register access.
// Then unlock the program memory access.
flash_unlock();
/*
* Erase a page in the Flash at BOOTLOADER_STATUS_STRUCT_ADDR - For STM32L073RZ
* (1) Set the ERASE and PROG bits in the FLASH_PECR register to enable page erasing
* (2) Write a 32-bit word value in an address of the selected page to start the erase sequence
* (3) Wait until the BSY bit is reset in the FLASH_SR register
* (4) Check the EOP flag in the FLASH_SR register
* (5) Clear EOP flag by software by writing EOP at 1
* (6) Reset the ERASE and PROG bits in the FLASH_PECR register to disable the page erase
* Program and erase control register (FLASH_PECR) - This register can only be written after a
* good write sequence done in FLASH_PEKEYR, resetting the PELOCK bit.
*/
FLASH->PECR |= FLASH_PECR_ERASE | FLASH_PECR_PROG;
*(__IO uint32_t *)BOOTLOADER_STATUS_STRUCT_ADDR = (uint32_t)0;
while ((FLASH->SR & FLASH_SR_BSY) != 0) {
/* For robust implementation, add here time-out management */
}
if ((FLASH->SR & FLASH_SR_EOP) != 0) {
FLASH->SR = FLASH_SR_EOP;
}
else {
/* Manage the error cases */
}
FLASH->PECR &= ~(FLASH_PECR_ERASE | FLASH_PECR_PROG);
/*
* Write status struct to the flash
* (1) Set the PROG and FPRG bits in the FLASH_PECR register to enable a half page programming
* (2) Perform the data write (half-word) at the desired address
* (3) Wait until the BSY bit is reset in the FLASH_SR register
* (4) Check the EOP flag in the FLASH_SR register
* (5) clear it by software by writing it at 1
* (6) Reset the PROG and FPRG bits to disable programming
*/
uint32_t *data = (uint32_t *)&status;
uint32_t address = BOOTLOADER_STATUS_STRUCT_ADDR;
for (unsigned int i = 0; i < sizeof(status) / sizeof(uint32_t); i++) {
flash_program(address, *data);
data++;
address += 4;
}
// Locking FLASH_PECR register again
// Set the PRGLOCK Bit to lock the FLASH Registers access
SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
}
// Called from main
void check_bootloader(void)
{
//print_info("App1...\r\n");
// Read the bootloader status from the flash memory location
BootloaderStatus status_reg = *((BootloaderStatus *)BOOTLOADER_STATUS_STRUCT_ADDR);
// If the Bootloader Status is ATTEMPT_NEW_APP, change it to STABLE_APP
if (status_reg.status == BootloaderState::ATTEMPT_NEW_APP) {
status_reg.status = BootloaderState::STABLE_APP;
write_status_reg(status_reg); // Write the status to flash
//print_info("Switched to stable app...\r\n");
}
}
#endif /*BOOTLOADER_ENABLED*/
-86
View File
@@ -1,86 +0,0 @@
/*
* Copyright (c) 2019 Scene Connect Ltd.
*
* This code is based on the bootloader developed by Okra Solar.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef BL_SUPPORT_H
#define BL_SUPPORT_H
#ifdef BOOTLOADER_ENABLED
#include <cstdint>
#include "config.h"
/** Length of the bootloader name string (including \0 termination) */
const uint8_t BOOTLADER_NAME_LENGTH = 18;
/**
* Flash address for the bootloader status structure.
* This address must be aligned to a flash page. Each time a new application
* is detected by the bootloader (BootloaderState::newApp),
* the full page is erased, and the updated struct is written to the address
*/
const uint32_t BOOTLOADER_STATUS_STRUCT_ADDR = 0x0802FF80; // The last flash page
/**
* Bootloader state enumeration. This state needs to be set to "newApp"
* by the application after an update, and to "stableApp" after the
* first successful boot
*/
enum BootloaderState {
NO_STATE = 0, ///< State not properly initialized
NEW_APP, ///< Set By App after download of the binary
ATTEMPT_NEW_APP, ///< Set by Bootloader when first booting the new binary
STABLE_APP, ///< Set by App after sucessful boot of the new app
};
/**
* Bootloader status struct. This struct's status field should be updated
* in flash by the app after first boot (stableApp) or after an update of the
* other firmware binary (newApp)
*/
struct BootloaderStatus {
char bootloader_name[BOOTLADER_NAME_LENGTH];
uint32_t bootloader_version;
uint32_t status; ///< Update this field and write to flash in your app!
uint32_t live_app_select;
uint32_t retry_count;
};
/**
* Write the bootloader status to the flash address 'BOOTLOADER_STATUS_STRUCT_ADDR'.
*
* @param status: The struct containing the bootloader status information.
*/
void write_status_reg(BootloaderStatus &status);
/**
* Unlock the FLASH control register access and the program memory access.
*/
void flash_unlock(void);
/**
* Program a word at a specified address in the flash memory.
* (1) Perform the data write (32-bit word) at the desired address
* (2) Wait until the BSY bit is reset in the FLASH_SR register
* (3) Check the EOP flag in the FLASH_SR register
* (4) clear it by software by writing it at 1
*
* @param address The flash address to write to.
* @param data The data to write to the flash.
*/
void flash_program(uint32_t address, uint32_t data);
/**
* Called from main. This implements the bootloader status update from the application side.
*/
void check_bootloader(void);
#endif /* BOOTLOADER_ENABLED */
#endif /* BL_SUPPORT_H */

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