A Lyndon word can be characterized as the lexicographically smallest word among its cycle rotations. Hence, Lyndon words can be viewed as (representatives of) equivalence classes of words w.r.t. cyclic rotations. Then for enumeration of Lyndon words with a given weight, we can employ [PET][1] as follows. Let $Z_n(a_1,a_2,\dots)=\frac{1}{n}\sum_{k\mid n} \varphi(k)a_k^{n/k}$ be the [cycle index of the cyclic group $C_n$][2]. Then the number of Lyndon words of length $n$ and weight $m$ equals the coefficient of $t^m$ in $$Z_n(t^{d_a}+t^{d_b},t^{2d_a}+t^{2d_b},\dots)=\frac{1}{n}\sum_{k\mid n} \varphi(k) (t^{kd_a}+t^{kd_b})^{n/k}.$$ [1]: https://en.wikipedia.org/wiki/P%C3%B3lya_enumeration_theorem [2]: https://en.wikipedia.org/wiki/Cycle_index#Cyclic_group_Cn