A project log for Heartbeat Logger

A portable device that logs a snippet of your heart at the push of a button.

Ole Andreas UtstumoOle Andreas Utstumo 06/01/2019 at 16:400 Comments

Among the things that could have caused the mass storage device to crash is timing issues. As the datasheet suggests, a minimum deselect time between each word in the write cycle must be T_BP = 10 µs.

The HAL framework has no delay function for microseconds, so unless you want to implement this yourself, you could employ a dirty trick like this:

        for(uint16_t k=1; k < 55; k++){

A "nop" is an instruction that does nothing, but occupies a certain number of clock cycles and therefore a tiny amount of time. However, if you start changing the core frequency of the MCU, then interesting things happen, which it truly did in my case. Resetting the clocks to default, checking the write operation in the scope and adjusting k in the delay cycle above we're back on track. However, increasing the clock of the SPI has marginal impact:

Those blue streaks are two bytes written to the flash plus a control byte. The parts where nothing is happening is sadly overhead in the HAL libraries and can be overcome by writing your own SPI functions, or minimized by increasing the clock of the core. For my use it's good enough.