Giter VIP home page Giter VIP logo

pdk-includes's Introduction

pdk-includes

This repository contains include files for Padauk MCUs.

Example code that uses these include files can be found here: free-pdk-examples

Warning: This is a work in progress and may change significantly before being considered stable. Use at your own risk.

This repo is intended to be integrated into other projects either as a git Submodule or by manual file copy.

This repo should be installed into a pdk/ subdirectory in the root includes directory of a parent project.

To install as a git Submodule:

These include files assume the use of:

File Layout:

  • device.h - The main include file.
    • Factory that pulls in the appropriate device/XXX.h include file and other supporting files.
      • NOTE: Requires definition of the intended Padauk IC device, usually by specifying -D$(DEVICE) on the SDCC command line
  • device/XXX.h - The main device specific include files, one per device.
    • Contain device specific configuration values like: register addresses, fuse address/values, factory calibration address(es), peripheral configuration, etc...
    • Usually pulled in automatically by including device.h.
      • NOTE: If needed, up to one of these can be included manually instead of by including device.h. Doing so may also require manual inclusion of the other include files below.
  • device/periph/XXX.h - Common device peripheral include files.
    • Contain peripheral specific register __sfr and value definitions.
    • The appropriate ones are pulled in automatically by device/XXX.h files.
    • When there is enough commonality between devices, they share the same peripheral file (with some configurability allowed), otherwise the peripheral files are split and the device/XXX.h file pulls in the appropriate one.
  • util.h - Common utility macros.
    • Contains macros for built-in opcodes and inline assembler statements
    • This is pulled in automatically by device.h
  • fuse.h -
    • Contains a macro for setting the FUSE word at the appropriate address.
      • The FUSE address is usually the last word of the device
      • Requires definition of FUSE_ADDR and FUSE values, usually performed by device/XXX.h.
    • This is pulled in automatically by device.h
  • factory_calibration.h - Factory calibration macros
    • Contains macros for using factory installed calibration values (IHRCR and/or BGTR).
      • OTP devices usually only include factory calibration for BGTR (bandgap)
      • MTP devices usually contain factory calibration for boty IHRCR (internal 16MHz high speed oscillator) as well at BGTR (bandgap)
      • Requires definition of FACTORY_IHRCR_ADDR and/or FACTORY_BGTR_ADDR values, usually performed by device/XXX.h.
    • This is pulled in automatically by device.h
  • sysclock.h - System clock macros
    • Contains macros for setting the system clock to the various IHRC and ILRC frequencies.
      • Requires definition of CLKMD_* values, usually performed by device/XXX.h.
    • This is pulled in automatically by device.h

Copyright and License:

pdk-includes's People

Contributors

cmfcmf avatar cpldcpu avatar ignasurba avatar serisman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdk-includes's Issues

HAS_* macro names

I think the HAS_* macro names have a high risk of conflicting with user names (one can easily imagine a programmer choosing HAS_COMP or HAS_ADC for a macro referring to some feature in their software).
Maybe some kind of prefix could help?

Merge easy-pdk includes into this repository / inclusion in SDCC

I am just in the process of setting up a new project from scratch and am trying to use the most recent includes, which I intendend to clone into my path somewhere. (Before I was just lazy and reused old structures)

It turns out this is quite cumbersome due to the need to put the easy-pdk includes somewhere else. So my suggestion would be to clone or move them also into this repository?

Furthermore, the substructure of the later include path could be reproduced also in this repository. In the example these includes are in the subfolder "pdk", while this is not defined here.

macros for using factory calibration values

Now that SDCC generates efficient code for assignment from an address that is just a cast integer literal to a __sfr, IMO the asm macros for factory clibration aren't needed anymore.
Inline asm tends to interfere with optimizations, so for larger functions containing a use of factory calibration values, the assignment is likely to result in more efficient code being generated by SDCC.

Small differences between devices

How we should deal with small differences between devices , or in another words difference between default periph/xxx and device ?
For example minus input of comparator, on PFS154 GPCC[3-1] '101' is PB7 but on PMS150C is PA7 . by default we have GPCC_COMP_MINUS_PB7 but on PMS150C should be GPCC_COMP_MINUS_PA7 for same value

Create another version of comparator.h ?
add overrides inside device/xxx.h
or maybe create another .h with overrides form default like

override_PMS150C.h

#undef GPCC_COMP_MINUS_PB7
#define GPCC_COMP_MINUS_PA7          (5 << GPCC_COMP_MINUS_BIT0)

How to add a new device?

I'm considering adding support for PFC161. For peripherals this should be straightforward; I can look up the register definitions in the datasheet, add them to the device-specific header and if necessary modify the common peripheral headers. But what about code options? Where do you find the values for those?

Also is there anything else to consider when adding support for a new device?

Add LICENSE

This repo need a clearly identified LICENSE so people know what can and cannot be done with it.

@freepdk, my preference for this is MIT, but these files have their roots from easy-pdk-programmer-software (even though they have been changed dramatically from what was/is there) which is GPL v3. Are you ok with (re-)licensing these include files as MIT?

Rework fuse handling?

I think the fuse handling as it is now is confusing. It currently works by OR-ing FUSE_RES_BITS_HIGH with the individual fuse settings. I'll further detail my thinking with the PFS173 as an example.

I would expect that calling PDK_SET_FUSE(); would use the factory default values (i.e., no security, strong PB4/PB5, fast bootup). However, it currently sets a mix of factory default and non-default values:

  • non-default: security on, PB4/PB5 normal, bootup slow
  • default: all other code options: lvr, interrupt src0/1, comparator, pwm source, tmx source

If we later add a #define for the currently missing code options (such as lvr, comparator, ...), we would also need to change FUSE_RES_BITS_HIGH. This, in turn, would change the behavior of calling PDK_SET_FUSE();!

I suggest to rework the fuse handling like this:

#define FUSE_RES_BITS_HIGH  0b111111111111111

#define FUSE_SECURITY_ON    0b111111111111110
#define FUSE_SECURITY_OFF   0b111111111111111
#define FUSE_PB4_PB5_NORMAL 0b111111011111111
#define FUSE_PB4_PB5_STRONG 0b111111111111111
#define FUSE_BOOTUP_SLOW    0b110011111111111
#define FUSE_BOOTUP_FAST    0b111111111111111

// ...

#define PDK_SET_FUSE(f) \
    __asm__( \
      ".area FUSE (ABS)                               \n" \
      ".org ("_STR(FUSE_WORD_ADDR)"*2)                \n" \
      ".word ("_STR(FUSE_RES_BITS_HIGH)"&"_STR(f)")   \n" \ 
      ".area CODE                                     \n" \
    )

The macro would now work as expected:

  • PDK_SET_FUSE(); sets all to factory values, even if we later add definitions for more fuses
  • PDK_SET_FUSE(FUSE_SECURITY_ON); enabled security, leaves all other values at factory default
  • PDK_SET_FUSE(FUSE_SECURITY_ON & FUSE_PB4_PB5_NORMAL); enabled security and normal I/O, all bootup at factory default.

Note that you have to bitwise-and the fuse settings instead of bitwise-oring them. If we don't like that, we could also instead invert the fuse definitions:

#define FUSE_RES_BITS_HIGH  0b0111111111111111

#define FUSE_SECURITY_ON     0b000000000000001
#define FUSE_SECURITY_OFF    0b000000000000000
#define FUSE_PB4_PB5_NORMAL  0b000000100000000
#define FUSE_PB4_PB5_STRONG  0b000000000000000
#define FUSE_BOOTUP_SLOW     0b001100000000000
#define FUSE_BOOTUP_FAST     0b000000000000000

// ...

#define PDK_SET_FUSE(f) \
    __asm__( \
      ".area FUSE (ABS)                                    \n" \
      ".org ("_STR(FUSE_WORD_ADDR)"*2)                     \n" \
      ".word ("_STR(FUSE_RES_BITS_HIGH)" & ~("_STR(f)"))   \n" \ 
      ".area CODE                                          \n" \
    )

(I'm not entirely sure if that is how inline assembler works and if bitwise inverting 0b000000000000000 will lead 0b11111111 or 0b1111111111111111)

This would allow us to use PDK_SET_FUSE(FUSE_SECURITY_ON | FUSE_PB4_PB5_NORMAL);

Discrepency with PFS154 fuses versus current datasheet

There seems to be a discrepancy regarding what fuses are supported by the PFS154 between current information on the Free-PDK website, device headers, and currently published datasheet by Padauk.

The website asserts that the PFS154 does not support LVR fuse settings (instead using MISCLVR register), and the pfs154.h device header correspondingly does not include definitions for the LVR fuses. However, according to the datasheet available from Padauk (dated Mar 23, 2023) the PFS154 does feature LVR fuses.

pfs154-fuses

The datasheet also contains no mention of a MISCLVR register.

Is the Free-PDK information incorrect, or has Padauk changed the PFS154?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.