Skip to content

Commit a2e1867

Browse files
committed
_canio: Minimal implementation for SAM E5x MCUs
Tested & working: * Send standard packets * Receive standard packets (1 FIFO, no filter) Interoperation between SAM E54 Xplained running this tree and MicroPython running on STM32F405 Feather with an external transceiver was also tested. Many other aspects of a full implementation are not yet present, such as error detection and recovery.
1 parent e7a213a commit a2e1867

30 files changed

Lines changed: 2190 additions & 3 deletions

main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
#include "supervisor/shared/bluetooth.h"
8282
#endif
8383

84+
#if CIRCUITPY_CANIO
85+
#include "common-hal/_canio/CAN.h"
86+
#endif
87+
8488
void do_str(const char *src, mp_parse_input_kind_t input_kind) {
8589
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
8690
if (lex == NULL) {
@@ -226,6 +230,10 @@ void cleanup_after_vm(supervisor_allocation* heap) {
226230
free_memory(heap);
227231
supervisor_move_memory();
228232

233+
#ifdef CIRCUITPY_CANIO
234+
common_hal_canio_reset();
235+
#endif
236+
229237
reset_port();
230238
#if CIRCUITPY_BOARD
231239
reset_board_busses();

ports/atmel-samd/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ SRC_QSTR += $(HEADER_BUILD)/sdiodata.h
393393
$(HEADER_BUILD)/sdiodata.h: tools/mksdiodata.py | $(HEADER_BUILD)
394394
$(Q)$(PYTHON3) $< > $@
395395

396+
SRC_QSTR += $(HEADER_BUILD)/candata.h
397+
$(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD)
398+
$(Q)$(PYTHON3) $< > $@
399+
396400
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
397401
# Sources that only hold QSTRs after pre-processing.
398402
SRC_QSTR_PREPROCESSOR += peripherals/samd/$(PERIPHERALS_CHIP_FAMILY)/clocks.c

ports/atmel-samd/asf4_conf/same54/peripheral_clk_config.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,88 @@
11651165
#define CONF_SDHC1_SLOW_FREQUENCY 12000000
11661166
#endif
11671167

1168+
// <h> CAN Clock Settings
1169+
// <y> CAN Clock source
1170+
1171+
// <GCLK_PCHCTRL_GEN_GCLK0_Val"> Generic clock generator 0
1172+
1173+
// <GCLK_PCHCTRL_GEN_GCLK1_Val"> Generic clock generator 1
1174+
1175+
// <GCLK_PCHCTRL_GEN_GCLK2_Val"> Generic clock generator 2
1176+
1177+
// <GCLK_PCHCTRL_GEN_GCLK3_Val"> Generic clock generator 3
1178+
1179+
// <GCLK_PCHCTRL_GEN_GCLK4_Val"> Generic clock generator 4
1180+
1181+
// <GCLK_PCHCTRL_GEN_GCLK5_Val"> Generic clock generator 5
1182+
1183+
// <GCLK_PCHCTRL_GEN_GCLK6_Val"> Generic clock generator 6
1184+
1185+
// <GCLK_PCHCTRL_GEN_GCLK7_Val"> Generic clock generator 7
1186+
1187+
// <GCLK_PCHCTRL_GEN_GCLK8_Val"> Generic clock generator 8
1188+
1189+
// <GCLK_PCHCTRL_GEN_GCLK9_Val"> Generic clock generator 9
1190+
1191+
// <GCLK_PCHCTRL_GEN_GCLK10_Val"> Generic clock generator 10
1192+
1193+
// <GCLK_PCHCTRL_GEN_GCLK11_Val"> Generic clock generator 11
1194+
1195+
// <i> Select the clock source for CAN.
1196+
// <id> sdhc_gclk_selection
1197+
#ifndef CONF_GCLK_CAN0_SRC
1198+
#define CONF_GCLK_CAN0_SRC GCLK_PCHCTRL_GEN_GCLK0_Val
1199+
#endif
1200+
1201+
/**
1202+
* \def CAN FREQUENCY
1203+
* \brief CAN's Clock frequency
1204+
*/
1205+
#ifndef CONF_CAN0_FREQUENCY
1206+
#define CONF_CAN0_FREQUENCY 120000000
1207+
#endif
1208+
1209+
// <h> CAN Clock Settings
1210+
// <y> CAN Clock source
1211+
1212+
// <GCLK_PCHCTRL_GEN_GCLK0_Val"> Generic clock generator 0
1213+
1214+
// <GCLK_PCHCTRL_GEN_GCLK1_Val"> Generic clock generator 1
1215+
1216+
// <GCLK_PCHCTRL_GEN_GCLK2_Val"> Generic clock generator 2
1217+
1218+
// <GCLK_PCHCTRL_GEN_GCLK3_Val"> Generic clock generator 3
1219+
1220+
// <GCLK_PCHCTRL_GEN_GCLK4_Val"> Generic clock generator 4
1221+
1222+
// <GCLK_PCHCTRL_GEN_GCLK5_Val"> Generic clock generator 5
1223+
1224+
// <GCLK_PCHCTRL_GEN_GCLK6_Val"> Generic clock generator 6
1225+
1226+
// <GCLK_PCHCTRL_GEN_GCLK7_Val"> Generic clock generator 7
1227+
1228+
// <GCLK_PCHCTRL_GEN_GCLK8_Val"> Generic clock generator 8
1229+
1230+
// <GCLK_PCHCTRL_GEN_GCLK9_Val"> Generic clock generator 9
1231+
1232+
// <GCLK_PCHCTRL_GEN_GCLK10_Val"> Generic clock generator 10
1233+
1234+
// <GCLK_PCHCTRL_GEN_GCLK11_Val"> Generic clock generator 11
1235+
1236+
// <i> Select the clock source for CAN.
1237+
// <id> sdhc_gclk_selection
1238+
#ifndef CONF_GCLK_CAN1_SRC
1239+
#define CONF_GCLK_CAN1_SRC GCLK_PCHCTRL_GEN_GCLK0_Val
1240+
#endif
1241+
1242+
/**
1243+
* \def CAN FREQUENCY
1244+
* \brief CAN's Clock frequency
1245+
*/
1246+
#ifndef CONF_CAN1_FREQUENCY
1247+
#define CONF_CAN1_FREQUENCY 120000000
1248+
#endif
1249+
11681250
// <<< end of configuration section >>>
11691251

11701252
#endif // PERIPHERAL_CLK_CONFIG_H

ports/atmel-samd/boards/common.template.ld

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SECTIONS
5151
{
5252
. = ALIGN(4);
5353
_srelocate = .; /* create a global symbol at data start; used by startup code in order to initialize the .data section in RAM */
54+
. = ALIGN(4);
5455
*(.ramfunc)
5556
*(.ramfunc*)
5657
*(.data) /* .data sections */
@@ -61,11 +62,15 @@ SECTIONS
6162
} >RAM
6263

6364
/* Uninitialized data section */
64-
.bss :
65+
.bss (NOLOAD) :
6566
{
6667
. = ALIGN(4);
6768
_sbss = .;
6869
_szero = .; /* define a global symbol at bss start; used by startup code */
70+
/* Data accessed by the CAN peripheral must be in the first 64kB RAM */
71+
_scanram = .;
72+
*(.canram)
73+
_ecanram = .;
6974
*(.bss)
7075
*(.bss*)
7176
*(COMMON)

ports/atmel-samd/boards/same54_xplained/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ EXTERNAL_FLASH_DEVICES = "N25Q256A"
1212
LONGINT_IMPL = MPZ
1313

1414
CIRCUITPY_SDIOIO = 1
15+
CIRCUITPY_CANIO = 1

ports/atmel-samd/boards/same54_xplained/pins.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
4848

4949
{ MP_OBJ_NEW_QSTR(MP_QSTR_QT), MP_ROM_PTR(&pin_PA16) },
5050

51-
{ MP_OBJ_NEW_QSTR(MP_QSTR_CANRX), MP_ROM_PTR(&pin_PB12) },
52-
{ MP_OBJ_NEW_QSTR(MP_QSTR_CANTX), MP_ROM_PTR(&pin_PB13) },
51+
{ MP_OBJ_NEW_QSTR(MP_QSTR_CAN_RX), MP_ROM_PTR(&pin_PB13) },
52+
{ MP_OBJ_NEW_QSTR(MP_QSTR_CAN_TX), MP_ROM_PTR(&pin_PB12) },
53+
{ MP_OBJ_NEW_QSTR(MP_QSTR_CAN_STANDBY), MP_ROM_PTR(&pin_PC13) },
5354

5455
// EXT1 header
5556
{ MP_OBJ_NEW_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) },

0 commit comments

Comments
 (0)