Clinical studies today are funded entirely by the pharma companies, keep that. Selling at cost of production would be something extra, for patients who want the drugs but aren't enrolled in an actual study. The company doesn't get solid data it can use for regulatory approval, so making them donate the drugs in that case seems excessive.
A downside would be that for drugs that don't cost much to produce, patients might be less willing to enroll in the studies, given the chance of getting a placebo. That could be handled by shutting down the informal access while the study is enrolled, for anyone who's eligible. I'm sure there are other wrinkles that would need to be considered too.