mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-27 20:48:29 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fa66cab0e | ||
|
|
0f7166c5ad |
No files matched your search
+165
-102
@@ -12202,6 +12202,52 @@ bool mg_ota_end(void) {
|
||||
|
||||
#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1180
|
||||
|
||||
// Take non-specified Flash chip settings from dev board family
|
||||
#if MG_OTA == MG_OTA_RT1050
|
||||
#ifndef MG_IMXRT_HYPER
|
||||
#define MG_IMXRT_HYPER 1
|
||||
#endif
|
||||
#ifndef MG_IMXRT_SECTOR_SIZE
|
||||
#define MG_IMXRT_SECTOR_SIZE (256 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_BLOCK_SIZE
|
||||
#define MG_IMXRT_BLOCK_SIZE (256 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_PAGE_SIZE
|
||||
#define MG_IMXRT_PAGE_SIZE 512
|
||||
#endif
|
||||
#ifndef MG_IMXRT_FLASH_SIZE
|
||||
#define MG_IMXRT_FLASH_SIZE (64 * 1024 * 1024)
|
||||
#endif
|
||||
#else // rest of the boards
|
||||
#ifndef MG_IMXRT_HYPER
|
||||
#define MG_IMXRT_HYPER 0
|
||||
#endif
|
||||
#ifndef MG_IMXRT_SECTOR_SIZE
|
||||
#define MG_IMXRT_SECTOR_SIZE (4 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_BLOCK_SIZE
|
||||
#define MG_IMXRT_BLOCK_SIZE (64 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_PAGE_SIZE
|
||||
#define MG_IMXRT_PAGE_SIZE 256
|
||||
#endif
|
||||
#if MG_OTA == MG_OTA_RT1180 // now define per-board flash size
|
||||
#ifndef MG_IMXRT_FLASH_SIZE
|
||||
#define MG_IMXRT_FLASH_SIZE (16 * 1024 * 1024)
|
||||
#endif
|
||||
#else // rest of the boards
|
||||
#ifndef MG_IMXRT_FLASH_SIZE
|
||||
#define MG_IMXRT_FLASH_SIZE (8 * 1024 * 1024)
|
||||
#endif // default flash size gate
|
||||
#endif // per-board flash size
|
||||
#endif // default flash settings
|
||||
|
||||
#ifndef MG_IMXRT_PARAM_SECTOR_COUNT
|
||||
// Number of small parameter sectors at the bottom of flash
|
||||
#define MG_IMXRT_PARAM_SECTOR_COUNT 0
|
||||
#endif
|
||||
|
||||
static bool mg_imxrt_write(void *, const void *, size_t);
|
||||
static bool mg_imxrt_swap(void);
|
||||
|
||||
@@ -12219,12 +12265,14 @@ static bool mg_imxrt_swap(void);
|
||||
#define FLEXSPI_NOR_INSTANCE 2
|
||||
#endif
|
||||
|
||||
#if MG_OTA == MG_OTA_RT1050
|
||||
#define MG_IMXRT_SECTOR_SIZE (256 * 1024)
|
||||
#define MG_IMXRT_PAGE_SIZE 512
|
||||
#if MG_OTA == MG_OTA_RT1180
|
||||
#ifndef MG_FLEXSPI_SERIAL_CLK_FREQ
|
||||
#define MG_FLEXSPI_SERIAL_CLK_FREQ 5 // 100MHz
|
||||
#endif
|
||||
#else
|
||||
#define MG_IMXRT_SECTOR_SIZE (4 * 1024)
|
||||
#define MG_IMXRT_PAGE_SIZE 256
|
||||
#ifndef MG_FLEXSPI_SERIAL_CLK_FREQ
|
||||
#define MG_FLEXSPI_SERIAL_CLK_FREQ 7 // 133MHz
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// TODO(): fill at init, support more devices in a dynamic way
|
||||
@@ -12330,6 +12378,7 @@ struct mg_flexspi_nor_config {
|
||||
#define MG_FLEXSPI_4PAD 2
|
||||
#define MG_FLEXSPI_8PAD 3
|
||||
|
||||
// [1]'s 0x06 sets 6 post-read latency cycles, otherwise use a lower speed
|
||||
#define MG_FLEXSPI_QSPI_LUT \
|
||||
{ \
|
||||
[0] = MG_FLEXSPI_LUT_SEQ(MG_CMD_SDR, MG_FLEXSPI_1PAD, 0xEB, MG_RADDR_SDR, \
|
||||
@@ -12352,6 +12401,7 @@ struct mg_flexspi_nor_config {
|
||||
MG_STOP, MG_FLEXSPI_1PAD, 0x0), \
|
||||
}
|
||||
|
||||
// [1]'s 0x0c sets HyperBus post-address latency; use a lower speed if needed
|
||||
#define MG_FLEXSPI_HYPER_LUT \
|
||||
{ \
|
||||
[0] = MG_FLEXSPI_LUT_SEQ(MG_CMD_DDR, MG_FLEXSPI_8PAD, 0xA0, MG_RADDR_DDR, \
|
||||
@@ -12574,15 +12624,31 @@ struct mg_flexspi_nor_driver_interface {
|
||||
|
||||
static bool s_flash_irq_disabled;
|
||||
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
MG_IRAM static size_t flash_sector_size(volatile uint32_t *dst) {
|
||||
char *base = (char *) s_mg_flash_imxrt.start;
|
||||
size_t offset = (size_t) ((char *) dst - base);
|
||||
size_t params = MG_IMXRT_PARAM_SECTOR_COUNT * MG_IMXRT_SECTOR_SIZE;
|
||||
if (offset >= params) return MG_IMXRT_BLOCK_SIZE;
|
||||
return s_mg_flash_imxrt.secsz;
|
||||
}
|
||||
#endif
|
||||
|
||||
MG_IRAM static bool flash_page_start(volatile uint32_t *dst) {
|
||||
char *base = (char *) s_mg_flash_imxrt.start,
|
||||
*end = base + s_mg_flash_imxrt.size;
|
||||
volatile char *p = (char *) dst;
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
return p >= base && p < end && ((p - base) % flash_sector_size(dst)) == 0;
|
||||
#else
|
||||
return p >= base && p < end && ((p - base) % s_mg_flash_imxrt.secsz) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MG_OTA == MG_OTA_RT1050
|
||||
// Configuration for Hyper flash memory
|
||||
#if MG_IMXRT_HYPER
|
||||
// Configuration for HyperFlash memory
|
||||
// serialClkFreq, dataValidTime, and lookupTable (MG_FLEXSPI_HYPER_LUT code)
|
||||
// must agree to flash specs
|
||||
static struct mg_flexspi_nor_config default_config = {
|
||||
.memConfig =
|
||||
{
|
||||
@@ -12596,8 +12662,8 @@ static struct mg_flexspi_nor_config default_config = {
|
||||
MG_BIT(6) | MG_BIT(4) | MG_BIT(3) | MG_BIT(0),
|
||||
.deviceType = 1, // serial NOR
|
||||
.sflashPadType = 8,
|
||||
.serialClkFreq = 7, // 133MHz
|
||||
.sflashA1Size = 64 * 1024 * 1024,
|
||||
.serialClkFreq = MG_FLEXSPI_SERIAL_CLK_FREQ,
|
||||
.sflashA1Size = MG_IMXRT_FLASH_SIZE,
|
||||
.dataValidTime = {15, 0},
|
||||
.busyOffset = 15,
|
||||
.busyBitPolarity = 1,
|
||||
@@ -12605,22 +12671,16 @@ static struct mg_flexspi_nor_config default_config = {
|
||||
.lookupTable = MG_FLEXSPI_HYPER_LUT,
|
||||
.lutCustomSeq = MG_LUT_CUSTOM_SEQ,
|
||||
},
|
||||
.pageSize = 512,
|
||||
.sectorSize = 256 * 1024,
|
||||
.pageSize = MG_IMXRT_PAGE_SIZE,
|
||||
.sectorSize = MG_IMXRT_SECTOR_SIZE,
|
||||
.ipcmdSerialClkFreq = 1,
|
||||
.serialNorType = 1u,
|
||||
.blockSize = 256 * 1024,
|
||||
.blockSize = MG_IMXRT_BLOCK_SIZE,
|
||||
.isUniformBlockSize = true};
|
||||
#else
|
||||
// Note: this QSPI configuration works for RTs supporting QSPI
|
||||
// Configuration for QSPI memory
|
||||
#if MG_OTA == MG_OTA_RT1180
|
||||
#define MG_FLEXSPI_QSPI_SERIAL_CLK_FREQ 5 // 100MHz
|
||||
#define MG_FLEXSPI_QSPI_FLASH_SIZE (16 * 1024 * 1024)
|
||||
#else
|
||||
#define MG_FLEXSPI_QSPI_SERIAL_CLK_FREQ 7 // 133MHz
|
||||
#define MG_FLEXSPI_QSPI_FLASH_SIZE (8 * 1024 * 1024)
|
||||
#endif
|
||||
// serialClkFreq (AHB/read clock) and lookupTable (MG_FLEXSPI_QSPI_LUT code)
|
||||
// must agree to flash specs
|
||||
static struct mg_flexspi_nor_config default_config = {
|
||||
.memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG,
|
||||
.version = MG_FLEXSPI_CFG_BLK_VERSION,
|
||||
@@ -12630,13 +12690,13 @@ static struct mg_flexspi_nor_config default_config = {
|
||||
.controllerMiscOption = MG_BIT(4),
|
||||
.deviceType = 1, // serial NOR
|
||||
.sflashPadType = 4,
|
||||
.serialClkFreq = MG_FLEXSPI_QSPI_SERIAL_CLK_FREQ,
|
||||
.sflashA1Size = MG_FLEXSPI_QSPI_FLASH_SIZE,
|
||||
.serialClkFreq = MG_FLEXSPI_SERIAL_CLK_FREQ,
|
||||
.sflashA1Size = MG_IMXRT_FLASH_SIZE,
|
||||
.lookupTable = MG_FLEXSPI_QSPI_LUT},
|
||||
.pageSize = 256,
|
||||
.sectorSize = 4 * 1024,
|
||||
.pageSize = MG_IMXRT_PAGE_SIZE,
|
||||
.sectorSize = MG_IMXRT_SECTOR_SIZE,
|
||||
.ipcmdSerialClkFreq = 1,
|
||||
.blockSize = 64 * 1024,
|
||||
.blockSize = MG_IMXRT_BLOCK_SIZE,
|
||||
.isUniformBlockSize = false};
|
||||
#endif
|
||||
|
||||
@@ -12686,8 +12746,13 @@ MG_IRAM static bool flash_erase(struct mg_flexspi_nor_config *config,
|
||||
|
||||
void *dst = (void *) ((char *) addr - (char *) s_mg_flash_imxrt.start);
|
||||
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
bool ok = (flexspi_nor->erase(FLEXSPI_NOR_INSTANCE, config, (uint32_t) dst,
|
||||
flash_sector_size(addr)) == 0);
|
||||
#else
|
||||
bool ok = (flexspi_nor->erase(FLEXSPI_NOR_INSTANCE, config, (uint32_t) dst,
|
||||
s_mg_flash_imxrt.secsz) == 0);
|
||||
#endif
|
||||
MG_DEBUG(("Sector starting at %p erasure: %s", addr, ok ? "ok" : "fail"));
|
||||
return ok;
|
||||
}
|
||||
@@ -12750,14 +12815,13 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
||||
}
|
||||
#else
|
||||
// When supported, prefer the read API call.
|
||||
uint32_t src_ofs =
|
||||
(uint32_t) src - (uint32_t) s_mg_flash_imxrt.start;
|
||||
status = flexspi_nor->read(FLEXSPI_NOR_INSTANCE, config_ptr, tmp,
|
||||
src_ofs, s_mg_flash_imxrt.align);
|
||||
uint32_t src_ofs = (uint32_t) src - (uint32_t) s_mg_flash_imxrt.start;
|
||||
status = flexspi_nor->read(FLEXSPI_NOR_INSTANCE, config_ptr, tmp, src_ofs,
|
||||
s_mg_flash_imxrt.align);
|
||||
#endif
|
||||
if (status == 0) {
|
||||
status = flexspi_nor->program(FLEXSPI_NOR_INSTANCE, config_ptr,
|
||||
dst_ofs, tmp);
|
||||
status = flexspi_nor->program(FLEXSPI_NOR_INSTANCE, config_ptr, dst_ofs,
|
||||
tmp);
|
||||
}
|
||||
} else {
|
||||
status = flexspi_nor->program(FLEXSPI_NOR_INSTANCE, config_ptr,
|
||||
@@ -12789,7 +12853,11 @@ MG_IRAM static void single_bank_swap(char *p1, char *p2, size_t s, size_t ss) {
|
||||
}
|
||||
|
||||
MG_IRAM static bool mg_imxrt_swap(void) {
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
size_t ss = MG_IMXRT_BLOCK_SIZE;
|
||||
#else
|
||||
size_t ss = s_mg_flash_imxrt.secsz;
|
||||
#endif
|
||||
char *p1 = (char *) s_mg_flash_imxrt.start;
|
||||
char *p2 = p1 + s_mg_flash_imxrt.size / 2;
|
||||
size_t s = s_mg_flash_imxrt.size / 2 - ss;
|
||||
@@ -12803,7 +12871,11 @@ MG_IRAM static bool mg_imxrt_swap(void) {
|
||||
}
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
size_t max = s_mg_flash_imxrt.size / 2 - MG_IMXRT_BLOCK_SIZE;
|
||||
#else
|
||||
size_t max = s_mg_flash_imxrt.size / 2 - s_mg_flash_imxrt.secsz;
|
||||
#endif
|
||||
if (new_firmware_size > max) {
|
||||
MG_ERROR(("Firmware %lu too big for single-bank OTA, max %lu",
|
||||
new_firmware_size, max));
|
||||
@@ -33128,7 +33200,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) {
|
||||
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||
NETC_EMDIO->EMDIO_CFG =
|
||||
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
|
||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||
mg_phy_init(&phy, d->phy_addr, 0);
|
||||
|
||||
// Initialize ENETC1 PSI0 and port
|
||||
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||
@@ -33632,22 +33704,20 @@ bool __attribute__((weak)) mg_wifi_ap_stop(void) {
|
||||
|
||||
|
||||
|
||||
enum { // ID1 ID2
|
||||
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
||||
MG_PHY_DP83x = 0x2000, //
|
||||
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
||||
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
||||
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
||||
MG_PHY_LANxVSCx = 0x7, // 0007 xxxx | cxxx: SMSC | 0xxx: Vitesse
|
||||
MG_PHY_LAN87x = 0xc0f0, // 0007 c0fx - LAN8720
|
||||
MG_PHY_VSC8531 = 0x0572, // 0007 0572 - VSC8531-02
|
||||
MG_PHY_RTL82x = 0x1c, //
|
||||
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
||||
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
||||
MG_PHY_ICS1894x = 0x15, //
|
||||
enum { // ID1 ID2
|
||||
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
||||
MG_PHY_DP83x = 0x2000,
|
||||
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
||||
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
||||
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
||||
MG_PHY_LAN87x = 0x7, // 0007 c0fx - LAN8720
|
||||
MG_PHY_RTL82x = 0x1c,
|
||||
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
||||
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
||||
MG_PHY_ICS1894x = 0x15,
|
||||
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
|
||||
MG_PHY_YT85x = 0x4f51, //
|
||||
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
||||
MG_PHY_YT85x = 0x4f51,
|
||||
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -33666,44 +33736,45 @@ enum {
|
||||
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
|
||||
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
|
||||
MG_PHY_ICS189432_REG_POLL = 17,
|
||||
MG_PHY_VSC8531_REG_DACS = 28,
|
||||
MG_PHY_YT8531_REG_PHYSTS = 17,
|
||||
MG_PHY_YT8531_REG_EXT_ADDR = 30,
|
||||
MG_PHY_YT8531_REG_EXT_DATA = 31
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
|
||||
switch (id1) {
|
||||
case MG_PHY_DP83x:
|
||||
switch (id2) {
|
||||
case MG_PHY_DP83867: return "DP83867";
|
||||
case MG_PHY_DP83848: return "DP83848";
|
||||
case MG_PHY_DP83825: return "DP83825";
|
||||
default: return "DP83x";
|
||||
}
|
||||
case MG_PHY_KSZ8x: return "KSZ8x";
|
||||
case MG_PHY_LANxVSCx:
|
||||
switch (id2) {
|
||||
case MG_PHY_VSC8531: return "VSC8531";
|
||||
case MG_PHY_DP83867:
|
||||
return "DP83867";
|
||||
case MG_PHY_DP83848:
|
||||
return "DP83848";
|
||||
case MG_PHY_DP83825:
|
||||
return "DP83825";
|
||||
default:
|
||||
if ((id2 & 0xFFF0) == MG_PHY_LAN87x) return "LAN87x";
|
||||
return "DP83x";
|
||||
}
|
||||
break;
|
||||
case MG_PHY_KSZ8x:
|
||||
return "KSZ8x";
|
||||
case MG_PHY_LAN87x:
|
||||
return "LAN87x";
|
||||
case MG_PHY_RTL82x:
|
||||
switch (id2) {
|
||||
case MG_PHY_RTL8201: return "RTL8201";
|
||||
case MG_PHY_RTL8211: return "RTL8211";
|
||||
default: return "RTL82x";
|
||||
case MG_PHY_RTL8201:
|
||||
return "RTL8201";
|
||||
case MG_PHY_RTL8211:
|
||||
return "RTL8211";
|
||||
default:
|
||||
return "RTL82x";
|
||||
}
|
||||
case MG_PHY_ICS1894x: return "ICS1894x";
|
||||
case MG_PHY_ICS1894x:
|
||||
return "ICS1894x";
|
||||
case MG_PHY_YT85x:
|
||||
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
|
||||
default: break;
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||
uint16_t id1, id2;
|
||||
@@ -33715,28 +33786,29 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
|
||||
|
||||
if (config & MG_PHY_RGMII) {
|
||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||
uint16_t value;
|
||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
||||
// We temporarily force enabling autoneg, until a workaround is found.
|
||||
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
||||
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||
phy->write_reg(phy_addr, 0x0d,
|
||||
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||
phy->write_reg(phy_addr, 0x0e, 0x170);
|
||||
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
||||
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
||||
}
|
||||
} else if (config & MG_PHY_CLOCKS_MAC) { // RMII
|
||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||
uint16_t value;
|
||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
||||
// We temporarily force enabling autoneg, until a workaround is found.
|
||||
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
||||
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||
}
|
||||
|
||||
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||
phy->write_reg(phy_addr, 0x0d, 0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||
phy->write_reg(phy_addr, 0x0e, 0x170);
|
||||
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
||||
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
||||
}
|
||||
|
||||
if (config & MG_PHY_CLOCKS_MAC) {
|
||||
// Use PHY crystal oscillator (preserve defaults)
|
||||
// nothing to do
|
||||
} else { // RMII, MAC clocks PHY, PHY has no xtal.
|
||||
} else { // MAC clocks PHY, PHY has no xtal
|
||||
// Enable 50 MHz external ref clock at XI (preserve defaults)
|
||||
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
|
||||
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
|
||||
@@ -33749,7 +33821,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||
// now do clock stuff
|
||||
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
|
||||
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
|
||||
} else if (id1 == MG_PHY_LANxVSCx && (id2 & 0xFFF0) == MG_PHY_LAN87x) {
|
||||
} else if (id1 == MG_PHY_LAN87x) {
|
||||
// nothing to do
|
||||
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
|
||||
// assume PHY has been hardware strapped properly
|
||||
@@ -33795,19 +33867,10 @@ bool mg_phy_up(struct mg_phy *phy, uint8_t phy_addr, bool *full_duplex,
|
||||
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
|
||||
*full_duplex = pc1r & MG_BIT(2);
|
||||
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
|
||||
} else if (id1 == MG_PHY_LANxVSCx) {
|
||||
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||
if (id2 == MG_PHY_VSC8531) {
|
||||
uint16_t dacs = phy->read_reg(phy_addr, MG_PHY_VSC8531_REG_DACS);
|
||||
*full_duplex = dacs & MG_BIT(5);
|
||||
*speed = (dacs & MG_BIT(4)) ? MG_PHY_SPEED_1000M
|
||||
: (dacs & MG_BIT(3)) ? MG_PHY_SPEED_100M
|
||||
: MG_PHY_SPEED_10M;
|
||||
} else {
|
||||
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
||||
*full_duplex = scsr & MG_BIT(4);
|
||||
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
||||
}
|
||||
} else if (id1 == MG_PHY_LAN87x) {
|
||||
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
||||
*full_duplex = scsr & MG_BIT(4);
|
||||
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
||||
} else if (id1 == MG_PHY_RTL82x) {
|
||||
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||
if (id2 == MG_PHY_RTL8211) {
|
||||
@@ -39816,7 +39879,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) {
|
||||
|
||||
// init phy
|
||||
struct mg_phy phy = {eth_read_phy, eth_write_phy};
|
||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC);
|
||||
|
||||
(void) d;
|
||||
return true;
|
||||
|
||||
+2
-4
@@ -5605,10 +5605,8 @@ struct mg_phy {
|
||||
enum {
|
||||
// Set if PHY LEDs are connected to ground
|
||||
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
||||
// Set on RMII when PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||
MG_PHY_CLOCKS_MAC = (1 << 1),
|
||||
// Set on RGMII. Otherwise, we assume RMII
|
||||
MG_PHY_RGMII = (1 << 2)
|
||||
// Set when PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||
MG_PHY_CLOCKS_MAC = (1 << 1)
|
||||
};
|
||||
|
||||
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
|
||||
|
||||
+1
-1
@@ -242,7 +242,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) {
|
||||
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||
NETC_EMDIO->EMDIO_CFG =
|
||||
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
|
||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||
mg_phy_init(&phy, d->phy_addr, 0);
|
||||
|
||||
// Initialize ENETC1 PSI0 and port
|
||||
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
|
||||
|
||||
+60
-69
@@ -2,22 +2,20 @@
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
enum { // ID1 ID2
|
||||
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
||||
MG_PHY_DP83x = 0x2000, //
|
||||
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
||||
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
||||
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
||||
MG_PHY_LANxVSCx = 0x7, // 0007 xxxx | cxxx: SMSC | 0xxx: Vitesse
|
||||
MG_PHY_LAN87x = 0xc0f0, // 0007 c0fx - LAN8720
|
||||
MG_PHY_VSC8531 = 0x0572, // 0007 0572 - VSC8531-02
|
||||
MG_PHY_RTL82x = 0x1c, //
|
||||
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
||||
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
||||
MG_PHY_ICS1894x = 0x15, //
|
||||
enum { // ID1 ID2
|
||||
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
|
||||
MG_PHY_DP83x = 0x2000,
|
||||
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
|
||||
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
|
||||
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
|
||||
MG_PHY_LAN87x = 0x7, // 0007 c0fx - LAN8720
|
||||
MG_PHY_RTL82x = 0x1c,
|
||||
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
|
||||
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
|
||||
MG_PHY_ICS1894x = 0x15,
|
||||
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
|
||||
MG_PHY_YT85x = 0x4f51, //
|
||||
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
||||
MG_PHY_YT85x = 0x4f51,
|
||||
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -36,44 +34,45 @@ enum {
|
||||
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
|
||||
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
|
||||
MG_PHY_ICS189432_REG_POLL = 17,
|
||||
MG_PHY_VSC8531_REG_DACS = 28,
|
||||
MG_PHY_YT8531_REG_PHYSTS = 17,
|
||||
MG_PHY_YT8531_REG_EXT_ADDR = 30,
|
||||
MG_PHY_YT8531_REG_EXT_DATA = 31
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
|
||||
switch (id1) {
|
||||
case MG_PHY_DP83x:
|
||||
switch (id2) {
|
||||
case MG_PHY_DP83867: return "DP83867";
|
||||
case MG_PHY_DP83848: return "DP83848";
|
||||
case MG_PHY_DP83825: return "DP83825";
|
||||
default: return "DP83x";
|
||||
}
|
||||
case MG_PHY_KSZ8x: return "KSZ8x";
|
||||
case MG_PHY_LANxVSCx:
|
||||
switch (id2) {
|
||||
case MG_PHY_VSC8531: return "VSC8531";
|
||||
case MG_PHY_DP83867:
|
||||
return "DP83867";
|
||||
case MG_PHY_DP83848:
|
||||
return "DP83848";
|
||||
case MG_PHY_DP83825:
|
||||
return "DP83825";
|
||||
default:
|
||||
if ((id2 & 0xFFF0) == MG_PHY_LAN87x) return "LAN87x";
|
||||
return "DP83x";
|
||||
}
|
||||
break;
|
||||
case MG_PHY_KSZ8x:
|
||||
return "KSZ8x";
|
||||
case MG_PHY_LAN87x:
|
||||
return "LAN87x";
|
||||
case MG_PHY_RTL82x:
|
||||
switch (id2) {
|
||||
case MG_PHY_RTL8201: return "RTL8201";
|
||||
case MG_PHY_RTL8211: return "RTL8211";
|
||||
default: return "RTL82x";
|
||||
case MG_PHY_RTL8201:
|
||||
return "RTL8201";
|
||||
case MG_PHY_RTL8211:
|
||||
return "RTL8211";
|
||||
default:
|
||||
return "RTL82x";
|
||||
}
|
||||
case MG_PHY_ICS1894x: return "ICS1894x";
|
||||
case MG_PHY_ICS1894x:
|
||||
return "ICS1894x";
|
||||
case MG_PHY_YT85x:
|
||||
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
|
||||
default: break;
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||
uint16_t id1, id2;
|
||||
@@ -85,28 +84,29 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
|
||||
|
||||
if (config & MG_PHY_RGMII) {
|
||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||
uint16_t value;
|
||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
||||
// We temporarily force enabling autoneg, until a workaround is found.
|
||||
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
||||
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||
phy->write_reg(phy_addr, 0x0d,
|
||||
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||
phy->write_reg(phy_addr, 0x0e, 0x170);
|
||||
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
||||
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
||||
}
|
||||
} else if (config & MG_PHY_CLOCKS_MAC) { // RMII
|
||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||
uint16_t value;
|
||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
||||
// We temporarily force enabling autoneg, until a workaround is found.
|
||||
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
||||
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||
}
|
||||
|
||||
if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||
phy->write_reg(phy_addr, 0x0d, 0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||
phy->write_reg(phy_addr, 0x0e, 0x170);
|
||||
phy->write_reg(phy_addr, 0x0d, 0x401f);
|
||||
phy->write_reg(phy_addr, 0x0e, 0x10d);
|
||||
}
|
||||
|
||||
if (config & MG_PHY_CLOCKS_MAC) {
|
||||
// Use PHY crystal oscillator (preserve defaults)
|
||||
// nothing to do
|
||||
} else { // RMII, MAC clocks PHY, PHY has no xtal.
|
||||
} else { // MAC clocks PHY, PHY has no xtal
|
||||
// Enable 50 MHz external ref clock at XI (preserve defaults)
|
||||
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
|
||||
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
|
||||
@@ -119,7 +119,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
||||
// now do clock stuff
|
||||
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
|
||||
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
|
||||
} else if (id1 == MG_PHY_LANxVSCx && (id2 & 0xFFF0) == MG_PHY_LAN87x) {
|
||||
} else if (id1 == MG_PHY_LAN87x) {
|
||||
// nothing to do
|
||||
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
|
||||
// assume PHY has been hardware strapped properly
|
||||
@@ -165,19 +165,10 @@ bool mg_phy_up(struct mg_phy *phy, uint8_t phy_addr, bool *full_duplex,
|
||||
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
|
||||
*full_duplex = pc1r & MG_BIT(2);
|
||||
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
|
||||
} else if (id1 == MG_PHY_LANxVSCx) {
|
||||
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||
if (id2 == MG_PHY_VSC8531) {
|
||||
uint16_t dacs = phy->read_reg(phy_addr, MG_PHY_VSC8531_REG_DACS);
|
||||
*full_duplex = dacs & MG_BIT(5);
|
||||
*speed = (dacs & MG_BIT(4)) ? MG_PHY_SPEED_1000M
|
||||
: (dacs & MG_BIT(3)) ? MG_PHY_SPEED_100M
|
||||
: MG_PHY_SPEED_10M;
|
||||
} else {
|
||||
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
||||
*full_duplex = scsr & MG_BIT(4);
|
||||
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
||||
}
|
||||
} else if (id1 == MG_PHY_LAN87x) {
|
||||
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
|
||||
*full_duplex = scsr & MG_BIT(4);
|
||||
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
|
||||
} else if (id1 == MG_PHY_RTL82x) {
|
||||
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
|
||||
if (id2 == MG_PHY_RTL8211) {
|
||||
|
||||
+2
-4
@@ -11,10 +11,8 @@ struct mg_phy {
|
||||
enum {
|
||||
// Set if PHY LEDs are connected to ground
|
||||
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
|
||||
// Set on RMII when PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||
MG_PHY_CLOCKS_MAC = (1 << 1),
|
||||
// Set on RGMII. Otherwise, we assume RMII
|
||||
MG_PHY_RGMII = (1 << 2)
|
||||
// Set when PHY clocks MAC. Otherwise, MAC clocks PHY
|
||||
MG_PHY_CLOCKS_MAC = (1 << 1)
|
||||
};
|
||||
|
||||
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) {
|
||||
|
||||
// init phy
|
||||
struct mg_phy phy = {eth_read_phy, eth_write_phy};
|
||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII);
|
||||
mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC);
|
||||
|
||||
(void) d;
|
||||
return true;
|
||||
|
||||
+103
-31
@@ -5,6 +5,52 @@
|
||||
|
||||
#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1180
|
||||
|
||||
// Take non-specified Flash chip settings from dev board family
|
||||
#if MG_OTA == MG_OTA_RT1050
|
||||
#ifndef MG_IMXRT_HYPER
|
||||
#define MG_IMXRT_HYPER 1
|
||||
#endif
|
||||
#ifndef MG_IMXRT_SECTOR_SIZE
|
||||
#define MG_IMXRT_SECTOR_SIZE (256 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_BLOCK_SIZE
|
||||
#define MG_IMXRT_BLOCK_SIZE (256 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_PAGE_SIZE
|
||||
#define MG_IMXRT_PAGE_SIZE 512
|
||||
#endif
|
||||
#ifndef MG_IMXRT_FLASH_SIZE
|
||||
#define MG_IMXRT_FLASH_SIZE (64 * 1024 * 1024)
|
||||
#endif
|
||||
#else // rest of the boards
|
||||
#ifndef MG_IMXRT_HYPER
|
||||
#define MG_IMXRT_HYPER 0
|
||||
#endif
|
||||
#ifndef MG_IMXRT_SECTOR_SIZE
|
||||
#define MG_IMXRT_SECTOR_SIZE (4 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_BLOCK_SIZE
|
||||
#define MG_IMXRT_BLOCK_SIZE (64 * 1024)
|
||||
#endif
|
||||
#ifndef MG_IMXRT_PAGE_SIZE
|
||||
#define MG_IMXRT_PAGE_SIZE 256
|
||||
#endif
|
||||
#if MG_OTA == MG_OTA_RT1180 // now define per-board flash size
|
||||
#ifndef MG_IMXRT_FLASH_SIZE
|
||||
#define MG_IMXRT_FLASH_SIZE (16 * 1024 * 1024)
|
||||
#endif
|
||||
#else // rest of the boards
|
||||
#ifndef MG_IMXRT_FLASH_SIZE
|
||||
#define MG_IMXRT_FLASH_SIZE (8 * 1024 * 1024)
|
||||
#endif // default flash size gate
|
||||
#endif // per-board flash size
|
||||
#endif // default flash settings
|
||||
|
||||
#ifndef MG_IMXRT_PARAM_SECTOR_COUNT
|
||||
// Number of small parameter sectors at the bottom of flash
|
||||
#define MG_IMXRT_PARAM_SECTOR_COUNT 0
|
||||
#endif
|
||||
|
||||
static bool mg_imxrt_write(void *, const void *, size_t);
|
||||
static bool mg_imxrt_swap(void);
|
||||
|
||||
@@ -22,12 +68,14 @@ static bool mg_imxrt_swap(void);
|
||||
#define FLEXSPI_NOR_INSTANCE 2
|
||||
#endif
|
||||
|
||||
#if MG_OTA == MG_OTA_RT1050
|
||||
#define MG_IMXRT_SECTOR_SIZE (256 * 1024)
|
||||
#define MG_IMXRT_PAGE_SIZE 512
|
||||
#if MG_OTA == MG_OTA_RT1180
|
||||
#ifndef MG_FLEXSPI_SERIAL_CLK_FREQ
|
||||
#define MG_FLEXSPI_SERIAL_CLK_FREQ 5 // 100MHz
|
||||
#endif
|
||||
#else
|
||||
#define MG_IMXRT_SECTOR_SIZE (4 * 1024)
|
||||
#define MG_IMXRT_PAGE_SIZE 256
|
||||
#ifndef MG_FLEXSPI_SERIAL_CLK_FREQ
|
||||
#define MG_FLEXSPI_SERIAL_CLK_FREQ 7 // 133MHz
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// TODO(): fill at init, support more devices in a dynamic way
|
||||
@@ -133,6 +181,7 @@ struct mg_flexspi_nor_config {
|
||||
#define MG_FLEXSPI_4PAD 2
|
||||
#define MG_FLEXSPI_8PAD 3
|
||||
|
||||
// [1]'s 0x06 sets 6 post-read latency cycles, otherwise use a lower speed
|
||||
#define MG_FLEXSPI_QSPI_LUT \
|
||||
{ \
|
||||
[0] = MG_FLEXSPI_LUT_SEQ(MG_CMD_SDR, MG_FLEXSPI_1PAD, 0xEB, MG_RADDR_SDR, \
|
||||
@@ -155,6 +204,7 @@ struct mg_flexspi_nor_config {
|
||||
MG_STOP, MG_FLEXSPI_1PAD, 0x0), \
|
||||
}
|
||||
|
||||
// [1]'s 0x0c sets HyperBus post-address latency; use a lower speed if needed
|
||||
#define MG_FLEXSPI_HYPER_LUT \
|
||||
{ \
|
||||
[0] = MG_FLEXSPI_LUT_SEQ(MG_CMD_DDR, MG_FLEXSPI_8PAD, 0xA0, MG_RADDR_DDR, \
|
||||
@@ -377,15 +427,31 @@ struct mg_flexspi_nor_driver_interface {
|
||||
|
||||
static bool s_flash_irq_disabled;
|
||||
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
MG_IRAM static size_t flash_sector_size(volatile uint32_t *dst) {
|
||||
char *base = (char *) s_mg_flash_imxrt.start;
|
||||
size_t offset = (size_t) ((char *) dst - base);
|
||||
size_t params = MG_IMXRT_PARAM_SECTOR_COUNT * MG_IMXRT_SECTOR_SIZE;
|
||||
if (offset >= params) return MG_IMXRT_BLOCK_SIZE;
|
||||
return s_mg_flash_imxrt.secsz;
|
||||
}
|
||||
#endif
|
||||
|
||||
MG_IRAM static bool flash_page_start(volatile uint32_t *dst) {
|
||||
char *base = (char *) s_mg_flash_imxrt.start,
|
||||
*end = base + s_mg_flash_imxrt.size;
|
||||
volatile char *p = (char *) dst;
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
return p >= base && p < end && ((p - base) % flash_sector_size(dst)) == 0;
|
||||
#else
|
||||
return p >= base && p < end && ((p - base) % s_mg_flash_imxrt.secsz) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MG_OTA == MG_OTA_RT1050
|
||||
// Configuration for Hyper flash memory
|
||||
#if MG_IMXRT_HYPER
|
||||
// Configuration for HyperFlash memory
|
||||
// serialClkFreq, dataValidTime, and lookupTable (MG_FLEXSPI_HYPER_LUT code)
|
||||
// must agree to flash specs
|
||||
static struct mg_flexspi_nor_config default_config = {
|
||||
.memConfig =
|
||||
{
|
||||
@@ -399,8 +465,8 @@ static struct mg_flexspi_nor_config default_config = {
|
||||
MG_BIT(6) | MG_BIT(4) | MG_BIT(3) | MG_BIT(0),
|
||||
.deviceType = 1, // serial NOR
|
||||
.sflashPadType = 8,
|
||||
.serialClkFreq = 7, // 133MHz
|
||||
.sflashA1Size = 64 * 1024 * 1024,
|
||||
.serialClkFreq = MG_FLEXSPI_SERIAL_CLK_FREQ,
|
||||
.sflashA1Size = MG_IMXRT_FLASH_SIZE,
|
||||
.dataValidTime = {15, 0},
|
||||
.busyOffset = 15,
|
||||
.busyBitPolarity = 1,
|
||||
@@ -408,22 +474,16 @@ static struct mg_flexspi_nor_config default_config = {
|
||||
.lookupTable = MG_FLEXSPI_HYPER_LUT,
|
||||
.lutCustomSeq = MG_LUT_CUSTOM_SEQ,
|
||||
},
|
||||
.pageSize = 512,
|
||||
.sectorSize = 256 * 1024,
|
||||
.pageSize = MG_IMXRT_PAGE_SIZE,
|
||||
.sectorSize = MG_IMXRT_SECTOR_SIZE,
|
||||
.ipcmdSerialClkFreq = 1,
|
||||
.serialNorType = 1u,
|
||||
.blockSize = 256 * 1024,
|
||||
.blockSize = MG_IMXRT_BLOCK_SIZE,
|
||||
.isUniformBlockSize = true};
|
||||
#else
|
||||
// Note: this QSPI configuration works for RTs supporting QSPI
|
||||
// Configuration for QSPI memory
|
||||
#if MG_OTA == MG_OTA_RT1180
|
||||
#define MG_FLEXSPI_QSPI_SERIAL_CLK_FREQ 5 // 100MHz
|
||||
#define MG_FLEXSPI_QSPI_FLASH_SIZE (16 * 1024 * 1024)
|
||||
#else
|
||||
#define MG_FLEXSPI_QSPI_SERIAL_CLK_FREQ 7 // 133MHz
|
||||
#define MG_FLEXSPI_QSPI_FLASH_SIZE (8 * 1024 * 1024)
|
||||
#endif
|
||||
// serialClkFreq (AHB/read clock) and lookupTable (MG_FLEXSPI_QSPI_LUT code)
|
||||
// must agree to flash specs
|
||||
static struct mg_flexspi_nor_config default_config = {
|
||||
.memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG,
|
||||
.version = MG_FLEXSPI_CFG_BLK_VERSION,
|
||||
@@ -433,13 +493,13 @@ static struct mg_flexspi_nor_config default_config = {
|
||||
.controllerMiscOption = MG_BIT(4),
|
||||
.deviceType = 1, // serial NOR
|
||||
.sflashPadType = 4,
|
||||
.serialClkFreq = MG_FLEXSPI_QSPI_SERIAL_CLK_FREQ,
|
||||
.sflashA1Size = MG_FLEXSPI_QSPI_FLASH_SIZE,
|
||||
.serialClkFreq = MG_FLEXSPI_SERIAL_CLK_FREQ,
|
||||
.sflashA1Size = MG_IMXRT_FLASH_SIZE,
|
||||
.lookupTable = MG_FLEXSPI_QSPI_LUT},
|
||||
.pageSize = 256,
|
||||
.sectorSize = 4 * 1024,
|
||||
.pageSize = MG_IMXRT_PAGE_SIZE,
|
||||
.sectorSize = MG_IMXRT_SECTOR_SIZE,
|
||||
.ipcmdSerialClkFreq = 1,
|
||||
.blockSize = 64 * 1024,
|
||||
.blockSize = MG_IMXRT_BLOCK_SIZE,
|
||||
.isUniformBlockSize = false};
|
||||
#endif
|
||||
|
||||
@@ -489,8 +549,13 @@ MG_IRAM static bool flash_erase(struct mg_flexspi_nor_config *config,
|
||||
|
||||
void *dst = (void *) ((char *) addr - (char *) s_mg_flash_imxrt.start);
|
||||
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
bool ok = (flexspi_nor->erase(FLEXSPI_NOR_INSTANCE, config, (uint32_t) dst,
|
||||
flash_sector_size(addr)) == 0);
|
||||
#else
|
||||
bool ok = (flexspi_nor->erase(FLEXSPI_NOR_INSTANCE, config, (uint32_t) dst,
|
||||
s_mg_flash_imxrt.secsz) == 0);
|
||||
#endif
|
||||
MG_DEBUG(("Sector starting at %p erasure: %s", addr, ok ? "ok" : "fail"));
|
||||
return ok;
|
||||
}
|
||||
@@ -553,14 +618,13 @@ MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
|
||||
}
|
||||
#else
|
||||
// When supported, prefer the read API call.
|
||||
uint32_t src_ofs =
|
||||
(uint32_t) src - (uint32_t) s_mg_flash_imxrt.start;
|
||||
status = flexspi_nor->read(FLEXSPI_NOR_INSTANCE, config_ptr, tmp,
|
||||
src_ofs, s_mg_flash_imxrt.align);
|
||||
uint32_t src_ofs = (uint32_t) src - (uint32_t) s_mg_flash_imxrt.start;
|
||||
status = flexspi_nor->read(FLEXSPI_NOR_INSTANCE, config_ptr, tmp, src_ofs,
|
||||
s_mg_flash_imxrt.align);
|
||||
#endif
|
||||
if (status == 0) {
|
||||
status = flexspi_nor->program(FLEXSPI_NOR_INSTANCE, config_ptr,
|
||||
dst_ofs, tmp);
|
||||
status = flexspi_nor->program(FLEXSPI_NOR_INSTANCE, config_ptr, dst_ofs,
|
||||
tmp);
|
||||
}
|
||||
} else {
|
||||
status = flexspi_nor->program(FLEXSPI_NOR_INSTANCE, config_ptr,
|
||||
@@ -592,7 +656,11 @@ MG_IRAM static void single_bank_swap(char *p1, char *p2, size_t s, size_t ss) {
|
||||
}
|
||||
|
||||
MG_IRAM static bool mg_imxrt_swap(void) {
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
size_t ss = MG_IMXRT_BLOCK_SIZE;
|
||||
#else
|
||||
size_t ss = s_mg_flash_imxrt.secsz;
|
||||
#endif
|
||||
char *p1 = (char *) s_mg_flash_imxrt.start;
|
||||
char *p2 = p1 + s_mg_flash_imxrt.size / 2;
|
||||
size_t s = s_mg_flash_imxrt.size / 2 - ss;
|
||||
@@ -606,7 +674,11 @@ MG_IRAM static bool mg_imxrt_swap(void) {
|
||||
}
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
#if MG_IMXRT_PARAM_SECTOR_COUNT > 0
|
||||
size_t max = s_mg_flash_imxrt.size / 2 - MG_IMXRT_BLOCK_SIZE;
|
||||
#else
|
||||
size_t max = s_mg_flash_imxrt.size / 2 - s_mg_flash_imxrt.secsz;
|
||||
#endif
|
||||
if (new_firmware_size > max) {
|
||||
MG_ERROR(("Firmware %lu too big for single-bank OTA, max %lu",
|
||||
new_firmware_size, max));
|
||||
|
||||
Reference in new issue
Block a user