Commit b11893f4 authored by Clément Foucher's avatar Clément Foucher
Browse files

Adapt code for Zephyr 2.6.

- Quick (and dirty) fix to replace deprecated `CONFIG_CLOCK_STM32_APB2_PRESCALER` symbol;
- Replace deprecated `device_pm_control_nop` macro by `NULL`;
- Remove NEWLIB config that causes compilation errors (multiple definition of mutex-related functions included by kernel.h);
- Update NGND driver to use Zephyr's new GPIO device tree interface.
parent b4af377f
......@@ -17,7 +17,7 @@ extra_configs = src/owntech.ini
framework = zephyr
platform = ststm32
platform = ststm32@14.1.0
# Serial monitor baud rate
monitor_speed = 115200
......
description: GPIO parent node
description: Neutral-Ground Switch
compatible: "ngnd-gpio"
compatible: "ngnd-switch"
child-binding:
description: NGND GPIO child node
description: Neutral-Ground GPIO node
properties:
gpios:
ngnd-gpios:
type: phandle-array
required: true
label:
......
/ {
ngnd-gpio {
compatible = "ngnd-gpio";
neutral_gnd: n_gnd {
gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>;
ngnd-switch {
compatible = "ngnd-switch";
ngnd_pin: ngnd-gpio-pin {
ngnd-gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>;
label = "Neutral to GND shunt";
};
};
aliases {
ngnd = &neutral_gnd;
ngnd = &ngnd_pin;
};
};
\ No newline at end of file
......@@ -243,7 +243,7 @@ struct stm32_dac_driver_data dac1_data =
DEVICE_DT_DEFINE(DAC1_NODELABEL,
dac_stm32_init,
device_pm_control_nop,
NULL,
&dac1_data,
NULL,
PRE_KERNEL_1,
......@@ -265,7 +265,7 @@ struct stm32_dac_driver_data dac2_data =
DEVICE_DT_DEFINE(DAC2_NODELABEL,
dac_stm32_init,
device_pm_control_nop,
NULL,
&dac2_data,
NULL,
PRE_KERNEL_1,
......@@ -287,7 +287,7 @@ struct stm32_dac_driver_data dac3_data =
DEVICE_DT_DEFINE(DAC3_NODELABEL,
dac_stm32_init,
device_pm_control_nop,
NULL,
&dac3_data,
NULL,
PRE_KERNEL_1,
......
......@@ -29,6 +29,8 @@
* @author Antoine Boche <antoine.boche@laas.fr>
*/
#include <stm32_ll_rcc.h>
#include "hrtim_voltage_mode.h"
#include "assert.h"
......@@ -74,9 +76,9 @@ static inline uint32_t _period_ckpsc(hrtim_t hrtim, uint32_t freq,
uint16_t *per, uint8_t *ckpsc)
{
#if defined(CONFIG_SOC_SERIES_STM32F3X)
uint32_t f_hrtim = CLOCK_APB2 * 2;
uint32_t f_hrtim = hrtim_get_apb2_clock() * 2;
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
uint32_t f_hrtim = CLOCK_APB2;
uint32_t f_hrtim = hrtim_get_apb2_clock();
#else
#warning "unsupported stm32XX family"
#endif
......@@ -455,9 +457,9 @@ void hrtim_pwm_dt(hrtim_t hrtim, hrtim_tu_t tu, uint16_t ns)
/* t_dtg = (2^dtpsc) * (t_hrtim / 8)
* = (2^dtpsc) / (f_hrtim * 8) */
#if defined(CONFIG_SOC_SERIES_STM32F3X)
uint32_t f_hrtim = CLOCK_APB2 * 2;
uint32_t f_hrtim = hrtim_get_apb2_clock() * 2;
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
uint32_t f_hrtim = CLOCK_APB2;
uint32_t f_hrtim = hrtim_get_apb2_clock();
#else
#warning "unsupported stm32XX family"
#endif
......@@ -507,3 +509,29 @@ void hrtim_adc_trigger_dis(hrtim_t hrtim, hrtim_adc_t adc, hrtim_adc_trigger_t e
case ADC4R: dev(hrtim)->sCommonRegs.ADC4R &= ~evt; break;
}
}
int hrtim_get_apb2_clock()
{
int prescaler = 1;
switch(LL_RCC_GetAPB2Prescaler())
{
case RCC_CFGR_PPRE2_DIV1:
prescaler=1;
break;
case RCC_CFGR_PPRE2_DIV2:
prescaler=2;
break;
case RCC_CFGR_PPRE2_DIV4:
prescaler=4;
break;
case RCC_CFGR_PPRE2_DIV8:
prescaler=8;
break;
case RCC_CFGR_PPRE2_DIV16:
prescaler=16;
break;
}
return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / prescaler;
}
......@@ -38,7 +38,7 @@
#include <pinmux/stm32/pinmux_stm32.h>
#include <hrtim.h>
#include "hrtim.h"
#ifdef __cplusplus
extern "C" {
......@@ -46,7 +46,6 @@ extern "C" {
#define DT_DRV_COMPAT hrtim
#define CLOCK_APB2 (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / CONFIG_CLOCK_STM32_APB2_PRESCALER)
#define HRTIM_NUMOF (1)
/**
......@@ -519,6 +518,8 @@ void hrtim_adc_trigger_en(hrtim_t dev, hrtim_adc_t adc, hrtim_adc_trigger_t evt)
*/
void hrtim_adc_trigger_dis(hrtim_t dev, hrtim_adc_t adc, hrtim_adc_trigger_t evt);
int hrtim_get_apb2_clock();
#ifdef __cplusplus
}
#endif
......
......@@ -27,6 +27,8 @@
#ifndef NGND_H_
#define NGND_H_
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -36,18 +36,17 @@
static struct owntech_ngnd_driver_dev_data
{
const struct device* gpio_dev;
struct gpio_dt_spec ngnd_pin_spec;
} data;
static int ngnd_init(const struct device* dev)
{
struct owntech_ngnd_driver_dev_data* data = dev->data;
data->gpio_dev = device_get_binding(NGND_GPIO_LABEL);
struct owntech_ngnd_driver_dev_data* data = dev->data;
__ASSERT(data->gpio_dev, "ERROR: unable to obtain ngnd device binding");
const struct gpio_dt_spec ngnd_spec = GPIO_DT_SPEC_GET(NGND_GPIO_NODE, ngnd_gpios);
data->ngnd_pin_spec = ngnd_spec;
gpio_pin_configure(data->gpio_dev, NGND_GPIO_PIN, GPIO_OUTPUT_ACTIVE | NGND_GPIO_FLAGS);
gpio_pin_configure_dt(&data->ngnd_pin_spec, GPIO_OUTPUT_ACTIVE);
return 0;
}
......@@ -60,7 +59,7 @@ void ngnd_set(const struct device* dev, int value)
{
struct owntech_ngnd_driver_dev_data* data = dev->data;
gpio_pin_set(data->gpio_dev, NGND_GPIO_PIN, value);
gpio_pin_set(data->ngnd_pin_spec.port, data->ngnd_pin_spec.pin, value);
}
......@@ -70,7 +69,7 @@ void ngnd_set(const struct device* dev, int value)
DEVICE_DEFINE(owntech_ngnd_driver,
NGND_LABEL,
ngnd_init,
device_pm_control_nop,
NULL,
&data,
NULL,
PRE_KERNEL_2,
......
......@@ -34,9 +34,6 @@ extern "C" {
#define NGND_GPIO_NODE DT_ALIAS(ngnd)
#define NGND_GPIO_LABEL DT_GPIO_LABEL(NGND_GPIO_NODE, gpios)
#define NGND_GPIO_PIN DT_GPIO_PIN(NGND_GPIO_NODE, gpios)
#define NGND_GPIO_FLAGS DT_GPIO_FLAGS(NGND_GPIO_NODE, gpios)
static int ngnd_init(const struct device* dev);
......
......@@ -177,7 +177,7 @@ struct stm32_timer_driver_data timer6_data =
DEVICE_DT_DEFINE(TIMER6_NODELABEL,
timer_stm32_init,
device_pm_control_nop,
NULL,
&timer6_data,
NULL,
PRE_KERNEL_1,
......@@ -200,7 +200,7 @@ struct stm32_timer_driver_data timer7_data =
DEVICE_DT_DEFINE(TIMER7_NODELABEL,
timer_stm32_init,
device_pm_control_nop,
NULL,
&timer7_data,
NULL,
PRE_KERNEL_1,
......
......@@ -44,7 +44,7 @@ static int vrefbuf_init(const struct device* dev)
DEVICE_DEFINE(vrefbuf_driver,
"vrefbuf_driver",
vrefbuf_init,
device_pm_control_nop,
NULL,
NULL,
NULL,
PRE_KERNEL_1,
......
......@@ -6,7 +6,7 @@ CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
#CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_DSP_CONTROLLER=y
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment