Had the same issue. Replaced Crankshaft position sensor and Camshaft position sensor.
All fixed
this was the throttle body that caused this issue, i had that replaced and all is well with it. the p0505 code said egr vacuum issue the proper bmw reader pulled stuck/sticky throttle body. so that was the issue on mine. thanks for the comment though bud.