Compare commits

...

5 Commits

1 changed files with 35 additions and 28 deletions

63
stm8s.h
View File

@ -576,7 +576,7 @@ typedef struct {
#define CLK_PCKENR1 (*(volatile uint8_t *)(CLK_BASE + 0x07))
#define CLK_PCKENR1_I2C (1U << 0)
#define CLK_PCKENR1_SPI (1U << 1)
#define CLK_PCKENR1_UART1234 (3 << 2)
#define CLK_PCKENR1_UART1234 (3U << 2)
#define CLK_PCKENR1_TIM46 (1U << 4)
#define CLK_PCKENR1_TIM25 (1U << 5)
#define CLK_PCKENR1_TIM3 (1U << 6)
@ -1895,7 +1895,7 @@ typedef union {
uint8_t OC1PE:1; /*!< bit 3: Output compare 1 preload enable */
uint8_t OC1M:3; /*!< bit 4..6: Output compare 1 mode */
uint8_t OC1CE:1; /*!< bit 7: Output compare 1 clear enable */
} outpur_fields; /*!< structure used for bit access */
} output_fields; /*!< structure used for bit access */
struct {
uint8_t CC1S:2; /*!< bit 0..1: Capture/compare 1 selection */
uint8_t IC1PSC:2; /*!< bit 2..3: Input capture 1 prescaler */
@ -1910,7 +1910,7 @@ typedef union {
uint8_t :1; /*!< bit 2: Reserved */
uint8_t OC1PE:1; /*!< bit 3: Output compare 1 preload enable */
uint8_t OC1M:3; /*!< bit 4..6: Output compare 1 mode */
} outpur_fields; /*!< structure used for bit access */
} output_fields; /*!< structure used for bit access */
struct {
uint8_t CC1S:2; /*!< bit 0..1: Capture/compare 1 selection */
uint8_t IC1PSC:2; /*!< bit 2..3: Input capture 1 prescaler */
@ -3294,26 +3294,31 @@ typedef union {
uint8_t reg; /*!< type used for register access */
} OPT_NOPT1_type; /*!< */
// NOTE: OPT2 fields depends on device's pin count
typedef union {
struct {
uint8_t :1; /*!< bit 0: Reserved */
uint8_t AFR0:1; /*!< bit 0: Alternate function remapping option 0 */
uint8_t AFR1:1; /*!< bit 1: Alternate function remapping option 1 */
uint8_t :3; /*!< bit 2..4: Reserved */
uint8_t AFR2:1; /*!< bit 2: Alternate function remapping option 2 */
uint8_t AFR3:1; /*!< bit 3: Alternate function remapping option 3 */
uint8_t AFR4:1; /*!< bit 4: Alternate function remapping option 4 */
uint8_t AFR5:1; /*!< bit 5: Alternate function remapping option 5 */
uint8_t AFR6:1; /*!< bit 6: Alternate function remapping option 6 */
uint8_t :1; /*!< bit 7: Reserved */
uint8_t AFR7:1; /*!< bit 7: Alternate function remapping option 7 */
} fields; /*!< structure used for bit access */
uint8_t reg; /*!< type used for register access */
} OPT_OPT2_type; /*!< */
typedef union {
struct {
uint8_t :1; /*!< bit 0: Reserved */
uint8_t NAFR0:1; /*!< bit 0: Alternate function remapping option 0 */
uint8_t NAFR1:1; /*!< bit 1: Alternate function remapping option 1 */
uint8_t :3; /*!< bit 2..4: Reserved */
uint8_t NAFR2:1; /*!< bit 2: Alternate function remapping option 2 */
uint8_t NAFR3:1; /*!< bit 3: Alternate function remapping option 3 */
uint8_t NAFR4:1; /*!< bit 4: Alternate function remapping option 4 */
uint8_t NAFR5:1; /*!< bit 5: Alternate function remapping option 5 */
uint8_t NAFR6:1; /*!< bit 6: Alternate function remapping option 6 */
uint8_t :1; /*!< bit 7: Reserved */
uint8_t NAFR7:1; /*!< bit 7: Alternate function remapping option 7 */
} fields; /*!< structure used for bit access */
uint8_t reg; /*!< type used for register access */
} OPT_NOPT2_type; /*!< */
@ -3388,14 +3393,14 @@ typedef struct {
#define OPT_BASE 0x4800
#define OPT ((OPT_type*)OPT_BASE)
#define OPT0 (*(volatile uint8_t *)(OPT_BASE + 0x00))
#define ROP OPT0
#define OPT1 (*(volatile uint8_t *)(OPT_BASE + 0x01))
#define UBC OPT1
#define NOPT1 (*(volatile uint8_t *)(OPT_BASE + 0x02))
#define NUBC NOPT1
#define OPT2 (*(volatile uint8_t *)(OPT_BASE + 0x03))
#define AFR OPT2
#define OPT_OPT0 (*(volatile uint8_t *)(OPT_BASE + 0x00))
#define ROP OPT_OPT0
#define OPT_OPT1 (*(volatile uint8_t *)(OPT_BASE + 0x01))
#define UBC OPT_OPT1
#define OPT_NOPT1 (*(volatile uint8_t *)(OPT_BASE + 0x02))
#define NUBC OPT_NOPT1
#define OPT_OPT2 (*(volatile uint8_t *)(OPT_BASE + 0x03))
#define AFR OPT_OPT2
#define AFR_AFR0 (1U << 0)
#define AFR_AFR1 (1U << 1)
#define AFR_AFR2 (1U << 2)
@ -3404,8 +3409,8 @@ typedef struct {
#define AFR_AFR5 (1U << 5)
#define AFR_AFR6 (1U << 6)
#define AFR_AFR7 (1U << 7)
#define NOPT2 (*(volatile uint8_t *)(OPT_BASE + 0x04))
#define NAFR NOPT2
#define OPT_NOPT2 (*(volatile uint8_t *)(OPT_BASE + 0x04))
#define NAFR OPT_NOPT2
#define AFR_NAFR0 (1U << 0)
#define AFR_NAFR1 (1U << 1)
#define AFR_NAFR2 (1U << 2)
@ -3414,32 +3419,32 @@ typedef struct {
#define AFR_NAFR5 (1U << 5)
#define AFR_NAFR6 (1U << 6)
#define AFR_NAFR7 (1U << 7)
#define OPT3 (*(volatile uint8_t *)(OPT_BASE + 0x05))
#define OPT_OPT3 (*(volatile uint8_t *)(OPT_BASE + 0x05))
#define OPT3_WWDG_HALT (1U << 0)
#define OPT3_WWDG_HW (1U << 1)
#define OPT3_IWDG_HW (1U << 2)
#define OPT3_LSI_EN (1U << 3)
#define OPT3_HSI_TRIM (1U << 4)
#define NOPT3 (*(volatile uint8_t *)(OPT_BASE + 0x06))
#define OPT_NOPT3 (*(volatile uint8_t *)(OPT_BASE + 0x06))
#define NOPT3_NWWDG_HALT (1U << 0)
#define NOPT3_NWWDG_HW (1U << 1)
#define NOPT3_NIWDG_HW (1U << 2)
#define NOPT3_NLSI_EN (1U << 3)
#define NOPT3_NHSI_TRIM (1U << 4)
#define OPT4 (*(volatile uint8_t *)(OPT_BASE + 0x07))
#define OPT_OPT4 (*(volatile uint8_t *)(OPT_BASE + 0x07))
#define OPT4_PRS_C0 (1U << 0)
#define OPT4_PRS_C1 (1U << 1)
#define OPT4_CKAWU_SEL (1U << 2)
#define OPT4_EXT_CLK (1U << 3)
#define NOPT4 (*(volatile uint8_t *)(OPT_BASE + 0x08))
#define OPT_NOPT4 (*(volatile uint8_t *)(OPT_BASE + 0x08))
#define NOPT4_NPRS_C0 (1U << 0)
#define NOPT4_NPRS_C1 (1U << 1)
#define NOPT4_NCKAWU_SEL (1U << 2)
#define NOPT4_NEXT_CLK (1U << 3)
#define OPT5 (*(volatile uint8_t *)(OPT_BASE + 0x09))
#define HSECNT OPT5
#define NOPT5 (*(volatile uint8_t *)(OPT_BASE + 0x0A))
#define NHSECNT NOPT5
#define OPT_OPT5 (*(volatile uint8_t *)(OPT_BASE + 0x09))
#define HSECNT OPT_OPT5
#define OPT_NOPT5 (*(volatile uint8_t *)(OPT_BASE + 0x0A))
#define NHSECNT OPT_NOPT5
// Unique ID
typedef struct {
@ -3451,9 +3456,11 @@ typedef struct {
/* some useful assembly instructions */
// wait for event (go to sleep)
#define wfe() { __asm__("wfi\n"); }
#define wfe() { __asm__("wfe\n"); }
// wait for interrupt (go to sleep)
#define wfi() { __asm__("wfi\n"); }
// go into halt mode
#define halt() { __asm__("halt\n"); }
// disable interrupts
#define sim() { __asm__("sim"); }
// enable interrupts