using dd in ultibo

Discussion and questions about programming with Ultibo.
develone
Posts: 265
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

using dd in ultibo

Postby develone » Fri May 18, 2018 7:36 pm

I use dd if=$1 of=/dev/spidev0.0 in a bash script plus 3 GPIO pins to program the FPGA.
The files are 135100 bytes.
see
https://github.com/develone/catboard_yosys/blob/master/config_cat

What would be the best way to test using using Ultibo to program the fpga.
Thanks,
User avatar
Ultibo
Site Admin
Posts: 1895
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: using dd in ultibo

Postby Ultibo » Sat May 19, 2018 2:58 am

develone wrote:I use dd if=$1 of=/dev/spidev0.0 in a bash script plus 3 GPIO pins to program the FPGA.
The files are 135100 bytes.
see
https://github.com/develone/catboard_yosys/blob/master/config_cat

What would be the best way to test using using Ultibo to program the fpga.
Thanks,

We don't have anything like dd but reproducing what it is doing is quite simple.

Under Linux the device /dev/spidev0.0 refers to SPI0 Chip Select 0 so we can create a function using the Ultibo SPI unit that looks like this:

This is for Pi3 but can be easily adjusted for any other model, make sure your uses clauses contains the SPI and BCM2710 units.

Code: Select all

function SPISendFile(const Filename: String): Boolean;
var
  Count:LongWord = 0;
  SPIDevice: PSPIDevice;
  MemoryStream: TMemoryStream;
begin
  Result := False;

  //Check the file
  if not FileExists(Filename) then
    Exit;

  //Open the file
  MemoryStream := TMemoryStream.Create;
  try
   //Load the file
   MemoryStream.LoadFromFile(Filename);

   ;
   //Locate the SPI device (Adjust for boards other than Pi3)
   SPIDevice := SPIDeviceFindByDescription(BCM2710_SPI0_DESCRIPTION);
   if SPIDevice = nil then
     Exit;

   //Configure SPI Chip Select 0
   if SPIDeviceSetClockRate(SPIDevice ,SPI_CS_0, 1000000) <> ERROR_SUCCESS then
     Exit;

   //Start the SPI device
   if SPIDeviceStart(SPIDevice, SPI_MODE_4WIRE, 1000000, SPI_CLOCK_PHASE_LOW, SPI_CLOCK_POLARITY_LOW) <> ERROR_SUCCESS then
     Exit;

   //Write the data (Note: You can also pass the flag SPI_TRANSFER_DMA to enable DMA transfers)
   if SPIDeviceWrite(SPIDevice, SPI_CS_0, MemoryStream.Memory, MemoryStream.Size, SPI_TRANSFER_NONE, Count) <> ERROR_SUCCESS then
     Exit;

   //Close the SPI device
   SPIDeviceStop(SPIDevice);

   Result := True;
  finally
    //Close File
    MemoryStream.Free;
  end;
end;

The function makes the assumption that 1MHz will be ok as a clock rate, without knowing anything more about the device this seems like it should be a reasonable default. Note that I haven't checked what dd does when talking to an SPI device, it should just perform a raw write of the input bytes but if that isn't the case then you will need to adjust the function accordingly.

You would then call this function in your Ultibo application as simply as:

Code: Select all

 SPISendFile('FPGA-bin-file');

The only other thing your config_cat script does is setup GPIO 17, 22 and 25. I'm sure you can work out how to reproduce that using the GPIOFunctionSelect(), GPIOOutputSet() and GPIOInputGet() functions shown in many other examples.
Ultibo.org | Make something amazing
https://ultibo.org
develone
Posts: 265
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: using dd in ultibo

Postby develone » Sun May 20, 2018 7:05 pm

First of all thanks for you code snippet for the SPI.
The command dd must be doing buffering, normally uses bs=xxM. Did not see in
config_cat.

I created a program
https://github.com/develone/Ultibo_Projects/tree/master/progcat
.
Like the the others in this repository, that provide for TFTP of a new kernel7.img
with the command TFTP xx.xx.xx.xx < cmdstftp. These also provide a webserver, and
logging using a client/server. see server_log below

WiringPi provides a program spiSpeed.c which tries 1,2,4,8,16 and 32 MHz
+-------+--------+----------+----------+-----------+------------+
| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |
+-------+--------+----------+----------+-----------+------------+

| 1 | 4096 | 48.310 | 20.7 | 0.64686 | 15.54200 |
| 1 | 8192 SPI failure: Message too long
| 32 | 4096 | 1.210 | 826.4 | 25.82645 | 0.18600 |
| 32 | 8192 SPI failure: Message too long
All size over 4096 fail.
rw-r--r-- 1 pi pi 135100 May 19 17:23 clktest.bin
slipt the file into 32 files of 4095 & 1 file of 4060
I am getting -1 returned from SPISendFile(Fn);
see
https://github.com/develone/Ultibo_Projects/blob/master/progcat/test.png

Any idea why I am getting a -1 returned? When the file is not present I get 0.
Thanks in advance.
running ./server > xx.txt provides the output below.
server_log
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:06 192.168.1.215 Network: 0000009E - 006DA244:0 - Network: IP: Configuration completed for adapter Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:06 192.168.1.215 Network: 0000009F - 006DA244:0 - Network: IP: Config = CONFIG_TYPE_DHCPr adapter Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:06 192.168.1.215 Network: 000000A0 - 006DA244:0 - Network: IP: Address = 192.168.1.215CPr adapter Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:06 192.168.1.215 Network: 000000A1 - 006DA244:0 - Network: IP: Netmask = 255.255.255.0CPr adapter Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:06 192.168.1.215 Network: 000000A2 - 006DA244:0 - Network: IP: Gateway = 192.168.1.254CPr adapter Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:06 192.168.1.215 Network: 000000A3 - 006DA244:0 - Network: IP: Server = 192.168.1.2544CPr adapter Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <14>Dec 30 00:00:06 192.168.1.215 000000A4 - 0045D9AC:0 - Logging message sent by Main flg 0 at 30-12-99 00:00:06er Network0
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000A5 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE)ðÝñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000A6 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000A7 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000A8 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000A9 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000AA - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000AB - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000AC - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000AD - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000AE - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000AF - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B0 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B1 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B2 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B3 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B4 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B5 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B6 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B7 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B8 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000B9 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000BA - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:07 192.168.1.215 Device: 000000BB - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000BC - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000BD - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000BE - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000BF - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C0 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C1 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C2 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C3 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C4 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C5 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C6 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C7 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C8 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000C9 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000CA - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000CB - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000CC - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000CD - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000CE - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000CF - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D0 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D1 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D2 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D3 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D4 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D5 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D6 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D7 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D8 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000D9 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000DA - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000DB - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000DC - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000DD - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000DE - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000DF - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E0 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E1 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E2 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E3 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E4 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E5 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_ENABLE))Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>Dec 30 00:00:08 192.168.1.215 Device: 000000E6 - 0045D9AC:0 - Device: Sending device notification (Name=SPI0 Class=DEVICE_CLASS_SPI Notification=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...Received packet from 192.168.1.215:49268
Data: <30>May 20 18:23:57 192.168.1.215 Services: 000000E7 - 006528A4:2 - Services: NTP: Setting time to 20-5-18 18:23:57 (from 30-12-99 00:00:10)fication=DEVICE_NOTIFICATION_DISABLE)Ýñ~ïÝñ~ÌÛñ~°Ûñ~ÌLïv`Uñv 
Waiting for data...
User avatar
Ultibo
Site Admin
Posts: 1895
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: using dd in ultibo

Postby Ultibo » Mon May 21, 2018 12:43 am

develone wrote:All size over 4096 fail.

Yes, I forgot that SPI0 has a 16bit size field in the hardware registers.

Here is a updated version of the function that allows you to split the file into chunks "on the fly"

Code: Select all

function SPISendFile2(const Filename: String; BlockSize: LongWord): Boolean;
var
  Size:LongWord;
  Remain:LongWord;
  Offset:PtrUInt;
  Count:LongWord = 0;
  SPIDevice: PSPIDevice;
  MemoryStream: TMemoryStream;
begin
  Result := False;

  //Check the file
  if not FileExists(Filename) then
    Exit;

  //Open the file
  MemoryStream := TMemoryStream.Create;
  try
   //Load the file
   MemoryStream.LoadFromFile(Filename);

   //Locate the SPI device (Adjust for boards other than Pi3)
   SPIDevice := SPIDeviceFindByDescription(BCM2710_SPI0_DESCRIPTION);
   if SPIDevice = nil then
     Exit;

   //Configure SPI Chip Select 0
   if SPIDeviceSetClockRate(SPIDevice ,SPI_CS_0, 1000000) <> ERROR_SUCCESS then
     Exit;

   //Start the SPI device
   if SPIDeviceStart(SPIDevice, SPI_MODE_4WIRE, 1000000, SPI_CLOCK_PHASE_LOW, SPI_CLOCK_POLARITY_LOW) <> ERROR_SUCCESS then
     Exit;

   //Send block size pieces to SPI device
   Remain := MemoryStream.Size;
   Offset := 0;
   while Remain > 0 do
   begin
     //Determine write size
     Size := BlockSize;
     if Size > Remain then Size := Remain;

     //Write the data (Note: You can also pass the flag SPI_TRANSFER_DMA to enable DMA transfers)
     if SPIDeviceWrite(SPIDevice, SPI_CS_0, Pointer(MemoryStream.Memory + Offset), Size, SPI_TRANSFER_NONE, Count) <> ERROR_SUCCESS then
       Exit;

     //Update Remain and Offset
     Dec(Remain, Size);
     Inc(Offset, Size);
   end;

   //Close the SPI device
   SPIDeviceStop(SPIDevice);

   Result := True;
  finally
    //Close File
    MemoryStream.Free;
  end;
end;

Calling this would be similar to the previous version except you need to specify the block size as well.

Code: Select all

 SPISendFile2('FPGA-bin-file', 4096);

develone wrote:Any idea why I am getting a -1 returned? When the file is not present I get 0.

Notice that the function returns a Boolean value, in FPC a Boolean is 0 for False and -1 for True so the -1 return means True (or Success).
Ultibo.org | Make something amazing
https://ultibo.org
develone
Posts: 265
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: using dd in ultibo

Postby develone » Mon May 21, 2018 2:44 am

Tested the new version still getting a -1.
Thanks again.

flg1:=SPISendFile2(Fn,4096,DemoUDPListener.FWindowHandle);

I added the passing of the Window.

Code: Select all

function SPISendFile2(const Filename: String; BlockSize: LongWord;Window:TWindowHandle): Boolean;
var
  Size:LongWord;
  Remain:LongWord;
  Offset:PtrUInt;
  Count:LongWord = 0;
  SPIDevice: PSPIDevice;
  MemoryStream: TMemoryStream;
begin
  Result := False;

  //Check the file
  if not FileExists(Filename) then
    Exit;

  //Open the file
  MemoryStream := TMemoryStream.Create;
  try
   //Load the file
   MemoryStream.LoadFromFile(Filename);

   //Locate the SPI device (Adjust for boards other than Pi3)
   SPIDevice := SPIDeviceFindByDescription(BCM2710_SPI0_DESCRIPTION);

   if SPIDevice = nil then
     Exit;

   //Configure SPI Chip Select 0
   if SPIDeviceSetClockRate(SPIDevice ,SPI_CS_0, 1000000) <> ERROR_SUCCESS then
     Exit;

   //Start the SPI device
   if SPIDeviceStart(SPIDevice, SPI_MODE_4WIRE, 1000000, SPI_CLOCK_PHASE_LOW, SPI_CLOCK_POLARITY_LOW) <> ERROR_SUCCESS then
     Exit;

   //Send block size pieces to SPI device
   Remain := MemoryStream.Size;
   Offset := 0;
   while Remain > 0 do
   begin
     //Determine write size
     Size := BlockSize;
     if Size > Remain then Size := Remain;

     //Write the data (Note: You can also pass the flag SPI_TRANSFER_DMA to enable DMA transfers)
     if SPIDeviceWrite(SPIDevice, SPI_CS_0, Pointer(MemoryStream.Memory + Offset), Size, SPI_TRANSFER_NONE, Count) <> ERROR_SUCCESS then
       Exit;
     ConsoleWindowWriteLn(Window,'In SPISendFile2 '+InttoStr(Remain));
     //Update Remain and Offset
     Dec(Remain, Size);
     Inc(Offset, Size);
   end;


I see that the 135100 is sent to SPI in blocks of 4096.

https://github.com/develone/Ultibo_Proj ... estspi.png
develone
Posts: 265
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: using dd in ultibo

Postby develone » Mon May 21, 2018 10:59 am

Ulttibo wrote
Notice that the function returns a Boolean value, in FPC a Boolean is 0 for False and -1 for True so the -1 return means True (or Success).

I was looking for it to return 1 since this was what I used
ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'return '+Fn+' '+BooltoStr(flg1));
develone
Posts: 265
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: using dd in ultibo

Postby develone » Mon May 21, 2018 5:42 pm

{No pullup pins 11.15,and 22}

Code: Select all

   GPIOPullSelect(GPIO_PIN_11,GPIO_PULL_NONE);
   GPIOPullSelect(GPIO_PIN_15,GPIO_PULL_NONE);
   GPIOPullSelect(GPIO_PIN_22,GPIO_PULL_NONE);

These are BCM 17 pin 11, BCM 22 pin 15, and BCM25 pin 22?
Following the reset the CDONE should go lo This appears to not to happening.
see

https://github.com/develone/Ultibo_Projects/blob/master/progcat/testspi.png


All 3 of the pins have 4.7K pull up resistors.
see
https://github.com/develone/Ultibo_Projects/blob/master/progcat/flash.png

see
https://github.com/develone/Ultibo_Projects/blob/master/progcat/prog.png

Any ideas are welcomed.

Code: Select all

{pin 11 set as input}
   {BCM 17 CDONE}

   GPIOFunctionSelect(GPIO_PIN_11,GPIO_FUNCTION_IN);

   {pins 15 & 22  set as output}
   {BCM 22 CRESET_B}

   GPIOFunctionSelect(GPIO_PIN_15,GPIO_FUNCTION_OUT);

   {BCM 25 R12 IOB_108_SS}

   GPIOFunctionSelect(GPIO_PIN_22,GPIO_FUNCTION_OUT);

   {At this point our UDP server has been started independently of our current thread and will
    continue to run by itself even if this thread terminates. For the sake of the example we will
    go into a loop and send logging messages which should be received by our server}
    LoggingOutput('Logging message sent by ' + ThreadGetName(ThreadGetCurrent) + ' flg '+ IntToStr(flg) + ' at ' + DateTimeToStr(Now));
    HTTPListener:=THTTPListener.Create;
    HTTPListener.Active:=True;
    WebStatusRegister(HTTPListener,'','',True);
    {here is where the new code will be put}

    {BCM 25 R12 IOB_108_SS setting low}
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'setting IOB_108_SS low');
    GPIOOutputSet(GPIO_PIN_22,GPIO_LEVEL_LOW);
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'IOB_108_SS '+ inttostr(GPIOInputGet(GPIO_PIN_22)));

    {Resetting FPGA}
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'Resetting FPGA');
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'Setting Reset low');
    GPIOOutputSet(GPIO_PIN_15,GPIO_LEVEL_LOW);
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'Reset '+ inttostr(GPIOInputGet(GPIO_PIN_15)));

    Sleep(1000);
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'Setting Reset high');
    GPIOOutputSet(GPIO_PIN_15,GPIO_LEVEL_HIGH);
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'Reset '+ inttostr(GPIOInputGet(GPIO_PIN_15)));

    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'CDONE '+ inttostr(GPIOInputGet(GPIO_PIN_11)));

    Fn:='clktest.bin';
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'Sending to SPI ' + Fn);
    flg1:=SPISendFile2(Fn,4096,DemoUDPListener.FWindowHandle);
    if (flg1 )  then ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'True returned from SPI wr '+Fn);
    //ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'return '+Fn+' '+BooltoStr(flg1));

    Fn:='sixzeros.bin';
    flg1:=SPISendFile2(Fn,6,DemoUDPListener.FWindowHandle);
    if (flg1 )  then ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'True returned from SPI wr '+Fn);
    //ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'return '+Fn+' '+BooltoStr(flg1));
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'CDONE '+ inttostr(GPIOInputGet(GPIO_PIN_11)));

    {BCM 25 R12 IOB_108_SS setting high}
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'setting IOB_108_SS high');
    GPIOOutputSet(GPIO_PIN_22,GPIO_LEVEL_HIGH);
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'IOB_108_SS '+ inttostr(GPIOInputGet(GPIO_PIN_22)));
    ConsoleWindowWriteLn(DemoUDPListener.FWindowHandle,'CDONE '+ inttostr(GPIOInputGet(GPIO_PIN_11)));
User avatar
Ultibo
Site Admin
Posts: 1895
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: using dd in ultibo

Postby Ultibo » Mon May 21, 2018 11:33 pm

develone wrote:These are BCM 17 pin 11, BCM 22 pin 15, and BCM25 pin 22?

No, the pin numbers shown in your config_cat script are already the correct numbers to use when talking to the GPIO device.

Simply use GPIO_PIN_17, GPIO_PIN_22 and GPIO_PIN_25 exactly as per the script and it should work.
Ultibo.org | Make something amazing
https://ultibo.org
Gavinmc42
Posts: 1329
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: using dd in ultibo

Postby Gavinmc42 » Tue May 22, 2018 12:44 am

Could this method be used to program the Atmel micros that use SPI programming?
develone
Posts: 265
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: using dd in ultibo

Postby develone » Tue May 22, 2018 2:26 am

That was the fix, bare metal can now program the catboard.
Thanks for all the help in getting this working.

https://github.com/develone/Ultibo_Projects/blob/master/progcat/testspi.png

The catboard & RPi is a complete FPGA development that fits in the palm of your.
The yosys, arachne-pnr, and icestorm provide the means to Synthesis Verilog and create the bitfile.
Now Ultibo provides the means to down load the bitfile into the FPGA.
Thanks, :D :D :D

Return to “General”

Who is online

Users browsing this forum: No registered users and 0 guests