Author Topic: Initialising SPI memory  (Read 7681 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Initialising SPI memory
« on: December 08, 2008, 04:17:35 PM »
Hi Mark,
  I have a device sharing the spi bus with external memory. To save power, I power up this device through an IO expander port I have on the I2C bus, so this has to be carried out before the fnConfigSPIFileSystem() is called.

I have moved the fnConfigSPIFileSystem(..) routine from the EXTERNSTATIC void fnInitHW(void)  within m5223x.c file, and placed it after my initialisation code. It works fine, but wondering if this may cause problems with utasker?

I would have liked to place my init code in the fnUserHWInit() routine which gets called before the above, but as fnUserHWInit() is before heap available, and I have to setup my device through I2C, then not sure if this would work.

Regards
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Initialising SPI memory
« Reply #1 on: December 08, 2008, 07:33:51 PM »
Hi Neil

As long as nothing is trying to access the SPI device before the SPI interface has been initialised I see no problems (the only thing that could cause problems is when the parameters are also in SPI FLASH and the Ethernet task - one of the first started in the original configuration - tries to get the IP and MAC address settings from there - You probably have these parameters in internal FLASH).

The routine fnInitHW is foreseen for things that need to be set up as soon as possible (like ports, but not driver interfaces because it is so early on that there are not yet any tasks configured and also no heap available).
Driver configurations are not critical - they just need to be opened before being used - so doing this in a task is no problem.

The only reason for putting the SPI initialisation so early on in the hardware code is because it is usually something that can be performed 'behind the curtains' so it is performed together with other basic low level stuff. In your case it seems reasonable to change it as you have done.

Regards

Mark