|
31 | 31 | #include "EefcFlash.h"
|
32 | 32 | #include "NvmFlash.h"
|
33 | 33 |
|
| 34 | +void |
| 35 | +Device::readChipId(uint32_t& chipId, uint32_t& extChipId) |
| 36 | +{ |
| 37 | + if ((chipId = _samba.readWord(0x400e0740)) != 0) |
| 38 | + { |
| 39 | + extChipId = _samba.readWord(0x400e0744); |
| 40 | + } |
| 41 | + else if ((chipId = _samba.readWord(0x400e0940)) != 0) |
| 42 | + { |
| 43 | + extChipId = _samba.readWord(0x400e0944); |
| 44 | + } |
| 45 | +} |
| 46 | + |
34 | 47 | void
|
35 | 48 | Device::create()
|
36 | 49 | {
|
37 | 50 | Flash* flashPtr;
|
38 | 51 | uint32_t chipId = 0;
|
| 52 | + uint32_t cpuId = 0; |
39 | 53 | uint32_t extChipId = 0;
|
40 | 54 | uint32_t deviceId = 0;
|
41 | 55 |
|
42 | 56 | // Device identification must be performed carefully to avoid reading from
|
43 |
| - // addresses that devices do not support. |
| 57 | + // addresses that devices do not support which will lock up the CPU |
44 | 58 |
|
45 | 59 | // All devices support addresss 0 as the ARM reset vector so if the vector is
|
46 | 60 | // a ARM7TDMI branch, then assume we have an Atmel SAM7/9 CHIPID register
|
47 | 61 | if ((_samba.readWord(0x0) & 0xff000000) == 0xea000000)
|
48 | 62 | {
|
49 | 63 | chipId = _samba.readWord(0xfffff240);
|
50 | 64 | }
|
51 |
| - // Next try the ARM CPUID register since all Coretex-M devices support it. |
52 |
| - // If it identifies a Coretex M0+, then assume we have a SAMD device |
53 |
| - // that only supports the ARM device ID register |
54 |
| - else if ((_samba.readWord(0xe000ed00) & 0x0000fff0) == 0xC600) |
55 |
| - { |
56 |
| - deviceId = _samba.readWord(0x41002018); |
57 |
| - } |
58 |
| - // Assume we have a SAM3, SAM4 or SAME70 so check the CHIPID registers |
59 |
| - else if ((chipId = _samba.readWord(0x400e0740)) != 0) |
60 |
| - { |
61 |
| - extChipId = _samba.readWord(0x400e0744); |
62 |
| - } |
63 |
| - else if ((chipId = _samba.readWord(0x400e0940)) != 0) |
64 |
| - { |
65 |
| - extChipId = _samba.readWord(0x400e0944); |
66 |
| - } |
67 |
| - // Else we don't know what the device is |
68 | 65 | else
|
69 | 66 | {
|
70 |
| - throw DeviceUnsupportedError(); |
| 67 | + // Next try the ARM CPUID register since all Cortex-M devices support it |
| 68 | + cpuId = _samba.readWord(0xe000ed00) & 0x0000fff0; |
| 69 | + |
| 70 | + // Cortex-M0+ |
| 71 | + if (cpuId == 0xC600) |
| 72 | + { |
| 73 | + // These should support the ARM device ID register |
| 74 | + deviceId = _samba.readWord(0x41002018); |
| 75 | + } |
| 76 | + // Cortex-M4 |
| 77 | + else if (cpuId == 0xC240) |
| 78 | + { |
| 79 | + // SAM4 processors have a reset vector to the SAM-BA ROM |
| 80 | + if ((_samba.readWord(0x4) & 0xfff00000) == 0x800000) |
| 81 | + { |
| 82 | + readChipId(chipId, extChipId); |
| 83 | + } |
| 84 | + // Else we should have a device that supports the ARM device ID register |
| 85 | + else |
| 86 | + { |
| 87 | + deviceId = _samba.readWord(0x41002018); |
| 88 | + } |
| 89 | + } |
| 90 | + // For all other Cortex versions try the Atmel chip ID registers |
| 91 | + else |
| 92 | + { |
| 93 | + readChipId(chipId, extChipId); |
| 94 | + } |
71 | 95 | }
|
72 | 96 |
|
73 | 97 | // Instantiate the proper flash for the device
|
@@ -486,7 +510,7 @@ Device::create()
|
486 | 510 | }
|
487 | 511 |
|
488 | 512 | void
|
489 |
| -Device::reset(void) |
| 513 | +Device::reset() |
490 | 514 | {
|
491 | 515 | try
|
492 | 516 | {
|
|
0 commit comments