A semiconductor device includes an oscillator configured to generate a first clock signal, a first terminal via which an input clock signal is fed in from the outside, a first counter configured to count a clock signal based on the first clock signal between edges in the input clock signal, and a controller configured to send to the oscillator an instruction to adjust the frequency of the first clock signal based on the result of comparison of the count value by the first counter with an expected value.