Skip to content

Commit

Permalink
kernel,driver,busses: enhanced stm32 busses detection in template (ou…
Browse files Browse the repository at this point in the history
…tpost-os#111)

Handle more complex bus architecture.
Some SOC have got more busses than available registers and reset and
clocken might not be consistent.

e.g. AHB3/4 on the same xxxENR register and APB3ENR reserved for
companion core.
  • Loading branch information
fvalette-ledger authored Jan 8, 2025
2 parents 79b3176 + 76c0951 commit ead9d97
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions kernel/include/sentry/arch/asm-cortex-m/stm32l4-buses.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,68 @@
#ifndef BUSES_H
#define BUSES_H

{#-
XXX:
Note that `name` comes from svd soc name in lowercase.
That being said, heterogeneous soc (i.e. with 2 distinct cpu cores, e.g. a generic core
and a dedicated for radio or machine learning) are suffixed with an `_` as separator
between soc family name and core arch to consider.
-#}
{%- set name = name.split('_')[0] %}

#include <dt-bindings/clock/{{ name[:-2].lower() }}_clock.h>

{% set peripheral = (peripherals|selectattr('groupName', 'eq', 'RCC')|first) or (peripherals|selectattr('name', 'eq', NAME)|first) -%}
{%- set peripheral = (peripherals|selectattr('groupName', 'eq', 'RCC')|first) or (peripherals|selectattr('name', 'eq', NAME)|first) -%}

{%- macro get_busses_reset(registers) %}
{% set reset = [] %}
{% for reg in registers if reg.name.endswith('RSTR') or reg.name.endswith('RSTR1') %}
{% set _ = reset.append(reg.name[:4]) %}
{% endfor %}
{{ reset|unique|list }}
{%- endmacro %}

{%- macro get_busses_clken(registers) %}
{%- set clken = [] -%}
{%- for reg in registers if reg.name.startswith('A') and (reg.name.endswith('ENR') or reg.name.endswith('ENR1')) %}
{%- set _ = clken.append(reg.name[:4]) %}
{%- endfor %}
{{- clken|unique|list -}}
{%- endmacro %}

{%- set busses = (get_busses_clken(peripheral.registers)|trim(chars='[]')).split(',')|map("trim", chars=' \'')|list %}

/**
* @brief list of platform bused.
* Based on the {{ NAME }} device register naming.
* This template works for all STM32L4 SoCs
*/
typedef enum bus_identifier {
{% for register in peripheral.registers -%}
{% if register.name.endswith('RSTR') -%}
BUS_{{register.name[0:4]}} = STM32_CLOCK_BUS_{{register.name[0:4]}},
{% endif -%}
{% if register.name.endswith('RSTR1') -%}
BUS_{{register.name[0:4]}} = STM32_CLOCK_BUS_{{register.name[0:4]}},
{% endif -%}
{% endfor -%}
{%- for bus in busses %}
BUS_{{bus}} = STM32_CLOCK_BUS_{{bus}},
{%- endfor %}
} bus_id_t;

/*
* XXX:
* Fixme with clock tree issue (188, 254)
*/
{% for register in peripheral.registers -%}
{% if register.name.endswith('RSTR') or register.name.endswith('RSTR1') -%}
#define HAS_BUS_{{register.name[0:4]}} 1
{% endif -%}
{% endfor %}
{%- for bus in busses %}
#define HAS_BUS_{{bus}} 1
{%- endfor %}

#define BUS_IS_VALID(bus) ( \
{% for register in peripheral.registers -%}
{% if register.name.endswith('RSTR') -%}
(bus == BUS_{{register.name[0:4]}}) || \
{% endif -%}
{% if register.name.endswith('RSTR1') -%}
(bus == BUS_{{register.name[0:4]}}) || \
{% endif -%}
{% endfor -%}
{%- for bus in busses %}
(bus == BUS_{{bus}}) || \
{%- endfor %}
false)

/*@
logic boolean bus_is_valid(uint32_t bus) =
(
{% for register in peripheral.registers -%}
{% if register.name.endswith('RSTR') -%}
bus == STM32_CLOCK_BUS_{{register.name[0:4]}} ||
{% endif -%}
{% if register.name.endswith('RSTR1') -%}
bus == STM32_CLOCK_BUS_{{register.name[0:4]}} ||
{% endif -%}
{% endfor -%}
{%- for bus in busses %}
(bus == BUS_{{bus}}) ||
{%- endfor -%}
\false
);
*/
Expand Down

0 comments on commit ead9d97

Please sign in to comment.