Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding support for a new board Byvac BP2
30-07-2016, 02:10 AM, (This post was last modified: 30-07-2016, 02:14 AM by pingry.)
Adding support for a new board Byvac BP2
So having finally re-visited Pinguino and found that version 12.0.0-beta.1 installs, I am re-visiting a project which I started almost exactly 2 years ago!

At that time I purchased a Olimex Pinguino-Micro board. That's how I found out about Pinguino and at that time got a simple example working with that board.
Some 6 months later having moved I re-visited Pinguino with the hope to add support for a board called the BP2. It is from an English company (from whom I have bought stuff previously). It uses the PIC32MX340F512H and has the same footprint as an Arduino Uno (unlike the Olimex), so allows shields to be plugged in.
At that time I had a nightmare installing the latest version of Pinguino and getting it running, mainly due to installers failing and the folder structure being wrong. I spend more time adding debug code to print out where the tool was looking for a reported missing file, than actually adding support for the BP2 board.

Note that the PIC32MX340F512H processor does not have USB. The board does have space to solder a header which is compatible with the PICkit-3.

Anyway, over the past couple of weeks by poking around in the Python source code and elsewhere, I have managed to add support for the BP2 board. Perhaps I should add a Wiki page to explain how to do this?

There are still some things which are not quite working correctly, but after some guess work and edits I finally managed to get the LED Blink program to blink the LED on the BP2.

I see in the stdout that the final step is to create the hex file from the elf. For some reason I so not get the hex file, but if I open a cmd.exe shell and cut and paste the p32-objcopy.exe command, I do get a hex file. After much searching in the Python source I was unable to find any trace of the code to execute this command. I finally stumbled across it in the in the c:\pinguino\v12\source directory. I see it is a makefile and the target is "convert". If I add other commands to this target they get executed and I see evidence in the stdout log. So why on earth is the p32-objcopy.exe not getting executed???

Now when I eventually got the hex file and loaded into PICkit-3 I could see that the config fuse settings were missing. So I found another hex file from a project which used the Microchip IDE (V8) for the same BP2 board. I cut and pasted the hex code for the fuse settings into the main32.hex file manually. Now the fuses were OK in PICkit-3.

But the code didn't run. I noted that in PICkit-3 the memory display is from 1D000000 and was empty having loaded the main32.hex. I saw that in main32.hex the extended page was set to 9D00 (the first record :020000049D005D). So I changed the 9D to 1D and re-loaded the hex into PICkit-3, and now I see some data. I reset the BP2 board, but the LED did not flash. I noted another record which I am pretty sure is for the boot code in boot flash (:02000004BFC07B). I changed the BF to 1F and re-loaded the hex and programmed the PIC. I reset the PIC and to my utter amazement the LED started to flash. Success!!!

So why does the PCIkit-3 require code to be loaded at 1D000000 and what do I need to change to make this happen. I did change the variables: memstart; memend; and ivtstart in, and although the hex file now had 1D the LED did not flash.

So I would appreciate any help
1) to understand why the p32objcopy.exe in the Makefile is not creating the hex (the binary does exist - I just checked).
2) to understand what command needs adjusting to re-locate the hex from 9D000000 to 1D000000 to keep PICkit-3 happy.
3) what do I need to modify to get the necessary hex for the config fuses added to main32.hex? (BTW, I realise if using a bootloader this is not required).

30-07-2016, 03:26 PM,
RE: Adding support for a new board Byvac BP2

I'll be back from holidays in 10 days. If you don't find it out meanwhile please take contact with me and I'll help you to solve this.
It is easier to complain than it is to do, but it is better to do than it is to complain.
15-08-2016, 01:13 AM,
RE: Adding support for a new board Byvac BP2
I'm slowing continuing modifying all the necessary files (that I know of).
I now have the analogue read working.
Only question is the #define __ANALOG__. Where is this defined? In pin.h the values of A0, A1 etc seem to alter depending upon whether it is defined or not, and I can't figure out why. I needed to fix this so that A0 was 0 and this fixed the problem I was having.
15-08-2016, 12:05 PM,
RE: Adding support for a new board Byvac BP2
analog.c:31:#ifndef __ANALOG__
analog.c:32:#define __ANALOG__

It is easier to complain than it is to do, but it is better to do than it is to complain.
17-08-2016, 01:37 AM,
RE: Adding support for a new board Byvac BP2
Hi Regis, I hope that you had a nice holiday...

I am still not 100% where all the files are to be found, so it is not so easy to grep for a specific string, but I was aware of the above in analog.c
The question is is analog.c always "included" or for some boards is this file excluded, so that __ANALOG__ is not defined?
Anyhow I have added an #ifdef for the BP2 board and defined A0 as 0, A1 as 1, etc. This works and should not affect code for any other board.

I have the spare serial connector working as "Serial2", but I haven't checked out the standard Rx/Tx pins on the digital pins 0 and 1.

Something I hope to try soon is plugging in a 2 line LCD display, to see if this works.

More postings and questions will follow.....
17-08-2016, 06:06 PM,
RE: Adding support for a new board Byvac BP2
You can use -R or -r or --recursive to grep recursively or a command like
find path -iname '*.[ch]' -print0 | xargs -0 grep pattern

(zeroes not letter ohs)

18-08-2016, 10:16 AM,
RE: Adding support for a new board Byvac BP2
Pinguino C files are included only when some keywords are used.

These keywords and the files to include are defined in the pdl (or pdl32 for the 32-bit) files.
All these pdl(32) files are scanned when the IDE start to make a kind of Pinguino's instructions dictionary.

Let's find which pdl32 file includes analog.c :
>grep -rnw '/opt/pinguino/v12/p32/pdl' -e 'analog.c'

/opt/pinguino/v12/p32/pdl/pinguino.pdl32:6:analogRead analogRead#include <analog.c>

So when the Pinguino analogRead() keyword is used, the IDE replaces it with the C analogRead() function which takes place in analog.c. When analog.c is included, __ANALOG__ is defined.
It is easier to complain than it is to do, but it is better to do than it is to complain.
18-08-2016, 10:47 PM,
RE: Adding support for a new board Byvac BP2
OK thanks. I didn't know about the pdl32 files.

I tried the 2 line LCD program but the LCD didn't display anything. So I decided to write some test code to make sure I have mapped the digital pins correctly.
For the first time I noted that you can view main.c, user.c and define.h. In define.h I can see a number of defines which appear to be based on the keywords found in the code. I assume that analog.c is only included in define.h if an analog function is found?

Anyway I have a link error. The problem is pinMode. This is very strange as the LED blink program compiles and links OK. I note that the define.h file for my broken test code does not have the line #define PINMODE. The function call is clearly there in setup(), and in fact the text came from the auto-function-insert feature. So I am now scratching my head as to what has gone wrong.

I found the digital.pdl and saw the pinMode entry, so I am puzzled why the #define PINMODE is missing.
18-08-2016, 11:06 PM,
RE: Adding support for a new board Byvac BP2
I have just found the pinMode problem.
I was being lazy and didn't indent the code. This appears to have been the problem.
I added a space before the pinMode function call, and the program linked correctly.
I would suggest this is a bug, as spaces at the start of a line are not necessary for the syntax, although almost always found.

My digital test is working and I see channels D0 to D12 all toggling correctly on the scope.

So more debugging to solve the LCD problem.

I also need to debug BlinkWithoutDelay where the USERLED is not blinking.
20-08-2016, 09:42 PM,
RE: Adding support for a new board Byvac BP2
If millis() is used, this seems to cause an immediate crash/lock-up.

I suspect interrupts, and have been checking the sources of any files which appear relevant.

It coulds also be somewhere in procdef.ld

Could me more tricky to debug. I'm not a fan (and not an expert) in PIC32 interrupts.

Forum Jump:

Users browsing this thread: 1 Guest(s)