Commit Graph

770 Commits (master)

Author SHA1 Message Date
Chun-Chieh Li a72075b5ad M467: Fix invoking GPIO_SET_DEBOUNCE_TIME
Fix missing gpio_base on invoking GPIO_SET_DEBOUNCE_TIME()
2024-09-04 16:42:19 +08:00
Martin Kojtal 95fee2f75a
Merge pull request #15500 from OpenNuvoton/nuvoton_fix_function_undeclare
NUVOTON: Fix undeclared function as error
2024-04-24 19:07:38 +02:00
Chun-Chieh Li c1c9550539 NUVOTON: CAN: Fix filter mask being zero
On mask being zero, it means any match, not exact match.

NOTE: This fix only targets CAN (M453/M487), not CAN-FD (M467).
NOTE: NUC472 CAN doesn't support filter.
2024-04-18 13:29:24 +08:00
Chun-Chieh Li 989a694c5a NUVOTON: CAN: Fix Message Object number for Tx and recognition of Rx interrupt
1.  The same Message Object number cannot use for both Tx and Rx simultaneously.
    For Tx, Message Object number 31 is reserved instead of 0.
    For Rx, Message Object numbers 0~30 are used and for filters.
2.  NewDat bit (CAN_IsNewDataReceived()) isn't exclusive to Rx.
    Recognize Rx interrupt by Message Object number other than 31.

NOTE: This fix only targets CAN (NUC472/M453/M487), not CAN-FD (M467).
2024-04-18 11:04:15 +08:00
Chun-Chieh Li bfd4ceb20b NUVOTON: CAN: Fix Rx interrupt doesn't work
Major modifications:
1. Handle Rx interrupt based on Message Object interrupt (CAN_IIDR=0x0001~0x0020) instead of CAN_STATUS.RxOK
2. Also handle Tx interrupt following above for consistency

Other related modifications:
1. Fix signature type error in CAN_CLR_INT_PENDING_BIT()
2. Add CAN_CLR_INT_PENDING_ONLY_BIT() which doesn't clear NewDat flag so that user can fetch received message in thread context

NOTE: This fix only targets CAN (NUC472/M453/M487), not CAN-FD (M467).
2024-04-18 11:04:15 +08:00
Chun-Chieh Li 63bdb26915 NUVOTON: CAN: Fix filter mask
NOTE: This fix only targets CAN (M453/M487), not CAN-FD (M467).
NOTE: NUC472 CAN doesn't support filter.
2024-04-18 11:04:15 +08:00
Chun-Chieh Li 11d99971c8 NUVOTON: Serial: Fix undeclared function gpio_set
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2024-03-18 09:55:16 +08:00
Chun-Chieh Li 25c0491284 NUVOTON: I2C: Fix undeclared function gpio_set
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2024-03-18 09:54:58 +08:00
Chun-Chieh Li 4366b6811d NUVOTON: SPI: Fix undeclared function gpio_set
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2024-03-18 09:54:45 +08:00
Chun-Chieh Li cf7a07f106 NUVOTON: AnalogOut: Fix undeclared function gpio_set
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2024-03-18 09:53:55 +08:00
Chun-Chieh Li 1be9ff0b5e NUVOTON: CAN: Fix undeclared function gpio_set
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2024-03-15 13:26:03 +08:00
Chun-Chieh Li 5a4a4fd970 NUVOTON: AnalogIn: Fix undeclared function gpio_set
ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2024-03-15 13:18:55 +08:00
cyliang tw 772c5d3eec Fix NUC472 wrong define of set-zero-packet 2023-12-14 11:18:31 +08:00
cyliang tw 0ecb9bd268 Nuvoton HUSBD support endpoint write ZLP 2023-12-05 19:44:43 +08:00
Chun-Chieh Li 8b69a94cef M2354: Fix debug failure in Mbed Studio
In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line
3.  Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line
    https://docs.mcuboot.com/design.html#image-trailer

Related issue:
https://github.com/ARMmbed/mbed-os/issues/15417
2023-06-02 09:15:55 +08:00
Chun-Chieh Li 91a1b59c95 Nuvoton: Enable extending sampling time for ADC/EADC
For all Nuvoton targets, enable extending sampling time in ADC/EADC clocks on per-pin basis.
2023-05-15 14:40:10 +08:00
Chun-Chieh Li d3b7a07597 M467: Support CAN bus
1.  Update BSP CANFD driver
2.  Notes for implementation
    (1) Each CANFD instance supports two IRQ lines. Use only line 0. Line 1 is not used.
    (2) For Rx disabling multiple filter handles,
        1)  Map all filter handles to filter handle 0
        2)  Use Rx FIFO 0 for filter handle 0
    (3) For Rx enabling multiple filter handles,
        1)  Use Rx FIFO 0 for filter handle 0
        2)  Use Rx FIFO 1 for filter handle through first invoking can_filter()
        3)  Use dedicated Rx Buffer for other filter handles
        NOTE: H/W supports mask on Rx FIFO 0/1 but not on dedicated Rx Buffer.
    (4) For Tx, use only dedicated Tx Buffer. BSP CANFD driver doesn't support Tx FIFO/Queue.
    (5) Support no CAN FD.
2023-04-13 17:28:48 +08:00
Chun-Chieh Li e638da4a69 M487: Remove unused variable 'u32EscapeFrame'
Remove unused variable 'u32EscapeFrame' in BSP m480_ccap.h to avoid warnings
2023-03-09 11:29:57 +08:00
cyliangtw 89ddd3f8e8 M2354 support FS-USBD and update TF-M for USB PHY select 2022-11-23 19:31:55 +08:00
Martin Kojtal 90837c5674
Merge pull request #15337 from OpenNuvoton/nuvoton_m467_iot
Nuvoton: Support new target NUMAKER_IOT_M467
2022-11-02 13:24:01 +00:00
Chun-Chieh Li 733512d4ec M467: Remove invalid UTF-8 byte sequence 2022-10-19 13:33:21 +08:00
Chun-Chieh Li dbc0f5b2b3 Nuvoton: I2C: Fix potential role switch failure
Fix in i2c_do_trsn(), interrupt doesn't change back to enabled due to premature return.

Fix targets:
-   NUMAKER_PFM_NANO130
-   NUMAKER_PFM_NUC472
-   NUMAKER_PFM_M453
-   NUMAKER_PFM_M487/NUMAKER_IOT_M487
-   NUMAKER_IOT_M252
-   NUMAKER_IOT_M263A
-   NU_M2354
2022-09-23 09:45:56 +08:00
Chun-Chieh Li 5ba8afbd99 M467: Support NuMaker-IoT-M467 board
Pinout comparison between NuMaker-M467HJ and NuMaker-IoT-M467 boards:
1.  UNO are unchanged
2.  LEDs are unchanged
3.  Buttons are unchanged, except button names
4.  NuMaker-M467HJ has HBI but NuMaker-IoT-M467 does
5.  NuMaker-M467HJ doesn't have ESP8266 but NuMaker-IoT-M467 does
6.  SDHC are unchanged
2022-09-22 19:03:41 +08:00
Chun-Chieh Li eaaec1c730 M467: Adjust UART pinmap to pass FPGA CI Test Shield test 2022-09-22 19:03:41 +08:00
Chun-Chieh Li a0a50865e9 M467: Exclude UNO SPI pins from FPGA CI Test Shield test
UNO D8/D9/D10/D11/D12/D13 can wire to on-board SPI flash.
Exclude these pins from FPGA CI Test Shield test.
2022-09-22 19:03:40 +08:00
Chun-Chieh Li 42cfb84119 M467: I2C: Fix potential role switch failure
Fix in i2c_do_trsn(), interrupt doesn't change back to enabled due to premature return.
2022-09-22 19:00:38 +08:00
Chun-Chieh Li e8dd9f43fa M467: Make mbedtls H/W port removable
Some M460 chips don't support AES/SHA/ECC/RSA H/W.
Make them removable from mbedtls H/W port through '"target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"]'.
2022-09-01 10:02:19 +08:00
cyliangtw 2f8b60d501 M467: support fullspeed usb device 2022-09-01 10:02:19 +08:00
Chun-Chieh Li 88a529180f M467: Support Crypto RSA H/W
1.  Crypto RSA H/W supports 1024/2048/3072/4096 key bits. Fall back to software implementation for other key bits.
2.  For decrypt, if MBEDTLS_RSA_NO_CRT isn't defined, go CRT, or normal.
3.  For decrypt, when blinding (f_rng != NULL), enable SCAP mode.
4.  Recover from Crypto RSA H/W failure:
    (1) Enable timed-out wait to escape from RSA H/W trap
    (2) On RSA H/W timeout, stop this RSA H/W operation
    (3) Fall back to S/W implementation on failure

NOTE: RSA 4096 key bits can fail with default mbedtls configuration MBEDTLS_MPI_MAX_SIZE.
      Enlarge MBEDTLS_MPI_MAX_SIZE to 1024 or larger if this feature is required.
NOTE: Fixed in BSP RSA driver, for non-CRT+SCAP mode, temporary buffer for MADDR6 requires to be key length plus 128 bits.
NOTE: Fixed in BSP RSA driver, DMA buffer must be 4-word aligned, or RSA H/W will trap.
2022-09-01 10:02:18 +08:00
Chun-Chieh Li 21970e30f1 M467: Seed PRNG with TRNG for SCAP
According to TRM, it is suggested PRNG be seeded by TRNG on every Crypto H/W reset.
2022-09-01 10:02:17 +08:00
Chun-Chieh Li d92d75e9ac M467: Improve Crypto H/W wait helper routine
Add crypto_xxx_wait2 helper routine to replace crypto_xxx_wait for Crypto H/W control
2022-09-01 10:02:17 +08:00
Chun-Chieh Li 24b0feb17f M467: Support Crypto SHA/ECC H/W
1.  Prepare crypto common code
2.  Support list
    -   SHA
    -   ECC
    NOTE: AES/RSA are to support in other works
    NOTE: Compared to M487, M467's SHA supports context save & restore (DMA Cascade mode) and so no software fallback is needed.
    NOTE: M467's ECC, following M487, goes partial-module replacement and it can just improve primitives e.g. point addition/doubling by 2X,
          and cannot improve high level point multiplication because MbedTLS doesn’t open it.
          To improve performance best, full-module replacement is needed.
    NOTE: Continuing above, add support for Montgomery curve
2022-09-01 10:02:16 +08:00
Chun-Chieh Li 0494866f5f M467: Support HyperRAM
1.  For GCC, support multi-block .data/.bss initialization
2.  HyperRAM is mapped to two regions: 0x0A000000 and 0x80000000
    According to default system address map, 0x0A000000 is located at 'Code' region and 0x80000000 at 'RAM' region.
    With MPU enabled on Mbed OS, 'Code' region is write-never and 'RAM' region execute-never.
    0x80000000 is chosen because 'RAM' regioin is naturally for HyperRAM.
3.  Configurable multi-function pins for HBI
4.  To locate code/data at external HyperRAM:
    -   Specify __attribute__((section(".text.nu.exthyperram"))) for RO/.text/readonly section type
        Invoke mbed_mpu_manager_lock_ram_execution()/mbed_mpu_manager_unlock_ram_execution() to run HyperRAM code
    -   Specify __attribute__((section(".data.nu.exthyperram"))) for RW/.data/readwrite section type
    -   Specify __attribute__((section(".bss.nu.exthyperram"))) for ZI/.bss/zeroinit section type
5.  Add readme
2022-09-01 10:02:15 +08:00
Chun-Chieh Li 8da2e31336 M467: Fix Greentea reset_reason test failure
HRESETRF is combined reset flag. Filter it out to avoid interference with reset reason check.
2022-09-01 10:02:15 +08:00
Chun-Chieh Li df77485f02 Support Nuvoton target NUMAKER_IOT_M467
1.  Based on alpha version BSP (85564a2716548e7b6d6a79a490c6d94a24cf9bcf)
2.  Continuing above, tweak BSP:
    (1) Add EPWM_ConfigOutputChannel2() to enable below 1Hz and below 1% duty cycle for PWM output (m460_epwm.h/c).
    (2) Add dummy RTC_WaitAccessEnable() for consistency with previous ports (m460_rtc.h).
3.  Target NuMaker-M467HJ V0.1 board temporarily
4.  Support Arduino UNO form factor for NUMAKER_IOT_M467 target
5.  Enable export to Keil/IAR project
    -   tools/arm_pack_manager/index.json
    -   tools/export/iar/iar_definitions.json
2022-09-01 10:02:14 +08:00
Martin Kojtal 26876c0b91
Merge pull request #15190 from hazzlim/make_gpio_irq_api_portable
Make gpio irq api portable
2022-01-31 10:27:18 +01:00
wally0258 4a0df44ec9
Resolve compiler warning and disable CAN0 IRQ 2022-01-27 09:40:55 +08:00
Hari Limaye f4e5359710 GPIO: Use uintptr_t for gpio_irq_api context
The HAL gpio_irq_api stores object IDs, which serve as a form of context
for the dispatch of the interrupt handler in the drivers level
InterruptIn Class. The way this is achieved is that the InterruptIn
Class casts its address to uint32_t, which is stored as the ID.
This results in compilation failure when the size of an object pointer
is greater than uint32_t, for example when building on a PC for unit
testing.

In order to allow Unit Testing of the InterruptIn Class, we replace the
use of uint32_t with uintptr_t (type capable of holding a pointer),
which allows portability and expresses intentions more clearly.
In aid of this latter goal, we also replace the use of the name "id"
with "context", to improve clarity - these are addresses of the context
related to that callback.
2022-01-26 18:12:52 +00:00
wally0258 94833a0ba6
Update can_api.c
Update Copyright
2022-01-25 09:05:31 +08:00
Wally 6e09135b58 Add Nuvoton NuMaker-IoT-M263A CAN bus support 2022-01-17 14:32:42 +08:00
Chun-Chieh Li 926cda5e8f M487: Fix UART 6/7 base address encoding
Fix UART 6/7 base addresses are incorrectly encoded into peripheral names
2022-01-07 16:39:59 +08:00
Chun-Chieh Li d0f72015c0 M2354: Fix potential issues in TF-M
Fix the following issues in TF-M to avoid emergence in the future:
1.  Enable initial stack not located in SRAM bank0
    On reset, only SRAM bank0 is enabled. And SRAM bank1/2 will be enabled in immediately following SystemInit().
    When initial stack is located in SRAM bank1/2, we will meet trouble because SystemInit() itself needs to use initial stack.
    To conquer the dilemma, we add preceding code in front of original Systeminit(), which is responsible for enabling SRAM bank1/2 and guarantees no using initial stack.
2.  Fix sector maps of internal/external (SDH) Flash are incompatible, caused by TF-M's MCUboot port.
    This is done by adapting external (SDH) Flash sector size to internal Flash's.
3.  Enlarge firmware upgrade scratch size. There are two advantages:
    (1) Get around MCUboot limit which requires scratch size not smaller than image trailer size
    (2) Improve wear leveling for the scratch area
2021-11-22 13:57:22 +08:00
Chun-Chieh Li 5992676276 M2354: Adjust TF-M configuration to fit AWS IoT
1.  In TF-M, enlarge ITS max asset number/size
    NOTE: RSA key size is larger
2.  In TF-M, enlarge mbedtls dedicated heap
    NOTE: RSA algorithm needs more memory.
    NOTE: psa_aead_decrypt() (for mbedtls_ssl_read()) needs memory proportional to data size.
2021-10-29 10:38:27 +08:00
Martin Kojtal 0fac696bfc
Merge pull request #15077 from hazzlim/make_can_api_portable
CAN: Use uintptr_t for can_irq_ids
2021-09-29 10:26:37 +01:00
Hari Limaye b493a15a53 CAN: Use uintptr_t for can_irq_ids
The HAL can_api stores an array of IDs in order to dispatch interrupts
to the correct CAN object. The drivers level CAN Class casts a pointer
to itself to an uint32_t, which is stored as the ID and then cast back
to a CAN * in order to call the correct handler. This results in
compilation failure when the size of an object pointer is greater than
uint32_t, for example when building on a PC for unit testing.

In order to allow Unit Testing of the CAN Class, we replace the use of
uint32_t with uintptr_t (type capable of holding a pointer), which
allows portability and expresses intentions more clearly. In aid of this
latter goal, we also replace the use of the name "id" with "context",
to improve clarity. These are addresses of the context related to that
callback.
2021-09-17 13:36:43 +01:00
Chun-Chieh Li bbc5ad9505 M2354: Fix TF-M 1.4
1.  In TF-M, fix NSPE interrupt-disabled NSC call broken. Check:
    https://developer.trustedfirmware.org/T966
2.  In TF-M, enable mcuboot log enabled forcibly. This is to help check firmware update process.
3.  Update readme and script
2021-09-17 13:44:58 +08:00
Robert Walton 3d17e1646c "Update secure binaries for [('NU_M2354', 'GNUARM')]" 2021-09-14 17:32:42 +01:00
Martin Kojtal 9eed4272f5
Merge pull request #15029 from OpenNuvoton/nuvoton_m2354_tfm_import_mcu_partition
M2354: Fix incorrectly resolved peripheral base with security
2021-09-09 08:00:37 +01:00
Martin Kojtal 3031898929
Merge pull request #15027 from OpenNuvoton/nuvoton_m2354_tfm_fw_version
M2354: Generate unique MCUboot image version
2021-09-08 14:47:54 +01:00
Chun-Chieh Li dcd30e0cb0 M2354: Change MCUboot image versioning for unique version
Change MCUboot image versioning to meet requirements below:
1. Major.Minor.Revision must be non-decremental when used to derive security counter (-s 'auto').
2. Make Major.Minor.Revision+Build incremental to identify the firmware itself through psa_fwu_query().
3. Get around MCUboot failure with TF-M underestimated MAX_BOOT_RECORD_SZ
2021-09-02 09:18:25 +08:00