How do I calculate the voltage across a capacitor when the source is a square wave?
Here's a great article about RC filters: https://www.electronics-tutorials.ws/filter/filter_2.html

You'll see that lowpass RC filters affect the input based on the following formula:


Where:



Now, the formula for a square wave can be expressed as the following Fourier series:


It might look complicated, but it's really just a sum of different sine waves called harmonics. Each of those will be affected differently by the filter because they have different frequencies.

So to know what output you'll have, just replace Vin in the first equation by the last equation and you'll get the output. You can calculate the full series on Matlab or a fancy graphic calculator, or you'll get pretty close if you estimate the input to be only the first 5-10 harmonics.