drivers: can: stm32: switch to supporting CAN_MODE_ONE_SHOT

Switch from using a driver-specific, compile-time devicetree one-shot
property to supporting the newly added CAN_MODE_ONE_SHOT flag for
enabling/disabling one-shot mode at run-time.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-07-12 22:16:48 +02:00 committed by Carles Cufí
commit c0cba8f21a
3 changed files with 8 additions and 15 deletions

View file

@ -351,7 +351,7 @@ static int can_stm32_set_mode(const struct device *dev, can_mode_t mode)
LOG_DBG("Set mode %d", mode);
if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_LISTENONLY)) != 0) {
if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_LISTENONLY | CAN_MODE_ONE_SHOT)) != 0) {
LOG_ERR("unsupported mode: 0x%08x", mode);
return -ENOTSUP;
}
@ -386,6 +386,13 @@ static int can_stm32_set_mode(const struct device *dev, can_mode_t mode)
can->BTR &= ~CAN_BTR_SILM;
}
if ((mode & CAN_MODE_ONE_SHOT) != 0) {
/* No automatic retransmission */
can->MCR |= CAN_MCR_NART;
} else {
can->MCR &= ~CAN_MCR_NART;
}
done:
ret = can_leave_init_mode(can);
if (ret) {
@ -534,10 +541,6 @@ static int can_stm32_init(const struct device *dev)
#ifdef CONFIG_CAN_AUTO_BUS_OFF_RECOVERY
can->MCR |= CAN_MCR_ABOM;
#endif
if (cfg->one_shot) {
can->MCR |= CAN_MCR_NART;
}
timing.sjw = cfg->sjw;
if (cfg->sample_point && USE_SP_ALGO) {
ret = can_calc_timing(dev, &timing, cfg->bus_speed,
@ -1202,7 +1205,6 @@ static const struct can_stm32_config can_stm32_cfg_##inst = { \
.prop_ts1 = DT_INST_PROP_OR(inst, prop_seg, 0) + \
DT_INST_PROP_OR(inst, phase_seg1, 0), \
.ts2 = DT_INST_PROP_OR(inst, phase_seg2, 0), \
.one_shot = DT_INST_PROP(inst, one_shot), \
.pclken = { \
.enr = DT_INST_CLOCKS_CELL(inst, bits), \
.bus = DT_INST_CLOCKS_CELL(inst, bus), \

View file

@ -74,7 +74,6 @@ struct can_stm32_config {
uint8_t sjw;
uint8_t prop_ts1;
uint8_t ts2;
bool one_shot;
struct stm32_pclken pclken;
void (*config_irq)(CAN_TypeDef *can);
const struct pinctrl_dev_config *pcfg;

View file

@ -20,14 +20,6 @@ properties:
pinctrl-names:
required: true
one-shot:
type: boolean
required: false
description: |
Disable automatic retransmissions. A CAN frame will only be transmitted
once, independently of the transmission result (successful, error, or
arbitration lost).
master-can-reg:
type: int
required: false