Replace the register-level half_bridge.c module by the new half-bridge drivers. The Dcdc class gets the half-bridge device injected via its constructor, so that the emulated driver can be used in unit tests. Board devicetrees are migrated to the new compatibles: - TIM1 boards use libresolar,stm32-half-bridge with complementary outputs on channel 1. The ADC trigger via OC6/TRGO2 is enabled for the STM32G4 boards as before. - MPPT 1210 HUS uses libresolar,stm32-half-bridge with TIM3 channel 3 (high side) and channel 4 (low side). - Nucleo G474RE uses libresolar,stm32-hrtim-half-bridge. The HRTIM node gets the timer clock source as second clock. Instead of the half-bridge compatible, the halfbridge node label is now used to detect if the board has a DC/DC converter. The half-bridge unit tests are removed, as they are superseded by the driver test suite in tests/drivers/half_bridge. Note for out-of-tree boards: Nodes with "half-bridge" compatible must be migrated to one of the new compatibles, and the deadtime property was renamed to deadtime-ns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
2.6 KiB
C++
93 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) The Libre Solar Project Contributors
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include "hardware.h"
|
|
|
|
#include "helper.h"
|
|
#include "leds.h"
|
|
#include "load.h"
|
|
#include "mcu.h"
|
|
#include "setup.h"
|
|
|
|
#ifndef UNIT_TEST
|
|
|
|
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), boot0))
|
|
#define BOOT0_NODE DT_CHILD(DT_PATH(outputs), boot0)
|
|
#endif
|
|
|
|
#include <zephyr/drivers/gpio.h>
|
|
#include <zephyr/sys/reboot.h>
|
|
|
|
LOG_MODULE_REGISTER(hardware, CONFIG_HW_LOG_LEVEL);
|
|
|
|
void start_stm32_bootloader()
|
|
{
|
|
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), boot0))
|
|
// pin is connected to BOOT0 via resistor and capacitor
|
|
const struct gpio_dt_spec boot0 = GPIO_DT_SPEC_GET(BOOT0_NODE, gpios);
|
|
if (device_is_ready(boot0.port)) {
|
|
gpio_pin_configure_dt(&boot0, GPIO_OUTPUT_ACTIVE);
|
|
k_sleep(K_MSEC(100)); // wait for capacitor at BOOT0 pin to charge up
|
|
reset_device();
|
|
}
|
|
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
|
|
if ((FLASH->CR & FLASH_CR_OPTLOCK) != 0U) {
|
|
/* Authorizes the Option Byte register programming */
|
|
FLASH->OPTKEYR = FLASH_OPTKEY1;
|
|
FLASH->OPTKEYR = FLASH_OPTKEY2;
|
|
}
|
|
|
|
// Set proper bits for booting the embedded bootloader (see table
|
|
// 5 in section 2.6.1 in document RM0440)
|
|
|
|
// nBOOT0: nBOOT0 option bit (equivalent to the BOOT0 pin)
|
|
// nSWBOOT0: 0: BOOT0 taken from the option bit nBOOT0
|
|
// nSWBOOT0: 1: BOOT0 taken from PB8/BOOT0 pin
|
|
// nBOOT1: Together with the BOOT0 pin, this bit selects boot mode
|
|
// from the Flash main memory, SRAM1 or the System memory.
|
|
|
|
FLASH->OPTR &= ~(FLASH_OPTR_nSWBOOT0 | FLASH_OPTR_nBOOT0);
|
|
FLASH->OPTR |= FLASH_OPTR_nBOOT1;
|
|
|
|
// Save the current registers in flash, to be reloaded at reset
|
|
FLASH->CR |= FLASH_CR_OPTSTRT;
|
|
k_sleep(K_MSEC(20));
|
|
|
|
// Reload the option registers from flash; should trigger a system
|
|
// reset.
|
|
FLASH->CR |= FLASH_CR_OBL_LAUNCH;
|
|
|
|
// If OBL_LAUNCH did not reset (it should), we'll force it by
|
|
// first locking back the flash registers and going for a reboot.
|
|
FLASH->CR |= FLASH_CR_OPTLOCK;
|
|
reset_device();
|
|
#endif
|
|
}
|
|
|
|
void reset_device()
|
|
{
|
|
sys_reboot(SYS_REBOOT_COLD);
|
|
}
|
|
|
|
void task_wdt_callback(int channel_id, void *user_data)
|
|
{
|
|
printk("Task watchdog callback (channel: %d, thread: %s)\n", channel_id,
|
|
k_thread_name_get((k_tid_t)user_data));
|
|
|
|
printk("Resetting device...\n");
|
|
|
|
sys_reboot(SYS_REBOOT_COLD);
|
|
}
|
|
|
|
#else
|
|
|
|
// dummy functions for unit tests
|
|
void start_stm32_bootloader() {}
|
|
void reset_device() {}
|
|
void task_wdt_callback(int channel_id, void *user_data) {}
|
|
|
|
#endif /* UNIT_TEST */
|