Mbed TLS ECC P521 Curve Key Generation

Hi All,
I’m relatively new to mbed TLS platform and am trying to do an interface where the application is as described below:
Application - i want to generate a pair of keys using p521 curve ecc and store the key values in the internal flash of the microcontroller.
The following sequence i have used for the same:

  1. mbedtls_pk_init(&key); mbedtls_entropy_init( &entropy ); mbedtls_ctr_drbg_init(&ctr_drbg);
  2. mbedtls_pk_setup
  3. mbedtls_ctr_drbg_seed
  4. mbedtls_ecp_gen_key - with p521 curve selected.

The above mentioned are the function calls that were used. Am i correct with respect to the use case that was described above. My query is how can i store the variables of the public key and the private key inside the flash memory of the controller as the values of the controller are stored as private members in the mbed tLS Library. Can anyone share the sequence or steps required for the same. Also can anyone suggest a reference manual for the same.
Please don’t mind if the query is very basic as I’m very new to the mbed tls implementation.
Thanks for the support in advance.