The turbulent plasma dynamics in the periphery of a fusion device plays a key role in determining its overall performance. In fact, the periphery controls the heat load on the vessel walls, the plasma confinement, the level of impurities in the core, the plasma fuelling and the removal of fusion ashes. Hence, understanding and predicting the plasma turbulence in this region is of crucial importance for the success of the fusion program. The GBS code has been developed in past years to simulate plasma turbulence in the periphery of limited tokamaks. The goal of the present thesis is to extend GBS to the treatment of diverted scenarios. Such configurations are of interest for present state-of-the-art experiments and future fusion reactors. For the implementation of this geometry, we express the model in toroidal coordinates, abandoning the flux coordinates previously used in limited configuration, and overcoming the singularity that this coordinate system presents at the X-point of diverted configurations. The accuracy of the numerical scheme is improved by upgrading the second order finite differences scheme to fourth order on staggered grids. The resulting version of GBS is carefully verified through a series of tests (i.e., a benchmark with the previous version of GBS in limited configuration, a rigorous check of the correctness of the code implementation with the method of manufactured solutions, and a convergence study on a relatively simple diverted configuration). The results of a GBS simulation is then used to investigate the dynamics of coherent turbulent structures, called blobs, that characterise plasma turbulence in the periphery of fusion devices. A diverted double-null configuration is considered, and the blob motion is studied using a pattern recognition algorithm. The velocity of the blobs in the presence of an X-point matches the analytical scaling that we derived by considering the different blob properties in the divertor and main SOL regions, retaining the correction terms that account for blob density and ellipticity. In addition, we show that the blob current pattern observed in the simulation results match the theoretical expectations. Finally, the new version of GBS is run with a realistic diverted magnetic equilibrium, taken from an experiment carried out on the TCV tokamak. First insights of the turbulence properties are in good agreement with the current physical understanding of plasma dynamics in the periphery of diverted tokamaks.