Hey guys,
I'd like to share a little story with you. The past few days I've been working on my Maple Dataflash library (yes, free plug). I've been working on optimizing the library as much as possible, trying to maximize transfer speeds. I decided to go away from the wirish digitalWrite
calls -- which were taking 480ns -- and move to direct GPIO register access.
I re-factored the entire library to support this new functionality, and wow! Write speeds increased by 7x! Or so I thought. Turns out, all of the data I read back was corrupt. "Interesting," I mumbled to myself. I stashed my changes and reverted to a previous working version of the library. Indeed, everything previously worked so my latest changes must have broken something. I applied changes one by one, built, programmed, and checked. Everything works just fine.. until I introduce the GPIOx->regs->xRR
writes. "Funny," I thought. I can go on for hours, in fact I can explain what happened for the next 3 days, but you probably don't care how I decided to take a shower, eat, or everything else I've done so I'll spare those details.
Just 10 minutes ago, I noticed something interesting. It's as if the dataflash IC doesn't know I'm sending commands to it. I took a look at the datasheet and noticed there is a minimum of a 50 nS HIGH time for CS. Looking at my logic analyzer, the STM32 was actually too fast! It's only taking 41 nS to toggle CS! Oh no! The Dataflash REALLY didn't know it was being talked to. Adding a minor delay increases the CS high time to meet the minimum requirement, and alas: The dataflash works just fine now.
The moral of the story: Don't make things run toooo fast!
-robodude666