• AVR Freaks

Hot!Harmony 3 SPI flash driver chipSelect - who is in charge?

Author
boatbodger
Junior Member
  • Total Posts : 85
  • Reward points : 0
  • Joined: 2011/03/27 15:39:07
  • Location: 0
  • Status: offline
2019/12/17 04:12:04 (permalink)
0

Harmony 3 SPI flash driver chipSelect - who is in charge?

The source file drv_at25df.c appears to drive the chip select pin directly - and that could be a problem for two reasons:
1) The SPI hardware automatically drives the chip select pin, assuming MSSEN is enabled, which seems to be the default and most logical way.
2) The calls to read() and write() through from the driver to the plib are non-blocking - so the driver would remove the chip select assertion too early.
In short, I can't see how this could ever work.  There seems to be a complete mismatch between the architecture of the plib driver, and that of the at25df driver.
 
What am I missing?  How best to proceed?  It loooks to me as if a rather major hack of this driver would be necessary for it to happily cohabit with the Harmony plib.
#1

9 Replies Related Threads

    Mysil
    Super Member
    • Total Posts : 3666
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/17 07:40:22 (permalink)
    0
    Hi,
    There are at least 3 different ways this could be done.
    Drivers for SPI peripheral may have been rewritten a couple of times since I was looking at it,
    so I have no idea what is there now.
    1:
    Use MSSEN,  This more or less implies use of Framed mode, with one synch pulse on the _SS line for each word transferred, either 32 bit word, 16 bit word or 8 bit.
    2:
    When a SPI driver object is created and configured,
    the driver might offer options to define which Port and Pin is to be used for Chip Select signal,
    together with possible options for how it is to be used.
    3:
    SPI driver might offer hooks for Callback function pointers,
    such that a function that you provide, is called by the driver when transfer is ready to be started, 
    have ended, or something interesting happen.
    Such callback functions should be coded, and reside in your code, but will be executed by the driver,
    or by the driver's ISR code and context.
    4:
    Write and use your own driver, independent of what Harmony might offer.
     
        Mysil
    post edited by Mysil - 2019/12/17 08:01:39
    #2
    boatbodger
    Junior Member
    • Total Posts : 85
    • Reward points : 0
    • Joined: 2011/03/27 15:39:07
    • Location: 0
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/17 08:27:53 (permalink)
    0
    OK - having slapped the storage 'scope on the thing, I can see that MSSEN is actually useless for standard flash memory access style things - it is a bit too automatic, pulling the CE line up at times when I don't want it to.
     
    I shall adjust my expectations accordingly.
     
    I think there is still an issue whereby the Harmony-supplied driver is liable to whip the CE away too soon on a fast processor with the SPI clock speed set low-ish.
    But at least I now understand the need to use 'manual' methods to drive the CE line from the driver.
    Thank you for your response.
    #3
    LamdaElectronics
    Assembly_For_Ever
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/23 01:39:51 (permalink)
    0
    The " non-blocking" myth, I can see has expanded! I'm afraid that you are lost in the same loop as I am. 
    Try to debug and step though the routines read() and write(), you will find out that there were created by an artificial intelligence program. Any any case YOU should have the upper hand. In my case I use the good old LATLATFbits.LATXX=0 command for CE, it will NEVER let you down.
    You are sailing in uncharted waters (also Harmony and v.3) my friend, good luck!
     
    #4
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3835
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/23 03:58:49 (permalink)
    0
    SPI only needs a few lines of exchange code - it does not even need a library.
     
    "LATLATFbits.LATXX=0 command for CE"
    It's not a command, that is clearing a bit but I agree that manual is better and it removes the extra layer.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #5
    boatbodger
    Junior Member
    • Total Posts : 85
    • Reward points : 0
    • Joined: 2011/03/27 15:39:07
    • Location: 0
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/23 07:45:07 (permalink)
    0
    Gort2015
    SPI only needs a few lines of exchange code - it does not even need a library
     

    Thanks for your comment - and I agree.  I am still learning (bumpily...) the parts where Harmony is helpful, and where I'm better off on my own.
    For this project I'm about to venture into the A to D area - and have decided to 'roll my own' after the recent SPI experience.
     
    With that said, for another recent project I was using SQI, with its built-in DMA channels, and I think for that, Harmony did save me some time.
    As I say - very much 'still learning'
    #6
    LamdaElectronics
    Assembly_For_Ever
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/30 03:33:53 (permalink)
    0
    Gort2015
    "LATLATFbits.LATXX=0 command for CE"
    <<It's not a command>>

    According to the Oxford Dictionary:  (https://www.oxfordlearnersdictionaries.com/definition/english/command_1)
    command: noun
    BrE /kəˈmɑːnd/ ; NAmE /kəˈmænd/
    2.  for computer ​ [countable] an instruction given to a computer
     
    And for the Real Programmers (those who understand Assembly) this "command" could be broken down to two assembly (PIC18) instructions:
    MOVLW XXX0XXXb  ;Select your desired pin 
    MOVWF LATX          ; Latch it to the desired port

    As it is shown, this indeed clears the selected pin! And does the job of "Chip Selecting" (or Slave Select).



    #7
    crosland
    Super Member
    • Total Posts : 1875
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/30 04:27:55 (permalink)
    4 (1)
    lamdaelectronics
    And for the Real Programmers (those who understand Assembly)

    Do you claim to fall into that group?
     
    this "command" could be broken down to two assembly (PIC18) instructions:
    MOVLW XXX0XXXb  ;Select your desired pin 
    MOVWF LATX          ; Latch it to the desired port

    As it is shown, this indeed clears the selected pin! And does the job of "Chip Selecting" (or Slave Select).

    It also sets all the other LAT bits to whatever XXX bits were loaded into W.
     
    It's actually a single BSF instruction.
    #8
    Mysil
    Super Member
    • Total Posts : 3666
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/30 07:52:15 (permalink)
    0
    Hi,
    From when did PIC18 assembly instructions become relevant for Harmony 3,
    and when did BSF instruction become part of MIPS32 instruction set?
     
    Yes, there are Bit field instructions in MIPS instruction set, but that only work on CPU registers,
    not for memory mapped SFR registers.
     
    PIC32 microcontrollers have logic gates integrated with SFR registers, 
    to perform bit set and bit clear operations using a single atomic write instruction to SFR memory,
    without disturbing other bits in the register:
        LATxCLR = _LATx_LATxbit_MASK;  /* Clear port latch register bit, where x is port Letter and bit is Bit number in Latch register. */
        LATxSET = _LATx_LATxbit_MASK;  /* Set port latch register bit. */
    /* Example */
        LATFCLR = _LATF_LATF5_MASK;
        LATFSET = _LATF_LATF5_MASK; 

    XC32 compiler provide Device support header file for every PIC device.
    It have definitions of symbolic names for all SFR registers, and mask names for register bits and fields.
    #include <xc.h>
     
    Harmony provide inline functions that wrap around these SFR write statements.
     
        Mysil
    #9
    crosland
    Super Member
    • Total Posts : 1875
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: Harmony 3 SPI flash driver chipSelect - who is in charge? 2019/12/31 03:58:07 (permalink)
    0
    Mysil
    Hi,
    From when did PIC18 assembly instructions become relevant for Harmony 3,



    Since post #4 it would seem :)
     
    It's all too easy to get sucked along by the thread drift, especially these cross-currents.
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5