You cannot use the lstlisting-environment within a macro-definition/as component of a \def's definition-text.
This is because the lstlisting-environment expects to obtain the tokens belonging to it by reading and tokenizing things from the .tex-file while the category-code-régime is temporarily changed and not by having tokens inserted in the course of delivering the replacement-text of a macro-token whereby that replacement-text got tokenized under unchanged catcode-régime at the time of carrying out the \def-directive for defini8ng that macro-token.
The following, however, where the lstlisting-environment is not inside \def, does work:
sub.tex
\begin{lstlisting}[style=CStyle]
uint8_t a = 0xAB;
\end{lstlisting}
test.tex
\documentclass{article}
\usepackage{color}
\definecolor{backgroundColour}{RGB}{255,240,245}
\usepackage{listings}
\lstdefinestyle{CStyle}{
backgroundcolor=\color{backgroundColour},
commentstyle=\color{mGreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{mGray},
}
\begin{document}
\input{sub.tex}
\end{document}

Alternatively, instead of \def you can implement your own definition-command which does read the definition-text in verbatim-catcode-régime and define the command to pass the stuff that was read in verbatim-catcode-régime to \scantokens. You need some \newlinechar=\endlinechar-trickery to get the linebreaks right. You need to insert a comment-character at the end of what is passed to \scantokens to make sure the last endline-character inserted by the \scantokens-routine won't yield an unwanted empty line. Could look like the following example. Be aware that indentation within lstlistings-environments and thus within the second argument of \MyDefVerbatim occurring in sub.tex does matter.
sub.tex
\MyDefVerbatim\callDefined{%
\begin{lstlisting}[style=CStyle]
uint7_t a = 0xAB;
uint8_t a = 0xAB;
uint9_t a = 0xAB;
\end{lstlisting}
}%
main.tex
% With TeXLive 2020 and newer, the xparse-package doesn't need to be
% loaded explicitly as most of its features are integrated into the
% LaTeX 2e-kernel.
% With TeXLive 2019 and older, the xparse-package needs to be
% loaded explicitly.
% Seems currently (Novemer 16, 2021) overleaf uses
% TeXLive 2019 (legacy) by default.
\RequirePackage{xparse}
\NewDocumentCommand\MyDefVerbatim{m}{%
\begingroup\catcode\^^I=12 \innderdefineverbatim{#1}% }% \begingroup\catcode^^A=14 \catcode`%=12 \csname @firstofone\endcsname{^^A
\endgroup
\NewDocumentCommand\innderdefineverbatim{m+v}{^^A
\endgroup
\NewDocumentCommand{#1}{}{^^A
\begingroup\newlinechar=\endlinechar\scantokens{\endgroup#2%}^^A
}^^A
}^^A
}%
\documentclass{article}
\usepackage{color}
\definecolor{backgroundColour}{RGB}{255,240,245}
\usepackage{listings}
\lstdefinestyle{CStyle}{
backgroundcolor=\color{backgroundColour},
commentstyle=\color{mGreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{mGray},
}
\input{sub.tex}
\begin{document}
\callDefined
\end{document}
