Thanks a lot for your help Johan.
I think I finally got it.
I confess I still not understanding the code at all, specially because the complex pointers arithmetic, but it's working for me. Some pieces of the code below, mainly the code which initializes the buffers, I've copied from "rapp_test_morph_bin.c" in rapp installation "test" folder. I'm sharing it so I believe can help others.
/*
Performs a limiarization and then dilates an u8 image, out_8u stores the resulting dilated binarized u8 image.
width and height are always 640x480; The resulting image, in "out_8u" has the dilated image pixels.
*/
void rapp_pgs_test(unsigned char *img_8u, int width, int height, unsigned char *out_8u)
{
uint8_t *pat_buf = NULL; /* Pattern buffer */
uint8_t *pad_buf = NULL; /* Source buffer with padding */
uint8_t *src_buf = NULL; /* Source buffer */
uint8_t *dst_buf = NULL; /* Destination buffer */
uint8_t *ref_buf = NULL; /* Reference buffer */
void *work = NULL; /* Working buffer (scratch) */
int src_dim; /* Source buffer dimension */
int dst_dim; /* Destination buffer dimension */
int pad_len; /* Padded source buffer in bytes */
int se_square_size = 4; // size of the morph structuring element
int size = MIN(width, height);
int minxpixpad = MIN(
se_square_size / 2, 16);
int minypixpad = MIN(
se_square_size / 2, 16);
int minxpad = rapp_align((minxpixpad + 7) / 8);
int pos;
bool ok = false;
/* Allocate the buffers */
dst_dim = rapp_align((width + 7) / 8);
src_dim = dst_dim + 2*minxpad;
pat_buf = (uint8_t*)rapp_malloc(height*dst_dim, 0);
pad_len = (height + 2*minypixpad)*src_dim;
pad_buf = (uint8_t*)rapp_malloc(pad_len, 0);
src_buf = &pad_buf[minypixpad*src_dim + minxpad];
dst_buf = (uint8_t*)rapp_malloc(height*dst_dim, 0);
ref_buf = (uint8_t*)rapp_malloc(height*dst_dim, 0);
work = (uint8_t*)rapp_malloc(rapp_morph_worksize_bin(width, height), 0);
rapp_thresh_gt_u8(src_buf, src_dim, img_8u, width, width, height, 100);//binarizes the u8 image int an binary image buffer.
rapp_morph_dilate_rect_bin(dst_buf, dst_dim, src_buf, src_dim, width, height,
se_square_size,
se_square_size, work);
rapp_type_bin_to_u8(out_8u, width, dst_buf, dst_dim, width, height);//out_8u can be easyly encapsulated into an Opencv Mat
rapp_free(pat_buf);
rapp_free(pad_buf);
rapp_free(dst_buf);
rapp_free(ref_buf);
rapp_free(work);
}