From c1e22b8d80756e2f88f4622e728f63ba50e54b89 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 28 Nov 2023 12:38:25 +0100 Subject: [PATCH 1/6] dsi: fix clock for Giga_CM4 --- libraries/Arduino_H7_Video/src/dsi.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/Arduino_H7_Video/src/dsi.cpp b/libraries/Arduino_H7_Video/src/dsi.cpp index fc1c79948..28379fd62 100644 --- a/libraries/Arduino_H7_Video/src/dsi.cpp +++ b/libraries/Arduino_H7_Video/src/dsi.cpp @@ -51,6 +51,8 @@ int dsi_init(uint8_t bus, struct edid *edid, struct display_timing *dt) { static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV3; static const uint32_t DSI_PLLODF = DSI_PLL_OUT_DIV1; static const uint32_t DSI_TXEXCAPECLOCKDIV = 4; + #undef HSE_VALUE + #define HSE_VALUE 16000000 #else static const uint32_t DSI_PLLNDIV = 40; static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV2; From 870d15ad64362a82c68496adf0579c20e3372ebf Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 24 Nov 2023 14:35:11 +0100 Subject: [PATCH 2/6] libraries: get rid of stray printf VARIANT_M4_GENERIC doesn't define any console pins (due to obvious reasons) so the default printf will make the application crash without mbed blinks of death. --- libraries/Portenta_SDRAM/src/SDRAM.cpp | 8 ++++---- libraries/SocketWrapper/src/MbedUdp.cpp | 2 +- libraries/USBHOST/src/USB251xB.cpp | 4 ++-- libraries/WiFi/src/WiFi.cpp | 2 +- libraries/openamp_arduino/src/openamp.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/Portenta_SDRAM/src/SDRAM.cpp b/libraries/Portenta_SDRAM/src/SDRAM.cpp index 4090a0b3f..9c7377f19 100644 --- a/libraries/Portenta_SDRAM/src/SDRAM.cpp +++ b/libraries/Portenta_SDRAM/src/SDRAM.cpp @@ -5,9 +5,9 @@ extern "C" { int SDRAMClass::begin(uint32_t start_address) { - printf("FMC_SDRAM_DEVICE->SDCMR: %x\n", FMC_SDRAM_DEVICE->SDCMR); + //printf("FMC_SDRAM_DEVICE->SDCMR: %x\n", FMC_SDRAM_DEVICE->SDCMR); if (FMC_SDRAM_DEVICE->SDCMR == 0x00000000U) { - printf("initializing external ram\n"); + //printf("initializing external ram\n"); bool ret = sdram_init(); if (ret == false) { return 0; @@ -19,7 +19,7 @@ int SDRAMClass::begin(uint32_t start_address) { */ if (SDRAM_START_ADDRESS != 0xC0000000) { - printf("remap ram to 0x60000000\n"); + //printf("remap ram to 0x60000000\n"); HAL_SetFMCMemorySwappingConfig(FMC_SWAPBMAP_SDRAM_SRAM); } @@ -62,7 +62,7 @@ int SDRAMClass::begin(uint32_t start_address) { } if (start_address) { - printf("malloc_addblock: allocate %d bytes\n", SDRAM_END_ADDRESS - start_address); + //printf("malloc_addblock: allocate %d bytes\n", SDRAM_END_ADDRESS - start_address); malloc_addblock((void*)start_address, SDRAM_END_ADDRESS - start_address); } diff --git a/libraries/SocketWrapper/src/MbedUdp.cpp b/libraries/SocketWrapper/src/MbedUdp.cpp index 2a02daee1..e5605a74c 100644 --- a/libraries/SocketWrapper/src/MbedUdp.cpp +++ b/libraries/SocketWrapper/src/MbedUdp.cpp @@ -42,7 +42,7 @@ uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) { SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port); if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) { - printf("Error joining the multicast group\n"); + //printf("Error joining the multicast group\n"); return 0; } diff --git a/libraries/USBHOST/src/USB251xB.cpp b/libraries/USBHOST/src/USB251xB.cpp index 48b34813a..55953771a 100644 --- a/libraries/USBHOST/src/USB251xB.cpp +++ b/libraries/USBHOST/src/USB251xB.cpp @@ -133,8 +133,8 @@ void write_hub_configuration(struct usb251xb* hub) { wbuf[0] = USB251XB_I2C_WRITE_SZ; memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ); - printf("writing %d byte block %d to 0x%02X\n", - USB251XB_I2C_WRITE_SZ, i, offset); + //printf("writing %d byte block %d to 0x%02X\n", + // USB251XB_I2C_WRITE_SZ, i, offset); Wire.beginTransmission(0x2C); Wire.write(offset); diff --git a/libraries/WiFi/src/WiFi.cpp b/libraries/WiFi/src/WiFi.cpp index cea1949ae..6f017972b 100644 --- a/libraries/WiFi/src/WiFi.cpp +++ b/libraries/WiFi/src/WiFi.cpp @@ -90,7 +90,7 @@ void* arduino::WiFiClass::handleAPEvents(whd_interface_t ifp, const whd_event_he if (osSemaphoreGetCount(whd_driver->ap_info.whd_wifi_sleep_flag) < 1) { osStatus_t result = osSemaphoreRelease(whd_driver->ap_info.whd_wifi_sleep_flag); if (result != osOK) { - printf("Release whd_wifi_sleep_flag ERROR: %d", result); + //printf("Release whd_wifi_sleep_flag ERROR: %d", result); } } } diff --git a/libraries/openamp_arduino/src/openamp.c b/libraries/openamp_arduino/src/openamp.c index 62c26bbc0..02eb74eed 100644 --- a/libraries/openamp_arduino/src/openamp.c +++ b/libraries/openamp_arduino/src/openamp.c @@ -175,7 +175,7 @@ int OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline) MAILBOX_Poll(rvdev.vdev); } if (millis() >= deadline) { - printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept); + //printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept); return -1; } return 0; From 04aa43b985d91f452fffad2a1dabc9db99568e38 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 28 Nov 2023 12:40:21 +0100 Subject: [PATCH 3/6] SDRAM: fix CM4 functionality --- libraries/Portenta_SDRAM/src/SDRAM.cpp | 80 +++++++++++--------------- libraries/Portenta_SDRAM/src/SDRAM.h | 7 +-- 2 files changed, 35 insertions(+), 52 deletions(-) diff --git a/libraries/Portenta_SDRAM/src/SDRAM.cpp b/libraries/Portenta_SDRAM/src/SDRAM.cpp index 9c7377f19..aff4dad88 100644 --- a/libraries/Portenta_SDRAM/src/SDRAM.cpp +++ b/libraries/Portenta_SDRAM/src/SDRAM.cpp @@ -3,11 +3,34 @@ extern "C" { #include "ram_internal.h" } +static void MPU_Config() { + MPU_Region_InitTypeDef MPU_InitStruct; + + /* Disable the MPU */ + HAL_MPU_Disable(); + + // Initialize SDRAM Start as shareable + MPU_InitStruct.Enable = MPU_REGION_ENABLE; + MPU_InitStruct.BaseAddress = SDRAM_START_ADDRESS; + MPU_InitStruct.Size = ARM_MPU_REGION_SIZE_8MB; + //MPU_InitStruct.SubRegionDisable = 0x00; + MPU_InitStruct.Number = MPU_REGION_NUMBER5; + MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0; + MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS; + MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE; + MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE; + MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE; + MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE; + + HAL_MPU_ConfigRegion(&MPU_InitStruct); + + /* Enable the MPU */ + HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); +} + int SDRAMClass::begin(uint32_t start_address) { - //printf("FMC_SDRAM_DEVICE->SDCMR: %x\n", FMC_SDRAM_DEVICE->SDCMR); if (FMC_SDRAM_DEVICE->SDCMR == 0x00000000U) { - //printf("initializing external ram\n"); bool ret = sdram_init(); if (ret == false) { return 0; @@ -18,51 +41,16 @@ int SDRAMClass::begin(uint32_t start_address) { then enable access/caching for the size used */ - if (SDRAM_START_ADDRESS != 0xC0000000) { - //printf("remap ram to 0x60000000\n"); + if (SDRAM_START_ADDRESS == 0x60000000) { HAL_SetFMCMemorySwappingConfig(FMC_SWAPBMAP_SDRAM_SRAM); } -#if 0 - - printf("setup mpu\n"); - #define MPU_SDRAM_EXEC_REGION_NUMBER MPU_REGION_SDRAM1 - #define MPU_SDRAM_REGION_TEX (0x4 << MPU_RASR_TEX_Pos) /* Cached memory */ - #define MPU_SDRAM_EXEC_REGION_SIZE (22 << MPU_RASR_SIZE_Pos) /* 2^(22+1) = 8Mo */ - #define MPU_SDRAM_ACCESS_PERMSSION (0x03UL << MPU_RASR_AP_Pos) - #define MPU_SDRAM_REGION_CACHABLE (0x01UL << MPU_RASR_C_Pos) - #define MPU_SDRAM_REGION_BUFFERABLE (0x01UL << MPU_RASR_B_Pos) - - MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; - /* Configure SDARM region as first region */ - MPU->RNR = MPU_SDRAM_EXEC_REGION_NUMBER; - /* Set MPU SDARM base address (0xD0000000) */ - MPU->RBAR = SDRAM_START_ADDRESS; - /* - - Execute region: RASR[size] = 22 -> 2^(22+1) -> size 8MB - - Access permission: Full access: RASR[AP] = 0b011 - - Cached memory: RASR[TEX] = 0b0100 - - Disable the Execute Never option: to allow the code execution on SDRAM: RASR[XN] = 0 - - Enable the region MPU: RASR[EN] = 1 - */ - MPU->RASR = (MPU_SDRAM_EXEC_REGION_SIZE | MPU_SDRAM_ACCESS_PERMSSION | MPU_SDRAM_REGION_TEX | \ - MPU_RASR_ENABLE_Msk | MPU_SDRAM_REGION_BUFFERABLE) & ~MPU_RASR_XN_Msk ; - - /* Enable MPU and leave the predefined regions to default configuration */ - MPU->CTRL |= MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_ENABLE_Msk; -#endif - -#if 0 - mpu_config_start(); - mpu_config_region(MPU_REGION_SDRAM1, SDRAM_START_ADDRESS, MPU_CONFIG_DISABLE(0x00, MPU_REGION_SIZE_512MB)); - mpu_config_region(MPU_REGION_SDRAM2, SDRAM_START_ADDRESS, MPU_CONFIG_SDRAM(SDRAM_MPU_REGION_SIZE)); - mpu_config_end(); -#endif - + #ifdef CORE_CM4 + MPU_Config(); + #endif } if (start_address) { - //printf("malloc_addblock: allocate %d bytes\n", SDRAM_END_ADDRESS - start_address); malloc_addblock((void*)start_address, SDRAM_END_ADDRESS - start_address); } @@ -77,7 +65,7 @@ void SDRAMClass::free(void* ptr) { ea_free(ptr); } -bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) { +bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast, Stream& _serial) { uint8_t const pattern = 0xaa; uint8_t const antipattern = 0x55; uint8_t *const mem_base = (uint8_t*)SDRAM_START_ADDRESS; @@ -86,7 +74,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) { for (uint8_t i = 1; i; i <<= 1) { *mem_base = i; if (*mem_base != i) { - printf("data bus lines test failed! data (%d)\n", i); + _serial.println("data bus lines test failed! data (" + String(i) + ")"); __asm__ volatile ("BKPT"); } } @@ -96,7 +84,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) { for (uint32_t i = 1; i < HW_SDRAM_SIZE; i <<= 1) { mem_base[i] = pattern; if (mem_base[i] != pattern) { - printf("address bus lines test failed! address (%p)\n", &mem_base[i]); + _serial.println("address bus lines test failed! address ("+ String((uint32_t)&mem_base[i], HEX) + ")"); __asm__ volatile ("BKPT"); } } @@ -105,7 +93,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) { mem_base[0] = antipattern; for (uint32_t i = 1; i < HW_SDRAM_SIZE; i <<= 1) { if (mem_base[i] != pattern) { - printf("address bus overlap %p\n", &mem_base[i]); + _serial.println("address bus overlap! address ("+ String((uint32_t)&mem_base[i], HEX) + ")"); __asm__ volatile ("BKPT"); } } @@ -115,7 +103,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) { for (uint32_t i = 0; i < HW_SDRAM_SIZE; ++i) { mem_base[i] = pattern; if (mem_base[i] != pattern) { - printf("address bus test failed! address (%p)\n", &mem_base[i]); + _serial.println("address bus test failed! address ("+ String((uint32_t)&mem_base[i], HEX) + ")"); __asm__ volatile ("BKPT"); } } diff --git a/libraries/Portenta_SDRAM/src/SDRAM.h b/libraries/Portenta_SDRAM/src/SDRAM.h index 5c75c1f01..d5e8ef36b 100644 --- a/libraries/Portenta_SDRAM/src/SDRAM.h +++ b/libraries/Portenta_SDRAM/src/SDRAM.h @@ -4,13 +4,8 @@ #include "Arduino.h" -#if !defined(CORE_CM4) #define SDRAM_END_ADDRESS (0x60800000) #define SDRAM_START_ADDRESS (0x60000000) -#else -#define SDRAM_END_ADDRESS (0xC0800000) -#define SDRAM_START_ADDRESS (0xC0000000) -#endif class SDRAMClass { public: @@ -18,7 +13,7 @@ class SDRAMClass { int begin(uint32_t start_address = SDRAM_START_ADDRESS); void* malloc(size_t size); void free(void* ptr); - bool test(bool fast = false); + bool test(bool fast = false, Stream& _serial = Serial); private: void mpu_config_start(void) { __disable_irq(); From fba55ce93b9cfe8ff1551df069483c2b73cffaf6 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 30 Nov 2023 11:06:01 +0100 Subject: [PATCH 4/6] dsi: anx: fix debug macros and M4 functionality --- libraries/Arduino_H7_Video/src/H7DisplayShield.cpp | 2 ++ libraries/Arduino_H7_Video/src/anx7625.cpp | 13 ++++++++----- libraries/Arduino_H7_Video/src/edid.c | 11 +++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libraries/Arduino_H7_Video/src/H7DisplayShield.cpp b/libraries/Arduino_H7_Video/src/H7DisplayShield.cpp index 033b550a3..82356a638 100644 --- a/libraries/Arduino_H7_Video/src/H7DisplayShield.cpp +++ b/libraries/Arduino_H7_Video/src/H7DisplayShield.cpp @@ -22,6 +22,8 @@ int USBCVideoClass::init(int edidmode) { struct edid recognized_edid; int err_code = 0; + memset(&recognized_edid, 0, sizeof(recognized_edid)); + //Initialization of ANX7625 err_code = anx7625_init(0); if(err_code < 0) { diff --git a/libraries/Arduino_H7_Video/src/anx7625.cpp b/libraries/Arduino_H7_Video/src/anx7625.cpp index 596e6f9be..552da163f 100644 --- a/libraries/Arduino_H7_Video/src/anx7625.cpp +++ b/libraries/Arduino_H7_Video/src/anx7625.cpp @@ -25,7 +25,7 @@ #include #include -#if defined(ARDUINO_PORTENTA_H7_M7) +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(PORTENTA_H7_PINS) #include "dsi.h" #include "anx7625.h" @@ -42,9 +42,12 @@ #define ANXDEBUG(format, ...) \ printk(BIOS_DEBUG, "%s: " format, __func__, ##__VA_ARGS__) #else - #define ANXERROR(format, ...) - #define ANXINFO(format, ...) - #define ANXDEBUG(format, ...) + #define ANXERROR(format, ...) \ + do { static volatile int _i = 5; _i++; } while (0) + #define ANXINFO(format, ...) \ + do { } while (0) + #define ANXDEBUG(format, ...) \ + do { } while (0) #endif #define FLASH_LOAD_STA 0x05 @@ -506,7 +509,7 @@ int anx7625_init(uint8_t bus) { return -1; } ANXINFO("Powering on anx7625 successfull.\n"); - mdelay(200); // Wait for anx7625 to be stable + mdelay(500); // Wait for anx7625 to be stable if(anx7625_is_power_provider(0)) { ANXINFO("OTG_ON = 0 -> VBUS ON\n"); diff --git a/libraries/Arduino_H7_Video/src/edid.c b/libraries/Arduino_H7_Video/src/edid.c index 76a6f8e1c..802483c2d 100644 --- a/libraries/Arduino_H7_Video/src/edid.c +++ b/libraries/Arduino_H7_Video/src/edid.c @@ -47,9 +47,12 @@ #define EDIDDEBUG(format, ...) \ printk(BIOS_SPEW, "%s: " format, __func__, ##__VA_ARGS__) #else - #define EDIDERROR(format, ...) - #define EDIDWARNING(format, ...) - #define EDIDDEBUG(format, ...) + #define EDIDERROR(format ...) \ + do { } while (0) + #define EDIDWARNING(format ...) \ + do { } while (0) + #define EDIDDEBUG(format ...) \ + do { } while (0) #endif struct edid_context { @@ -1034,7 +1037,7 @@ parse_extension(struct edid *out, unsigned char *x, struct edid_context *c) } static const struct { - int x, y, refresh; + unsigned int x, y, refresh; } established_timings[] = { /* 0x23 bit 7 - 0 */ {720, 400, 70}, From 2dddedf62835d7f073532e35888124babb2e3244 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 4 Dec 2023 14:22:23 +0100 Subject: [PATCH 5/6] RPC: openamp: modify addresses and singal timings --- libraries/openamp_arduino/src/mailbox_hsem_if.c | 4 ++-- libraries/openamp_arduino/src/openamp.c | 2 +- libraries/openamp_arduino/src/openamp_conf.h | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/openamp_arduino/src/mailbox_hsem_if.c b/libraries/openamp_arduino/src/mailbox_hsem_if.c index 04ab7f583..851ca98a5 100644 --- a/libraries/openamp_arduino/src/mailbox_hsem_if.c +++ b/libraries/openamp_arduino/src/mailbox_hsem_if.c @@ -77,14 +77,14 @@ void HAL_HSEM_FreeCallback(uint32_t SemMask) UNUSED(SemMask); msg_received = RX_NEW_MSG; - osSignalSet(eventHandlerThreadId, 0x1); - #ifdef CORE_CM7 HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_1)); #endif #ifdef CORE_CM4 HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0)); #endif + + osSignalSet(eventHandlerThreadId, 0x1); } /** diff --git a/libraries/openamp_arduino/src/openamp.c b/libraries/openamp_arduino/src/openamp.c index 02eb74eed..0ead7620b 100644 --- a/libraries/openamp_arduino/src/openamp.c +++ b/libraries/openamp_arduino/src/openamp.c @@ -135,7 +135,7 @@ int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb) } rpmsg_virtio_init_shm_pool(&shpool, (void *)VRING_BUFF_ADDRESS, - (size_t)SHM_SIZE); + (size_t)VRING_BUFF_SIZE); rpmsg_init_vdev(&rvdev, vdev, ns_bind_cb, shm_io, &shpool); diff --git a/libraries/openamp_arduino/src/openamp_conf.h b/libraries/openamp_arduino/src/openamp_conf.h index 57e2ae178..c39a41fe2 100644 --- a/libraries/openamp_arduino/src/openamp_conf.h +++ b/libraries/openamp_arduino/src/openamp_conf.h @@ -154,9 +154,10 @@ extern int __OPENAMP_region_end__[]; #endif #define VRING_RX_ADDRESS SHM_START_ADDRESS -#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x400) -#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x800) -#define VRING_ALIGNMENT 4 +#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x1000) +#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x2000) +#define VRING_BUFF_SIZE (SHM_SIZE - 0x2000) +#define VRING_ALIGNMENT 32 #define VRING_NUM_BUFFS 16 /* number of rpmsg buffers */ /* Fixed parameter */ From 57d6f9af036ad79850360e583c666a2b18a2adb5 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 4 Dec 2023 14:22:46 +0100 Subject: [PATCH 6/6] CAN: fix compatibility with M4 core --- libraries/Arduino_CAN/src/Arduino_CAN.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Arduino_CAN/src/Arduino_CAN.h b/libraries/Arduino_CAN/src/Arduino_CAN.h index b5d9fdd5a..649ae6f22 100644 --- a/libraries/Arduino_CAN/src/Arduino_CAN.h +++ b/libraries/Arduino_CAN/src/Arduino_CAN.h @@ -24,7 +24,7 @@ * COMPILE TIME CHECKS **************************************************************************************/ -#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA)) +#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA) || defined(CORE_CM4)) # error "CAN only available on Arduino Portenta H7 and Arduino Giga (of all ArduinoCore-mbed enabled boards)." #endif pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy