Need some advise to create a variant for SAM3S4B (Cortex M3)

Hi,

I try to create a variant for SAM3S4B. I copied the ARDUINO_DUE_X - variant and changed linker-scripts to match Memory Layout as well as boards.txt, variant.h and variant.cpp in order to match the MCU.

But when I try to compile an empty sketch (just setup() and loop()) I get this error:

C:\Users\THE-FA~1\AppData\Local\Temp\build8843946045277256087.tmp\syscalls_sam3.c.o
C:\Users\the-fallen\Desktop\arduino-1.5.8\hardware\arduino\sam\cores\arduino\syscalls_sam3.c: In function '_write':
C:\Users\the-fallen\Desktop\arduino-1.5.8\hardware\arduino\sam\cores\arduino\syscalls_sam3.c:123:13: error: 'UART' undeclared (first use in this function)
while ((UART->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY)
^

I was trying to find out why but I am not able to find it. One thing: there is no
instance_uart.h in hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3s\include\instance

and therefore not included in sam3s4b.h (which is the only difference to sam3xa that I found: there this file is available and included).

I think I have to deactivate a feature or property somewhere, but I do not know where. I hope somebody could point me to the right direction.

Thanks in advance.

Looking on the whitepapers I can see that the SAM3XA has uart while SAM3S has uart0 and uart1 but not uart (seems to be a thing of definitions) so I am pretty sure I just need to disable or change something. I hope somebody can tell me where.

In Atmel speak, "UART" is a basic UART with TX/RX, "USART" is a more advanced UART with modem control lines etc.

It appears that the UART block in the SAM3S is the same as the SAM3X UART. Only if there are more than one instance do they number them. So you should be able to replace UART with UART0.

Note that the way Arduino structure the system, code in hardware\arduino\sam\cores\arduino is effectively specific to SAM3X cores, although the name doesn't reflect that. So there will be several places where you need to change code for SAM3S.

Are you working with off-the-shelf board or your own design?

Thanks for your answear.

Looking on the whitepaper, the SAM3X does have uart, uart0 and uart1 (three times uart) and usart (according to the block scheme)
On the whitepaper of the SAM3S there is only uart0 and uart1 mentioned but no uart (without a trailing number). I will try to find out what will happen if I rename uart1 to uart, tomorrow.

I am using an off-the-shelf board (Olimex SAM3-H256) or at least I plan to use it. It just arrived yesterday.

I tried to alter everything that I found within the sam3x/a variant that is different to the sam3s. So I altered Memory Mapping, Pin Mapping, Clock Speed... but it is the first time I am doing that so I have no experience and might have done something wrong or missed something.

And something I seem to have missed and so this error appeares.

When I chance UART to UART1 it compiles (until some other errors occur).

Generally I noticed that hardware\arduino\sam\cores\arduino is kind of "specially adapted" to the Chip the DUE has (and the precessor they used on their first developement boards).
I also noticed that the Atmel Software Framework (ASF) seems to be outdated, which is not a problem as long as you do not want to add variants with different MCUs. :grin:

I continue trying to get my SAM3S4B working and hopefully will get it working.

At the moment I stuck with the TimerCounters. TC1 and TC2 tha is used in wiring_analog.c is not declared and I have not found out yet why it is declared for the DUE.

elfallino:
Generally I noticed that hardware\arduino\sam\cores\arduino is kind of "specially adapted" to the Chip the DUE has (and the precessor they used on their first developement boards).

I believe that is right. Looks like they started with a SAM3S but ended up with SAM3X8E.

elfallino:
I also noticed that the Atmel Software Framework (ASF) seems to be outdated, which is not a problem as long as you do not want to add variants with different MCUs. :grin:

I couldn't figure out which version of ASF Arduino had used, Atmel release a lot of versions of ASF with lots of changes, and they don't keep an archive of old versions.

elfallino:
At the moment I stuck with the TimerCounters. TC1 and TC2 tha is used in wiring_analog.c is not declared and I have not found out yet why it is declared for the DUE.

Due has 9 timers in 3 blocks of 3, the SAM3S4B has one block of 3 timers. Very confusingly, Atmel refer to the blocks as TCn and also timer channels as TCn. So I guess that missing references to TC1 and TC2 are to timer blocks that the SAM3S4B does not have.

The Due code has plenty of timers to play with, but you will have to figure out to manage with less timers :frowning: